IAM Role / Trust-relationships -trustpolicy required for access-grants-s3 cannot be created with CDK
- 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:

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

### 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
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