Skip to content

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

Open
@ttais2017

Description

@ttais2017

Describe the bug

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

Image

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-iamRelated to AWS Identity and Access ManagementbugThis issue is a bug.cause/not-a-bugNot a bug (might still be a documentation issue, might still need work)p3

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions