mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(iam): derive the request resources without corrections (#8187)
The request-resources generator carried 106 CORRECTIONS over 22 namespaces, each a hand-written entry for one operation. They are gone, and no Floci service states what an operation acts on either: a service only looks up what it holds where an entry asks it to. Every operation the corrections covered is now read from botocore's shapes and documentation and the Service Reference, or, in two places, from a fix to the handler whose behavior the correction worked around. One table stays stated by hand, MEASURED, for what AWS was measured to check where neither botocore nor the Service Reference says it. The generator admits an entry only when it links to its measurement, names types the reference does not list for the action, and gives what the rules do not; review admits only real AWS evidence. It holds DynamoDB ListTables, on table/* (#7336's probes and AWS's recorded denial), and Step Functions SendTaskSuccess, SendTaskFailure and SendTaskHeartbeat, on the token's activity or state machine (#7277's probes and AWS's recorded denial). The generator's older hand tables (FOUND_BY, THROUGH, MINTED_IDS, UNQUALIFIED, QUALIFIED_MEMBERS, ID_TARGETS, CLIENTS_NOT_READ, READ_IN_HAND_BUILT) are unchanged. Generator rules: documentation naming the type fills it when it says the member is a name or an id as the variable is; an ARN head noun, or a name ending in ArnList, makes an ARN member; fields of a top-level structure and of the structures in a map are members; the id a create answers beside another type's ARN is that type's (RunJobFlow's JobFlowId and ClusterArn); an account-id member fills AccountId; a qualified member fills first, and a ResourceId variable is the type's own id, filled by a member named ResourceId before one named after the type. An ARN member whose pattern names another service, or which its documentation gives as the ARN of another type of the service, is not read unless named after a type the action acts on. Each SDK client's model is read apart, resources the clients disagree on carry their endpoint, and a v2 load balancer's type is picked by its Type enum and documented default. A variable no member fills is fixed to the one value of an enum named after it that the operation's name gives (CodePipeline's Custom action type owner), and a type named only by an optional member documented as holding what the operation is about is reached through that thing when the member is left out (EMR's ModifyInstanceGroups, through its instance groups). Reader and service changes: a member left out, or a JSON null, names the service's default where it has one (Athena's primary workgroup and AwsDataCatalog, EventBridge's default bus, per PutEvents entry); two types whose formats differ by one variable are told apart by whether the member names that default (EventBridge rules); a name for an id variable is found by the service (Rekognition stream processors, Logs deliveries); a bare id of the type an operation is about reaches the acted-on type through its service (the project CodeBuild holds a build under, the delivery destinations of the source a Logs DeleteDeliverySource deletes). A member given a JSON null names nothing, as the handlers read it, wherever the reader fills a variable from it, so an EMR ClusterId or an IAM Identity Center TargetId of null no longer names cluster/null or account/null. The table no longer has absent or before, and the reader refuses a resource key it does not know. Checks that change where the old correction had no evidence of AWS behind it: a Step Functions Local <stateMachineArn>#<test case> is checked as given; Macie CreateMember on member/*; IAM Identity Center ProvisionPermissionSet for ALL_PROVISIONED_ACCOUNTS on its instance and permission set alone, the request-scoped account pinning that served the account check removed; Logs DeleteDeliverySource on its delivery destinations; a CodeBuild build id of no build Floci holds on *. Handler fixes: Athena's ListDatabases, ListTableMetadata and GetTableMetadata read Glue whichever catalog was named, so they were also checked on AwsDataCatalog. They now refuse a catalog whose metadata is not the account's Glue Data Catalog with MetadataException and are checked on the catalog they name. Cost Explorer's cost reads ignored BillingViewArn, so they were checked on *. They now answer the primary billing view alone, refuse another with ResourceNotFoundException, and are checked on the view they name. The passed-roles table had drifted from the Service Reference and is regenerated. AWS now passes CreateTrainingSession's role to training-session.sagemaker alone, so its RoleArn is read rather than left unread for naming two services, and AWS lists Secrets Manager's new AssociateCrossAccountReplica, which the pinned botocore does not model yet. The generator now leaves an operation no pinned model has unread on its own, until a bump brings it in, in place of a hand-written entry for each, so the two there were are gone. The tag-on-create table had drifted too: AWS no longer lists a tagging action for Network Firewall's CreateProxy, CreateProxyConfiguration and CreateProxyRuleGroup, and lists five operations the pinned botocore does not model yet. It is regenerated.
This commit is contained in:
1 parent
fa9190e110
commit
58930c9278
40 files changed
+2358
-1153
No files matched your search
@@ -53,7 +53,12 @@ final class RequestResourceMembers {
|
||||
/** The one id a child type's format appends to its parent's. */
|
||||
private static final Pattern APPENDED_ID = Pattern.compile("[/:]\\$\\{\\w+}");
|
||||
/** The keys a resource found by members does not take: it is read no other way. */
|
||||
private static final List<String> FOUND_ONLY = List.of("absent", "arnOf", "fixed", "before");
|
||||
private static final List<String> FOUND_ONLY = List.of("arnOf", "fixed");
|
||||
/** The keys of a resource read from a member holding its ARN. */
|
||||
private static final Set<String> ARN_KEYS = Set.of("types", "arn", "made", "endpoint");
|
||||
/** The keys of a resource whose format's variables members fill, or its service finds by them. */
|
||||
private static final Set<String> FILL_KEYS = Set.of("type", "fill", "when", "unless", "arnOf", "account", "fixed",
|
||||
"made", "find", "endpoint", "default", "whenDefault", "unlessDefault");
|
||||
/** The keys of a resource named through a member naming another of its service's own: it is read no other way. */
|
||||
private static final Set<String> THROUGH_KEYS = Set.of("types", "through", "when", "endpoint");
|
||||
/** The keys of a resource its service acts on for a request naming none of it: it is read no other way. */
|
||||
@@ -133,19 +138,15 @@ final class RequestResourceMembers {
|
||||
* A resource a request names: by a member holding its ARN, which names a resource of one of {@code types} when
|
||||
* it matches the type's format, or by members filling the variables of one type's format, the others open,
|
||||
* only {@code when} each member named has one of its values and {@code unless} it has one of those, an empty
|
||||
* one for the member absent or given a JSON null it is not read as a value for, in the account an {@code account} member gives (ECR's {@code registryId}), or else
|
||||
* the request's. A member {@code absent} from the request, or given a JSON null, is read as the value given for
|
||||
* it (an EventBridge request naming no event bus names {@code default}), and one in {@code arnOf} may give an
|
||||
* ARN of the type named for it instead of its name, read as that type's one variable, the resource then in the
|
||||
* ARN's account and Region, or the caller's and the request's where the ARN leaves them empty. A member filling
|
||||
* a variable may be a field of each of a list's structures ({@code Entries[].EventBusName}), which names one
|
||||
* resource for each structure, read as {@code absent} gives for one that lacks it and in the account and Region
|
||||
* 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}). 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
|
||||
* one for the member absent or given a JSON null, in the account an {@code account} member gives (ECR's
|
||||
* {@code registryId}), or else the request's. A member in {@code arnOf} may give an ARN of the type named for it
|
||||
* instead of its name, read as that type's one variable, the resource then in the ARN's account and Region, or the
|
||||
* caller's and the request's where the ARN leaves them empty. A member filling a variable may be a field of each
|
||||
* of a list's structures ({@code Entries[].EventBusName}), which names one resource for each structure, in the
|
||||
* account and Region of the ARN that structure gives, if any; a member is in {@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 of its enum the operation's name gives (a CodePipeline
|
||||
* custom action type's owner, {@code Custom}). 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). A type whose ARN is all an id its service mints is named instead by the members its service
|
||||
* finds it by, {@code find}, each one value, in the order its service reads them, filling none of its variables
|
||||
@@ -158,25 +159,34 @@ final class RequestResourceMembers {
|
||||
* instance group, by its {@code InstanceGroups[].InstanceGroupId}), {@code when} the request gives the values it
|
||||
* names, and read no other way. A resource {@code byDefault} is the one of its type its service acts on for a
|
||||
* request naming none of it, {@code when} the request leaves out the member that would (Resource Explorer's
|
||||
* {@code Search} with no {@code ViewArn}, on the Region's default view), read no other way.
|
||||
* {@code Search} with no {@code ViewArn}, on the Region's default view), read no other way. Of two types whose
|
||||
* formats differ by one variable a member fills, the one without it applies {@code whenDefault} that member is
|
||||
* absent or names its type's default resource, which the service gives, and the other {@code unlessDefault}: a
|
||||
* rule on EventBridge's default bus has no bus in its ARN. Each maps the member to that type.
|
||||
*/
|
||||
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,
|
||||
Member account, String before, Map<String, String> fixed, boolean made, List<Member> find,
|
||||
String endpoint, Member through, boolean byDefault) {
|
||||
Map<String, List<String>> unless, Map<String, String> arnOf, Member account,
|
||||
Map<String, String> fixed, boolean made, List<Member> find, String endpoint, Member through,
|
||||
boolean byDefault, Map<String, String> whenDefault, Map<String, String> unlessDefault) {
|
||||
|
||||
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,
|
||||
Member account, String before, Map<String, String> fixed, boolean made, List<Member> find,
|
||||
String endpoint, Member through) {
|
||||
this(types, arn, fill, when, unless, absent, arnOf, account, before, fixed, made, find, endpoint, through,
|
||||
false);
|
||||
Map<String, List<String>> unless, Map<String, String> arnOf, Member account,
|
||||
Map<String, String> fixed, boolean made, List<Member> find, String endpoint, Member through,
|
||||
boolean byDefault) {
|
||||
this(types, arn, fill, when, unless, arnOf, account, fixed, made, find, endpoint, through, byDefault,
|
||||
Map.of(), Map.of());
|
||||
}
|
||||
|
||||
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,
|
||||
Member account, String before, Map<String, String> fixed, boolean made, String endpoint) {
|
||||
this(types, arn, fill, when, unless, absent, arnOf, account, before, fixed, made, List.of(), endpoint, null);
|
||||
Map<String, List<String>> unless, Map<String, String> arnOf, Member account,
|
||||
Map<String, String> fixed, boolean made, List<Member> find, String endpoint, Member through) {
|
||||
this(types, arn, fill, when, unless, arnOf, account, fixed, made, find, endpoint, through, false);
|
||||
}
|
||||
|
||||
Resource(List<String> types, Member arn, Map<String, Member> fill, Map<String, List<String>> when,
|
||||
Map<String, List<String>> unless, Map<String, String> arnOf, Member account,
|
||||
Map<String, String> fixed, boolean made, String endpoint) {
|
||||
this(types, arn, fill, when, unless, arnOf, account, fixed, made, List.of(), endpoint, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,10 +394,12 @@ final class RequestResourceMembers {
|
||||
throw new IllegalStateException(RESOURCE_NAME + " serves a resource of " + operation
|
||||
+ " on no endpoint prefix");
|
||||
}
|
||||
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");
|
||||
Set<String> keys = resource.has("through") ? THROUGH_KEYS : resource.has("arn") ? ARN_KEYS : FILL_KEYS;
|
||||
List<String> unknown = resource.properties().stream().map(Map.Entry::getKey)
|
||||
.filter(key -> !keys.contains(key)).toList();
|
||||
if (!unknown.isEmpty()) {
|
||||
throw new IllegalStateException(RESOURCE_NAME + " gives a resource of " + operation + " " + unknown
|
||||
+ ", no key of its kind of resource");
|
||||
}
|
||||
if (resource.has("through")) {
|
||||
List<String> types = resource.path("types").valueStream().map(JsonNode::asText).toList();
|
||||
@@ -399,7 +411,7 @@ final class RequestResourceMembers {
|
||||
+ "members reading it otherwise");
|
||||
}
|
||||
return new Resource(types, null, Map.of(), values(operation, String.join(", ", types), resource.path("when")),
|
||||
Map.of(), Map.of(), Map.of(), null, null, Map.of(), false, List.of(), endpoint, through);
|
||||
Map.of(), Map.of(), null, Map.of(), false, List.of(), endpoint, through);
|
||||
}
|
||||
if (resource.has("arn")) {
|
||||
List<String> types = resource.path("types").valueStream().map(JsonNode::asText).toList();
|
||||
@@ -412,7 +424,7 @@ final class RequestResourceMembers {
|
||||
+ " and finds its resource by " + resource.path("find") + " too");
|
||||
}
|
||||
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, endpoint);
|
||||
Map.of(), Map.of(), null, Map.of(), made, endpoint);
|
||||
}
|
||||
String type = resource.path("type").asText("");
|
||||
ArnFormat format = formats.get(type);
|
||||
@@ -461,15 +473,12 @@ final class RequestResourceMembers {
|
||||
+ " as its service's default, which is not for a request naming none");
|
||||
}
|
||||
Set<String> filled = Set.copyOf(fill.values().stream().map(Member::path).toList());
|
||||
Map<String, String> absent = new LinkedHashMap<>();
|
||||
resource.path("absent").properties().forEach(member -> {
|
||||
if (!readAsOne(operation, member.getKey(), filled) || !member.getValue().isTextual()
|
||||
|| member.getValue().asText().isEmpty()) {
|
||||
throw new IllegalStateException(RESOURCE_NAME + " reads " + member.getKey() + " for " + operation
|
||||
+ " when absent as no value");
|
||||
}
|
||||
absent.put(member.getKey(), member.getValue().asText());
|
||||
});
|
||||
Map<String, String> whenDefault = defaultPair(operation, type, resource.path("whenDefault"), formats, null);
|
||||
Map<String, String> unlessDefault = defaultPair(operation, type, resource.path("unlessDefault"), formats, filled);
|
||||
if (!whenDefault.isEmpty() && !unlessDefault.isEmpty()) {
|
||||
throw new IllegalStateException(RESOURCE_NAME + " names " + type + " for " + operation
|
||||
+ " both when and unless a member names its default");
|
||||
}
|
||||
Map<String, String> arnOf = new LinkedHashMap<>();
|
||||
resource.path("arnOf").properties().forEach(member -> {
|
||||
ArnFormat named = formats.get(member.getValue().asText(""));
|
||||
@@ -485,8 +494,37 @@ final class RequestResourceMembers {
|
||||
throw new IllegalStateException(RESOURCE_NAME + " takes " + type + "'s account for " + operation
|
||||
+ " 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, before, Map.copyOf(fixed), made, List.copyOf(find), endpoint, null, byDefault);
|
||||
return new Resource(List.of(type), null, Map.copyOf(fill), when, unless, Map.copyOf(arnOf), account,
|
||||
Map.copyOf(fixed), made, List.copyOf(find), endpoint, null, byDefault, whenDefault, unlessDefault);
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@code whenDefault} or {@code unlessDefault}: one member and the type whose default it may name, a member the
|
||||
* resource fills for {@code unlessDefault} ({@code filled} given); empty when the resource has none.
|
||||
*/
|
||||
private static Map<String, String> defaultPair(String operation, String type, JsonNode pair,
|
||||
Map<String, ArnFormat> formats, Set<String> filled) {
|
||||
if (pair.isMissingNode()) {
|
||||
return Map.of();
|
||||
}
|
||||
if (!pair.isObject() || pair.size() != 1) {
|
||||
throw new IllegalStateException(RESOURCE_NAME + " names " + type + " for " + operation
|
||||
+ " by a default of no one member and type");
|
||||
}
|
||||
Map.Entry<String, JsonNode> entry = pair.properties().iterator().next();
|
||||
if (!formats.containsKey(entry.getValue().asText("")) || (filled != null && !filled.contains(entry.getKey()))) {
|
||||
throw new IllegalStateException(RESOURCE_NAME + " names " + type + " for " + operation + " by the default of "
|
||||
+ entry.getValue() + " " + entry.getKey() + " names, no type or no member it fills");
|
||||
}
|
||||
return Map.of(entry.getKey(), entry.getValue().asText());
|
||||
}
|
||||
|
||||
/**
|
||||
* A member of a request by its path, as {@code StoredResourceArns.actedOn} names one: {@code taskToken},
|
||||
* {@code account.accountId}, {@code InstanceGroups[].InstanceGroupId}.
|
||||
*/
|
||||
static Member selector(String path) {
|
||||
return arnMember("a service's selector", path);
|
||||
}
|
||||
|
||||
/** The values each member named in {@code when} or {@code unless} may have, an empty one for the member absent. */
|
||||
|
||||
@@ -59,7 +59,7 @@ public final class RequestResources {
|
||||
private RequestResources() {
|
||||
}
|
||||
|
||||
/** Whether the generated table owns this operation, including corrections to hand-built namespaces. */
|
||||
/** Whether the generated table owns this operation, including those of hand-built namespaces it reads. */
|
||||
public static boolean reads(String operation) {
|
||||
return operation != null && RequestResourceMembers.table().operations().containsKey(operation);
|
||||
}
|
||||
@@ -107,13 +107,14 @@ public final class RequestResources {
|
||||
}
|
||||
List<RequestResourceMembers.Resource> resources = operation == null ? null
|
||||
: served(table.operations().get(operation), ctx);
|
||||
if (resources == null || resources.isEmpty()) {
|
||||
if (resources == null) {
|
||||
return List.of();
|
||||
}
|
||||
Map<String, String> sent = IamConditionContextResolver.formParameters(ctx);
|
||||
JsonNode body = sent.isEmpty() ? located(table, operation, PassedRoles.jsonBody(ctx), ctx, labels) : null;
|
||||
Map<String, String> form = located(table, operation, sent, ctx, labels);
|
||||
return named(resources, formats(table, operation), form, body, partition, region, accountId, stored);
|
||||
return resources.isEmpty() ? List.of()
|
||||
: named(operation, resources, formats(table, operation), form, body, partition, region, accountId, stored);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,7 +133,7 @@ public final class RequestResources {
|
||||
if (resources == null || resources.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
return named(resources, formats(table, operation), Map.of(), body, partition, region, accountId, stored);
|
||||
return named(operation, resources, formats(table, operation), Map.of(), body, partition, region, accountId, stored);
|
||||
}
|
||||
|
||||
/** Whether the table holds the operation as one with no resource of its own, which is checked on {@code *}. */
|
||||
@@ -177,18 +178,20 @@ public final class RequestResources {
|
||||
}
|
||||
|
||||
/** The ARNs of the resources the request names, as {@link #of} reads them. */
|
||||
private static List<String> named(List<RequestResourceMembers.Resource> resources,
|
||||
private static List<String> named(String operation, List<RequestResourceMembers.Resource> resources,
|
||||
Map<String, RequestResourceMembers.ArnFormat> formats, Map<String, String> form,
|
||||
JsonNode body, String partition, String region, String accountId,
|
||||
StoredResourceArns stored) {
|
||||
Set<String> arns = new LinkedHashSet<>();
|
||||
for (RequestResourceMembers.Resource resource : resources) {
|
||||
if (!applies(resource, form, body, formats)) {
|
||||
if (!applies(resource, form, body, formats) || !onDefault(resource, form, body, formats, region, stored)) {
|
||||
continue;
|
||||
}
|
||||
if (resource.arn() != null) {
|
||||
for (String value : values(form, body, resource.arn())) {
|
||||
String named = before(value, resource.before());
|
||||
for (String named : values(form, body, resource.arn())) {
|
||||
if (longerFormat(named, resource.types(), formats)) {
|
||||
continue;
|
||||
}
|
||||
// An ARN fitting a customer's format and one AWS owns is AWS's: the account `aws` tells them apart.
|
||||
resource.types().stream().map(formats::get).filter(format -> format.pattern().matcher(named).matches())
|
||||
.min(Comparator.comparing(format -> !format.awsOwned()))
|
||||
@@ -262,16 +265,12 @@ public final class RequestResources {
|
||||
Map<String, String> form = located(table, operation, sent, ctx, labels);
|
||||
Map<String, RequestResourceMembers.ArnFormat> formats = formats(table, operation);
|
||||
if (creates == null) {
|
||||
return named(made, formats, form, body, partition, region, accountId, null);
|
||||
return named(operation, made, formats, form, body, partition, region, accountId, null);
|
||||
}
|
||||
Set<String> arns = new LinkedHashSet<>();
|
||||
for (RequestResourceMembers.Created created : creates) {
|
||||
String separator = table.operations().getOrDefault(operation, List.of()).stream()
|
||||
.filter(resource -> created.arn().equals(resource.arn()) && resource.before() != null)
|
||||
.map(RequestResourceMembers.Resource::before).findFirst().orElse(null);
|
||||
RequestResourceMembers.ArnFormat parentFormat = formats.get(created.parent());
|
||||
for (String value : values(form, body, created.arn())) {
|
||||
String named = before(value, separator);
|
||||
for (String named : values(form, body, created.arn())) {
|
||||
if (!parentFormat.pattern().matcher(named).matches()) {
|
||||
continue;
|
||||
}
|
||||
@@ -376,10 +375,48 @@ public final class RequestResources {
|
||||
|| resource.endpoint().equals(endpoint)).toList();
|
||||
}
|
||||
|
||||
/** The value up to {@code separator}, which its handler drops the rest after; the whole value without one. */
|
||||
private static String before(String value, String separator) {
|
||||
int at = separator == null ? -1 : value.indexOf(separator);
|
||||
return at < 0 ? value : value.substring(0, at);
|
||||
/**
|
||||
* Whether an ARN fits the format of a type of the namespace the resource does not read, longer than every one of
|
||||
* its own that it fits: an endpoint group's ARN under its accelerator's, {@code accelerator/<id>/listener/...},
|
||||
* is the endpoint group's, not the accelerator's.
|
||||
*/
|
||||
private static boolean longerFormat(String arn, List<String> types,
|
||||
Map<String, RequestResourceMembers.ArnFormat> formats) {
|
||||
List<RequestResourceMembers.ArnFormat> fits = types.stream().map(formats::get)
|
||||
.filter(format -> format != null && format.pattern().matcher(arn).matches()).toList();
|
||||
// A type checked without its qualifier takes the longer ARNs of its versions and aliases on purpose.
|
||||
if (fits.stream().anyMatch(RequestResourceMembers.ArnFormat::unqualified)) {
|
||||
return false;
|
||||
}
|
||||
int own = fits.stream().mapToInt(format -> format.format().length()).max().orElse(Integer.MAX_VALUE);
|
||||
return formats.entrySet().stream().anyMatch(other -> !types.contains(other.getKey())
|
||||
&& other.getValue().format().length() > own && other.getValue().pattern().matcher(arn).matches());
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a resource marked {@code whenDefault} or {@code unlessDefault} applies: the one without the variable when
|
||||
* its member is absent or names the default resource of its type, which the service gives ({@code findDefault}),
|
||||
* the other otherwise; true for a resource marked neither. With no service, only an absent member is the default.
|
||||
*/
|
||||
private static boolean onDefault(RequestResourceMembers.Resource resource, Map<String, String> form, JsonNode body,
|
||||
Map<String, RequestResourceMembers.ArnFormat> formats, String region,
|
||||
StoredResourceArns stored) {
|
||||
Map<String, String> pair = resource.whenDefault().isEmpty() ? resource.unlessDefault() : resource.whenDefault();
|
||||
if (pair.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
Map.Entry<String, String> member = pair.entrySet().iterator().next();
|
||||
RequestResourceMembers.ArnFormat format = formats.get(member.getValue());
|
||||
List<String> given = isNull(body, new RequestResourceMembers.Member(member.getKey(), false)) ? List.of()
|
||||
: values(form, body, new RequestResourceMembers.Member(member.getKey(), false));
|
||||
String value = given.isEmpty() ? "" : given.getFirst();
|
||||
if (format != null && format.pattern().matcher(value).matches()) {
|
||||
value = format.variable(value);
|
||||
}
|
||||
Optional<String> fallback = stored == null ? Optional.empty() : stored.findDefault(member.getValue(), region);
|
||||
boolean isDefault = value.isEmpty() || fallback.map(arn -> format != null && format.pattern().matcher(arn).matches()
|
||||
? format.variable(arn) : arn).filter(value::equals).isPresent();
|
||||
return resource.whenDefault().isEmpty() != isDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -405,7 +442,7 @@ public final class RequestResources {
|
||||
private static String first(RequestResourceMembers.Resource resource, Map<String, String> form, JsonNode body,
|
||||
String member, Map<String, RequestResourceMembers.ArnFormat> formats) {
|
||||
RequestResourceMembers.Member read = new RequestResourceMembers.Member(member, false);
|
||||
if (!resource.absent().containsKey(member) && isNull(body, read)) {
|
||||
if (isNull(body, read)) {
|
||||
return "";
|
||||
}
|
||||
List<String> given = given(resource, form, body, read, formats);
|
||||
@@ -413,32 +450,25 @@ public final class RequestResources {
|
||||
}
|
||||
|
||||
/**
|
||||
* The values a request gives a member as the resource reads them, as {@link #read} gives them, and, for a member
|
||||
* that may give an ARN of a type instead of its name, that type's one variable of such an ARN.
|
||||
* The values a request gives a member, and, for a member that may give an ARN of a type instead of its name, that
|
||||
* type's one variable of such an ARN.
|
||||
*/
|
||||
private static List<String> given(RequestResourceMembers.Resource resource, Map<String, String> form,
|
||||
JsonNode body, RequestResourceMembers.Member member,
|
||||
Map<String, RequestResourceMembers.ArnFormat> formats) {
|
||||
RequestResourceMembers.ArnFormat named = arnOf(resource, member.path(), formats);
|
||||
List<String> values = read(resource, form, body, member);
|
||||
List<String> values = values(form, body, member);
|
||||
return named == null ? values : values.stream()
|
||||
.map(value -> named.pattern().matcher(value).matches() ? named.variable(value) : value).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* The values a request gives a member: the one the resource reads for the member absent or given a JSON null,
|
||||
* as a handler reading it with {@code asText(null)} does (EventBridge's {@code EventBusName}), and, for a field
|
||||
* of each of a list's structures, one for each structure, that one for a structure lacking it (a
|
||||
* {@code PutEvents} entry naming no event bus is published to the default one), none for no structures.
|
||||
*/
|
||||
private static List<String> read(RequestResourceMembers.Resource resource, Map<String, String> form,
|
||||
JsonNode body, RequestResourceMembers.Member member) {
|
||||
String absent = resource.absent().get(member.path());
|
||||
if (absent != null && member.eachElement()) {
|
||||
return eachElement(form, body, member, absent);
|
||||
/** The values of a member, a JSON null, or one in an element of a list, giving none. */
|
||||
private static List<String> namingNoneWhenNull(Map<String, String> form, JsonNode body,
|
||||
RequestResourceMembers.Member member) {
|
||||
if (member.eachElement()) {
|
||||
return eachElement(form, body, member, "").stream().filter(value -> !value.isEmpty()).toList();
|
||||
}
|
||||
List<String> values = absent != null && isNull(body, member) ? List.of() : values(form, body, member);
|
||||
return values.isEmpty() && absent != null ? List.of(absent) : values;
|
||||
return isNull(body, member) ? List.of() : values(form, body, member);
|
||||
}
|
||||
|
||||
/** The format of the type whose ARN a member of the resource may give instead of its name; null for none. */
|
||||
@@ -489,11 +519,11 @@ public final class RequestResources {
|
||||
* 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). Each value is read
|
||||
* up to the resource's {@code before} character, when it has one (a CodeBuild build id's project), and without the
|
||||
* type's own path when it begins with one, as Route 53 returns its ids ({@code /hostedzone/Z1} names hosted zone
|
||||
* {@code Z1}). A value filling a {@code ...WithoutLeadingSlash} variable is a Parameter Store name instead, read
|
||||
* as {@link #asVariable} reads it. A value rendered past a type's format, when its service checks the
|
||||
* type without a qualifier, is cut where the format ends, as an ARN given is. A type
|
||||
* without the type's own path when it begins with one, as Route 53 returns its ids ({@code /hostedzone/Z1} names
|
||||
* hosted zone {@code Z1}). A value filling a {@code ...WithoutLeadingSlash} variable is a Parameter Store name
|
||||
* instead, read as {@link #asVariable} reads it. A value rendered past a type's format, when its service checks
|
||||
* the type without a qualifier, is cut where the format ends, as an ARN given is. A variable no member fills
|
||||
* takes the value the resource gives it {@code fixed}. 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.
|
||||
*/
|
||||
@@ -508,14 +538,23 @@ public final class RequestResources {
|
||||
}
|
||||
AwsArnUtils.Arn fromRequest = arnGiven(resource, form, body, formats);
|
||||
List<Filling> fillings = new ArrayList<>(List.of(new Filling(resource.fixed(), fromRequest)));
|
||||
// A member that is a JSON null names none, as a request leaving it out and as a handler reading it with
|
||||
// asText(null) does: an EventBridge rule with a null EventBusName is on the default bus, and an EMR request
|
||||
// with a null ClusterId names no cluster of its own.
|
||||
boolean given = false;
|
||||
for (Map.Entry<String, RequestResourceMembers.Member> variable : resource.fill().entrySet()) {
|
||||
List<String> values = read(resource, form, body, variable.getValue()).stream()
|
||||
.map(value -> before(value, resource.before()))
|
||||
List<String> values = namingNoneWhenNull(form, body, variable.getValue()).stream()
|
||||
.map(value -> variable.getKey().endsWith(WITHOUT_LEADING_SLASH)
|
||||
? asVariable(variable.getKey(), value)
|
||||
: withoutTypePath(value, resource.types().getFirst()))
|
||||
.toList();
|
||||
// An element of a list naming no resource names its service's default (a PutEvents entry with no bus).
|
||||
if (variable.getValue().eachElement() && stored != null && resource.fill().size() == 1) {
|
||||
List<String> elements = eachElement(form, body, variable.getValue(), "");
|
||||
if (elements.contains("")) {
|
||||
stored.findDefault(resource.types().getFirst(), region).ifPresent(arns::add);
|
||||
}
|
||||
}
|
||||
if (values.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
@@ -543,6 +582,12 @@ public final class RequestResources {
|
||||
fillings = next;
|
||||
}
|
||||
if (!resource.fill().isEmpty() && !given) {
|
||||
// A request leaving out every member naming the resource acts on the one its service uses then; a list's
|
||||
// elements each name their own (above), so a list of none names nothing (a PutEvents of no entries).
|
||||
boolean perElement = resource.fill().values().stream().anyMatch(RequestResourceMembers.Member::eachElement);
|
||||
if (stored != null && account.equals(accountId) && !perElement) {
|
||||
stored.findDefault(resource.types().getFirst(), region).ifPresent(arns::add);
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (Filling filling : fillings) {
|
||||
|
||||
@@ -23,6 +23,10 @@ import java.util.Optional;
|
||||
* permission sets are provisioned to; Resource Explorer, for its default view; OAM and RAM, for the sinks,
|
||||
* invitations and shares of other accounts they act on); looked up lazily by {@code ResourceArnBuilder} through {@code Instance<StoredResourceArns>}
|
||||
* for the namespace a request is of, so IAM never depends on that service directly.</p>
|
||||
*
|
||||
* <p>Each answer is a lookup of what the service holds, asked for by an entry of the generated table ({@code find},
|
||||
* {@code through}, a default): never a fact about what an operation acts on, which the table alone says, from
|
||||
* botocore and the Service Reference, or from AWS behaviour measured where neither carries it.</p>
|
||||
*/
|
||||
public interface StoredResourceArns {
|
||||
|
||||
|
||||
@@ -199,15 +199,18 @@ public class AthenaJsonHandler {
|
||||
}
|
||||
case "ListDatabases" -> {
|
||||
String catalog = catalogName(request);
|
||||
athenaService.requireGlueCatalog(region, catalog);
|
||||
yield Response.ok(Map.of("DatabaseList", athenaService.listDatabases(catalog))).build();
|
||||
}
|
||||
case "ListTableMetadata" -> {
|
||||
String catalog = catalogName(request);
|
||||
athenaService.requireGlueCatalog(region, catalog);
|
||||
String database = request.path("DatabaseName").asText(request.path("Database").asText(""));
|
||||
yield Response.ok(Map.of("TableMetadataList", athenaService.listTableMetadata(catalog, database))).build();
|
||||
}
|
||||
case "GetTableMetadata" -> {
|
||||
String catalog = catalogName(request);
|
||||
athenaService.requireGlueCatalog(region, catalog);
|
||||
String database = request.path("DatabaseName").asText(request.path("Database").asText(""));
|
||||
String tableName = request.get("TableName").asText();
|
||||
yield Response.ok(Map.of("TableMetadata", athenaService.getTableMetadata(catalog, database, tableName))).build();
|
||||
|
||||
@@ -942,6 +942,23 @@ public class AthenaService {
|
||||
"WorkGroup " + name + " is not found.", 400));
|
||||
}
|
||||
|
||||
/**
|
||||
* Refuses a metadata read of a data catalog whose metadata is not the account's Glue Data Catalog, which Floci
|
||||
* reads them from: a catalog of another type, or a Glue one registered for another account's catalog. Athena
|
||||
* answers {@code MetadataException} when it cannot read a catalog's metastore, and {@code InvalidRequestException}
|
||||
* for one it does not hold.
|
||||
*/
|
||||
public void requireGlueCatalog(String region, String name) {
|
||||
if (DEFAULT_CATALOG.equals(name)) {
|
||||
return;
|
||||
}
|
||||
DataCatalog catalog = requireDataCatalog(region, name);
|
||||
String catalogId = catalog.getParameters() == null ? null : catalog.getParameters().get("catalog-id");
|
||||
if (!"GLUE".equals(catalog.getType()) || (catalogId != null && !catalogId.equals(regionResolver.getAccountId()))) {
|
||||
throw new AwsException("MetadataException", "Unable to read the metadata of data catalog " + name + ".", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private DataCatalog requireDataCatalog(String region, String name) {
|
||||
return dataCatalogStore.get(catalogKey(region, name))
|
||||
.orElseThrow(() -> new AwsException("InvalidRequestException",
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package io.floci.aws.services.athena;
|
||||
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.common.StoredResourceArns;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* What IAM asks Athena of the resources a request names: the workgroup and the data catalog its handlers use for a
|
||||
* request naming none, {@code primary} and {@code AwsDataCatalog}.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class AthenaStoredResourceArns implements StoredResourceArns {
|
||||
|
||||
private final RegionResolver regionResolver;
|
||||
|
||||
@Inject
|
||||
public AthenaStoredResourceArns(RegionResolver regionResolver) {
|
||||
this.regionResolver = regionResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String namespace() {
|
||||
return "athena";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> find(String type, List<String> names, String region) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> findDefault(String type, String region) {
|
||||
return switch (type) {
|
||||
case "workgroup" -> Optional.of(regionResolver.buildArn("athena", region, "workgroup/primary"));
|
||||
case "datacatalog" -> Optional.of(regionResolver.buildArn("athena", region,
|
||||
"datacatalog/" + AthenaService.DEFAULT_CATALOG));
|
||||
default -> Optional.empty();
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,15 @@ package io.floci.aws.services.ce;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.floci.aws.core.common.AwsErrorResponse;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* JSON 1.1 handler for AWS Cost Explorer operations.
|
||||
* Dispatches {@code X-Amz-Target: AWSInsightsIndexService.*} actions to
|
||||
@@ -18,18 +22,28 @@ import org.jboss.logging.Logger;
|
||||
public class CostExplorerJsonHandler {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(CostExplorerJsonHandler.class);
|
||||
/** The reads that take a {@code BillingViewArn}, which they answer the costs of. */
|
||||
private static final Set<String> BILLING_VIEW_READS = Set.of("GetCostAndUsage", "GetCostAndUsageWithResources",
|
||||
"GetDimensionValues", "GetTags", "GetCostCategories");
|
||||
|
||||
private final CostExplorerService service;
|
||||
private final CostAnomalyService anomalies;
|
||||
|
||||
private final RegionResolver regionResolver;
|
||||
|
||||
@Inject
|
||||
public CostExplorerJsonHandler(CostExplorerService service, CostAnomalyService anomalies) {
|
||||
public CostExplorerJsonHandler(CostExplorerService service, CostAnomalyService anomalies,
|
||||
RegionResolver regionResolver) {
|
||||
this.service = service;
|
||||
this.anomalies = anomalies;
|
||||
this.regionResolver = regionResolver;
|
||||
}
|
||||
|
||||
public Response handle(String action, JsonNode request, String region) {
|
||||
LOG.debugv("CostExplorer action: {0}", action);
|
||||
if (BILLING_VIEW_READS.contains(action)) {
|
||||
requireServedBillingView(request);
|
||||
}
|
||||
return switch (action) {
|
||||
case "GetCostAndUsage" -> Response.ok(service.getCostAndUsage(request, region)).build();
|
||||
case "GetCostAndUsageWithResources" -> Response.ok(service.getCostAndUsageWithResources(request, region)).build();
|
||||
@@ -69,4 +83,21 @@ public class CostExplorerJsonHandler {
|
||||
.build();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Refuses a billing view other than the caller's primary one, the costs of the whole account, the only view Floci
|
||||
* answers the costs of: AWS answers {@code ResourceNotFoundException}, "The specified ARN in the request doesn't
|
||||
* exist.", for a view it does not hold. AWS does not document the primary view's ARN; Floci takes it as
|
||||
* {@code billingview/primary}. The view is that ARN exactly, of AWS Billing, global, in the request's partition
|
||||
* and account, as IAM checks it: one of another service or with a Region names no view IAM could check.
|
||||
*/
|
||||
private void requireServedBillingView(JsonNode request) {
|
||||
String view = request.path("BillingViewArn").asText("");
|
||||
if (view.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (!regionResolver.buildGlobalArn("billing", "billingview/primary").equals(view)) {
|
||||
throw new AwsException("ResourceNotFoundException", "The specified ARN in the request doesn't exist.", 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -229,6 +229,13 @@ public class CloudWatchLogsDeliveryService {
|
||||
deliveries.delete(key(region, id));
|
||||
}
|
||||
|
||||
/** The ARNs of the delivery destinations the deliveries from the delivery source of that name send to. */
|
||||
public List<String> destinationArnsFrom(String sourceName, String region) {
|
||||
return deliveries.scan(k -> k.startsWith(prefix(region))).stream()
|
||||
.filter(delivery -> sourceName.equals(delivery.getDeliverySourceName()))
|
||||
.map(Delivery::getDeliveryDestinationArn).distinct().toList();
|
||||
}
|
||||
|
||||
/** Every delivery, or those from one of {@code deliverySourceNames}. */
|
||||
public PaginatedResult<Delivery> describeDeliveries(Integer limit, String nextToken,
|
||||
List<String> deliverySourceNames, String region) {
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package io.floci.aws.services.cloudwatch.logs;
|
||||
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.StoredResourceArns;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* What IAM asks CloudWatch Logs of the resources a request names: the caller's delivery of the id it was created
|
||||
* with, and the delivery destinations the deliveries from a delivery source send to, which the Service Reference
|
||||
* checks a {@code DeleteDeliverySource} on.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class CloudWatchLogsStoredResourceArns implements StoredResourceArns {
|
||||
|
||||
private final CloudWatchLogsDeliveryService deliveries;
|
||||
|
||||
@Inject
|
||||
public CloudWatchLogsStoredResourceArns(CloudWatchLogsDeliveryService deliveries) {
|
||||
this.deliveries = deliveries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String namespace() {
|
||||
return "logs";
|
||||
}
|
||||
|
||||
/** The ARN of the caller's delivery of the id {@code names} gives, as the service stored it; empty for none. */
|
||||
@Override
|
||||
public Optional<String> find(String type, List<String> names, String region) {
|
||||
if (!"delivery".equals(type) || names.size() != 1) {
|
||||
return Optional.empty();
|
||||
}
|
||||
try {
|
||||
return Optional.ofNullable(deliveries.getDelivery(names.getFirst(), region).getArn());
|
||||
} catch (AwsException notFound) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
/** The delivery destinations the caller's deliveries from the delivery source a {@code name} names send to. */
|
||||
@Override
|
||||
public List<String> through(String member, String value, String region) {
|
||||
return "name".equals(member) ? deliveries.destinationArnsFrom(value, region) : List.of();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package io.floci.aws.services.codebuild;
|
||||
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.common.StoredResourceArns;
|
||||
import io.floci.aws.services.codebuild.model.Build;
|
||||
import io.floci.aws.services.codebuild.model.Project;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* What IAM asks CodeBuild of the resources a request names: the project the caller's build of an id belongs to, as
|
||||
* the service stores them, which CodeBuild checks a call naming the build on.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class CodeBuildStoredResourceArns implements StoredResourceArns {
|
||||
|
||||
private final CodeBuildService codeBuild;
|
||||
private final RegionResolver regionResolver;
|
||||
|
||||
@Inject
|
||||
public CodeBuildStoredResourceArns(CodeBuildService codeBuild, RegionResolver regionResolver) {
|
||||
this.codeBuild = codeBuild;
|
||||
this.regionResolver = regionResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String namespace() {
|
||||
return "codebuild";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> find(String type, List<String> names, String region) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/** The project of the caller's build of the id an {@code id} or {@code ids[]} gives; empty for one it has none of. */
|
||||
@Override
|
||||
public List<String> through(String member, String value, String region) {
|
||||
if (!"ids[]".equals(member) && !"id".equals(member)) {
|
||||
return List.of();
|
||||
}
|
||||
return codeBuild.batchGetBuilds(region, regionResolver.getAccountId(), List.of(value)).stream()
|
||||
.map(Build::getProjectName)
|
||||
.flatMap(name -> codeBuild.batchGetProjects(region, List.of(name)).stream())
|
||||
.map(Project::getArn)
|
||||
.distinct()
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
@@ -661,13 +661,20 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
/**
|
||||
* The cluster an instance group a {@code ModifyInstanceGroups} names by its id alone is in, the one
|
||||
* {@link #modifyInstanceGroups} finds it in and changes it there, read under the service's lock, as
|
||||
* {@code addInstanceGroups} adds to a cluster's groups.
|
||||
* {@code addInstanceGroups} adds to a cluster's groups; and the cluster a tag call's {@code ResourceId} names.
|
||||
*/
|
||||
@Override
|
||||
public List<String> through(String member, String value, String region) {
|
||||
return "InstanceGroups[].InstanceGroupId".equals(member)
|
||||
? call(() -> clusterWithGroup(region, value).map(EmrCluster::getClusterArn).stream().toList())
|
||||
: List.of();
|
||||
return switch (member) {
|
||||
case "InstanceGroups[].InstanceGroupId" ->
|
||||
call(() -> clusterWithGroup(region, value).map(EmrCluster::getClusterArn).stream().toList());
|
||||
// A tag call's ResourceId is a cluster's id, or a Studio's, which Floci does not serve: the cluster the
|
||||
// tag handlers find by it (findCluster), one recorded with no Region included.
|
||||
case "ResourceId" -> call(() -> clusterStore.get(value)
|
||||
.filter(cluster -> cluster.getRegion() == null || cluster.getRegion().equals(region))
|
||||
.map(EmrCluster::getClusterArn).stream().toList());
|
||||
default -> List.of();
|
||||
};
|
||||
}
|
||||
|
||||
public List<EmrInstanceGroup> listInstanceGroups(String clusterId) {
|
||||
|
||||
@@ -1917,6 +1917,13 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
return "events";
|
||||
}
|
||||
|
||||
/** The Region's default event bus, which a request naming no bus acts on. */
|
||||
@Override
|
||||
public Optional<String> findDefault(String type, String region) {
|
||||
return "event-bus".equals(type) ? Optional.of(regionResolver.buildArn("events", region, "event-bus/default"))
|
||||
: Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* The ARN of the caller's connection or API destination of the one name in the Region, which follows the name
|
||||
* with the id it was minted with, as its handlers look it up.
|
||||
|
||||
@@ -234,9 +234,9 @@ public class QuickSightService implements Resettable, StoredResourceArns {
|
||||
|
||||
@Override
|
||||
public Optional<String> find(String type, List<String> names, String region) {
|
||||
if ("user".equals(type) && names.size() == 3) {
|
||||
if (("user".equals(type) || "group".equals(type)) && names.size() == 3) {
|
||||
return Optional.of(regions.buildArn("quicksight", region, names.getFirst(),
|
||||
"user/" + names.get(1) + "/" + names.get(2)));
|
||||
type + "/" + names.get(1) + "/" + names.get(2)));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package io.floci.aws.services.rekognition;
|
||||
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.common.StoredResourceArns;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* What IAM asks Rekognition of the resources a request names: a stream processor by the name it was created with,
|
||||
* which its ARN ends in.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class RekognitionStoredResourceArns implements StoredResourceArns {
|
||||
|
||||
private final RegionResolver regionResolver;
|
||||
|
||||
@Inject
|
||||
public RekognitionStoredResourceArns(RegionResolver regionResolver) {
|
||||
this.regionResolver = regionResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String namespace() {
|
||||
return "rekognition";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> find(String type, List<String> names, String region) {
|
||||
return "streamprocessor".equals(type) && names.size() == 1
|
||||
? Optional.of(regionResolver.buildArn("rekognition", region, "streamprocessor/" + names.getFirst()))
|
||||
: Optional.empty();
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package io.floci.aws.services.ssoadmin;
|
||||
|
||||
import jakarta.enterprise.context.RequestScoped;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* What this request found, kept for the request.
|
||||
*
|
||||
* <p>A {@code ProvisionPermissionSet} for {@code ALL_PROVISIONED_ACCOUNTS} provisions a permission set to every
|
||||
* account it is provisioned to, and the permission check finds those accounts and checks each one. Another request
|
||||
* may provision the permission set to one more account while this one is running, with an assignment of its own,
|
||||
* and the request must provision to the accounts it was checked on: an account found again afterwards could be one
|
||||
* no policy was checked against.
|
||||
*/
|
||||
@RequestScoped
|
||||
public class SsoAdminRequestContext {
|
||||
|
||||
/** The accounts a permission set was provisioned to, by the permission set's ARN. */
|
||||
private final Map<String, List<String>> provisionedAccounts = new HashMap<>();
|
||||
|
||||
/**
|
||||
* The accounts the permission set was provisioned to when this request found them, and null when this request
|
||||
* has not looked for them yet.
|
||||
*/
|
||||
List<String> provisionedAccounts(String permissionSetArn) {
|
||||
return provisionedAccounts.get(permissionSetArn);
|
||||
}
|
||||
|
||||
/** Remembers the accounts the permission set is provisioned to, so that the request provisions to those. */
|
||||
void pinProvisionedAccounts(String permissionSetArn, List<String> accountIds) {
|
||||
provisionedAccounts.put(permissionSetArn, List.copyOf(accountIds));
|
||||
}
|
||||
}
|
||||
@@ -140,7 +140,6 @@ public class SsoAdminService implements Resettable, StoredResourceArns {
|
||||
private final StorageBackend<String, String> trustedTokenIssuerClientTokens;
|
||||
private final IdentityStoreService identityStoreService;
|
||||
private final OrganizationsService organizationsService;
|
||||
private final SsoAdminRequestContext requestContext;
|
||||
private final String defaultAccountId;
|
||||
private final String defaultRegion;
|
||||
/** The seeded instance lives in the deployment's home region, so its ARN takes that partition. */
|
||||
@@ -150,8 +149,7 @@ public class SsoAdminService implements Resettable, StoredResourceArns {
|
||||
|
||||
@Inject
|
||||
public SsoAdminService(StorageFactory storageFactory, IdentityStoreService identityStoreService,
|
||||
OrganizationsService organizationsService, SsoAdminRequestContext requestContext,
|
||||
EmulatorConfig config) {
|
||||
OrganizationsService organizationsService, EmulatorConfig config) {
|
||||
this(
|
||||
storageFactory.create("ssoadmin", "ssoadmin-permission-sets.json", new TypeReference<Map<String, PermissionSet>>() {}),
|
||||
storageFactory.create("ssoadmin", "ssoadmin-assignments.json", new TypeReference<Map<String, Assignment>>() {}),
|
||||
@@ -180,7 +178,6 @@ public class SsoAdminService implements Resettable, StoredResourceArns {
|
||||
storageFactory.create("ssoadmin", "ssoadmin-trusted-token-issuer-client-tokens.json", new TypeReference<Map<String, String>>() {}),
|
||||
identityStoreService,
|
||||
organizationsService,
|
||||
requestContext,
|
||||
config.defaultAccountId(),
|
||||
config.defaultRegion(),
|
||||
Clock.systemUTC());
|
||||
@@ -213,7 +210,6 @@ public class SsoAdminService implements Resettable, StoredResourceArns {
|
||||
StorageBackend<String, String> trustedTokenIssuerClientTokens,
|
||||
IdentityStoreService identityStoreService,
|
||||
OrganizationsService organizationsService,
|
||||
SsoAdminRequestContext requestContext,
|
||||
String defaultAccountId,
|
||||
String defaultRegion,
|
||||
Clock clock) {
|
||||
@@ -245,7 +241,6 @@ public class SsoAdminService implements Resettable, StoredResourceArns {
|
||||
this.trustedTokenIssuerClientTokens = trustedTokenIssuerClientTokens;
|
||||
this.identityStoreService = identityStoreService;
|
||||
this.organizationsService = organizationsService;
|
||||
this.requestContext = requestContext;
|
||||
this.defaultAccountId = defaultAccountId;
|
||||
this.defaultRegion = defaultRegion;
|
||||
this.bootstrapInstanceArn = globalArn("sso", defaultRegion, "", BOOTSTRAP_INSTANCE);
|
||||
@@ -1921,25 +1916,13 @@ public class SsoAdminService implements Resettable, StoredResourceArns {
|
||||
return operation;
|
||||
}
|
||||
|
||||
/**
|
||||
* The accounts the permission set is provisioned to, as this request found them.
|
||||
*
|
||||
* <p>They are found once for the request, and kept: the permission check of a {@code ProvisionPermissionSet} for
|
||||
* {@code ALL_PROVISIONED_ACCOUNTS} finds them and checks each one, and the request must provision to those.
|
||||
* Another request may provision the permission set to one more account in between, and an account found again
|
||||
* afterwards could be one no policy was checked against.
|
||||
*/
|
||||
/** The accounts the permission set is provisioned to. */
|
||||
private List<String> provisionedAccounts(String permissionSetArn) {
|
||||
List<String> accountIds = requestContext.provisionedAccounts(permissionSetArn);
|
||||
if (accountIds == null) {
|
||||
accountIds = permissionSetProvisionings.scan(key -> true).stream()
|
||||
.filter(provisioning -> permissionSetArn.equals(provisioning.permissionSetArn()))
|
||||
.map(PermissionSetProvisioning::accountId)
|
||||
.distinct()
|
||||
.toList();
|
||||
requestContext.pinProvisionedAccounts(permissionSetArn, accountIds);
|
||||
}
|
||||
return accountIds;
|
||||
return permissionSetProvisionings.scan(key -> true).stream()
|
||||
.filter(provisioning -> permissionSetArn.equals(provisioning.permissionSetArn()))
|
||||
.map(PermissionSetProvisioning::accountId)
|
||||
.distinct()
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1952,22 +1935,6 @@ public class SsoAdminService implements Resettable, StoredResourceArns {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* The accounts a permission set is provisioned to, in its partition, which a {@code ProvisionPermissionSet} for
|
||||
* {@code ALL_PROVISIONED_ACCOUNTS} provisions it to again, as {@link #provisionPermissionSet} does: the same
|
||||
* ones, found once for the request.
|
||||
*/
|
||||
@Override
|
||||
public List<String> through(String member, String value, String region) {
|
||||
if (!"PermissionSetArn".equals(member) || !AwsArnUtils.isArn(value)) {
|
||||
return List.of();
|
||||
}
|
||||
String partition = AwsArnUtils.parse(value).partition();
|
||||
return provisionedAccounts(value).stream()
|
||||
.map(accountId -> AwsArnUtils.Arn.global(partition, "sso", "", "account/" + accountId).toString())
|
||||
.toList();
|
||||
}
|
||||
|
||||
private void ensurePermissionSetProvisioned(String permissionSetArn, String accountId) {
|
||||
String key = permissionSetArn + "::" + accountId;
|
||||
permissionSetProvisionings.put(key, new PermissionSetProvisioning(
|
||||
|
||||
Reference in new issue
Block a user