mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(iam): read AWS Config from the generated tables (#9296)
Move `config` from NOT_COVERED to NAMESPACES in regen_iam_request_resources.py, so Config requests are checked on the resources they name instead of `*`. A config rule's, configuration recorder's and conformance pack's ARN ends in an id Config mints, which a request naming one by its name does not carry, so ConfigStoredResourceArns answers the table's lookups with the ARN Config stores it under; one Config holds none of is checked on its name with the id open. The tag calls are read from ResourceArn. Two generic readings are added to the generator, changing Config's PutAggregationAuthorization and PutConfigurationRecorder rows and no other operation's: a format naming an account or a Region of its own beside the ARN's takes them from the request's one account id member and its one Region member, and a member filling one of the format's variables is no longer also the ARN's account; and a type the request names but fills no variable of takes its one name variable from the request's structure named after the type (ConfigurationRecorder.name). PutConfigRule now updates the rule its ConfigRuleArn names, else its ConfigRuleId, else its ConfigRuleName, as the PutConfigRule reference lets an update name its rule by any of the three, and refuses an ARN or id that names no rule with InvalidParameterValueException. Finding the rule by name alone let a request carrying one rule's id and another rule's name be checked on the first and change the second.
This commit is contained in:
1 parent
0dd02aed44
commit
422c78866d
13 files changed
+648
-10
No files matched your search
@@ -69,7 +69,8 @@ import java.util.Optional;
|
||||
* association or an access entry; Resource Groups, for the tags of a group; CloudWatch Logs, for a delivery, the
|
||||
* delivery destinations of a delivery source and the tags of a log group, a destination, a delivery source, a
|
||||
* delivery destination or a delivery; Pricing Calculator, for the tags of a workload estimate; Amazon Managed Service
|
||||
* for Prometheus, for the tags of a workspace or a rule groups namespace); looked up lazily by
|
||||
* for Prometheus, for the tags of a workspace or a rule groups namespace; AWS Config, for the config rule,
|
||||
* configuration recorder or conformance pack a name names, whose id it minted); 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>
|
||||
*
|
||||
|
||||
@@ -37,6 +37,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.BooleanSupplier;
|
||||
@@ -177,7 +178,7 @@ public class AwsConfigService {
|
||||
* the tags alone, which TagResource/UntagResource change instead. The get-then-put runs under
|
||||
* the lock delete takes, so a delete cannot land between them and orphan the creation tags. */
|
||||
public ConfigRule putConfigRule(String region, ConfigRule requested, List<Map<String, String>> tagList) {
|
||||
String ruleName = requested.configRuleName();
|
||||
String ruleName = ruleNamed(region, requested);
|
||||
if (ruleName == null) {
|
||||
throw new AwsException("InvalidParameterValueException",
|
||||
"ConfigRuleName must be specified.", 400);
|
||||
@@ -187,6 +188,29 @@ public class AwsConfigService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the rule a put acts on. The PutConfigRule reference lets an update name its rule by
|
||||
* {@code ConfigRuleName}, {@code ConfigRuleId} or {@code ConfigRuleArn}, and requires the name only of a new
|
||||
* rule: a put giving an ARN or an id acts on the stored rule it names, the ARN first, and that rule keeps its
|
||||
* name; one giving neither is the rule of its name. An ARN or id naming no rule is refused, so a put never acts
|
||||
* on another rule than the one it names.
|
||||
*/
|
||||
private String ruleNamed(String region, ConfigRule requested) {
|
||||
String arn = requested.configRuleArn();
|
||||
String id = requested.configRuleId();
|
||||
if (isBlank(arn) && isBlank(id)) {
|
||||
return requested.configRuleName();
|
||||
}
|
||||
boolean byArn = !isBlank(arn);
|
||||
return configRules.getOrDefault(region, Map.of()).values().stream()
|
||||
.filter(rule -> byArn ? arn.equals(rule.configRuleArn()) : id.equals(rule.configRuleId()))
|
||||
.map(ConfigRule::configRuleName)
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new AwsException("InvalidParameterValueException", byArn
|
||||
? "The ConfigRuleArn " + arn + " does not name a config rule in this account and Region."
|
||||
: "The ConfigRuleId " + id + " does not name a config rule in this account and Region.", 400));
|
||||
}
|
||||
|
||||
private ConfigRule storeConfigRule(String region, ConfigRule requested, String ruleName,
|
||||
List<Map<String, String>> tagList) {
|
||||
Map<String, ConfigRule> store = rulesFor(region);
|
||||
@@ -1070,6 +1094,23 @@ public class AwsConfigService {
|
||||
return new Paged<>(page, end < items.size() ? String.valueOf(end) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* The ARN the Region's config rule, configuration recorder or conformance pack of the name is stored under, which
|
||||
* carries the id the service minted for it; empty for a name it holds none of, any other type, or a recorder saved
|
||||
* before recorders had an ARN. Reads the stores without adding a Region to them.
|
||||
*/
|
||||
public Optional<String> storedArn(String type, String region, String name) {
|
||||
return switch (type) {
|
||||
case "ConfigRule" -> Optional.ofNullable(configRules.getOrDefault(region, Map.of()).get(name))
|
||||
.map(ConfigRule::configRuleArn);
|
||||
case "ConfigurationRecorder" -> Optional.ofNullable(configurationRecorders.get(region))
|
||||
.filter(recorder -> recorder.name().equals(name)).map(ConfigurationRecorder::arn);
|
||||
case "ConformancePack" -> Optional.ofNullable(conformancePacks.getOrDefault(region, Map.of()).get(name))
|
||||
.map(ConformancePack::conformancePackArn);
|
||||
default -> Optional.empty();
|
||||
};
|
||||
}
|
||||
|
||||
// --- Helpers ---
|
||||
|
||||
private Map<String, ConfigRule> rulesFor(String region) {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package io.floci.aws.services.configservice;
|
||||
|
||||
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 AWS Config of the resources a request names: the ARN the caller's config rule, configuration recorder
|
||||
* or conformance pack of the name a request gives is stored under, whose last part is the id Config minted for it,
|
||||
* which the name alone does not carry.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class ConfigStoredResourceArns implements StoredResourceArns {
|
||||
|
||||
private final AwsConfigService config;
|
||||
|
||||
@Inject
|
||||
public ConfigStoredResourceArns(AwsConfigService config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String namespace() {
|
||||
return "config";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> find(String type, List<String> names, String region) {
|
||||
if (names.size() != 1 || names.getFirst() == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return config.storedArn(type, region, names.getFirst()).filter(arn -> !arn.isBlank());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user