-
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
chore(s3): use bucket policy instead of ACL for logging access control #20898
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.
Does the policy need to be added to the source bucket if the access logs are configured to be sent to the source bucket?
this.addToResourcePolicy(new PolicyStatement({ | ||
principals: [new ServicePrincipal('logging.s3.amazonaws.com')], | ||
actions: ['s3:PutObject'], | ||
conditions: { |
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.
Should this also include the condition:
"StringEquals": {
"aws:SourceAccount": "SOURCE-ACCOUNT-ID"
}
https://docs.aws.amazon.com/AmazonS3/latest/userguide/enable-server-access-logging.html
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.
Added.
Does the policy need to be added to the source bucket if the access logs are configured to be sent to the source bucket?
I think so. Otherwise, the service principal wouldn't have permission to write the logs.
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 don't think this is being done today.
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.
Not sure if I understand... today the LOG_DELIVERY_WRITE
ACL is applied to the target bucket. If it happens that the source and target are the same, then the ACL is applied to the source bucket. By the same logic, this change applies the policy to the source bucket if source and target are the same.
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 added a comment that tries to clarify.
@otaviomacedo another thing I just thought of is I wonder if customers might be using a centralized access log bucket. Not all access logs support the |
In that case, the logging bucket is created without setting the aws-cdk/packages/@aws-cdk/aws-cloudfront/lib/distribution.ts Lines 443 to 458 in 42d1d7c
|
2 similar comments
In that case, the logging bucket is created without setting the aws-cdk/packages/@aws-cdk/aws-cloudfront/lib/distribution.ts Lines 443 to 458 in 42d1d7c
|
In that case, the logging bucket is created without setting the aws-cdk/packages/@aws-cdk/aws-cloudfront/lib/distribution.ts Lines 443 to 458 in 42d1d7c
|
I'm more meaning if you did something like this const centralLoggingBucket = new s3.Bucket(this, 'Logging');
new s3.Bucket(this, 'SomeOtherBucket', {
serverAccessLogsBucket: centralLoggingBucket,
serverAccessLogsPrefix: 'someotherbucket',
});
new cloudfront.Distribution(this, 'Distro', {
logBucket: centralLoggingBucket,
logFilePrefix: 'cloudfront',
}); |
@corymhall I see. Re-reading the documentation, I realised that it strongly suggests the use of |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
|
||
// Enforce AWS Foundational Security Best Practice | ||
if (props.enforceSSL) { | ||
this.enforceSSLStatement(); | ||
} | ||
|
||
if (props.serverAccessLogsBucket instanceof Bucket) { | ||
props.serverAccessLogsBucket.allowLogDelivery(); | ||
props.serverAccessLogsBucket.allowLogDelivery(this, Stack.of(this).account, props.serverAccessLogsPrefix); |
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.
This is where we setup the log delivery policy/acl, but it only gets done if the user passes in a bucket to serverAccessLogsBucket
. If a user provides serverAccessLogsPrefix
but does not provide serverAccessLogsBucket
, then access logs are sent to the source bucket. Does it need to be something like
if (props.serverAccessLogsBucket instanceof Bucket) {
...
} else if (props.serverAcessLogsPrefix && !props.serverAccessLogsBucket) {
this.allowLogDelivery(this, Stack.of(this).account, props.serverAccessLogsPrefix);
}
It's not being done today so it could be a bug or it could be that you don't need to grant access to allow access logs to be written to the same bucket?
|
||
this.accessControl = BucketAccessControl.LOG_DELIVERY_WRITE; |
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.
Does this need to be added back then?
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 think so, which means that this change adds no value. Closing the PR until CloudFront (and possibly other services) catches up.
As of December 2021 AWS recommends using bucket policies instead of ACLs for logging access control.
In addition to adding the bucket policy, this change also sets the object ownership to
BUCKET_OWNER_ENFORCED
, effectively disabling ACLs.Fixes #19603.
All Submissions:
Adding new Unconventional Dependencies:
New Features
yarn integ
to deploy the infrastructure and generate the snapshot (i.e.yarn integ
without--dry-run
)?By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license