aws / aws/aws-cdk

(integ-runner-alpha): (Support for Lake Formation permissions in assertion Lambda roles)

Open
#37,164 3 comments 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-lambda feature-request p3
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
1d 19h
Merged PRs (30d)
74

Description

### Describe the bug

## Description

### Problem Statement
When writing integration tests that validate AWS Glue Data Catalog operations using `integ.assertions.aws_api_call()`, the assertion Lambda requires both IAM and Lake Formation (LF) permissions. While IAM permissions can be granted via `provider.add_to_role_policy()`, there is no way to grant Lake Formation permissions at CDK synthesis time because:

- The assertion Lambda role has hash suffix in name which is randomly generated by CloudFormation
- Lake Formation `CfnPrincipalPermissions` does not support wildcard role ARNs
- The role ARN is only available as a CDK Token at synthesis time, not as a concrete string

### Regression Issue

- [ ] Select this option if this issue appears to be a regression.

### Last Known Working CDK Library Version

_No response_

### Expected Behavior

Expected Behavior
One of the following solutions would resolve this:

Option 1: Expose a method to grant LF permissions (Preferred)
Option 2: Allow specifying a custom role name

| Property | Value |
| -------- | ----- |
| **CDK Version** | 2.197.1 |
| **integ-tests-alpha Version** | 2.197.1-alpha.0 |
| **Affected Services** | AWS Glue, AWS Lake Formation |
| **Language** | Python 3.10 |

### Current Behavior

### Current Behavior

```python
# Integration test with Glue assertion
get_table_call = integ.assertions.aws_api_call(
"Glue", "getTable",
parameters={"DatabaseName": "my_db", "Name": "my_table"}
)

# ✅ IAM permissions work fine
get_table_call.provider.add_to_role_policy({
"Effect": "Allow",
"Action": ["glue:GetTable", "lakeformation:GetDataAccess"],
"Resource": "*"
})

# ❌ Lake Formation permissions CANNOT be granted via CDK
# Attempt 1: Using role ARN token - fails because LF doesn't support wildcards
wildcard_arn = f"arn:aws:iam::{account}:role/MyTestStack*"
lakeformation.CfnPrincipalPermissions(
scope, "LFPermission",
principal={"DataLakePrincipalIdentifier": wildcard_arn}, # Fails with InvalidRequest
resource={"Database": {"Name": "my_db"}},
permissions=["DESCRIBE"]
)

# Attempt 2: Using Token - fails because LF needs concrete role ARN
lakeformation.CfnPrincipalPermissions(
scope, "LFPermission",
principal={"DataLakePrincipalIdentifier": Token.as_string(provider.handler_role_arn)},
resource={"Database": {"Name": "my_db"}},
permissions=["DESCRIBE"]
)
# Error: "Insufficient Glue permissions" - circular dependency issue

Resource handler returned message: "Principal identifier:arn:aws:iam::123456789:role/MyTestStack*
Does not match inputted principal type:IAM_ROLE (Service: LakeFormation, Status Code: 400)"

### Reproduction Steps

If try to run AWS api assertions to validate glue table viw the intg.runner lambda it doesnt work since the lambda role name/ arn is generated at deploy time, but to give LF permission to the assertion lambda we need to know the role name at the time of syntesise

### Possible Solution

1. Any method which exposes the arn which automatically getting created by the integ runner lambda at the time of synthesize
2. A custom way to procvide lambda role name by the user

### Additional Information/Context

_No response_

### AWS CDK Library version (aws-cdk-lib)

2.197.1

### AWS CDK CLI version

2.1019.2

### Node.js Version

20.19.5

### OS

Debian Bookworm(via docker container on gitlab kubernetes runner)

### Language

Python

### Language Version

3.10.18

### Other information

poetry version: 1.8.5
gitlab runner (linux-amd64-m tags)

Contributor guide

Open the contributing guide

Research direction

Start with the integ.assertions.aws_api_call() entry point and its provider.add_to_role_policy() behavior, then review how the assertion Lambda role ARN is created and passed to Lake Formation CfnPrincipalPermissions. Done means providing a supported way to grant Lake Formation permissions or configure a usable custom role name at synthesis time, with the circular dependency resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python, typescript
Domain
cloud, devtools, infrastructure
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.