core: permissions boundary not being applied to custom resource role
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
I'm deploying a stack through CDK pipelines and have a permissions boundary configured within `cdk.json`. Every role is being configured app wide with the permissions boundary apart from one which seems to be created by CDK itself for my `AwsCustomResource`.
### Expected Behavior
I expect the permissions boundary to be applied the CDK application app wide and not miss any roles deployed by the CDK application
### Current Behavior
The CDK created role is failing to add the permissions boundary to the application.
### Reproduction Steps
CDK pipelines is being deployed using bootstrapped roles with a custom qualifier and where the permission boundary is required.
```python
synth_object = cdk.DefaultStackSynthesizer(
qualifier=config["cdk_synth_qualifier"],
)
```
AwsCustomResource
```python
response = AwsCustomResource(
self,
"describe-enis",
on_update={
"service": "EC2",
"action": "describeNetworkInterfaces",
"output_paths": output_paths,
"parameters": {"NetworkInterfaceIds": eni_ids},
"physical_resource_id": PhysicalResourceId.of(str(random.random())),
},
policy=AwsCustomResourcePolicy.from_statements(
statements=[
iam.PolicyStatement(
effect=iam.Effect.ALLOW,
actions=["ec2:DescribeNetworkInterfaces"],
resources=["*"],
),
],
),
)
```
The role in question not being provided the permission boundary
AWSCDKCfnUtilsProviderCustomResourceProviderRoleFE0EE867
```json
"AWSCDKCfnUtilsProviderCustomResourceProviderRoleFE0EE867": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
]
},
"ManagedPolicyArns": [
{
"Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
]
},
```
The `cdk.json` config
```json
"@aws-cdk/core:permissionsBoundary": {
"name": "cdk-permissions-boundary-policy"
}
```
### Possible Solution
_No response_
### Additional Information/Context
I have tried adding the permission boundary to the stack itself, as well as the custom resource itself following the documentation here: https://docs.aws.amazon.com/cdk/api/v1/python/aws_cdk.aws_iam/README.html#permissions-boundaries
I have also tried creating a custom aspect to add the stack and the stage but none of these worked either:
https://github.com/aws/aws-cdk/issues/3242#issuecomment-561064190
### CDK CLI Version
2.141.0
### Framework Version
_No response_
### Node.js Version
v22.1.0
### OS
Sonoma 14.2.1
### Language
Python
### Language Version
3.12.3
### Other information
_No response_
Contributor guide
Research direction
Start by synthesizing the provided Python AwsCustomResource example and inspect the generated AWSCDKCfnUtilsProviderCustomResourceProviderRoleFE0EE867 role in the CloudFormation template. Trace how the cdk.json permissionsBoundary setting is applied to generated custom-resource roles; the work is done when this role includes the configured boundary and the synthesized output reflects the expected configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python, typescript
- Domain
- cloud, infrastructure, security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100