Open
Description
Describe the bug
Using S3 bucket.grantRead to grant x-account access successfully creates a bucket policy statement but does not restrict the resource correctly
bucket.grantRead(new ArnPrincipal(arn:aws:iam::XXXXXXXXXX:role/x-account-role), 's3-prefix/*');
Regression Issue
- Select this option if this issue appears to be a regression.
Last Known Working CDK Library Version
No response
Expected Behavior
The bucket policy restricts to the S3 prefix I provided
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::XXXXXXXXXX:role/x-account-role"
},
"Action": [
"s3:GetObject*",
"s3:GetBucket*",
"s3:List*"
],
"Resource": [
"arn:aws:s3:::bucket-name/s3-prefix/*"
]
}
]
}
Current Behavior
The bucket policy grants read to the entire bucket
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::XXXXXXXXXX:role/x-account-role"
},
"Action": [
"s3:GetObject*",
"s3:GetBucket*",
"s3:List*"
],
"Resource": [
"arn:aws:s3:::bucket-name",
"arn:aws:s3:::bucket-name/s3-prefix/*"
]
}
]
}
Reproduction Steps
dataBucket = new SecureBucket(this, "DataBucket", {
bucketName: props.bucketName,
encryption: BucketEncryption.KMS,
enforceSSL: true,
versioned: true,
bucketKeyEnabled: true,
lifecycleRules: [
{
expiredObjectDeleteMarker: true,
noncurrentVersionExpiration: Duration.days(30),
},
],
});
bucket.grantRead(new ArnPrincipal(arn:aws:iam::XXXXXXXXXX:role/x-account-role), 's3-prefix/*');
Possible Solution
No response
Additional Information/Context
No response
AWS CDK Library version (aws-cdk-lib)
2.180.0
AWS CDK CLI version
2.1016.1
Node.js Version
20
OS
MacOS
Language
TypeScript
Language Version
No response
Other information
No response