Skip to content

AwsCustomResource: automatic policy fails if API call name is different from IAM name #19355

@caojoshua

Description

@caojoshua

What is the problem?

By default, AwsCustomResource sdk calls for (get|put)BucketLifecycleConfiguration grants the executor role s3:(Get|Put)BucketLifecycleConfiguration. The correct permissions should be s3:(get|put)LifecycleConfiguration permissions (notice the lack of Bucket). I believe that the error is from this code.

Reproduction Steps

new AwsCustomResource(this, physicalId, {                                    
            policy: AwsCustomResourcePolicy.fromSdkCalls({ resources: AwsCustomResourcePolicy.ANY_RESOURCE }),
            onUpdate: {
                service: 'S3',
                action: '(get|put)BucketLifecycleConfiguration',
                parameters: {
                    ...
                },
                physicalResourceId: PhysicalResourceId.of(physicalId),
            },
});

This custom resource will get a AccessDenied response. As a workaround, we can specify a policy that explicitly gives the correct permissions (get|put)LifecycleConfiguration.

policy: AwsCustomResourcePolicy.fromStatements([
              new iam.PolicyStatement({
                sid: 'foo',
                effect: iam.Effect.ALLOW,
                actions: ['s3:(Get|Put)LifecycleConfiguration'],
                resources: ['bar'],
              }),
            ]),

What did you expect to happen?

SDK calls should work as normal.

What actually happened?

Access Denied response.

CDK CLI Version

1.145.0

Framework Version

No response

Node.js Version

v14.19.0

OS

Amazon Linux

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.closed-for-stalenessThis issue was automatically closed because it hadn't received any attention in a while.effort/mediumMedium work item – several days of effortp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions