fix(iam): check CodeBuild and Kinesis Data Analytics on the resources their requests name (#6884)

Under IAM enforcement, CodeBuild and Kinesis Data Analytics (Amazon
Managed Service for Apache Flink) requests were checked on `*`, so a
grant scoped to a project, a report group or an application was
refused, and a deny scoped to one never applied.

The generated table of the resources requests name now reads them, 92
operations, from AWS's Service Reference and botocore as it reads the
first two batches: their namespaces move from the generator's
NOT_COVERED to NAMESPACES and the table is regenerated, nothing in it
edited by hand; 614 operations over 12 namespaces. Each resource type's
ARN format is the one Floci's handler mints, which the tests check
against the ARN each create returns: `project/<name>`,
`report-group/<name>`, `build/<project>:<number>` and
`application/<name>`.

Kinesis Data Analytics v1, the KinesisAnalytics_20150814 target of SQL
applications, is not read: Floci serves v2 only, and v1's operations
share v2's names with other members. It joins EventBridge V2 in the
generator's CLIENTS_NOT_READ, with its reason.

CodeBuild authorizes a build on its project: the CodeBuild User
Guide's permissions reference gives BatchGetBuilds, StopBuild,
RetryBuild and BatchDeleteBuilds the resource project/project-name.
Their requests name builds by id, which is `<project>:<id>` (its
CODEBUILD_BUILD_ID example is codebuild-demo-project:b1e6661e-...), so
four corrections read the project from the id up to its `:`. For them
the table may read a member filling a variable up to a character
`before`, as it already read an ARN member, in the generator, the
loader and the reader. Without them a policy granting StartBuild and
BatchGetBuilds on a project, as a pipeline's CodeBuild action role
has, allowed starting a build and refused watching it.

A list filling a type's one variable may mix names and ARNs: CodeBuild's
BatchGetProjects takes either for each of `names`. Each value that is
an ARN of the type now names that resource and the others are read as
names, where the reader took ARNs as given only when every value was
one, and otherwise put an ARN inside the name's format, refusing a
caller granted both projects.

Not in this change: a build batch, whose id the documents give no
format for and which Floci does not serve, and a report, named by a
report ARN where AWS checks its report group, stay on `*`.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-10-28 21:59:51 -05:00
1 parent 591d5f533b
commit 407ac4e210
9 files changed
+242 -37

No files matched your search

@@ -150,9 +150,14 @@ class RequestResourceMembersTest {
assertEquals(List.of(new Resource(List.of("thing"), new Member("A", true, new Member("ThingArns", true)), Map.of(),
Map.of(), Map.of(), Map.of(), Map.of(), null, null, Map.of(), false)), parseUnchecked(document(formats, "{\"types\":[\"thing\"],\"arn\":\"A[].ThingArns[]\"}"))
.operations().get("a:Op"));
// An ARN read before more than one character.
// A member read before more than one character, holding an ARN or filling a variable.
assertThrows(IllegalStateException.class, () -> parse(document(formats,
"{\"types\":[\"thing\"],\"arn\":\"ThingArn\",\"before\":\"##\"}")));
assertThrows(IllegalStateException.class, () -> parse(document(formats,
"{\"type\":\"thing\",\"fill\":{\"ThingName\":\"Id\"},\"before\":\"##\"}")));
// A member filling a variable read up to a character, as a CodeBuild build id names its project.
assertEquals(":", parseUnchecked(document(formats, "{\"type\":\"thing\",\"fill\":{\"ThingName\":\"Id\"},"
+ "\"before\":\":\"}")).operations().get("a:Op").getFirst().before());
// An account from a list, or for a type whose format has no account.
assertThrows(IllegalStateException.class, () -> parse(document(formats,
"{\"type\":\"thing\",\"fill\":{\"ThingName\":\"Name\"},\"account\":\"Ids[]\"}")));
@@ -418,6 +418,26 @@ class RequestResourcesTest {
json("{\"Name\":\"s\",\"NamespaceId\":\"ns-a\"}")));
}
/** A CodeBuild build is checked on its project, which its id names before its {@code :}. */
@Test
void aBuildIsCheckedOnItsProject() {
String project = "arn:aws:codebuild:us-east-1:000000000000:project/";
assertEquals(List.of(project + "a"), of("codebuild:StopBuild", json("{\"id\":\"a:1\"}")));
assertEquals(List.of(project + "a", project + "b"), of("codebuild:BatchGetBuilds",
json("{\"ids\":[\"a:1\",\"b:2\",\"a:3\"]}")));
assertEquals(List.of(project + "a"), of("codebuild:RetryBuild", form("Action=RetryBuild&id=a:1")));
}
/** A list taking a name or an ARN for each value names each value's resource, whichever it gives. */
@Test
void aListMixingNamesAndArnsNamesEachValuesResource() {
String project = "arn:aws:codebuild:us-east-1:000000000000:project/";
assertEquals(List.of(project + "b", project + "a"), of("codebuild:BatchGetProjects",
json("{\"names\":[\"a\",\"" + project + "b\"]}")));
assertEquals(List.of(project + "a", project + "b"), of("codebuild:BatchGetProjects",
json("{\"names\":[\"" + project + "a\",\"" + project + "b\"]}")));
}
@Test
void aRequestNamingNoResourceOrOfANamespaceTheTableDoesNotReadIsCheckedOnStar() {
assertEquals(List.of(), of("ecr:DescribeRepositories", json("{}")));
@@ -10,6 +10,7 @@ import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.common.http.TestHTTPResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.restassured.path.json.config.JsonPathConfig;
import io.restassured.response.ValidatableResponse;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.BeforeAll;
@@ -724,6 +725,66 @@ class IamRequestResourceEnforcementIntegrationTest {
return id;
}
/**
* A build is checked on its project, which its id names before its {@code :}, as CodeBuild authorizes builds,
* and a project on the ARN its name gives, a list naming it by name and by ARN alike.
*/
@Test
void aBuildIsCheckedOnTheProjectItsIdNames() {
String project = "res-project-" + suffix();
String arn = adminJson("codebuild", "CodeBuild_20161006.CreateProject").body("{\"name\":\"" + project
+ "\",\"source\":{\"type\":\"NO_SOURCE\",\"buildspec\":\"version: 0.2\"},\"artifacts\":{\"type\":"
+ "\"NO_ARTIFACTS\"},\"environment\":{\"type\":\"LINUX_CONTAINER\",\"image\":\"aws/codebuild/standard:7.0\","
+ "\"computeType\":\"BUILD_GENERAL1_SMALL\"},\"serviceRole\":\"arn:aws:iam::" + ACCOUNT
+ ":role/codebuild-role\"}").post("/").then().statusCode(200).extract().path("project.arn");
cleanup.register(() -> adminJson("codebuild", "CodeBuild_20161006.DeleteProject")
.body("{\"name\":\"" + project + "\"}").post("/"));
assertEquals("arn:aws:codebuild:" + REGION + ":" + ACCOUNT + ":project/" + project, arn);
User user = user("res-build");
user.policy(allowOn("codebuild:BatchGetProjects", arn) + "," + allowOn("codebuild:BatchGetBuilds", arn) + ","
+ allowOn("codebuild:StopBuild", arn));
codeBuild(user, "BatchGetProjects", "{\"names\":[\"" + project + "\"]}").statusCode(200);
codeBuild(user, "BatchGetProjects", "{\"names\":[\"" + project + "\",\"" + arn + "\"]}").statusCode(200);
codeBuild(user, "BatchGetBuilds", "{\"ids\":[\"" + project + ":1\"]}").statusCode(200);
refusedJson(codeBuild(user, "BatchGetBuilds", "{\"ids\":[\"" + project + ":1\",\"" + project + "-other:1\"]}"),
"codebuild:BatchGetBuilds");
codeBuild(user, "StopBuild", "{\"id\":\"" + project + ":1\"}").statusCode(400)
.body(containsString("ResourceNotFoundException"));
refusedJson(codeBuild(user, "StopBuild", "{\"id\":\"" + project + "-other:1\"}"), "codebuild:StopBuild");
}
/** A Managed Service for Apache Flink application is checked on the ARN its name gives. */
@Test
void anApplicationIsCheckedOnTheArnItsNameGives() {
String name = "res-app-" + suffix();
String arn = adminJson("kinesisanalytics", "KinesisAnalytics_20180523.CreateApplication")
.body("{\"ApplicationName\":\"" + name + "\",\"RuntimeEnvironment\":\"FLINK-1_18\","
+ "\"ServiceExecutionRole\":\"arn:aws:iam::" + ACCOUNT + ":role/flink-role\"}")
.post("/").then().statusCode(200).extract().path("ApplicationDetail.ApplicationARN");
cleanup.register(() -> adminJson("kinesisanalytics", "KinesisAnalytics_20180523.DeleteApplication")
.body("{\"ApplicationName\":\"" + name + "\",\"CreateTimestamp\":"
+ adminJson("kinesisanalytics", "KinesisAnalytics_20180523.DescribeApplication")
.body("{\"ApplicationName\":\"" + name + "\"}").post("/").then().statusCode(200).extract()
.jsonPath(new JsonPathConfig(JsonPathConfig.NumberReturnType.BIG_DECIMAL))
.getString("ApplicationDetail.CreateTimestamp") + "}").post("/"));
assertEquals("arn:aws:kinesisanalytics:" + REGION + ":" + ACCOUNT + ":application/" + name, arn);
User user = user("res-application");
user.policy(allowOn("kinesisanalytics:DescribeApplication", arn));
describeApplication(user, name).statusCode(200);
refusedJson(describeApplication(user, name + "-other"), "kinesisanalytics:DescribeApplication");
}
private static ValidatableResponse codeBuild(User user, String operation, String body) {
return user.json("codebuild", "CodeBuild_20161006." + operation, "1.1").body(body).post("/").then();
}
private static ValidatableResponse describeApplication(User user, String name) {
return user.json("kinesisanalytics", "KinesisAnalytics_20180523.DescribeApplication", "1.1")
.body("{\"ApplicationName\":\"" + name + "\"}").post("/").then();
}
private static RequestSpecification adminJson(String service, String target) {
return admin(service).header("X-Amz-Target", target).contentType("application/x-amz-json-1.1");
}