-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
fix(s3): default BlockPublicAccess class properties to true (under feature flag) #33001
Changes from 2 commits
e7776ff
ee421d3
d965576
c75abfc
41e1cb0
1b61d31
74287fe
c42e87e
b7313a5
33d386f
2f735b9
25436a4
f170fd5
7e62563
c69b118
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1092,10 +1092,10 @@ export class BlockPublicAccess { | |
public restrictPublicBuckets: boolean | undefined; | ||
|
||
constructor(options: BlockPublicAccessOptions) { | ||
this.blockPublicAcls = options.blockPublicAcls; | ||
this.blockPublicPolicy = options.blockPublicPolicy; | ||
this.ignorePublicAcls = options.ignorePublicAcls; | ||
this.restrictPublicBuckets = options.restrictPublicBuckets; | ||
this.blockPublicAcls = options.blockPublicAcls ?? true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit the docstrings for these don't have a default it looks like
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aaythapa - Could you please elaborate on your comment? I'm unable to understand the suggested change. |
||
this.blockPublicPolicy = options.blockPublicPolicy ?? true; | ||
this.ignorePublicAcls = options.ignorePublicAcls ?? true; | ||
this.restrictPublicBuckets = options.restrictPublicBuckets ?? true; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -972,6 +972,34 @@ describe('bucket', () => { | |
}); | ||
}); | ||
|
||
test('unspecified blockPublicAccess properties should default to true', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test is failing since this does not take into account the feature flag. Please refactor to something like this. test('featureFlag @aws-cdk/aws-s3:blockPublicAccessPropertiesDefaultToTrue unspecified blockPublicAccess properties should default to true', () => {
// GIVEN
const app = new cdk.App({
context: {
'@aws-cdk/aws-s3:blockPublicAccessPropertiesDefaultToTrue': true,
},
});
// WHEN
const stack = new cdk.Stack(app);
new s3.Bucket(stack, 'MyBucketNewDefaults', {
blockPublicAccess: new s3.BlockPublicAccess({
blockPublicPolicy: false,
restrictPublicBuckets: false,
}),
});
// THEN
Template.fromStack(stack).templateMatches({
'Resources': {
'MyBucketNewDefaultsC1A67BCD': {
'Type': 'AWS::S3::Bucket',
'Properties': {
'PublicAccessBlockConfiguration': {
'BlockPublicAcls': true,
'BlockPublicPolicy': false,
'IgnorePublicAcls': true,
'RestrictPublicBuckets': false,
},
},
'DeletionPolicy': 'Retain',
'UpdateReplacePolicy': 'Retain',
},
},
});
}); |
||
const stack = new cdk.Stack(); | ||
new s3.Bucket(stack, 'MyBucket', { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we create a new bucket please. MyBucket is already being created as a part of other tests and the test might become flaky in future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also dont see the feature flag being set in the test. does this work? |
||
blockPublicAccess: new s3.BlockPublicAccess({ | ||
blockPublicPolicy: false, | ||
restrictPublicBuckets: false, | ||
}), | ||
}); | ||
|
||
Template.fromStack(stack).templateMatches({ | ||
'Resources': { | ||
'MyBucketF68F3FF0': { | ||
'Type': 'AWS::S3::Bucket', | ||
'Properties': { | ||
'PublicAccessBlockConfiguration': { | ||
'BlockPublicAcls': true, | ||
'BlockPublicPolicy': false, | ||
'IgnorePublicAcls': true, | ||
'RestrictPublicBuckets': false, | ||
}, | ||
}, | ||
'DeletionPolicy': 'Retain', | ||
'UpdateReplacePolicy': 'Retain', | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
test('bucket with default block public access setting to throw error msg', () => { | ||
const stack = new cdk.Stack(); | ||
|
||
|
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.
These new defaults should be set depending on the feature flag, e.g.:
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.
Good catch, will update in the next commit.
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.
@gracelu0 -
FeatureFlags.of(this)
- I could not usethis
because the current context, i.e. class BlockPublicAccess doesn't implementIConstruct
. In my latest commit, I've used a workaround where in I declare a top level variable to represent the feature flag, modify it inside theBucket
constructor and then use its value insideBlockPublicAccess
class constructor. I know it doesn't look neat, but could not think of a better way. Let me know if you have a better suggestion.