Skip to content

Commit

Permalink
feat(s3): bucket access control (aws#3391)
Browse files Browse the repository at this point in the history
Implements missing Bucket [AccessControl](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket.html#cfn-s3-bucket-accesscontrol) property
The documentation was for the canned ACLs was retrieved from [the developer guide](https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl).

Fixes aws#3383
  • Loading branch information
Jimmy Gaussen authored and Elad Ben-Israel committed Jul 23, 2019
1 parent dd574cc commit 820575b
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
61 changes: 60 additions & 1 deletion packages/@aws-cdk/aws-s3/lib/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,13 @@ export interface BucketProps {
*/
readonly websiteRedirect?: RedirectTarget;

/**
* Specifies a canned ACL that grants predefined permissions to the bucket.
*
* @default BucketAccessControl.PRIVATE
*/
readonly accessControl?: BucketAccessControl;

/**
* Grants public read access to all objects in the bucket.
* Similar to calling `bucket.grantPublicAccess()`
Expand Down Expand Up @@ -933,7 +940,8 @@ export class Bucket extends BucketBase {
websiteConfiguration: this.renderWebsiteConfiguration(props),
publicAccessBlockConfiguration: props.blockPublicAccess,
metricsConfigurations: Lazy.anyValue({ produce: () => this.parseMetricConfiguration() }),
corsConfiguration: Lazy.anyValue({ produce: () => this.parseCorsConfiguration() })
corsConfiguration: Lazy.anyValue({ produce: () => this.parseCorsConfiguration() }),
accessControl: props.accessControl,
});

resource.applyRemovalPolicy(props.removalPolicy);
Expand Down Expand Up @@ -1426,6 +1434,57 @@ export interface OnCloudTrailBucketEventOptions extends events.OnEventOptions {
readonly paths?: string[];
}

/**
* Default bucket access control types.
*
* @see https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html
*/
export enum BucketAccessControl {
/**
* Owner gets FULL_CONTROL. No one else has access rights.
*/
PRIVATE = 'Private',

/**
* Owner gets FULL_CONTROL. The AllUsers group gets READ access.
*/
PUBLIC_READ = 'PublicRead',

/**
* Owner gets FULL_CONTROL. The AllUsers group gets READ and WRITE access.
* Granting this on a bucket is generally not recommended.
*/
PUBLIC_READ_WRITE = 'PublicReadWrite',

/**
* Owner gets FULL_CONTROL. The AuthenticatedUsers group gets READ access.
*/
AUTHENTICATED_READ = 'AuthenticatedRead',

/**
* The LogDelivery group gets WRITE and READ_ACP permissions on the bucket.
* @see https://docs.aws.amazon.com/AmazonS3/latest/dev/ServerLogs.html
*/
LOG_DELIVERY_WRITE = 'LogDeliveryWrite',

/**
* Object owner gets FULL_CONTROL. Bucket owner gets READ access.
* If you specify this canned ACL when creating a bucket, Amazon S3 ignores it.
*/
BUCKET_OWNER_READ = 'BucketOwnerRead',

/**
* Both the object owner and the bucket owner get FULL_CONTROL over the object.
* If you specify this canned ACL when creating a bucket, Amazon S3 ignores it.
*/
BUCKET_OWNER_FULL_CONTROL = 'BucketOwnerFullControl',

/**
* Owner gets FULL_CONTROL. Amazon EC2 gets READ access to GET an Amazon Machine Image (AMI) bundle from Amazon S3.
*/
AWS_EXEC_READ = 'AwsExecRead',
}

function mapOrUndefined<T, U>(list: T[] | undefined, callback: (element: T) => U): U[] | undefined {
if (!list || list.length === 0) {
return undefined;
Expand Down
21 changes: 21 additions & 0 deletions packages/@aws-cdk/aws-s3/test/test.bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,27 @@ export = {
test.done();
},

'bucket with custom canned access control'(test: Test) {
const stack = new cdk.Stack();
new s3.Bucket(stack, 'MyBucket', {
accessControl: s3.BucketAccessControl.LOG_DELIVERY_WRITE
});

expect(stack).toMatch({
"Resources": {
"MyBucketF68F3FF0": {
"Type": "AWS::S3::Bucket",
"Properties": {
"AccessControl": "LogDeliveryWrite"
},
"DeletionPolicy": "Retain",
"UpdateReplacePolicy": "Retain",
}
}
});
test.done();
},

'permissions': {

'addPermission creates a bucket policy'(test: Test) {
Expand Down

0 comments on commit 820575b

Please sign in to comment.