Skip to content

Commit 93fafc5

Browse files
authoredDec 13, 2021
feat(aws-s3): add support for BucketOwnerEnforced to S3 ObjectOwnershipType (#17961)
closes #17926 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent da07cb1 commit 93fafc5

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed
 

‎packages/@aws-cdk/aws-s3/README.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ bucket.virtualHostedUrlForObject('objectname', { regional: false }); // Virtual
417417

418418
## Object Ownership
419419

420-
You can use the two following properties to specify the bucket [object Ownership].
420+
You can use one of following properties to specify the bucket [object Ownership].
421421

422422
[object Ownership]: https://docs.aws.amazon.com/AmazonS3/latest/dev/about-object-ownership.html
423423

@@ -441,6 +441,16 @@ new s3.Bucket(this, 'MyBucket', {
441441
});
442442
```
443443

444+
### Bucket owner enforced (recommended)
445+
446+
ACLs are disabled, and the bucket owner automatically owns and has full control over every object in the bucket. ACLs no longer affect permissions to data in the S3 bucket. The bucket uses policies to define access control.
447+
448+
```ts
449+
new s3.Bucket(this, 'MyBucket', {
450+
objectOwnership: s3.ObjectOwnership.BUCKET_OWNER_ENFORCED,
451+
});
452+
```
453+
444454
## Bucket deletion
445455

446456
When a bucket is removed from a stack (or the stack is deleted), the S3
@@ -466,7 +476,7 @@ by deploying with CDK version `1.126.0` or later **before** switching this value
466476

467477
## Transfer Acceleration
468478

469-
[Transfer Acceleration](https://docs.aws.amazon.com/AmazonS3/latest/userguide/transfer-acceleration.html) can be configured to enable fast, easy, and secure transfers of files over long distances:
479+
[Transfer Acceleration](https://docs.aws.amazon.com/AmazonS3/latest/userguide/transfer-acceleration.html) can be configured to enable fast, easy, and secure transfers of files over long distances:
470480

471481
```ts
472482
const bucket = new s3.Bucket(this, 'MyBucket', {

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

+7
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,13 @@ export interface Inventory {
12061206
*
12071207
*/
12081208
export enum ObjectOwnership {
1209+
/**
1210+
* ACLs are disabled, and the bucket owner automatically owns
1211+
* and has full control over every object in the bucket.
1212+
* ACLs no longer affect permissions to data in the S3 bucket.
1213+
* The bucket uses policies to define access control.
1214+
*/
1215+
BUCKET_OWNER_ENFORCED = 'BucketOwnerEnforced',
12091216
/**
12101217
* Objects uploaded to the bucket change ownership to the bucket owner .
12111218
*/

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

+26
Original file line numberDiff line numberDiff line change
@@ -2303,6 +2303,32 @@ describe('bucket', () => {
23032303

23042304
});
23052305

2306+
test('Bucket with objectOwnership set to BUCKET_OWNER_ENFORCED', () => {
2307+
const stack = new cdk.Stack();
2308+
new s3.Bucket(stack, 'MyBucket', {
2309+
objectOwnership: s3.ObjectOwnership.BUCKET_OWNER_ENFORCED,
2310+
});
2311+
expect(stack).toMatchTemplate({
2312+
'Resources': {
2313+
'MyBucketF68F3FF0': {
2314+
'Type': 'AWS::S3::Bucket',
2315+
'Properties': {
2316+
'OwnershipControls': {
2317+
'Rules': [
2318+
{
2319+
'ObjectOwnership': 'BucketOwnerEnforced',
2320+
},
2321+
],
2322+
},
2323+
},
2324+
'UpdateReplacePolicy': 'Retain',
2325+
'DeletionPolicy': 'Retain',
2326+
},
2327+
},
2328+
});
2329+
2330+
});
2331+
23062332
test('Bucket with objectOwnership set to BUCKET_OWNER_PREFERRED', () => {
23072333
const stack = new cdk.Stack();
23082334
new s3.Bucket(stack, 'MyBucket', {

0 commit comments

Comments
 (0)
Please sign in to comment.