mirror of
https://github.com/floci-io/floci.git
synced 2026-11-26 23:29:28 -05:00
fix(iam): check four more services on the resources their requests name (#7365)
Under IAM enforcement, DataSync, EMR, Rekognition and IAM Identity
Center requests were checked on `*`, so a grant scoped to a DataSync
agent, an EMR cluster, an Identity Center permission set or a
Rekognition custom model was refused, and a deny scoped to one never
applied.
The generated table of the resources requests name now reads them, 276
operations, from AWS's Service Reference and botocore as it reads the
earlier batches: their namespaces move from the generator's
NOT_COVERED to NAMESPACES and the table is regenerated, nothing in it
edited by hand; 1385 operations over 33 namespaces. Each resource
type Floci serves has the ARN format it mints: DataSync's
`agent/agent-<id>`, `location/loc-<id>` and `task/task-<id>`, EMR's
`cluster/<id>`, and IAM Identity Center's instances and permission
sets, with no Region or account. Of Rekognition, Floci serves the image
analyses alone, which act on no resource but a custom model.
Corrections, each with its reason:
- EMR requests naming a cluster by its job flow id, JobFlowId or
JobFlowIds (AddInstanceGroups, AddJobFlowSteps, DescribeJobFlows,
TerminateJobFlows and the four Set operations), are checked on that
cluster: a job flow's id is the cluster's.
- EMR's AddTags and RemoveTags are checked on the cluster their
ResourceId names, the one Floci tags, not on the one their ClusterId
gives, which only scopes a session-scoped resource's tags. Read as
generated, a ClusterId the grant covers would have let a request tag
another cluster.
- EMR's ModifyInstanceGroups may leave out its ClusterId ("Required:
No") and name each instance group by its id alone, which EMR then
finds the cluster of. Such a request is checked on the cluster each
group is in, where it was checked on `*`; a null ClusterId is read as
none, as the handler reads it. An InstanceGroups that is not a list
names no group to the check, and the handler now refuses it as naming
none, where it modified the groups an object's values named.
- Rekognition's stream processor operations are checked on
`streamprocessor/<Name>`: the Developer Guide's example gives a
processor named streamProcessorForCam the ARN
`...:streamprocessor/streamProcessorForCam`.
- IAM Identity Center's CreateAccountAssignment,
DeleteAccountAssignment and ProvisionPermissionSet are also checked on
the account their TargetId names, `account/<id>`, which the action
acts on beside the instance and the permission set. A
ProvisionPermissionSet for ALL_PROVISIONED_ACCOUNTS names no TargetId
and provisions the permission set to every account it is provisioned
to (the User Guide: up to 3,500 accounts that way, one with
AWS_ACCOUNT), so it is checked on each of them, where a grant on the
instance and the permission set alone let it through. Its TargetId
names the account only for AWS_ACCOUNT, so a null one with
ALL_PROVISIONED_ACCOUNTS names none.
The two lookups are the existing `through` entries, which named the
cluster or workgroup a Redshift Data session runs on: one may now read
each value of a list's field, and apply only `when` the request names
its resource no other way. StoredResourceArns.through gives a list of
ARNs, which EmrService and SsoAdminService now answer from what they
store, EmrService under the lock its handlers change clusters under.
Fixes the new formats needed:
- DataSync's ARN formats, and IAM Identity Center's applications' and
trusted token issuers', name their account `${AccountId}` where every
other format has `${Account}`. The generator now reads that slot as
`${Account}`, so the caller's account fills it; a new Identity Center
application was otherwise checked on `arn:aws:sso::*:application/*/*`,
which no account-scoped grant matches.
- Identity Center's application providers are AWS's own,
`arn:aws:sso::aws:applicationProvider/<id>`. An ARN of a type whose
format fixes the account as `aws` is now checked in that account
alone, not also as the caller's own copy, which does not exist and
which a grant on the provider did not cover. An ARN of any other type
giving the account `aws` is still checked as the caller's too.
- A permission set, an application or a trusted token issuer an
Identity Center create makes is in the instance its InstanceArn
names, whose id its ARN carries, `permissionSet/<instance id>/<id>`.
It was checked with both ids open, which no grant scoped to an
instance's permission sets matched. The generator now fills a variable
no member fills from the ARN of another type the action acts on whose
format is that variable alone, given by the ARN member named after it.
Left as generated, on `*`: Rekognition's CreateStreamProcessor and
StartMediaAnalysisJob, which name their collection or model two
structures deep, where the table reads none, and which Floci does not
serve.
Elastic Beanstalk and Redshift Serverless, which have as few resource
types, stay unread, each with its reason: an environment's ARN carries
an application name its requests do not give, and Redshift Serverless'
ARNs end in ids its requests name by name, so both need the stored
ARNs found first.
iam.md lists the four services, and AWS Payment Cryptography, which
the table already read, and gives the corrections, the rule for an
AWS-owned resource's ARN, and the cluster, accounts and instance the
lookups and the creates are checked on.
This commit is contained in:
1 parent
96fafbd4dc
commit
5c303afac6
14 files changed
+987
-103
No files matched your search
@@ -50,7 +50,7 @@ final class RequestResourceMembers {
|
||||
/** The keys a resource found by members does not take: it is read no other way, in the caller's account. */
|
||||
private static final List<String> FOUND_ONLY = List.of("absent", "arnOf", "account", "fixed", "before");
|
||||
/** 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", "endpoint");
|
||||
private static final Set<String> THROUGH_KEYS = Set.of("types", "through", "when", "endpoint");
|
||||
|
||||
/**
|
||||
* A top-level request member that holds a string, or a list of them when {@code list}, or, with a
|
||||
@@ -103,6 +103,14 @@ final class RequestResourceMembers {
|
||||
return arn.substring(0, at);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether AWS owns the type's resources, its format's account being {@code aws}
|
||||
* ({@code arn:${Partition}:sso::aws:applicationProvider/...}), so an ARN of one names none of the caller's.
|
||||
*/
|
||||
boolean awsOwned() {
|
||||
return "aws".equals(format.split(":", 6)[4]); // partition-literal: the account AWS owns resources in
|
||||
}
|
||||
|
||||
/** The one variable of a format whose resource ends in it ({@code event-bus/${EventBusName}}), from an ARN of it. */
|
||||
String variable(String arn) {
|
||||
String resource = format.split(":", 6)[5];
|
||||
@@ -134,8 +142,10 @@ final class RequestResourceMembers {
|
||||
* scalable dimension). A resource with an {@code endpoint} applies only to a request the service of that endpoint
|
||||
* prefix serves, where two APIs share the operation's name and nothing in a request tells them apart
|
||||
* (EventBridge's {@code events} and EventBridge V2's {@code eventsv2}); null for every request. A resource of one
|
||||
* of {@code types} may be named {@code through} a member of one value naming a resource of its service's own the
|
||||
* table gives no type, which runs on it (a Data API session, by its {@code SessionId}), and read no other way.
|
||||
* of {@code types} may be named {@code through} a member naming, by each of its values, a resource of its
|
||||
* service's own that runs on it, is in it or reaches it (a Data API session, by its {@code SessionId}; an EMR
|
||||
* instance group, by its {@code InstanceGroups[].InstanceGroupId}), {@code when} the request gives the values it
|
||||
* names, and read no other way.
|
||||
*/
|
||||
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,
|
||||
@@ -266,15 +276,15 @@ final class RequestResourceMembers {
|
||||
}
|
||||
if (resource.has("through")) {
|
||||
List<String> types = resource.path("types").valueStream().map(JsonNode::asText).toList();
|
||||
Member through = member(operation, resource.path("through").asText(""));
|
||||
if (types.isEmpty() || !formats.keySet().containsAll(types) || through.list() || resource.properties()
|
||||
Member through = fillMember(operation, resource.path("through").asText(""));
|
||||
if (types.isEmpty() || !formats.keySet().containsAll(types) || resource.properties()
|
||||
.stream().map(Map.Entry::getKey).anyMatch(key -> !THROUGH_KEYS.contains(key))) {
|
||||
throw new IllegalStateException(RESOURCE_NAME + " names a resource of " + operation + " through "
|
||||
+ resource.path("through") + ", no member of one value naming types with a format, or beside "
|
||||
+ resource.path("through") + ", no member naming types with a format, or beside "
|
||||
+ "members reading it otherwise");
|
||||
}
|
||||
return new Resource(types, null, Map.of(), Map.of(), Map.of(), Map.of(), Map.of(), null, null, Map.of(),
|
||||
false, List.of(), endpoint, through);
|
||||
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);
|
||||
}
|
||||
if (resource.has("arn")) {
|
||||
List<String> types = resource.path("types").valueStream().map(JsonNode::asText).toList();
|
||||
|
||||
@@ -30,7 +30,7 @@ import java.util.regex.Pattern;
|
||||
* another account or Region than the request's is checked as given and as each resource of that name a handler may
|
||||
* act on instead, in the ARN's account or the caller's and in the ARN's Region or the request's, and the request is
|
||||
* refused if any is denied, as handlers mix them (ECR's tag handlers keep the ARN's account in the request's
|
||||
* Region).
|
||||
* Region); one of a resource AWS owns, whose account is {@code aws}, is checked in that account alone.
|
||||
*/
|
||||
public final class RequestResources {
|
||||
|
||||
@@ -70,7 +70,7 @@ public final class RequestResources {
|
||||
* As {@link #of(String, ContainerRequestContext, String, String, String)}, a resource of a type whose service
|
||||
* mints an id after its name, or as all of its ARN, being the one {@code stored} finds for the caller under the
|
||||
* name or the members the request gives, or else its ARN with that id open, as it is with no {@code stored}; and
|
||||
* one a request names through another of its service's own, the one {@code stored} gives, or none.
|
||||
* those a request names through another of its service's own, the ones {@code stored} gives, or none.
|
||||
*/
|
||||
public static List<String> of(String operation, ContainerRequestContext ctx, String partition, String region,
|
||||
String accountId, StoredResourceArns stored) {
|
||||
@@ -99,8 +99,8 @@ public final class RequestResources {
|
||||
for (String value : values(form, body, resource.arn())) {
|
||||
String named = before(value, resource.before());
|
||||
resource.types().stream().map(formats::get).filter(format -> format.pattern().matcher(named).matches())
|
||||
.findFirst().ifPresent(format -> addNamed(arns, format.checked(named), partition, region,
|
||||
accountId));
|
||||
.findFirst().ifPresent(format -> addNamed(arns, format.checked(named), format.awsOwned(),
|
||||
partition, region, accountId));
|
||||
}
|
||||
} else if (resource.through() != null) {
|
||||
through(arns, resource, formats, form, body, region, stored);
|
||||
@@ -152,7 +152,7 @@ public final class RequestResources {
|
||||
String under = parent.resource().substring(created.parentWord().length());
|
||||
addNamed(arns, new AwsArnUtils.Arn(parent.partition(), parent.service(), parent.region(),
|
||||
parent.accountId(), created.childWord() + under + created.separator() + "*").toString(),
|
||||
partition, region, accountId);
|
||||
false, partition, region, accountId);
|
||||
}
|
||||
}
|
||||
return List.copyOf(arns);
|
||||
@@ -319,7 +319,8 @@ public final class RequestResources {
|
||||
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));
|
||||
asArns.forEach(value -> addNamed(arns, format.checked(value), format.awsOwned(), partition, region,
|
||||
accountId));
|
||||
values = values.stream().filter(value -> !asArns.contains(value)).toList();
|
||||
if (values.isEmpty()) {
|
||||
return;
|
||||
@@ -348,7 +349,8 @@ public final class RequestResources {
|
||||
addNamed(arns, withId(render(format.format(), filling.variables(), from.partition(),
|
||||
from.region().isEmpty() ? region : from.region(),
|
||||
from.accountId().isEmpty() ? accountId : from.accountId()), format,
|
||||
resource.types().getFirst(), filling.variables(), null, region), partition, region, accountId);
|
||||
resource.types().getFirst(), filling.variables(), null, region), format.awsOwned(), partition,
|
||||
region, accountId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -380,21 +382,23 @@ public final class RequestResources {
|
||||
}
|
||||
|
||||
/**
|
||||
* The resource of one of the types a request names through a member naming another of its service's own, which
|
||||
* runs on it ({@code through}), when the request gives it one value: the ARN {@code stored} gives for the caller's
|
||||
* resource of that name; none when there is no such resource, which its handler refuses.
|
||||
* The resources of the types a request names through a member naming another of its service's own, which runs on
|
||||
* them, is in them or reaches them ({@code through}), for each value the request gives it: the ARNs
|
||||
* {@code stored} gives for the caller's resource of that name; none for a value naming no such resource, which
|
||||
* its handler refuses.
|
||||
*/
|
||||
private static void through(Set<String> arns, RequestResourceMembers.Resource resource,
|
||||
Map<String, RequestResourceMembers.ArnFormat> formats, Map<String, String> form,
|
||||
JsonNode body, String region, StoredResourceArns stored) {
|
||||
List<String> values = values(form, body, resource.through());
|
||||
if (stored == null || isNull(body, resource.through()) || values.size() != 1) {
|
||||
if (stored == null || isNull(body, resource.through())) {
|
||||
return;
|
||||
}
|
||||
stored.through(resource.through().name(), values.getFirst(), region)
|
||||
.filter(arn -> resource.types().stream().map(formats::get)
|
||||
.anyMatch(format -> format.pattern().matcher(arn).matches()))
|
||||
.ifPresent(arns::add);
|
||||
for (String value : values(form, body, resource.through())) {
|
||||
stored.through(resource.through().path(), value, region).stream()
|
||||
.filter(arn -> resource.types().stream().map(formats::get)
|
||||
.anyMatch(format -> format.pattern().matcher(arn).matches()))
|
||||
.forEach(arns::add);
|
||||
}
|
||||
}
|
||||
|
||||
/** Whether a member that may give an ARN of a type instead of its name gives one. */
|
||||
@@ -450,15 +454,18 @@ public final class RequestResources {
|
||||
/**
|
||||
* An ARN the request names: as given, and, when it names another partition, account or Region than the
|
||||
* request's, as each resource of that name in the request's partition, in the ARN's account or the caller's and
|
||||
* the ARN's Region or the request's, whichever its handler acts on. An ARN with no account or Region keeps none.
|
||||
* the ARN's Region or the request's, whichever its handler acts on. An ARN with no account or Region keeps none,
|
||||
* and one of a type AWS owns ({@code awsOwned}) its account, {@code aws}, which is no caller's.
|
||||
*/
|
||||
private static void addNamed(Set<String> arns, String arn, String partition, String region, String accountId) {
|
||||
private static void addNamed(Set<String> arns, String arn, boolean awsOwned, String partition, String region,
|
||||
String accountId) {
|
||||
arns.add(arn);
|
||||
if (!AwsArnUtils.isArn(arn)) {
|
||||
return;
|
||||
}
|
||||
AwsArnUtils.Arn named = AwsArnUtils.parse(arn);
|
||||
List<String> accounts = named.accountId().isEmpty() ? List.of("") : List.of(named.accountId(), accountId);
|
||||
List<String> accounts = named.accountId().isEmpty() || awsOwned ? List.of(named.accountId())
|
||||
: List.of(named.accountId(), accountId);
|
||||
List<String> regions = named.region().isEmpty() ? List.of("") : List.of(named.region(), region);
|
||||
for (String account : accounts) {
|
||||
for (String inRegion : regions) {
|
||||
|
||||
@@ -8,8 +8,9 @@ import java.util.Optional;
|
||||
* service knows: after the name a request gives ({@code connection/<name>/<id>}), or as all of it, a request naming
|
||||
* the resource by members its ARN does not hold
|
||||
* ({@code scalable-target/<id>}, named by its service namespace, resource id and scalable dimension;
|
||||
* {@code workgroup/<id>}, named by its name). Also the ARN of a resource a request names through another of its
|
||||
* service's own, which the table gives no type (the cluster or workgroup a Data API session runs on).
|
||||
* {@code workgroup/<id>}, named by its name). Also the ARNs of the resources a request names through another of its
|
||||
* service's own (the cluster or workgroup a Data API session runs on, the cluster an EMR instance group is in, the
|
||||
* accounts an IAM Identity Center permission set is provisioned to).
|
||||
*
|
||||
* <p>The reader asks for every type of the namespace, not only for the ones whose ARN carries an id the service
|
||||
* mints, so a service may answer for a type whose ARN it does not mint: a key an alias names is the key the alias
|
||||
@@ -18,7 +19,8 @@ import java.util.Optional;
|
||||
* <p>Implemented by the service that owns such resources or whose requests name them (EventBridge, for its
|
||||
* connections and API destinations; Application Auto Scaling, for its scalable targets; Redshift Data, for the
|
||||
* Redshift Serverless workgroups it runs statements on and the targets of its sessions; Payment Cryptography, for
|
||||
* the key an alias names); looked up lazily by {@code ResourceArnBuilder} through {@code Instance<StoredResourceArns>}
|
||||
* the key an alias names; EMR, for the clusters of its instance groups; IAM Identity Center, for the accounts its
|
||||
* permission sets are provisioned to); 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>
|
||||
*/
|
||||
public interface StoredResourceArns {
|
||||
@@ -35,12 +37,14 @@ public interface StoredResourceArns {
|
||||
Optional<String> find(String type, List<String> names, String region);
|
||||
|
||||
/**
|
||||
* The ARN of the resource the caller's resource named by {@code value} in its {@code member} runs on in the
|
||||
* Region, as a request naming it runs there (the cluster or workgroup of a Data API session, by its
|
||||
* {@code SessionId}); empty when the caller has none of that name, or the member is not one it reads.
|
||||
* The ARNs of the resources the caller's resource named by {@code value} in {@code member}, as the table writes
|
||||
* the member's path, runs on, is in or reaches in the Region, which a request naming it acts on (the cluster or
|
||||
* workgroup of a Data API session, by its {@code SessionId}; the cluster of an instance group, by its
|
||||
* {@code InstanceGroups[].InstanceGroupId}; the accounts of a permission set, by its {@code PermissionSetArn});
|
||||
* empty when the caller has none of that name, or the member is not one it reads.
|
||||
*/
|
||||
default Optional<String> through(String member, String value, String region) {
|
||||
return Optional.empty();
|
||||
default List<String> through(String member, String value, String region) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -462,13 +462,18 @@ public class EmrHandler {
|
||||
|
||||
private Response handleModifyInstanceGroups(JsonNode request, String region) {
|
||||
List<EmrService.InstanceGroupModification> modifications = new ArrayList<>();
|
||||
for (JsonNode g : request.path("InstanceGroups")) {
|
||||
JsonNode count = g.path("InstanceCount");
|
||||
JsonNode configurations = g.path("Configurations");
|
||||
modifications.add(new EmrService.InstanceGroupModification(
|
||||
g.path("InstanceGroupId").asText(null),
|
||||
count.isMissingNode() || count.isNull() ? null : count.asInt(),
|
||||
configurations.isArray() ? configurations.toString() : null));
|
||||
// Only a list names groups, as the other list members here and the IAM check read one: any other
|
||||
// InstanceGroups names none, which the service refuses.
|
||||
JsonNode groups = request.path("InstanceGroups");
|
||||
if (groups.isArray()) {
|
||||
for (JsonNode g : groups) {
|
||||
JsonNode count = g.path("InstanceCount");
|
||||
JsonNode configurations = g.path("Configurations");
|
||||
modifications.add(new EmrService.InstanceGroupModification(
|
||||
g.path("InstanceGroupId").asText(null),
|
||||
count.isMissingNode() || count.isNull() ? null : count.asInt(),
|
||||
configurations.isArray() ? configurations.toString() : null));
|
||||
}
|
||||
}
|
||||
service.modifyInstanceGroups(text(request, "ClusterId"), region, modifications);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
|
||||
@@ -14,6 +14,7 @@ import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.RequestScopes;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
|
||||
import io.github.hectorvent.floci.core.common.StoredResourceArns;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
@@ -74,7 +75,7 @@ import java.util.function.Supplier;
|
||||
* BOOTSTRAPPING, and leave the image its steps then run in.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class EmrService implements Resettable {
|
||||
public class EmrService implements Resettable, StoredResourceArns {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(EmrService.class);
|
||||
private static final String UPPER_ALNUM = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
@@ -584,6 +585,28 @@ public class EmrService implements Resettable {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String namespace() {
|
||||
return "elasticmapreduce";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> find(String type, List<String> names, String region) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@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();
|
||||
}
|
||||
|
||||
public List<EmrInstanceGroup> listInstanceGroups(String clusterId) {
|
||||
return call(() -> snapshotOf(requireCluster(clusterId)).getInstanceGroups());
|
||||
}
|
||||
@@ -1024,12 +1047,17 @@ public class EmrService implements Resettable {
|
||||
if (instanceGroupId == null) {
|
||||
throw invalid("InstanceGroupId is required.");
|
||||
}
|
||||
return clusterWithGroup(region, instanceGroupId)
|
||||
.map(this::settle)
|
||||
.orElseThrow(() -> invalid("Instance group " + instanceGroupId + " is not valid."));
|
||||
}
|
||||
|
||||
/** The caller's cluster in the Region that has the instance group, as stored. */
|
||||
private Optional<EmrCluster> clusterWithGroup(String region, String instanceGroupId) {
|
||||
return clusterStore.scan(k -> true).stream()
|
||||
.filter(c -> region.equals(c.getRegion()))
|
||||
.filter(c -> c.getInstanceGroups().stream().anyMatch(g -> instanceGroupId.equals(g.getId())))
|
||||
.findFirst()
|
||||
.map(this::settle)
|
||||
.orElseThrow(() -> invalid("Instance group " + instanceGroupId + " is not valid."));
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
private static AwsException invalid(String message) {
|
||||
|
||||
+3
-2
@@ -234,8 +234,9 @@ public class RedshiftDataService implements Resettable, StoredResourceArns {
|
||||
|
||||
/** The cluster or workgroup the caller's open session runs on, named by its {@code SessionId}, as it reads it. */
|
||||
@Override
|
||||
public Optional<String> through(String member, String value, String region) {
|
||||
return "SessionId".equals(member) ? sessions.targetArn(sessionScope(region, null), value) : Optional.empty();
|
||||
public List<String> through(String member, String value, String region) {
|
||||
return "SessionId".equals(member) ? sessions.targetArn(sessionScope(region, null), value).stream().toList()
|
||||
: List.of();
|
||||
}
|
||||
|
||||
private Admission replay(RedshiftDataIdempotencyStore.Receipt receipt, RedshiftDataIdempotencyStore.Scope scope,
|
||||
|
||||
@@ -10,6 +10,7 @@ import io.github.hectorvent.floci.core.common.EpochSeconds;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.Pagination;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import io.github.hectorvent.floci.core.common.StoredResourceArns;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
@@ -64,7 +65,7 @@ import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ApplicationScoped
|
||||
public class SsoAdminService implements Resettable {
|
||||
public class SsoAdminService implements Resettable, StoredResourceArns {
|
||||
private static final String BOOTSTRAP_INSTANCE = "instance/ssoins-7223b02a5d9f7c8e";
|
||||
private static final String IDENTITY_STORE_ID = "d-9067f2a3c1";
|
||||
private static final Pattern INSTANCE_ARN_PATTERN = Pattern.compile("arn:" + AwsArnUtils.PARTITION_REGEX + ":sso:::instance/(?:sso)?ins-[a-zA-Z0-9-.]{16}");
|
||||
@@ -1874,10 +1875,7 @@ public class SsoAdminService implements Resettable {
|
||||
if (targetId != null) {
|
||||
throw validation("TargetId must not be provided when TargetType is ALL_PROVISIONED_ACCOUNTS.");
|
||||
}
|
||||
permissionSetProvisionings.scan(key -> true).stream()
|
||||
.filter(provisioning -> permissionSetArn.equals(provisioning.permissionSetArn()))
|
||||
.map(PermissionSetProvisioning::accountId)
|
||||
.distinct()
|
||||
provisionedAccounts(permissionSetArn)
|
||||
.forEach(accountId -> ensurePermissionSetProvisioned(permissionSetArn, accountId));
|
||||
} else {
|
||||
throw validation("TargetType must be AWS_ACCOUNT or ALL_PROVISIONED_ACCOUNTS.");
|
||||
@@ -1889,6 +1887,40 @@ public class SsoAdminService implements Resettable {
|
||||
return operation;
|
||||
}
|
||||
|
||||
/** The accounts the permission set is provisioned to. */
|
||||
private List<String> provisionedAccounts(String permissionSetArn) {
|
||||
return permissionSetProvisionings.scan(key -> true).stream()
|
||||
.filter(provisioning -> permissionSetArn.equals(provisioning.permissionSetArn()))
|
||||
.map(PermissionSetProvisioning::accountId)
|
||||
.distinct()
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String namespace() {
|
||||
return "sso";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> find(String type, List<String> names, String region) {
|
||||
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.
|
||||
*/
|
||||
@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