-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(aws-s3): add option to specify block public access settings #1664
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a README entry on this
@@ -514,6 +519,10 @@ export abstract class BucketBase extends cdk.Construct implements IBucket { | |||
* @returns The `iam.PolicyStatement` object, which can be used to apply e.g. conditions. | |||
*/ | |||
public grantPublicAccess(keyPrefix = '*', ...allowedActions: string[]): iam.PolicyStatement { | |||
if (this.publicAccessBlocked) { | |||
throw new Error('Cannot grant public access when block public access settings are enabled'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change "block public access" to "blockPublicAccess"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
/** | ||
* Enables all block public access settings on the bucket. | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a "@see" with a link
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -666,7 +683,15 @@ export class Bucket extends BucketBase { | |||
bucketEncryption, | |||
versioningConfiguration: props.versioned ? { status: 'Enabled' } : undefined, | |||
lifecycleConfiguration: new cdk.Token(() => this.parseLifecycleConfiguration()), | |||
websiteConfiguration: this.renderWebsiteConfiguration(props) | |||
websiteConfiguration: this.renderWebsiteConfiguration(props), | |||
publicAccessBlockConfiguration: props.blockPublicAccess |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should support the entire surface area of the feature, but also find a way to provide a more ergonomic API.
How about using an "enum-like class":
export interface BlockPublicAccessOptions {
blockPublicAcls?: boolean;
ignorePublicAcls?: boolean;
blockPublicPolicy?: boolean;
restrictPublicBuckets?: boolean;
}
export class BlockPublicAccess {
public static blockAll = new BlockPublicAccess({ blockPublicAcls: true, ...true, true, true... });
public static block... // maybe there are other canned settings we can provide
constructor(options: BlockPublicAccessOptions) { ... }
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jogold have you seen this comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I understand your point. I initially thought that a propertyOverrides
would be sufficient here.
What kind of api/naming would like to see on the Bucket
construct? props.blockPublicAccess
becomes an instance of BlockPublicAccess
? Do I need to add an interface BlockPublicAccessOptions
as suggested or can I reuse the generated one (CfnBucket.PublicAccessBlockConfigurationProperty
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We try not to "leak" the CFN layer, eventually L2 should cover the entire surface area. We don't want people to need to traverse these layers to use prop overrides. Please define another props interface. In most cases it's not a 1:1 mapping (although it might be here). We also want to able to evolve those independently.
As for naming, blockPublicAccess
of type BlockPublicAccess
, so the usage would be:
blockPublicAccess: BlockPublicAccess.blockAll
(a bit of a mouthfull but not too bad)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See latest commit:
- used
BlockAll
(capitalized) - added
BlockAcls
grantPublicRead
now only throws whenblockPublicPolicy
is enabled because it's only in this case that S3 rejects calls to PUT Bucket policy.
/** | ||
* Whether all block public access settings are enabled | ||
*/ | ||
protected abstract publicAccessBlocked?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is not really accurate for the case of an imported bucket, rename this to disallowPublicAccess
. It will semantically reflect what this is actually used for instead falsely representing this configuration for imported buckets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is indeed better, done.
"PublicAccessBlockConfiguration": { | ||
"BlockPublicAcls": true, | ||
"BlockPublicPolicy": true, | ||
"IgnorePublicAcls": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verify behavior for imported buckets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you want me to check for imported buckets in the generated CF output? I don't get it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifically, I think the code not covered is grantPublicAccess
should throw an error, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | ||
* The block public access configuration of this bucket. | ||
*/ | ||
protected abstract blockPublicAccess?: BlockPublicAccess; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually think this should have remained disallowPublicAccess
because it reflects the intent to disallow grantPublicAccess
and not the specific type of public access blocked during configuration. Otherwise, you go back to faking it with the imported resource...
❤️ thanks! |
…#1664) Adds option to enable all block public access settings on the bucket (`blockPublicAccess`). Also throws an error when trying to use grantPublicAccess if blockPublicAccess is set to true. https://docs.aws.amazon.com/AmazonS3/latest/dev/access-control-block-public-access.html
Adds option to enable all block public access settings on the bucket (
blockPublicAccess
). Also throws an error when trying to usegrantPublicAccess
ifblockPublicAccess
is set to true.https://docs.aws.amazon.com/AmazonS3/latest/dev/access-control-block-public-access.html
Pull Request Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.