Skip to content

Commit 5bb589a

Browse files
feat(core): update s3 bucket ownership (#522)
* feat(core): update s3 bucket ownership * Adding override in custom construct
1 parent c364f85 commit 5bb589a

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/deployments/cdk/src/deployments/defaults/step-1.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ function createCentralBucketCopy(props: DefaultsStep1Props) {
9898
removalPolicy: cdk.RemovalPolicy.RETAIN,
9999
});
100100

101+
// TODO: Remove and use fields directly when CDK enhanced s3.Bucket.
102+
(bucket.node.defaultChild as s3.CfnBucket).addPropertyOverride('OwnershipControls', {
103+
Rules: [
104+
{
105+
ObjectOwnership: 'BucketOwnerPreferred',
106+
},
107+
],
108+
});
109+
101110
// Let the bucket name be generated by CloudFormation
102111
// The generated bucket name is based on the stack name + logical ID + random suffix
103112
overrideLogicalId(bucket, `config${masterAccountStack.region}`);
@@ -308,6 +317,15 @@ function createAesLogBucket(props: DefaultsStep1Props) {
308317
removalPolicy: cdk.RemovalPolicy.RETAIN,
309318
});
310319

320+
// TODO: Remove and use fields directly when CDK enhanced s3.Bucket.
321+
(logBucket.node.defaultChild as s3.CfnBucket).addPropertyOverride('OwnershipControls', {
322+
Rules: [
323+
{
324+
ObjectOwnership: 'BucketOwnerPreferred',
325+
},
326+
],
327+
});
328+
311329
// Let the bucket name be generated by CloudFormation
312330
// The generated bucket name is based on the stack name + logical ID + random suffix
313331
overrideLogicalId(logBucket, `aes${logAccountStack.region}`);

src/installer/cdk/src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,15 @@ async function main() {
287287
removalPolicy: cdk.RemovalPolicy.DESTROY,
288288
});
289289

290+
// TODO: Remove and use fields directly when CDK enhanced s3.Bucket.
291+
(installerArtifactsBucket.node.defaultChild as s3.CfnBucket).addPropertyOverride('OwnershipControls', {
292+
Rules: [
293+
{
294+
ObjectOwnership: 'BucketOwnerPreferred',
295+
},
296+
],
297+
});
298+
290299
new codepipeline.Pipeline(stack, 'Pipeline', {
291300
role: installerPipelineRole,
292301
pipelineName: `${acceleratorPrefix}InstallerPipeline`,

src/lib/cdk-constructs/src/s3/bucket.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ export class Bucket extends s3.Bucket {
4747

4848
// Get the underlying resource
4949
this.resource = this.node.findChild('Resource') as s3.CfnBucket;
50+
51+
// TODO: Remove and use fields directly when CDK enhanced s3.Bucket.
52+
this.resource.addPropertyOverride('OwnershipControls', {
53+
Rules: [
54+
{
55+
ObjectOwnership: 'BucketOwnerPreferred',
56+
},
57+
],
58+
});
5059
}
5160

5261
replicateFrom(principals: iam.IPrincipal[], organizationId: string, prefix: string) {

0 commit comments

Comments
 (0)