-
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
aws-s3: blockPublicAccess
has a counterintuitive behaviour
#32811
Comments
Hi @garysassano , thanks for reporting this. I tried to repro with 3 different scenario and here is my observation - export class BucketAccessv2Stack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const bucketWithDefaultAccess = new s3.Bucket(this, 'bucketdefaulted', {}); //means by default, it should have blockallPublicaccess :true which is true when seen in console
const bucketwithsetaccess = new s3.Bucket(this, 'bucketwithsetaccess', {
blockPublicAccess: new s3.BlockPublicAccess({
blockPublicAcls: true,
ignorePublicAcls: true,
blockPublicPolicy: true,
restrictPublicBuckets: true, // means it should have blockallPublicaccess :true
}),
});
const bukcetwithfalseaccess = new s3.Bucket(this, "bucketwithfalseaccess", {
blockPublicAccess: new s3.BlockPublicAccess({
blockPublicPolicy: false,
restrictPublicBuckets: false, //means it should have blockPublicaccess: false for defined policy and rest 2 which are undefined should be defaulted to true
}),
});
}
} In console , the setting for resppective buckets are -
As its seen in the code, default value for these variables is set to Code commit - 299fb6a#diff-97a6344bb43117c16441333d96eede412c2c7f7df034f88bbebb90b151eca42d export class BlockPublicAccess {
public static readonly BLOCK_ALL = new BlockPublicAccess({
blockPublicAcls: true,
blockPublicPolicy: true,
ignorePublicAcls: true,
restrictPublicBuckets: true,
});
public static readonly BLOCK_ACLS = new BlockPublicAccess({
blockPublicAcls: true,
ignorePublicAcls: true,
});
public blockPublicAcls: boolean | undefined;
public blockPublicPolicy: boolean | undefined;
public ignorePublicAcls: boolean | undefined;
public restrictPublicBuckets: boolean | undefined;
constructor(options: BlockPublicAccessOptions) {
this.blockPublicAcls = options.blockPublicAcls;
this.blockPublicPolicy = options.blockPublicPolicy;
this.ignorePublicAcls = options.ignorePublicAcls;
this.restrictPublicBuckets = options.restrictPublicBuckets;
}
} One can edit the settings by going through the console or setting the policies explicitly to true in the code But this should be addressed so I am marking this as P2 which means it won't be immediately addressed by the team but would be on their radar. |
Describe the bug
When a bucket is created without specifying the
blockPublicAccess
property:It is equivalent to explicitly setting all
BlockPublicAccess
options totrue
:This might lead you to assume that all
BlockPublicAccess
options default totrue
. However, that's not the case. For example, if you deploy a bucket like this:You would get this configuration:
This happens because all options within
BlockPublicAccess
areundefined
by default, which is equivalent tofalse
.This behavior is counterintuitive. If you do not define
blockPublicAccess
, all options default totrue
. However, if you define aBlockPublicAccess
, any unspecified options default tofalse
.This seemingly paradoxical situation stems from a change introduced a couple of years ago.
Regression Issue
Last Known Working CDK Version
No response
Expected Behavior
see above.
Current Behavior
see above.
Reproduction Steps
see above.
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.174.1
Framework Version
No response
Node.js Version
22.12.0
OS
Ubuntu 24.04.1
Language
TypeScript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: