feat(iam): read IAM Access Analyzer's request resources (#7567)

Access Analyzer's routes are vendored, but the table of request
resources did not read the namespace, so a route of an action AWS
checks on an analyzer, GetAnalyzer, CreateAnalyzer and DeleteAnalyzer
among the ones Floci serves, was left unchecked under enforcement: a
caller with no grant on the analyzer was let through and a deny on it
never applied.

- access-analyzer moves from NOT_COVERED to NAMESPACES: 39 operations,
  1544 over 35 namespaces, no other entry changed. An analyzer is read
  as analyzer/<analyzerName> from the path or the body, the ARN Floci
  mints, an archive rule as analyzer/<analyzerName>/archive-rule/<ruleName>,
  and the operations naming an analyzer by its ARN, in the body or the
  query, on that ARN.
- With every operation of the scope in the table, the routes check
  each by the resources-read half of the join rule. No vendored route
  is left unchecked: every routed scope is read, built by hand, or of
  an action of no resource type.
- The REST reason of the namespaces not read yet no longer says the
  path is not read: RequestResources reads it from the vendored routes,
  which do not have those namespaces' models yet.
- access-analyzer is read by the tag-on-create table too, so a
  CreateAnalyzer carrying tags also needs access-analyzer:TagResource
  on the analyzer it names, and its own action is checked with them as
  aws:RequestTag and aws:TagKeys, as the Service Reference lists. The
  regeneration also takes Config's PutServiceLinkedConfigurationRecorder,
  which the reference has listed with config:TagResource since the last
  sync; Floci does not serve it.

