aws / aws/aws-cdk

IAM Role / Trust-relationships -trustpolicy required for access-grants-s3 cannot be created with CDK

Open
#33,690 2 comments 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-iam bug cause/not-a-bug p3
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

Trying to create a trust-policy for a given role, like this:

![Image](https://github.com/user-attachments/assets/54a72711-df44-4e5e-9358-d05b257da783)

cannot be created with CDK.

### Regression Issue

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

### Last Known Working CDK Version

CDK Version: 2.1002.0 (build 09ef5a0)

### Expected Behavior

the trust-policy for a given role, will contain the given statements

![Image](https://github.com/user-attachments/assets/53366f6e-baa7-4357-ac9b-c911d30f0258)

### Current Behavior

the trust-policy will not be included in the role.

### Reproduction Steps

try this code:
```
let servicePrincipal = new iam.ServicePrincipal('access-grants.s3.amazonaws.com');
servicePrincipal.addToAssumeRolePolicy(trustPolicy);
servicePrincipal.addToPolicy(new iam.PolicyStatement({
sid: 'AccessGrantsTrustPolicy',
effect: iam.Effect.ALLOW,
principals: [new iam.ServicePrincipal('access-grants.s3.amazonaws.com')],
actions: ['sts:AssumeRole', 'sts:SetSourceIdentity'],
conditions: {
StringEquals: {
'aws:SourceAccount': '9xxx2',
'aws:SourceArn': 'arn:aws:s3:eu-central-1:9xxx2:access-grants/default',
},
},
}));

this.context.properties.accessGrantsRole = new iam.Role(this, this.id4res('AccessGrantsRole'), {
assumedBy: servicePrincipal,
inlinePolicies: {
'AccessGrantsPolicy': accessGrantsPolicy,
},
});
```

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### CDK CLI Version

CDK Version: 2.1002.0 (build 09ef5a0)

### Framework Version

_No response_

### Node.js Version

Node.js v22.12.0

### OS

Win11

### Language

TypeScript

### Language Version

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by synthesizing the reproduced TypeScript IAM Role using ServicePrincipal, addToAssumeRolePolicy, and addToPolicy, then inspect the generated trust policy. Compare it with the expected statements for access-grants.s3.amazonaws.com; done means the synthesized role contains the supplied trust-policy statements.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.