Skip to content

Commit 3e6ec5c

Browse files
authored
fix(s3-deployment): default role does not get PutAcl permissions on… (#20492)
… destination bucket when used with accessControl With the feature flag `@aws-cdk/aws-s3:grantWriteWithoutAcl` you no longer get `s3:PutObjectAcl` and `s3:PutObjectVersionAcl` permissions in the default role. These are however required when using the `accessControl` property. ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 75bfce7 commit 3e6ec5c

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts

+3
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ export class BucketDeployment extends CoreConstruct {
327327
const sources: SourceConfig[] = props.sources.map((source: ISource) => source.bind(this, { handlerRole }));
328328

329329
props.destinationBucket.grantReadWrite(handler);
330+
if (props.accessControl) {
331+
props.destinationBucket.grantPutAcl(handler);
332+
}
330333
if (props.distribution) {
331334
handler.addToRolePolicy(new iam.PolicyStatement({
332335
effect: iam.Effect.ALLOW,

packages/@aws-cdk/aws-s3-deployment/test/bucket-deployment.test.ts

+40
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,46 @@ testFutureBehavior('lambda execution role gets permissions to read from the sour
708708
});
709709
});
710710

711+
testFutureBehavior('lambda execution role gets putObjectAcl permission when deploying with accessControl', s3GrantWriteCtx, cdk.App, (app) => {
712+
// GIVEN
713+
const stack = new cdk.Stack(app);
714+
const source = new s3.Bucket(stack, 'Source');
715+
const bucket = new s3.Bucket(stack, 'Dest');
716+
717+
// WHEN
718+
new s3deploy.BucketDeployment(stack, 'Deploy', {
719+
sources: [s3deploy.Source.bucket(source, 'file.zip')],
720+
destinationBucket: bucket,
721+
accessControl: s3.BucketAccessControl.PUBLIC_READ,
722+
});
723+
724+
// THEN
725+
const map = Template.fromStack(stack).findResources('AWS::IAM::Policy');
726+
expect(map).toBeDefined();
727+
const resource = map[Object.keys(map)[0]];
728+
expect(resource.Properties.PolicyDocument.Statement).toContainEqual({
729+
Action: [
730+
's3:PutObjectAcl',
731+
's3:PutObjectVersionAcl',
732+
],
733+
Effect: 'Allow',
734+
Resource: {
735+
'Fn::Join': [
736+
'',
737+
[
738+
{
739+
'Fn::GetAtt': [
740+
'DestC383B82A',
741+
'Arn',
742+
],
743+
},
744+
'/*',
745+
],
746+
],
747+
},
748+
});
749+
});
750+
711751
test('memoryLimit can be used to specify the memory limit for the deployment resource handler', () => {
712752
// GIVEN
713753
const stack = new cdk.Stack();

0 commit comments

Comments
 (0)