fix(cloudtrail): isOrganizationTrail attaches insufficient permissions to bucket#29242
fix(cloudtrail): isOrganizationTrail attaches insufficient permissions to bucket#29242mergify[bot] merged 8 commits intoaws:mainfrom
Conversation
aws-cdk-automation
left a comment
There was a problem hiding this comment.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.
|
Exemption Request I can't think of a way to test this with an integ test as it requires a valid orgId to deploy but any suggestions are welcome. I have validated locally that I can deploy when |
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
| }, | ||
| })); | ||
|
|
||
| if (props.isOrganizationTrail) { |
There was a problem hiding this comment.
Could also add a warning in the case that isOrganizationTrai: true and orgId is not provided. Probably not an error even though it would fail to deploy since some users may have manually added the missing policy already and won't need to use the new orgId prop.
Warning could be something like this but any alternative suggestions are welcome:
Organization Trails require passing in an organization id using the orgId property to attach a missing policy.
| */ | ||
| readonly isOrganizationTrail?: boolean; | ||
|
|
||
| /** The orgId. |
There was a problem hiding this comment.
Why does it call orgId? Reaching this link, it seems to be The name of the folder where the log files are stored, including the bucket name, a prefix (if you specified one), and your AWS account ID. So more like account id?
There was a problem hiding this comment.
The missing permission is specified under this section for organization trails. Specifically the third policy in that section which requires the o-organizationID:
{
"Sid": "AWSCloudTrailOrganizationWrite20150319",
"Effect": "Allow",
"Principal": {
"Service": [
"cloudtrail.amazonaws.com"
]
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::myOrganizationBucket/AWSLogs/o-organizationID/*",
"Condition": {
"StringEquals": {
"s3:x-amz-acl": "bucket-owner-full-control",
"aws:SourceArn": "arn:aws:cloudtrail:region:managementAccountID:trail/trailName"
}
}
}
Apologies, I just realized the link to the exact code block just redirects you to the top of the page which is a bit misleading.
There was a problem hiding this comment.
This makes a lot more sense! Thanks!
|
|
||
| if (props.isOrganizationTrail) { | ||
| this.s3bucket.addToResourcePolicy(new iam.PolicyStatement({ | ||
| resources: [this.s3bucket.arnForObjects( |
There was a problem hiding this comment.
In the doc, it mentions "arn:aws:s3:::myBucketName/[optionalPrefix]/AWSLogs/myAccountID/*". I haven't looked deep into it, but is the optional prefix part of the bucket and it would be handled by this.s3bucket.arnForObjects?
There was a problem hiding this comment.
It would be this value for the resources: "arn:aws:s3:::myOrganizationBucket/AWSLogs/o-organizationID/*" where arn:aws:s3:::myOrganizationBucket/ is handled by this.s3bucket.arnForObjects. But for the case you're talking about it would not handle it, the optional prefix part is passed in from props:
this.s3bucket.addToResourcePolicy(new iam.PolicyStatement({
resources: [this.s3bucket.arnForObjects(
`${props.s3KeyPrefix ? `${props.s3KeyPrefix}/` : ''}AWSLogs/${Stack.of(this).account}/*`,
)],
| if (props.isOrganizationTrail) { | ||
| this.s3bucket.addToResourcePolicy(new iam.PolicyStatement({ | ||
| resources: [this.s3bucket.arnForObjects( | ||
| `AWSLogs/${props.orgId}/*`, |
There was a problem hiding this comment.
Looking at the below snippet, wouldn't the orgId be this.s3bucket.stack.account?
Resource": "arn:aws:s3:::myBucketName/[optionalPrefix]/AWSLogs/myAccountID/*",
"Condition": {
"StringEquals": {
"s3:x-amz-acl": "bucket-owner-full-control",
"aws:SourceArn": "arn:aws:cloudtrail:region:myAccountID:trail/trailName"
}
}
There was a problem hiding this comment.
That's a different permission from that one we are adding here:
"Resource": "arn:aws:s3:::myOrganizationBucket/AWSLogs/o-organizationID/*",
"Condition": {
"StringEquals": {
"s3:x-amz-acl": "bucket-owner-full-control",
"aws:SourceArn": "arn:aws:cloudtrail:region:managementAccountID:trail/trailName"
}
}
|
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
|
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Issue #22267 (if applicable)
Closes #22267.
Reason for this change
Setting the
isOrganizationTrailproperty totrueattaches insufficient permissions to the bucket thus failing to deploy theTrailwith:Description of changes
This PR adds a new property
orgIdtoTrailPropsthat will be used to attach the missing permissionwhen
isOrganizationTrail: true.Description of how you validated changes
Validated locally that I can deploy when
Trail.isOrganizationTrail: truewith a validorgId+ added unit test case.I can't think of a way to test this with an integ test as it requires a valid
orgIdto deploy but any suggestions are welcome.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license