-
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(appconfig): scope generated alarm role policy to '*' for composite alarm support #29171
Changes from 2 commits
e3f1873
24577ff
41c3922
0f0b773
3c1ef5b
8f419ff
c07e6ea
316d421
c393c86
b778fb4
7aa65c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -252,11 +252,11 @@ export class Environment extends EnvironmentBase { | |
applicationId: this.applicationId, | ||
name: this.name, | ||
description: this.description, | ||
monitors: this.monitors?.map((monitor, index) => { | ||
monitors: this.monitors?.map((monitor) => { | ||
return { | ||
alarmArn: monitor.alarmArn, | ||
...(monitor.monitorType === MonitorType.CLOUDWATCH | ||
? { alarmRoleArn: monitor.alarmRoleArn || this.createAlarmRole(monitor, index).roleArn } | ||
? { alarmRoleArn: monitor.alarmRoleArn || this.createAlarmRole().roleArn } | ||
: { alarmRoleArn: monitor.alarmRoleArn }), | ||
}; | ||
}), | ||
|
@@ -274,24 +274,16 @@ export class Environment extends EnvironmentBase { | |
this.application.addExistingEnvironment(this); | ||
} | ||
|
||
private createAlarmRole(monitor: Monitor, index: number): iam.IRole { | ||
const logicalId = monitor.isCompositeAlarm ? 'RoleCompositeAlarm' : `Role${index}`; | ||
private createAlarmRole(): iam.IRole { | ||
const logicalId = 'Role'; | ||
const existingRole = this.node.tryFindChild(logicalId) as iam.IRole; | ||
if (existingRole) { | ||
return existingRole; | ||
} | ||
const alarmArn = monitor.isCompositeAlarm | ||
? this.stack.formatArn({ | ||
service: 'cloudwatch', | ||
resource: 'alarm', | ||
resourceName: '*', | ||
arnFormat: ArnFormat.COLON_RESOURCE_NAME, | ||
}) | ||
: monitor.alarmArn; | ||
const policy = new iam.PolicyStatement({ | ||
effect: iam.Effect.ALLOW, | ||
actions: ['cloudwatch:DescribeAlarms'], | ||
resources: [alarmArn], | ||
resources: ['*'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why '*' and not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The integ test already tests this because there is only one policy being created now with resource set to Yeah, I discussed this with a senior engineer on my team and it is only being scoped to all resources for https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_DescribeAlarms.html There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. re: integ test the test checks if the policy is being created with the resource set to edit: you know what I'm fine with this as is. disregard the above statement. re: resource since it is just a scope for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
}); | ||
const document = new iam.PolicyDocument({ | ||
statements: [policy], | ||
|
@@ -338,7 +330,6 @@ export abstract class Monitor { | |
alarmArn: alarm.alarmArn, | ||
alarmRoleArn: alarmRole?.roleArn, | ||
monitorType: MonitorType.CLOUDWATCH, | ||
isCompositeAlarm: alarm instanceof cloudwatch.CompositeAlarm, | ||
}; | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Ooh, we should have a much more descriptive logicalId here if we are searching for it in the tree. This name feels far too generic and can result in collisions.
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.
Good catch! Updated