mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(accessanalyzer): give resource-tag conditions the tags of the analyzer a request names (#8778)
The generated request resources give Access Analyzer's Analyzer type the aws:ResourceTag/ key, but no service answered the access-analyzer namespace's stored tags, so a condition on an analyzer's tags saw none. AccessAnalyzerService now answers it: storedTags reads the analyzer stored under the Region the ARN names and its name, in the request's account, where the handlers read, in place, and matched on the whole ARN. An analyzer's tags are set when it is created and never change.
This commit is contained in:
1 parent
523eba559e
commit
8e88ba0915
5 files changed
+97
-7
No files matched your search
@@ -46,9 +46,9 @@ import java.util.Optional;
|
||||
* reference resolves to, its default cluster and the tags of a cluster, a task definition, a service, a capacity
|
||||
* provider, a task or a container instance; ACM, for the tags of a certificate; Firehose, for the tags of a delivery
|
||||
* stream; Cognito, for the tags of a user pool or an identity pool; OpenSearch, for the tags of a domain; Signer, for
|
||||
* the tags of a signing profile); looked up lazily by {@code ResourceArnBuilder} and
|
||||
* {@code IamConditionContextResolver} through {@code Instance<StoredResourceArns>} for the namespace a request or an
|
||||
* ARN is of, so IAM never depends on that service directly.</p>
|
||||
* the tags of a signing profile; Access Analyzer, for the tags of an analyzer); looked up lazily by
|
||||
* {@code ResourceArnBuilder} and {@code IamConditionContextResolver} through {@code Instance<StoredResourceArns>} for
|
||||
* the namespace a request or an ARN 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, {@code forwarded}, a type's {@code resourceTagKeys}): never a fact about what an operation acts on, which the table alone
|
||||
|
||||
@@ -2,11 +2,13 @@ package io.floci.aws.services.accessanalyzer;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.floci.aws.core.common.AwsArnUtils;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.PaginatedResult;
|
||||
import io.floci.aws.core.common.Pagination;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.common.Resettable;
|
||||
import io.floci.aws.core.common.StoredResourceArns;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.core.storage.StorageFactory;
|
||||
import io.floci.aws.services.accessanalyzer.model.Analyzer;
|
||||
@@ -17,11 +19,12 @@ import java.time.Instant;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ApplicationScoped
|
||||
public class AccessAnalyzerService implements Resettable {
|
||||
public class AccessAnalyzerService implements Resettable, StoredResourceArns {
|
||||
private static final Pattern ANALYZER_NAME = Pattern.compile("[A-Za-z][A-Za-z0-9_.-]*");
|
||||
private static final Set<String> ANALYZER_TYPES = Set.of(
|
||||
"ACCOUNT",
|
||||
@@ -88,6 +91,40 @@ public class AccessAnalyzerService implements Resettable {
|
||||
analyzers.delete(storageKey(region, analyzerName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String namespace() {
|
||||
return "access-analyzer";
|
||||
}
|
||||
|
||||
/** A request names an analyzer by its name, which its ARN carries whole, so there is nothing to find. */
|
||||
@Override
|
||||
public Optional<String> find(String type, List<String> names, String region) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* The tags of the analyzer whose ARN is {@code arn}, in the request's account, where the handlers read: an ARN of
|
||||
* another account names none. Read in place under the Region the ARN names and the analyzer's name, an analyzer
|
||||
* stored before storage was account-aware included, and matched on the whole ARN. An analyzer's tags are set
|
||||
* when it is created, before it is stored, and never change.
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> storedTags(String arn) {
|
||||
if (!AwsArnUtils.isArnFor(arn, "access-analyzer")) {
|
||||
return Map.of();
|
||||
}
|
||||
AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
|
||||
if (!parsed.accountId().equals(regionResolver.getAccountId()) || !parsed.resource().startsWith("analyzer/")) {
|
||||
return Map.of();
|
||||
}
|
||||
Map<String, String> tags = AccountAwareStorageBackend.readInAccount(analyzers, parsed.accountId(),
|
||||
storageKey(parsed.region(), parsed.resource().substring("analyzer/".length())))
|
||||
.filter(analyzer -> arn.equals(analyzer.getArn()))
|
||||
.map(Analyzer::getTags)
|
||||
.orElse(Map.of());
|
||||
return new LinkedHashMap<>(tags);
|
||||
}
|
||||
|
||||
private static int analyzerLimit(String type) {
|
||||
return switch (type) {
|
||||
case "ORGANIZATION", "ORGANIZATION_UNUSED_ACCESS" -> 5;
|
||||
|
||||
Reference in new issue
Block a user