IamRestRouteEnforcementIntegrationTest creates an analyzer and checks
GetAnalyzer, CreateAnalyzer and DeleteAnalyzer on the ARN Access
Analyzer gives it, a grant scoped to it, another analyzer refused and
a deny holding; the vendored-route test's unchecked example is gone.
IamActionRegistryTest checks the analyzer routes and keeps an unread
example on a fixture (Backup's GetBackupPlan); RequestResourcesTest
reads an analyzer from a path label and a body and an archive rule from
both; IamRestRouteCoverageTest pins the five operations Floci serves;
IamTagOnCreateEnforcementIntegrationTest checks a tagged CreateAnalyzer
needs TagResource on its analyzer and meets a request-tag condition,
and an untagged one CreateAnalyzer alone.
iam.md and access-analyzer.md say so.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-04 21:50:47 -06:00
1 parent 3a64d2b761
commit a64fa37cd7
11 files changed
+217 -56

No files matched your search

@@ -886,6 +886,24 @@ class RequestResourcesTest {
"aws", "us-east-1", "111111111111", null, Map.of()));
}
/**
* An Access Analyzer request names its analyzer by the label of its path ({@code GetAnalyzer}) or by its body's
* {@code analyzerName} ({@code CreateAnalyzer}), and an archive rule by both, {@code CreateArchiveRule} taking the
* analyzer from its path, where a body's {@code analyzerName} names nothing, and the rule from its body.
*/
@Test
void anAccessAnalyzerRequestNamesTheAnalyzerItsPathOrBodyGives() {
String analyzer = "arn:aws:access-analyzer:us-east-1:111111111111:analyzer/a";
assertEquals(List.of(analyzer), RequestResources.of("access-analyzer:GetAnalyzer", rest("GET", null, Map.of()),
"aws", "us-east-1", "111111111111", null, Map.of("analyzerName", "a")));
assertEquals(List.of(analyzer), RequestResources.of("access-analyzer:CreateAnalyzer",
rest("PUT", "{\"analyzerName\":\"a\",\"type\":\"ACCOUNT\"}", Map.of()), "aws", "us-east-1",
"111111111111", null, Map.of()));
assertEquals(List.of(analyzer + "/archive-rule/r"), RequestResources.of("access-analyzer:CreateArchiveRule",
rest("PUT", "{\"analyzerName\":\"other\",\"ruleName\":\"r\"}", Map.of()), "aws", "us-east-1",
"111111111111", null, Map.of("analyzerName", "a")));
}
private static ContainerRequestContext rest(String method, String body, Map<String, String> query) {
return rest(method, "application/json", body, query);
}
@@ -49,9 +49,9 @@ class IamActionRegistryTest {
* A REST request no rule maps is checked as the operation whose vendored route it matches, as that operation's
* action, when Floci checks it on the resources AWS does: built by hand for its namespace ({@code Invoke} as
* {@code lambda:InvokeFunction}), read by the vendored request resources ({@code DescribeRepositories}, and
* {@code DescribeDomain} from its path), or none, AWS authorizing its action on no resource type
* ({@code ListDomainNames}). One AWS checks on a resource Floci does not read stays unmapped ({@code GetAnalyzer}),
* as does a request matching no route, and a rule still decides a route it maps.
* {@code DescribeDomain} and {@code GetAnalyzer} from their paths), or none, AWS authorizing its action on no
* resource type ({@code ListDomainNames}). One AWS checks on a resource Floci does not read stays unmapped
* ({@code GetBackupPlan}), as does a request matching no route, and a rule still decides a route it maps.
*/
@Test
void aRouteNoRuleMapsIsCheckedAsItsOperationWhenFlociChecksItAsAwsDoes() throws IOException {
@@ -65,6 +65,9 @@ class IamActionRegistryTest {
"accessanalyzer": {"credentialScope": "access-analyzer", "operations": {
"GetAnalyzer": {"method": "GET", "requestUri": "/unmapped/analyzer/{analyzerName}"}
}},
"backup": {"credentialScope": "backup", "operations": {
"GetBackupPlan": {"method": "GET", "requestUri": "/unmapped/backup/plans/{backupPlanId}"}
}},
"ecr": {"credentialScope": "ecr", "operations": {
"DescribeRepositories": {"method": "GET", "requestUri": "/unmapped/repositories"}
}},
@@ -77,7 +80,9 @@ class IamActionRegistryTest {
MultivaluedMap<String, String> none = new MultivaluedHashMap<>();
assertEquals("es:ListDomainNames", routed.resolveRoute("es", mockCtx("GET", "/unmapped/domain", none, null, "")));
assertEquals("es:DescribeDomain", routed.resolveRoute("es", mockCtx("GET", "/unmapped/domain/logs", none, null, "")));
assertNull(routed.resolveRoute("access-analyzer", mockCtx("GET", "/unmapped/analyzer/a", none, null, "")));
assertEquals("access-analyzer:GetAnalyzer", routed.resolveRoute("access-analyzer",
mockCtx("GET", "/unmapped/analyzer/a", none, null, "")));
assertNull(routed.resolveRoute("backup", mockCtx("GET", "/unmapped/backup/plans/p", none, null, "")));
assertNull(routed.resolveRoute("es", mockCtx("GET", "/other/domain", none, null, "")));
assertNull(routed.resolveRoute("other", mockCtx("GET", "/unmapped/domain", none, null, "")));
assertEquals("lambda:InvokeFunction", routed.resolveRoute("lambda",
@@ -90,8 +95,7 @@ class IamActionRegistryTest {
/**
* With the vendored routes, OpenSearch's and Access Analyzer's requests whose actions act on no resource type
* are checked as their operations, the OpenSearch VPC endpoint operations among them, in both API versions;
* those AWS checks on an analyzer stay unmapped, so a grant scoped to one is not refused.
* are checked as their operations, the OpenSearch VPC endpoint operations among them, in both API versions.
*/
@ParameterizedTest
@CsvSource({"es,GET,/2021-01-01/domain,es:ListDomainNames",
@@ -111,11 +115,22 @@ class IamActionRegistryTest {
assertEquals(action, registry.resolveRoute(scope, mockCtx(method, path, new MultivaluedHashMap<>(), null, "")));
}
/**
* Access Analyzer's analyzer routes are checked as their operations, the vendored request resources reading the
* analyzer from the path or the body, and so are those of its archive rules, findings and access previews, which
* Floci does not serve.
*/
@ParameterizedTest
@CsvSource({"access-analyzer,PUT,/analyzer", "access-analyzer,GET,/analyzer/default",
"access-analyzer,DELETE,/analyzer/default"})
void aVendoredRouteAwsChecksOnAResourceStaysUnmapped(String scope, String method, String path) {
assertNull(registry.resolveRoute(scope, mockCtx(method, path, new MultivaluedHashMap<>(), null, "")));
@CsvSource({"PUT,/analyzer,access-analyzer:CreateAnalyzer",
"GET,/analyzer/default,access-analyzer:GetAnalyzer",
"DELETE,/analyzer/default,access-analyzer:DeleteAnalyzer",
"PUT,/analyzer/default/archive-rule,access-analyzer:CreateArchiveRule",
"GET,/analyzer/default/archive-rule/rule,access-analyzer:GetArchiveRule",
"POST,/finding,access-analyzer:ListFindings",
"GET,/access-preview/preview,access-analyzer:GetAccessPreview"})
void anAccessAnalyzerAnalyzerRouteIsCheckedAsItsOperation(String method, String path, String action) {
assertEquals(action, registry.resolveRoute("access-analyzer",
mockCtx(method, path, new MultivaluedHashMap<>(), null, "")));
}
/**
@@ -88,7 +88,8 @@ class IamRestRouteCoverageTest {
assertFalse(model.isMissingNode(), "Access Analyzer's routes must be vendored from the AWS model");
String scope = model.path("credentialScope").asText();
List<DynamicTest> tests = new ArrayList<>();
for (String operation : Set.of("ValidatePolicy")) {
for (String operation : Set.of("ValidatePolicy", "ListAnalyzers", "CreateAnalyzer", "GetAnalyzer",
"DeleteAnalyzer")) {
JsonNode http = model.path("operations").path(operation);
assertFalse(http.isMissingNode(), "no model route for " + operation);
Route route = new Route(scope, "accessanalyzer", operation,
@@ -265,8 +265,8 @@ class IamRestRouteEnforcementIntegrationTest {
@Test
void controlTowerTaggingIsChecked() {
// Control Tower requests name their resources in the path, which RequestResources does not read yet,
// so its tagging is checked on *.
// Control Tower requests name their resources in the path, and its routes are not vendored, so the request
// resources read none of them and its tagging is checked on *.
String user = user("route-controltower-tags");
String landingZone = "arn:aws:controltower:us-east-1:" + ACCOUNT + ":landingzone/ROUTE" + suffix();
@@ -494,8 +494,7 @@ class IamRestRouteEnforcementIntegrationTest {
/**
* A route no rule maps is checked as the operation of its vendored route when AWS authorizes that operation's
* action on no resource type, in both OpenSearch API versions and for Access Analyzer; one AWS checks on an
* analyzer stays unchecked, so a grant scoped to the analyzer is not refused for want of reading it.
* action on no resource type, in both OpenSearch API versions and for Access Analyzer.
*/
@Test
void aVendoredRouteIsCheckedWhenAwsAuthorizesItsActionOnNoResourceType() {
@@ -506,8 +505,6 @@ class IamRestRouteEnforcementIntegrationTest {
refused(as(user, "es").get("/2015-01-01/domain").then(), "es:ListDomainNames");
refused(as(user, "es").get("/2021-01-01/opensearch/versions").then(), "es:ListVersions");
refused(as(user, "access-analyzer").get("/analyzer").then(), "access-analyzer:ListAnalyzers");
as(user, "access-analyzer").get("/analyzer/route-missing-" + suffix()).then().statusCode(404)
.body(containsString("ResourceNotFoundException"));
policy(user, allow("es:ListDomainNames", "*"));
as(user, "es").get("/2021-01-01/domain").then().statusCode(200);
@@ -544,6 +541,41 @@ class IamRestRouteEnforcementIntegrationTest {
as(user, "es").get("/2021-01-01/opensearch/domain/other-" + domain).then().statusCode(409);
}
/**
* An Access Analyzer request naming its analyzer, in its path or its body, is checked on that analyzer, the ARN
* Access Analyzer gives it: a caller with no grant is refused, a grant scoped to the analyzer lets
* {@code GetAnalyzer} read it and {@code CreateAnalyzer} reach its validation of the type, a request naming
* another analyzer is refused, a deny on the analyzer holds under an allow on everything, and that allow lets
* {@code DeleteAnalyzer} delete it.
*/
@Test
void anAccessAnalyzerRequestIsCheckedOnTheAnalyzerItsPathOrBodyNames() {
String user = user("route-analyzer");
String analyzer = "route-analyzer-" + suffix();
String arn = "arn:aws:access-analyzer:us-east-1:" + ACCOUNT + ":analyzer/" + analyzer;
refused(as(user, "access-analyzer").get("/analyzer/" + analyzer).then(), "access-analyzer:GetAnalyzer");
accessAnalyzer().body("{\"analyzerName\":\"" + analyzer + "\",\"type\":\"ORGANIZATION\"}").put("/analyzer")
.then().statusCode(200).body("arn", equalTo(arn));
cleanup.register(() -> accessAnalyzer().delete("/analyzer/" + analyzer));
policy(user, allow("access-analyzer:GetAnalyzer", arn) + "," + allow("access-analyzer:DeleteAnalyzer", arn)
+ "," + allow("access-analyzer:CreateAnalyzer", arn));
as(user, "access-analyzer").get("/analyzer/" + analyzer).then().statusCode(200)
.body("analyzer.arn", equalTo(arn));
as(user, "access-analyzer").body(createAnalyzer(analyzer)).put("/analyzer").then().statusCode(400)
.body(containsString("ValidationException"));
refused(as(user, "access-analyzer").get("/analyzer/other-" + analyzer).then(), "access-analyzer:GetAnalyzer");
refused(as(user, "access-analyzer").delete("/analyzer/other-" + analyzer).then(),
"access-analyzer:DeleteAnalyzer");
refused(as(user, "access-analyzer").body(createAnalyzer("other-" + analyzer)).put("/analyzer").then(),
"access-analyzer:CreateAnalyzer");
policy(user, allow("access-analyzer:*", "*") + "," + deny("access-analyzer:GetAnalyzer", arn));
refused(as(user, "access-analyzer").get("/analyzer/" + analyzer).then(), "access-analyzer:GetAnalyzer");
as(user, "access-analyzer").get("/analyzer/other-" + analyzer).then().statusCode(404);
as(user, "access-analyzer").delete("/analyzer/" + analyzer).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
@@ -578,6 +610,16 @@ class IamRestRouteEnforcementIntegrationTest {
return "arn:aws:lambda:us-east-1:" + ACCOUNT + ":microvm-image:" + name;
}
/** A {@code CreateAnalyzer} body of a type Access Analyzer refuses, so a request let through creates nothing. */
private static String createAnalyzer(String analyzer) {
return "{\"analyzerName\":\"" + analyzer + "\",\"type\":\"NONE\"}";
}
/** An Access Analyzer request as the account's admin. */
private static RequestSpecification accessAnalyzer() {
return given().header("Authorization", auth(ADMIN, "access-analyzer")).contentType("application/json");
}
private static RequestSpecification admin() {
return given().header("Authorization", auth(ADMIN, "lambda")).contentType("application/json");
}
@@ -25,6 +25,7 @@ import java.util.Map;
import static io.github.hectorvent.floci.testing.EnforcementFixtures.auth;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -373,6 +374,37 @@ class IamTagOnCreateEnforcementIntegrationTest {
.delete("/2015-03-31/functions/{name}", name));
}
/**
* An analyzer created with tags needs {@code access-analyzer:TagResource} on the analyzer its body names, and
* {@code CreateAnalyzer} is checked with the tags it carries; one created with none needs {@code CreateAnalyzer}
* alone.
*/
@Test
void anAnalyzerCreatedWithTagsNeedsTagResourceOnTheAnalyzer() {
User user = user("tag-analyzer");
String name = "tag-analyzer-" + suffix();
String tagResource = "{\"Effect\":\"Allow\",\"Action\":\"access-analyzer:TagResource\",\"Resource\":"
+ "\"arn:aws:access-analyzer:us-east-1:" + ACCOUNT + ":analyzer/" + name + "\"}";
user.policy(allow("access-analyzer:CreateAnalyzer"));
refusedRest(user.rest("access-analyzer").body(analyzer(name, "blue")).put("/analyzer").then(),
"access-analyzer:TagResource");
user.policy("{\"Effect\":\"Allow\",\"Action\":\"access-analyzer:CreateAnalyzer\",\"Resource\":\"*\","
+ "\"Condition\":{\"StringEquals\":{\"aws:RequestTag/team\":\"blue\"}}}," + tagResource);
refusedRest(user.rest("access-analyzer").body(analyzer(name, "red")).put("/analyzer").then(),
"access-analyzer:CreateAnalyzer");
refusedRest(user.rest("access-analyzer").body(analyzer(name + "-other", "blue")).put("/analyzer").then(),
"access-analyzer:TagResource");
user.rest("access-analyzer").body(analyzer(name, "blue")).put("/analyzer").then().statusCode(200);
cleanup.register(() -> admin("access-analyzer").delete("/analyzer/{name}", name));
admin("access-analyzer").get("/analyzer/{name}", name).then().statusCode(200)
.body("analyzer.tags.team", equalTo("blue"));
user.policy(allow("access-analyzer:CreateAnalyzer"));
user.rest("access-analyzer").body(analyzer(name + "-untagged", null)).put("/analyzer").then().statusCode(200);
cleanup.register(() -> admin("access-analyzer").delete("/analyzer/{name}", name + "-untagged"));
}
/**
* CodeDeploy's handler reads a tag's key and value in either case, so the tagging action is checked for both,
* and the create's own action sees them.
@@ -434,6 +466,12 @@ class IamTagOnCreateEnforcementIntegrationTest {
"Tags":{"team":"blue"}}""".formatted(name, role);
}
/** 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 + "\"}";
return "{\"analyzerName\":\"" + name + "\",\"type\":\"ORGANIZATION\"" + tags + "}";
}
private static ValidatableResponse createTopic(User user, String name, Map<String, String> tags) {
RequestSpecification request = user.query("sns", "CreateTopic").formParam("Name", name);
int index = 1;