mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
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:
1 parent
591d5f533b
commit
407ac4e210
9 files changed
+242
-37
No files matched your search
@@ -120,9 +120,11 @@ final class RequestResourceMembers {
|
||||
* of the ARN that structure gives, if any. Such a member is in {@code absent} or {@code arnOf} only when it
|
||||
* fills a variable. A member filling a variable may also be a field of a structure ({@code pipeline.name}). A
|
||||
* variable no member gives may be {@code fixed} to the one value its handler uses (a CodePipeline custom action
|
||||
* type's owner, {@code Custom}). An ARN member's value is read up to the character {@code before}, when there
|
||||
* is one, as its handler drops the rest. A create naming other resources beside the one it makes marks that one
|
||||
* {@code made}, where its tags go (a webhook, not the pipeline it connects to).
|
||||
* type's owner, {@code Custom}). A member's value, an ARN or a variable's, is read up to the character
|
||||
* {@code before}, when there is one: Step Functions Local's handler drops a test case after {@code #}, and a
|
||||
* CodeBuild build id is {@code <project>:<id>}, a build being checked on its project. A create naming other
|
||||
* resources beside the one it makes marks that one {@code made}, where its tags go (a webhook, not the pipeline
|
||||
* it connects to).
|
||||
*/
|
||||
record Resource(List<String> types, Member arn, Map<String, Member> fill, Map<String, List<String>> when,
|
||||
Map<String, List<String>> unless, Map<String, String> absent, Map<String, String> arnOf,
|
||||
@@ -234,17 +236,17 @@ final class RequestResourceMembers {
|
||||
+ resource.path("made") + ", which is not true");
|
||||
}
|
||||
boolean made = resource.has("made");
|
||||
String before = resource.has("before") ? resource.path("before").asText("") : null;
|
||||
if (before != null && before.length() != 1) {
|
||||
throw new IllegalStateException(RESOURCE_NAME + " reads a member for " + operation
|
||||
+ " before " + before + ", no one character");
|
||||
}
|
||||
if (resource.has("arn")) {
|
||||
List<String> types = resource.path("types").valueStream().map(JsonNode::asText).toList();
|
||||
if (types.isEmpty() || !formats.keySet().containsAll(types)) {
|
||||
throw new IllegalStateException(RESOURCE_NAME + " reads an ARN for " + operation
|
||||
+ " of types with no format: " + types);
|
||||
}
|
||||
String before = resource.has("before") ? resource.path("before").asText("") : null;
|
||||
if (before != null && before.length() != 1) {
|
||||
throw new IllegalStateException(RESOURCE_NAME + " reads an ARN for " + operation
|
||||
+ " before " + before + ", no one character");
|
||||
}
|
||||
return new Resource(types, arnMember(operation, resource.path("arn").asText("")), Map.of(), Map.of(),
|
||||
Map.of(), Map.of(), Map.of(), null, before, Map.of(), made);
|
||||
}
|
||||
@@ -304,7 +306,7 @@ final class RequestResourceMembers {
|
||||
+ " from " + account.name() + ", no member of one account or a type of none");
|
||||
}
|
||||
return new Resource(List.of(type), null, Map.copyOf(fill), when, unless, Map.copyOf(absent), Map.copyOf(arnOf),
|
||||
account, null, Map.copyOf(fixed), made);
|
||||
account, before, Map.copyOf(fixed), made);
|
||||
}
|
||||
|
||||
/** The values each member named in {@code when} or {@code unless} may have, an empty one for the member absent. */
|
||||
|
||||
@@ -249,13 +249,16 @@ public final class RequestResources {
|
||||
|
||||
/**
|
||||
* The ARNs of a type the request names through the variables it fills: one for each value of a list member,
|
||||
* none when it gives none of them. A value that is itself an ARN of the type names that resource. They are in
|
||||
* the account the resource's account member gives, which its handler acts in, and none when that member holds
|
||||
* no account id; in the request's without one, or with a JSON null for it. An ARN given for a name puts the
|
||||
* none when it gives none of them. A value that is itself an ARN of the type names that resource, and the others
|
||||
* in the same list their own, as a handler taking a name or an ARN for each reads them (CodeBuild's
|
||||
* {@code BatchGetProjects}). They are in the account the resource's account member gives, which its handler
|
||||
* acts in, and none when that member holds no account id; in the request's without one, or with a JSON null for
|
||||
* it. An ARN given for a name puts the
|
||||
* resource in that ARN's account and Region, the caller's and the request's where it leaves them empty, as its
|
||||
* handler then acts on the caller's resource of that name, and it is named as an ARN the request gives is; for
|
||||
* a member naming one resource for each of a list's structures, each in the account and Region of the ARN its
|
||||
* structure gives, the request's for a name (a {@code PutEvents} entry, on the bus it names). A type
|
||||
* structure gives, the request's for a name (a {@code PutEvents} entry, on the bus it names). Each value is read
|
||||
* up to the resource's {@code before} character, when it has one (a CodeBuild build id's project). A type
|
||||
* whose service mints an id after its name is the caller's resource {@code stored} finds under that name, or
|
||||
* else has that id open.
|
||||
*/
|
||||
@@ -276,16 +279,21 @@ public final class RequestResources {
|
||||
List<Filling> fillings = new ArrayList<>(List.of(new Filling(resource.fixed(), fromRequest)));
|
||||
boolean given = false;
|
||||
for (Map.Entry<String, RequestResourceMembers.Member> variable : resource.fill().entrySet()) {
|
||||
List<String> values = read(resource, form, body, variable.getValue());
|
||||
List<String> values = read(resource, form, body, variable.getValue()).stream()
|
||||
.map(value -> before(value, resource.before())).toList();
|
||||
if (values.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
given = true;
|
||||
RequestResourceMembers.ArnFormat named = arnOf(resource, variable.getValue().path(), formats);
|
||||
if (resource.fill().size() == 1 && fromRequest == null && values.stream().allMatch(value ->
|
||||
!isArnOf(named, value) && format.pattern().matcher(value).matches())) {
|
||||
values.forEach(value -> addNamed(arns, format.checked(value), partition, region, accountId));
|
||||
return;
|
||||
if (resource.fill().size() == 1 && fromRequest == null) {
|
||||
List<String> asArns = values.stream()
|
||||
.filter(value -> !isArnOf(named, value) && format.pattern().matcher(value).matches()).toList();
|
||||
asArns.forEach(value -> addNamed(arns, format.checked(value), partition, region, accountId));
|
||||
values = values.stream().filter(value -> !asArns.contains(value)).toList();
|
||||
if (values.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
List<Filling> next = new ArrayList<>();
|
||||
for (Filling filling : fillings) {
|
||||
|
||||
Reference in new issue
Block a user