mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(iam): read CloudWatch from the generated tables (#9282)
CloudWatch was not read by the generated request-resources table, so under IAM enforcement every CloudWatch request was checked on `*`: a grant scoped to one alarm was refused and a deny scoped to one never applied. Move `cloudwatch` from NOT_COVERED to NAMESPACES in regen_iam_request_resources.py. The table reads an alarm from AlarmName or each of AlarmNames as alarm:<name>, a dashboard from DashboardName or each of DashboardNames with no Region in its ARN, a metric stream from Name or each of Names, and a tag call from ResourceARN: the ARNs CloudWatch mints. Metric data and the list calls name no resource and stay on `*`. No other namespace's rows change.
This commit is contained in:
1 parent
199ee18a6b
commit
172a785d85
7 files changed
+242
-7
No files matched your search
+57
@@ -3252,6 +3252,63 @@ class IamRequestResourceEnforcementIntegrationTest {
|
||||
.body(not(containsString("AccessDeniedException")));
|
||||
}
|
||||
|
||||
/**
|
||||
* A CloudWatch alarm is checked on the ARN CloudWatch mints for it, {@code alarm:<name>}: a grant on one alarm lets
|
||||
* the caller create it and not another, and a deny on one alarm refuses a request whose list names it, while the
|
||||
* same request naming another alarm goes through.
|
||||
*/
|
||||
@Test
|
||||
void aCloudWatchAlarmIsCheckedOnTheArnCloudWatchGivesIt() {
|
||||
String alarm = "res-alarm-" + suffix();
|
||||
String other = alarm + "-other";
|
||||
String alarmArn = "arn:aws:cloudwatch:" + REGION + ":" + ACCOUNT + ":alarm:" + alarm;
|
||||
cleanup.register(() -> admin("monitoring").formParam("Action", "DeleteAlarms").formParam("Version", "2010-08-01")
|
||||
.formParam("AlarmNames.member.1", alarm).formParam("AlarmNames.member.2", other).post("/"));
|
||||
User user = user("res-cw-alarm");
|
||||
user.policy(allowOn("cloudwatch:PutMetricAlarm", alarmArn));
|
||||
putMetricAlarm(user.query("monitoring", "PutMetricAlarm"), alarm).statusCode(200);
|
||||
refused(putMetricAlarm(user.query("monitoring", "PutMetricAlarm"), other), "cloudwatch:PutMetricAlarm");
|
||||
|
||||
putMetricAlarm(admin("monitoring").formParam("Action", "PutMetricAlarm"), other).statusCode(200);
|
||||
user.policy(allowOn("cloudwatch:DisableAlarmActions", "*") + ",{\"Effect\":\"Deny\",\"Action\":"
|
||||
+ "\"cloudwatch:DisableAlarmActions\",\"Resource\":\"" + alarmArn + "\"}");
|
||||
refused(user.query("monitoring", "DisableAlarmActions").formParam("Version", "2010-08-01")
|
||||
.formParam("AlarmNames.member.1", other).formParam("AlarmNames.member.2", alarm).post("/").then(),
|
||||
"cloudwatch:DisableAlarmActions");
|
||||
user.query("monitoring", "DisableAlarmActions").formParam("Version", "2010-08-01")
|
||||
.formParam("AlarmNames.member.1", other).post("/").then().statusCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* A CloudWatch dashboard is checked on its ARN, which has no Region, as AWS gives it and CloudWatch mints it, so a
|
||||
* grant on one dashboard lets the caller write and read it and not another.
|
||||
*/
|
||||
@Test
|
||||
void aCloudWatchDashboardIsCheckedOnItsArnWithoutARegion() {
|
||||
String dashboard = "res-dash-" + suffix();
|
||||
cleanup.register(() -> admin("monitoring").formParam("Action", "DeleteDashboards")
|
||||
.formParam("Version", "2010-08-01").formParam("DashboardNames.member.1", dashboard).post("/"));
|
||||
User user = user("res-cw-dash");
|
||||
user.policy(allowOn("cloudwatch:PutDashboard", "arn:aws:cloudwatch::" + ACCOUNT + ":dashboard/" + dashboard)
|
||||
+ "," + allowOn("cloudwatch:GetDashboard", "arn:aws:cloudwatch::" + ACCOUNT + ":dashboard/" + dashboard));
|
||||
putDashboard(user, dashboard).statusCode(200);
|
||||
refused(putDashboard(user, dashboard + "-other"), "cloudwatch:PutDashboard");
|
||||
user.query("monitoring", "GetDashboard").formParam("Version", "2010-08-01").formParam("DashboardName", dashboard)
|
||||
.post("/").then().statusCode(200).body(containsString(":dashboard/" + dashboard));
|
||||
}
|
||||
|
||||
private static ValidatableResponse putMetricAlarm(RequestSpecification request, String name) {
|
||||
return request.formParam("Version", "2010-08-01").formParam("AlarmName", name).formParam("Namespace", "Res")
|
||||
.formParam("MetricName", "Requests").formParam("Statistic", "Sum").formParam("Period", "60")
|
||||
.formParam("EvaluationPeriods", "1").formParam("Threshold", "1")
|
||||
.formParam("ComparisonOperator", "GreaterThanThreshold").post("/").then();
|
||||
}
|
||||
|
||||
private static ValidatableResponse putDashboard(User user, String name) {
|
||||
return user.query("monitoring", "PutDashboard").formParam("Version", "2010-08-01")
|
||||
.formParam("DashboardName", name).formParam("DashboardBody", "{\"widgets\":[]}").post("/").then();
|
||||
}
|
||||
|
||||
private static ValidatableResponse glue(String operation, String body) {
|
||||
return adminJson("glue", "AWSGlue." + operation).body(body).post("/").then();
|
||||
}
|
||||
|
||||
@@ -1835,6 +1835,47 @@ class ResourceArnBuilderTest {
|
||||
builder.buildResources("sns", "sns:TagResource", ctx, "us-east-1", ACCOUNT, "aws"));
|
||||
}
|
||||
|
||||
// ── CloudWatch ──────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* A CloudWatch request is checked on each alarm its AlarmNames list names, or the one its AlarmName names, as
|
||||
* {@code alarm:<name>} in the request's Region, the ARN CloudWatch mints for an alarm; one naming no alarm is
|
||||
* checked on {@code *}.
|
||||
*/
|
||||
@Test
|
||||
void cloudWatchChecksTheAlarmsARequestNames() {
|
||||
setFormBody("Action=DeleteAlarms&Version=2010-08-01&AlarmNames.member.1=high-cpu&AlarmNames.member.2=low-disk");
|
||||
assertEquals(List.of("arn:aws:cloudwatch:us-west-2:000000000000:alarm:high-cpu",
|
||||
"arn:aws:cloudwatch:us-west-2:000000000000:alarm:low-disk"),
|
||||
builder.buildResources("cloudwatch", "cloudwatch:DeleteAlarms", ctx, "us-west-2", ACCOUNT, "aws"));
|
||||
setJsonBody("{\"AlarmName\":\"high-cpu\",\"StateValue\":\"ALARM\",\"StateReason\":\"test\"}");
|
||||
when(ctx.getMediaType()).thenReturn(MediaType.valueOf("application/x-amz-json-1.0"));
|
||||
assertEquals(List.of("arn:aws:cloudwatch:us-west-2:000000000000:alarm:high-cpu"),
|
||||
builder.buildResources("cloudwatch", "cloudwatch:SetAlarmState", ctx, "us-west-2", ACCOUNT, "aws"));
|
||||
setFormBody("Action=DescribeAlarms&Version=2010-08-01&AlarmNamePrefix=high");
|
||||
assertEquals(List.of("*"),
|
||||
builder.buildResources("cloudwatch", "cloudwatch:DescribeAlarms", ctx, "us-west-2", ACCOUNT, "aws"));
|
||||
}
|
||||
|
||||
/**
|
||||
* A dashboard's ARN has no Region, as the Service Reference gives it and CloudWatch mints it, and a metric stream
|
||||
* is checked on the one its Name names; publishing or reading metric data names no resource, so is checked on
|
||||
* {@code *}.
|
||||
*/
|
||||
@Test
|
||||
void cloudWatchChecksADashboardWithoutItsRegionAndAMetricStreamByItsName() {
|
||||
setFormBody("Action=DeleteDashboards&Version=2010-08-01&DashboardNames.member.1=ops");
|
||||
assertEquals(List.of("arn:aws:cloudwatch::000000000000:dashboard/ops"),
|
||||
builder.buildResources("cloudwatch", "cloudwatch:DeleteDashboards", ctx, "us-west-2", ACCOUNT, "aws"));
|
||||
setJsonBody("{\"Name\":\"to-firehose\"}");
|
||||
when(ctx.getMediaType()).thenReturn(MediaType.valueOf("application/x-amz-json-1.0"));
|
||||
assertEquals(List.of("arn:aws:cloudwatch:us-west-2:000000000000:metric-stream/to-firehose"),
|
||||
builder.buildResources("cloudwatch", "cloudwatch:GetMetricStream", ctx, "us-west-2", ACCOUNT, "aws"));
|
||||
setFormBody("Action=PutMetricData&Version=2010-08-01&Namespace=App&MetricData.member.1.MetricName=Hits");
|
||||
assertEquals(List.of("*"),
|
||||
builder.buildResources("cloudwatch", "cloudwatch:PutMetricData", ctx, "us-west-2", ACCOUNT, "aws"));
|
||||
}
|
||||
|
||||
// ── S3 and S3 Control ───────────────────────────────────────────────────────
|
||||
|
||||
/** The resources an S3 or S3 Control request names, read from the generated table on the route it matches. */
|
||||
|
||||
Reference in new issue
Block a user