-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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(cloudtrail): Invalid resource for policy when using sendToCloudWatchLogs #1851
Conversation
…tchLogs Sets `this.cloudWatchLogsGroupArn` before using it, such that a correct resource ARN is used in the policy generated for CloudTrail to be able to create and use the required log stream. Fixes #1848
@@ -149,14 +149,13 @@ export class CloudTrail extends cdk.Construct { | |||
}); | |||
this.cloudWatchLogsGroupArn = logGroup.logGroupArn; | |||
|
|||
const logsRole = new iam.Role(this, 'LogsRole', {assumedBy: new iam.ServicePrincipal(cloudTrailPrincipal) }); | |||
const logsRole = new iam.Role(this, 'LogsRole', { assumedBy: new iam.ServicePrincipal(cloudTrailPrincipal) }); | |||
this.cloudWatchLogsRoleArn = logsRole.roleArn; | |||
|
|||
const streamArn = `${this.cloudWatchLogsRoleArn}:log-stream:*`; |
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.
Wait why was this not a static analysis error?
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.
The field is string | undefined
(there is no value if you don't enable CloudWatch/Logs output) - and unassigned it is undefined
, which is valid. Interpolating undefined
is totally valid (and it'll output a literal undefined
).
@@ -149,14 +149,13 @@ export class CloudTrail extends cdk.Construct { | |||
}); | |||
this.cloudWatchLogsGroupArn = logGroup.logGroupArn; | |||
|
|||
const logsRole = new iam.Role(this, 'LogsRole', {assumedBy: new iam.ServicePrincipal(cloudTrailPrincipal) }); | |||
const logsRole = new iam.Role(this, 'LogsRole', { assumedBy: new iam.ServicePrincipal(cloudTrailPrincipal) }); | |||
this.cloudWatchLogsRoleArn = logsRole.roleArn; |
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.
Why is cloudWatchLogsArn
optional?
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.
Because it is meaningless if you do not enable output in CloudWatch Logs.
The real question in fact was why do we have private members that are only ever accessed from the constructor. I'm removing those and that'll make the code a lot safer. |
Sets
this.cloudWatchLogsGroupArn
before using it, such that a correctresource ARN is used in the policy generated for CloudTrail to be able
to create and use the required log stream.
Fixes #1848
Pull Request Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.