fix(iam): check Security Hub and GuardDuty routes under enforcement (#7874)

Neither REST model was vendored in rest-routes.json and no rule mapped
their routes, so under enforcement every Security Hub and GuardDuty
request resolved to no action and was let through: a user with no
policies could EnableSecurityHub or ListDetectors.

- regen_rest_routes.MODELS reads securityhub and guardduty;
  rest-routes.json takes their routes from botocore 1.43.118, and
  iam-authorized-actions.json their actions of no resource type
  (securityhub 31, guardduty 70). Nothing else changed.
- Both move from NOT_COVERED to NAMESPACES in the table of request
  resources: 228 operations, 3350 over 46 namespaces, no other entry
  changed. Security Hub's hub actions are checked on the caller's hub
  in the Region, hub/default, the ARN Security Hub gives it, and
  GuardDuty's detector and publishing destination operations on the
  detector their path names.
- The generator gains a rule: an optional top-level member holding the
  ARN of a type whose format has no variable of its own also names
  that type when the request leaves it out. DescribeHub with no HubArn
  is so checked on hub/default, as AWS checks it, rather than on *,
  which would refuse a grant scoped to the hub. The rule changes no
  other operation.
- Both move to NAMESPACES in the tag-on-create table too: an
  EnableSecurityHub carrying tags also needs securityhub:TagResource on
  the hub, a GuardDuty create carrying tags guardduty:TagResource, and
  the create is checked with aws:RequestTag and aws:TagKeys.

Regenerated from the Service Reference retrieved 2026-11-11. It now
also gives two Lake Formation operations, GetGlueFunctionSessionContext
and GetTemporaryGlueFunctionCredentials, checked as
lakeformation:GetDataAccess; they are left to the next sync, which
--verify reports without failing. Macie is read by #7869.

IamRestRouteEnforcementIntegrationTest checks both services: a caller
with no grant refused, a grant scoped to the hub or detector let
through, another Region's hub and another detector refused, and a deny
holding under an allow on everything. IamTagOnCreateEnforcementIntegrationTest
checks a hub enabled and a detector created with tags: TagResource
needed, a request tag condition applied, and an untagged create
needing its own action alone. All four fail on main. iam.md says so.

Closes #7830
This commit is contained in:
David authored and GitHub committed 2026-11-11 15:01:28 -04:00
1 parent b3e5ecc486
commit 2fe25793c8
11 files changed
+814 -25

No files matched your search

@@ -647,6 +647,67 @@ class IamRestRouteEnforcementIntegrationTest {
as(user, "access-analyzer").delete("/analyzer/" + analyzer).then().statusCode(200);
}
/**
* A Security Hub request is checked on the caller's hub in the Region it is signed for, {@code hub/default}, the
* ARN Security Hub gives it, or on the hub its {@code HubArn} names: a caller with no grant is refused, a grant
* scoped to the hub lets {@code DescribeStandards} through and {@code DescribeHub} reach Security Hub, which is
* not enabled there, with or without the hub's ARN, a request naming or signed for another Region's hub is
* refused, and a deny on the hub holds under an allow on everything.
*/
@Test
void aSecurityHubRequestIsCheckedOnTheHub() {
String user = user("route-hub");
String region = "eu-west-3";
String hub = "arn:aws:securityhub:" + region + ":" + ACCOUNT + ":hub/default";
String otherHub = "arn:aws:securityhub:us-west-2:" + ACCOUNT + ":hub/default";
refused(as(user, region, "securityhub").get("/standards").then(), "securityhub:DescribeStandards");
refused(as(user, region, "securityhub").body("{}").post("/accounts").then(), "securityhub:EnableSecurityHub");
policy(user, allow("securityhub:DescribeStandards", hub) + "," + allow("securityhub:DescribeHub", hub));
as(user, region, "securityhub").get("/standards").then().statusCode(200);
as(user, region, "securityhub").get("/accounts").then().statusCode(404)
.body(containsString("ResourceNotFoundException"));
as(user, region, "securityhub").queryParam("HubArn", hub).get("/accounts").then().statusCode(404)
.body(containsString("ResourceNotFoundException"));
refused(as(user, region, "securityhub").queryParam("HubArn", otherHub).get("/accounts").then(),
"securityhub:DescribeHub");
refused(as(user, "us-west-2", "securityhub").get("/standards").then(), "securityhub:DescribeStandards");
policy(user, allow("securityhub:*", "*") + "," + deny("securityhub:DescribeStandards", hub));
refused(as(user, region, "securityhub").get("/standards").then(), "securityhub:DescribeStandards");
as(user, "us-west-2", "securityhub").get("/standards").then().statusCode(200);
}
/**
* A GuardDuty request naming its detector in its path is checked on that detector, the ARN GuardDuty gives it,
* and one naming none as its action on {@code *}: a caller with no grant is refused, a grant scoped to the
* detector lets {@code GetDetector} read it, a request naming another detector is refused, and a deny on the
* detector holds under an allow on everything.
*/
@Test
void aGuardDutyRequestIsCheckedOnTheDetectorItsPathNames() {
String user = user("route-detector");
String region = "eu-west-3";
refused(as(user, region, "guardduty").get("/detector").then(), "guardduty:ListDetectors");
String detector = given().header("Authorization", auth(ADMIN, region, "guardduty"))
.contentType("application/json").body("{\"enable\":true}").post("/detector")
.then().statusCode(200).extract().path("detectorId");
cleanup.register(() -> given().header("Authorization", auth(ADMIN, region, "guardduty"))
.delete("/detector/" + detector));
String arn = "arn:aws:guardduty:" + region + ":" + ACCOUNT + ":detector/" + detector;
refused(as(user, region, "guardduty").get("/detector/" + detector).then(), "guardduty:GetDetector");
policy(user, allow("guardduty:GetDetector", arn));
as(user, region, "guardduty").get("/detector/" + detector).then().statusCode(200)
.body("status", equalTo("ENABLED"));
refused(as(user, region, "guardduty").get("/detector/other" + detector).then(), "guardduty:GetDetector");
refused(as(user, region, "guardduty").get("/detector").then(), "guardduty:ListDetectors");
policy(user, allow("guardduty:*", "*") + "," + deny("guardduty:GetDetector", arn));
refused(as(user, region, "guardduty").get("/detector/" + detector).then(), "guardduty:GetDetector");
as(user, region, "guardduty").get("/detector").then().statusCode(200);
}
/**
* A segment ending in a matrix parameter, which the router ignores, is checked as the route it reaches, on the
* resource its path names: the routed path carries no matrix parameter, so the rule matches and the ARN is the
@@ -599,6 +599,76 @@ class IamTagOnCreateEnforcementIntegrationTest {
return "{\"Tags\":{\"team\":{\"TagKey\":\"team\",\"TagValue\":\"" + team + "\"}}}";
}
/**
* A hub enabled with tags needs {@code securityhub:TagResource} on the hub, {@code hub/default} in the Region the
* request is signed for, and {@code EnableSecurityHub} is checked with the tags it carries; one enabled with none
* needs {@code EnableSecurityHub} alone. Each enable is in a Region of its own, as a hub is enabled once.
*/
@Test
void aHubEnabledWithTagsNeedsTagResourceOnTheHub() {
User user = user("tag-hub");
String region = "ap-southeast-2";
String hub = "arn:aws:securityhub:" + region + ":" + ACCOUNT + ":hub/default";
user.policy(allow("securityhub:EnableSecurityHub"));
refusedRest(user.rest("securityhub", region).body(hub("blue")).post("/accounts").then(),
"securityhub:TagResource");
user.policy("{\"Effect\":\"Allow\",\"Action\":\"securityhub:EnableSecurityHub\",\"Resource\":\"*\","
+ "\"Condition\":{\"StringEquals\":{\"aws:RequestTag/team\":\"blue\"}}},"
+ "{\"Effect\":\"Allow\",\"Action\":\"securityhub:TagResource\",\"Resource\":\"" + hub + "\"}");
refusedRest(user.rest("securityhub", region).body(hub("red")).post("/accounts").then(),
"securityhub:EnableSecurityHub");
refusedRest(user.rest("securityhub", "ap-northeast-3").body(hub("blue")).post("/accounts").then(),
"securityhub:TagResource");
user.rest("securityhub", region).body(hub("blue")).post("/accounts").then().statusCode(200);
admin("securityhub", region).get("/tags/{arn}", hub).then().statusCode(200).body("Tags.team", equalTo("blue"));
user.policy(allow("securityhub:EnableSecurityHub"));
user.rest("securityhub", "ap-southeast-1").body(hub(null)).post("/accounts").then().statusCode(200);
}
/**
* A detector created with tags needs {@code guardduty:TagResource}, on {@code *} as the detector's id is one
* GuardDuty mints, and {@code CreateDetector} is checked with the tags it carries; one created with none needs
* {@code CreateDetector} alone.
*/
@Test
void aDetectorCreatedWithTagsNeedsTagResource() {
User user = user("tag-detector");
String region = "ap-southeast-2";
user.policy(allow("guardduty:CreateDetector"));
refusedRest(user.rest("guardduty", region).body(detector("blue")).post("/detector").then(),
"guardduty:TagResource");
user.policy("{\"Effect\":\"Allow\",\"Action\":\"guardduty:CreateDetector\",\"Resource\":\"*\","
+ "\"Condition\":{\"StringEquals\":{\"aws:RequestTag/team\":\"blue\"}}},"
+ allow("guardduty:TagResource"));
refusedRest(user.rest("guardduty", region).body(detector("red")).post("/detector").then(),
"guardduty:CreateDetector");
String tagged = user.rest("guardduty", region).body(detector("blue")).post("/detector").then().statusCode(200)
.extract().path("detectorId");
cleanup.register(() -> admin("guardduty", region).delete("/detector/{id}", tagged));
admin("guardduty", region).get("/detector/{id}", tagged).then().statusCode(200)
.body("tags.team", equalTo("blue"));
admin("guardduty", region).delete("/detector/{id}", tagged).then().statusCode(200);
user.policy(allow("guardduty:CreateDetector"));
String untagged = user.rest("guardduty", region).body(detector(null)).post("/detector").then()
.statusCode(200).extract().path("detectorId");
cleanup.register(() -> admin("guardduty", region).delete("/detector/{id}", untagged));
}
/** An {@code EnableSecurityHub} body tagging the hub with the {@code team} given, or with no tags. */
private static String hub(String team) {
return team == null ? "{\"EnableDefaultStandards\":false}"
: "{\"EnableDefaultStandards\":false,\"Tags\":{\"team\":\"" + team + "\"}}";
}
/** A {@code CreateDetector} body tagging the detector with the {@code team} given, or with no tags. */
private static String detector(String team) {
return team == null ? "{\"enable\":true}" : "{\"enable\":true,\"tags\":{\"team\":\"" + team + "\"}}";
}
/** A {@code CreateAnalyzer} body tagging the analyzer with the {@code team} given, or with no tags. */
private static String analyzer(String name, String team) {
String tags = team == null ? "" : ",\"tags\":{\"team\":\"" + team + "\"}";
@@ -709,6 +779,10 @@ class IamTagOnCreateEnforcementIntegrationTest {
return given().header("Authorization", auth(ADMIN, service));
}
private static RequestSpecification admin(String service, String region) {
return given().header("Authorization", auth(ADMIN, region, service));
}
private static String suffix() {
return Long.toString(System.nanoTime(), 36);
}
@@ -736,6 +810,10 @@ class IamTagOnCreateEnforcementIntegrationTest {
return given().header("Authorization", auth(accessKeyId, service)).contentType("application/json");
}
RequestSpecification rest(String service, String region) {
return given().header("Authorization", auth(accessKeyId, region, service)).contentType("application/json");
}
RequestSpecification cbor(String service) {
return given().header("Authorization", auth(accessKeyId, service)).header("smithy-protocol", "rpc-v2-cbor")
.contentType("application/cbor").accept("application/cbor");