mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(config): give the configuration recorder an ARN and keep its tags (#8117)
This commit is contained in:
1 parent
bb689885a3
commit
acdbde836a
8 files changed
+302
-45
No files matched your search
@@ -195,14 +195,15 @@ aws configservice delete-config-rule --config-rule-name s3-bucket-versioning
|
||||
`DeleteAggregationAuthorization` on an authorization that does not exist succeeds,
|
||||
because the Config API models no "not found" error for that operation.
|
||||
- `TagResource`, `UntagResource` and `ListTagsForResource` answer
|
||||
`ResourceNotFoundException` for a config rule, conformance pack or aggregation
|
||||
authorization ARN that does not name an existing resource in the caller's account and
|
||||
region. ARNs of resource kinds Floci does not model (configuration aggregators, stored
|
||||
queries, organization rules and packs, recorders) are accepted without a check.
|
||||
`ResourceNotFoundException` for a config rule, conformance pack, aggregation
|
||||
authorization or configuration recorder ARN that does not name an existing resource in the
|
||||
caller's account and region. ARNs of resource kinds Floci does not model (configuration
|
||||
aggregators, stored queries, organization rules and packs) are accepted without a check.
|
||||
- `PutConfigRule` applies its `Tags` only when it creates the rule; a later
|
||||
`PutConfigRule` for the same rule leaves its tags unchanged, as AWS documents. Use
|
||||
`TagResource` and `UntagResource` to change them. `DeleteConfigRule` drops the rule's tags.
|
||||
`PutConfigurationRecorder` and `DeleteConfigurationRecorder` do the same for the recorder.
|
||||
- `PutConfigRule` and `PutAggregationAuthorization` reject more than 50 `Tags`, a tag
|
||||
without a 1-128 character `Key`, or a `Value` over 256 characters with
|
||||
`InvalidParameterValueException`, and store nothing. A tag with no `Value` is stored with
|
||||
an empty value.
|
||||
`InvalidParameterValueException`, and store nothing. `PutConfigurationRecorder` rejects
|
||||
the same with `ValidationException`. A tag with no `Value` is stored with an empty value.
|
||||
@@ -684,11 +684,31 @@ public class AwsConfigService {
|
||||
|
||||
// --- Configuration Recorder ---
|
||||
|
||||
public void putConfigurationRecorder(String region, ConfigurationRecorder recorder) {
|
||||
/** Put is an upsert, and request tags are applied at creation only, as for config rules: the
|
||||
* PutConfigurationRecorder model says a later Put with different Tags leaves them unchanged.
|
||||
* A Put under another name replaces the recorder, so it gets a new ARN and the old one's tags
|
||||
* go. A recorder saved before recorders had an ARN gets one on its next Put. */
|
||||
public void putConfigurationRecorder(String region, ConfigurationRecorder recorder,
|
||||
List<Map<String, String>> tagList) {
|
||||
String name = (recorder.name() == null || recorder.name().isEmpty()) ? "default" : recorder.name();
|
||||
ConfigurationRecorder stored = new ConfigurationRecorder(name, recorder.roleARN(), recorder.recordingGroup(),
|
||||
recorder.recordingMode());
|
||||
configurationRecorders.put(region, stored);
|
||||
synchronized (lockFor(recorderLockKey(region))) {
|
||||
ConfigurationRecorder existing = configurationRecorders.get(region);
|
||||
boolean created = existing == null || !existing.name().equals(name);
|
||||
String arn = created || existing.arn() == null
|
||||
? AwsArnUtils.Arn.of("config", region, regionResolver.getAccountId(),
|
||||
"configuration-recorder/" + name + "/" + shortId()).toString()
|
||||
: existing.arn();
|
||||
// Tags before the recorder, as storeConfigRule does: a retry after a failed tag write
|
||||
// finds no recorder and creates both.
|
||||
if (created && tagList != null && !tagList.isEmpty()) {
|
||||
applyTags(arn, tagList);
|
||||
}
|
||||
configurationRecorders.put(region, new ConfigurationRecorder(arn, name, recorder.roleARN(),
|
||||
recorder.recordingGroup(), recorder.recordingMode()));
|
||||
if (created && existing != null) {
|
||||
tags.remove(existing.arn());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<ConfigurationRecorder> describeConfigurationRecorders(String region, List<String> names) {
|
||||
@@ -712,15 +732,22 @@ public class AwsConfigService {
|
||||
}
|
||||
|
||||
public void deleteConfigurationRecorder(String region, String name) {
|
||||
ConfigurationRecorder recorder = configurationRecorders.get(region);
|
||||
if (recorder == null || !recorder.name().equals(name)) {
|
||||
throw new AwsException("NoSuchConfigurationRecorderException",
|
||||
"Cannot find configuration recorder with the specified name.", 400);
|
||||
synchronized (lockFor(recorderLockKey(region))) {
|
||||
ConfigurationRecorder recorder = configurationRecorders.get(region);
|
||||
if (recorder == null || !recorder.name().equals(name)) {
|
||||
throw new AwsException("NoSuchConfigurationRecorderException",
|
||||
"Cannot find configuration recorder with the specified name.", 400);
|
||||
}
|
||||
configurationRecorders.remove(region);
|
||||
tags.remove(recorder.arn());
|
||||
recorderRunning.remove(runtimeKey(region));
|
||||
recorderLastStartTime.remove(runtimeKey(region));
|
||||
recorderLastStopTime.remove(runtimeKey(region));
|
||||
}
|
||||
configurationRecorders.remove(region);
|
||||
recorderRunning.remove(runtimeKey(region));
|
||||
recorderLastStartTime.remove(runtimeKey(region));
|
||||
recorderLastStopTime.remove(runtimeKey(region));
|
||||
}
|
||||
|
||||
private String recorderLockKey(String region) {
|
||||
return "configuration-recorder|" + runtimeKey(region);
|
||||
}
|
||||
|
||||
public void startConfigurationRecorder(String region, String name) {
|
||||
@@ -1023,12 +1050,13 @@ public class AwsConfigService {
|
||||
// --- Tagging ---
|
||||
|
||||
/** TagResource, UntagResource and ListTagsForResource each model ResourceNotFoundException.
|
||||
* For the kinds Floci stores (config rules, conformance packs, aggregation authorizations)
|
||||
* the ARN must name a resource that exists in the caller's account and the request Region,
|
||||
* so a deleted resource, or one in another account, Region or partition, is not found. The
|
||||
* check and the tag write run under the lock that resource's delete takes, so a delete cannot
|
||||
* land between them and leave an orphan tag entry for a resource that is gone. ARNs of kinds
|
||||
* Floci does not model are passed through unchecked, as before. */
|
||||
* For the kinds Floci stores (config rules, conformance packs, aggregation authorizations,
|
||||
* configuration recorders) the ARN must name a resource that exists in the caller's account
|
||||
* and the request Region, so a deleted resource, or one in another account, Region or
|
||||
* partition, is not found. The check and the tag write run under the lock that resource's
|
||||
* delete takes, so a delete cannot land between them and leave an orphan tag entry for a
|
||||
* resource that is gone. ARNs of kinds Floci does not model are passed through unchecked,
|
||||
* as before. */
|
||||
public void tagResource(String region, String arn, List<Map<String, String>> tagList) {
|
||||
onTaggableResource(region, arn, () -> {
|
||||
applyTags(arn, tagList);
|
||||
@@ -1104,6 +1132,13 @@ public class AwsConfigService {
|
||||
return rule != null && arn.equals(rule.configRuleArn());
|
||||
};
|
||||
}
|
||||
case "configuration-recorder" -> {
|
||||
lockKey = recorderLockKey(region);
|
||||
exists = () -> {
|
||||
ConfigurationRecorder recorder = configurationRecorders.get(region);
|
||||
return recorder != null && arn.equals(recorder.arn());
|
||||
};
|
||||
}
|
||||
default -> {
|
||||
return action.get();
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public class ConfigServiceJsonHandler {
|
||||
private Response putConfigRule(JsonNode req, String region) throws Exception {
|
||||
JsonNode ruleNode = req.path("ConfigRule");
|
||||
ConfigRule rule = ruleNode.isObject() ? mapper.treeToValue(ruleNode, ConfigRule.class) : null;
|
||||
service.putConfigRule(region, rule, extractCreationTags(req));
|
||||
service.putConfigRule(region, rule, extractCreationTags(req, "InvalidParameterValueException"));
|
||||
return Response.ok(mapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ public class ConfigServiceJsonHandler {
|
||||
|
||||
private Response putConfigurationRecorder(JsonNode req, String region) throws Exception {
|
||||
ConfigurationRecorder recorder = mapper.treeToValue(req.path("ConfigurationRecorder"), ConfigurationRecorder.class);
|
||||
service.putConfigurationRecorder(region, recorder);
|
||||
service.putConfigurationRecorder(region, recorder, extractCreationTags(req, "ValidationException"));
|
||||
return Response.ok(mapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
@@ -315,7 +315,7 @@ public class ConfigServiceJsonHandler {
|
||||
AggregationAuthorization authorization = service.putAggregationAuthorization(region,
|
||||
req.path("AuthorizedAccountId").asText(null),
|
||||
req.path("AuthorizedAwsRegion").asText(null),
|
||||
extractCreationTags(req));
|
||||
extractCreationTags(req, "InvalidParameterValueException"));
|
||||
ObjectNode resp = mapper.createObjectNode();
|
||||
resp.set("AggregationAuthorization", mapper.valueToTree(authorization));
|
||||
return Response.ok(resp).build();
|
||||
@@ -368,22 +368,22 @@ public class ConfigServiceJsonHandler {
|
||||
return tagList;
|
||||
}
|
||||
|
||||
/** PutConfigRule and PutAggregationAuthorization take a {@code TagsList} (config/2014-11-12:
|
||||
* at most 50 {@code Tag}s, Key 1-128 characters, optional Value of at most 256) and model
|
||||
* {@code InvalidParameterValueException} as their only parameter error. Checked before the
|
||||
* service stores anything, so a rejected request leaves no resource behind. An absent Value
|
||||
* is optional in the model and is stored as the empty string. */
|
||||
private List<Map<String, String>> extractCreationTags(JsonNode req) {
|
||||
/** PutConfigRule, PutAggregationAuthorization and PutConfigurationRecorder take a
|
||||
* {@code TagsList} (config/2014-11-12: at most 50 {@code Tag}s, Key 1-128 characters,
|
||||
* optional Value of at most 256). The first two model {@code InvalidParameterValueException}
|
||||
* as their only parameter error; PutConfigurationRecorder models {@code ValidationException}.
|
||||
* Checked before the service stores anything, so a rejected request leaves no resource
|
||||
* behind. An absent Value is optional in the model and is stored as the empty string. */
|
||||
private List<Map<String, String>> extractCreationTags(JsonNode req, String errorCode) {
|
||||
JsonNode tags = req.path("Tags");
|
||||
if (tags.isMissingNode() || tags.isNull()) {
|
||||
return List.of();
|
||||
}
|
||||
if (!tags.isArray()) {
|
||||
throw new AwsException("InvalidParameterValueException", "Tags must be a list.", 400);
|
||||
throw new AwsException(errorCode, "Tags must be a list.", 400);
|
||||
}
|
||||
if (tags.size() > 50) {
|
||||
throw new AwsException("InvalidParameterValueException",
|
||||
"Tags must contain at most 50 tags.", 400);
|
||||
throw new AwsException(errorCode, "Tags must contain at most 50 tags.", 400);
|
||||
}
|
||||
for (JsonNode tag : tags) {
|
||||
JsonNode key = tag.path("Key");
|
||||
@@ -391,7 +391,7 @@ public class ConfigServiceJsonHandler {
|
||||
boolean valueOk = value.isMissingNode() || value.isNull()
|
||||
|| (value.isTextual() && value.asText().length() <= 256);
|
||||
if (!key.isTextual() || key.asText().isEmpty() || key.asText().length() > 128 || !valueOk) {
|
||||
throw new AwsException("InvalidParameterValueException",
|
||||
throw new AwsException(errorCode,
|
||||
"Each tag needs a Key of 1-128 characters and a Value of at most 256 characters.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record ConfigurationRecorder(
|
||||
@JsonProperty("arn") String arn,
|
||||
@JsonProperty("name") String name,
|
||||
@JsonProperty("roleARN") String roleARN,
|
||||
@JsonProperty("recordingGroup") RecordingGroup recordingGroup,
|
||||
|
||||
+2
-1
@@ -46,7 +46,8 @@ class AwsConfigAccountIsolationTest {
|
||||
void recorderStartStopAndDeletionStayInTheirAccount() {
|
||||
for (String account : List.of(FIRST, SECOND)) {
|
||||
context.setAccountId(account);
|
||||
service.putConfigurationRecorder(REGION, new ConfigurationRecorder("default", "role", null, null));
|
||||
service.putConfigurationRecorder(REGION, new ConfigurationRecorder(null, "default", "role", null, null),
|
||||
null);
|
||||
service.putDeliveryChannel(REGION, new DeliveryChannel("default", "bucket", null, null, null, null));
|
||||
}
|
||||
context.setAccountId(FIRST);
|
||||
|
||||
+11
-7
@@ -42,11 +42,13 @@ class AwsConfigServicePersistenceTest {
|
||||
ConfigRule rule = first.putConfigRule(REGION,
|
||||
rule("s3-public-read", "AWS", "S3_BUCKET_PUBLIC_READ_PROHIBITED"));
|
||||
first.putConformancePack(REGION, "ops-pack", "s3://bucket/template.yaml", null);
|
||||
first.putConfigurationRecorder(REGION, new ConfigurationRecorder("default",
|
||||
"arn:aws:iam::000000000000:role/config", new RecordingGroup(true, false, null, null, null), null));
|
||||
first.putConfigurationRecorder(REGION, new ConfigurationRecorder(null, "default",
|
||||
"arn:aws:iam::000000000000:role/config", new RecordingGroup(true, false, null, null, null), null),
|
||||
null);
|
||||
first.putDeliveryChannel(REGION,
|
||||
new DeliveryChannel("default", "config-bucket", null, null, null, null));
|
||||
first.tagResource(REGION, rule.configRuleArn(), List.of(Map.of("Key", "env", "Value", "prod")));
|
||||
String recorderArn = first.describeConfigurationRecorders(REGION, null).getFirst().arn();
|
||||
|
||||
AwsConfigService reloaded = restartedService();
|
||||
|
||||
@@ -57,6 +59,7 @@ class AwsConfigServicePersistenceTest {
|
||||
.map(p -> p.conformancePackName()).toList());
|
||||
assertEquals("default",
|
||||
reloaded.describeConfigurationRecorders(REGION, null).getFirst().name());
|
||||
assertEquals(recorderArn, reloaded.describeConfigurationRecorders(REGION, null).getFirst().arn());
|
||||
assertEquals("config-bucket",
|
||||
reloaded.describeDeliveryChannels(REGION, null).getFirst().s3BucketName());
|
||||
assertEquals("prod", reloaded.listTagsForResource(REGION, rule.configRuleArn()).getFirst().get("Value"));
|
||||
@@ -139,8 +142,9 @@ class AwsConfigServicePersistenceTest {
|
||||
@Test
|
||||
void aStartedRecorderIsStillRecordingAfterRestart() {
|
||||
AwsConfigService first = restartedService();
|
||||
first.putConfigurationRecorder(REGION, new ConfigurationRecorder("default",
|
||||
"arn:aws:iam::000000000000:role/config", new RecordingGroup(true, false, null, null, null), null));
|
||||
first.putConfigurationRecorder(REGION, new ConfigurationRecorder(null, "default",
|
||||
"arn:aws:iam::000000000000:role/config", new RecordingGroup(true, false, null, null, null), null),
|
||||
null);
|
||||
first.putDeliveryChannel(REGION,
|
||||
new DeliveryChannel("default", "config-bucket", null, null, null, null));
|
||||
first.startConfigurationRecorder(REGION, "default");
|
||||
@@ -168,16 +172,16 @@ class AwsConfigServicePersistenceTest {
|
||||
@Test
|
||||
void aDeletedRecorderDoesNotComeBackRecordingAfterRestart() {
|
||||
AwsConfigService first = restartedService();
|
||||
ConfigurationRecorder recorder = new ConfigurationRecorder("default",
|
||||
ConfigurationRecorder recorder = new ConfigurationRecorder(null, "default",
|
||||
"arn:aws:iam::000000000000:role/config", new RecordingGroup(true, false, null, null, null), null);
|
||||
first.putConfigurationRecorder(REGION, recorder);
|
||||
first.putConfigurationRecorder(REGION, recorder, null);
|
||||
first.putDeliveryChannel(REGION,
|
||||
new DeliveryChannel("default", "config-bucket", null, null, null, null));
|
||||
first.startConfigurationRecorder(REGION, "default");
|
||||
first.deleteConfigurationRecorder(REGION, "default");
|
||||
|
||||
AwsConfigService reloaded = restartedService();
|
||||
reloaded.putConfigurationRecorder(REGION, recorder);
|
||||
reloaded.putConfigurationRecorder(REGION, recorder, null);
|
||||
|
||||
ConfigurationRecorderStatus status =
|
||||
reloaded.describeConfigurationRecorderStatus(REGION, null).getFirst();
|
||||
|
||||
@@ -2,10 +2,12 @@ package io.floci.aws.services.configservice;
|
||||
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.core.storage.InMemoryStorage;
|
||||
import io.floci.aws.core.storage.StorageBackend;
|
||||
import io.floci.aws.services.configservice.model.ConfigRule;
|
||||
import io.floci.aws.services.configservice.model.ConfigRuleSource;
|
||||
import io.floci.aws.services.configservice.model.ConfigurationRecorder;
|
||||
import io.floci.aws.testing.InMemoryStorageFactory;
|
||||
import io.floci.aws.testing.ParkingStore;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -24,6 +26,8 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
import static io.floci.aws.testing.ThreadStates.awaitBlockedOrDone;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@@ -37,6 +41,7 @@ class AwsConfigServiceTaggingTest {
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String ACCOUNT = "000000000000";
|
||||
private static final List<Map<String, String>> ENV_PROD = List.of(Map.of("Key", "env", "Value", "prod"));
|
||||
private static final List<Map<String, String>> TEAM_RED = List.of(Map.of("Key", "team", "Value", "red"));
|
||||
|
||||
private AwsConfigService service() {
|
||||
return new AwsConfigService(new RegionResolver(REGION, ACCOUNT), null);
|
||||
@@ -154,6 +159,74 @@ class AwsConfigServiceTaggingTest {
|
||||
assertAllThreeNotFound(service, REGION, arn);
|
||||
}
|
||||
|
||||
@Test
|
||||
void putConfigurationRecorderMintsAnArnAndAppliesRequestTagsAtCreationOnly() {
|
||||
AwsConfigService service = service();
|
||||
service.putConfigurationRecorder(REGION, recorder("default"), ENV_PROD);
|
||||
String arn = recorderArn(service);
|
||||
assertTrue(arn.startsWith("arn:aws:config:us-east-1:000000000000:configuration-recorder/default/"), arn);
|
||||
assertEquals(ENV_PROD, service.listTagsForResource(REGION, arn));
|
||||
|
||||
service.putConfigurationRecorder(REGION, recorder("default"), List.of(Map.of("Key", "env", "Value", "dev")));
|
||||
|
||||
assertEquals(arn, recorderArn(service));
|
||||
assertEquals(ENV_PROD, service.listTagsForResource(REGION, arn));
|
||||
service.tagResource(REGION, arn, TEAM_RED);
|
||||
service.untagResource(REGION, arn, List.of("env"));
|
||||
assertEquals(TEAM_RED, service.listTagsForResource(REGION, arn));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletingARecorderDropsItsTagsAndARecreatedRecorderGetsANewArn() {
|
||||
AwsConfigService service = service();
|
||||
service.putConfigurationRecorder(REGION, recorder("default"), ENV_PROD);
|
||||
String oldArn = recorderArn(service);
|
||||
|
||||
service.deleteConfigurationRecorder(REGION, "default");
|
||||
|
||||
assertTrue(service.storedTags(oldArn).isEmpty(), "delete must drop the recorder's tags");
|
||||
assertAllThreeNotFound(service, REGION, oldArn);
|
||||
service.putConfigurationRecorder(REGION, recorder("default"), TEAM_RED);
|
||||
assertNotEquals(oldArn, recorderArn(service));
|
||||
assertEquals(TEAM_RED, service.listTagsForResource(REGION, recorderArn(service)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aRecorderPutUnderAnotherNameReplacesTheOldOneAndItsTags() {
|
||||
AwsConfigService service = service();
|
||||
service.putConfigurationRecorder(REGION, recorder("default"), ENV_PROD);
|
||||
String oldArn = recorderArn(service);
|
||||
|
||||
service.putConfigurationRecorder(REGION, recorder("renamed"), TEAM_RED);
|
||||
|
||||
String newArn = recorderArn(service);
|
||||
assertTrue(newArn.contains(":configuration-recorder/renamed/"), newArn);
|
||||
assertEquals(TEAM_RED, service.listTagsForResource(REGION, newArn));
|
||||
assertAllThreeNotFound(service, REGION, oldArn);
|
||||
assertTrue(service.storedTags(oldArn).isEmpty(), "the replaced recorder's tags must go");
|
||||
}
|
||||
|
||||
@Test
|
||||
void aRecorderSavedWithoutAnArnGetsOneOnItsNextPut() {
|
||||
AwsConfigService service = serviceWithARecorderSavedWithoutAnArn();
|
||||
assertNull(recorderArn(service));
|
||||
|
||||
service.putConfigurationRecorder(REGION, recorder("default"), ENV_PROD);
|
||||
|
||||
String arn = recorderArn(service);
|
||||
assertTrue(arn.startsWith("arn:aws:config:us-east-1:000000000000:configuration-recorder/default/"), arn);
|
||||
assertTrue(service.listTagsForResource(REGION, arn).isEmpty(), "the recorder already existed");
|
||||
}
|
||||
|
||||
@Test
|
||||
void aRecorderSavedWithoutAnArnCanBeDeleted() {
|
||||
AwsConfigService service = serviceWithARecorderSavedWithoutAnArn();
|
||||
|
||||
service.deleteConfigurationRecorder(REGION, "default");
|
||||
|
||||
assertTrue(service.describeConfigurationRecorders(REGION, null).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void anArnOfAKindFlociDoesNotModelIsPassedThrough() {
|
||||
AwsConfigService service = service();
|
||||
@@ -225,6 +298,26 @@ class AwsConfigServiceTaggingTest {
|
||||
assertEquals(ENV_PROD, service.listTagsForResource(REGION, arn));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aRecorderPutRetriedAfterAFailedCreationTagWriteEndsWithTheTags() {
|
||||
AtomicBoolean failNextWrite = new AtomicBoolean(true);
|
||||
AwsConfigService service = serviceWithTagStore(new InMemoryStorage<String, Map<String, String>>() {
|
||||
@Override
|
||||
public void put(String key, Map<String, String> value) {
|
||||
if (failNextWrite.getAndSet(false)) {
|
||||
throw new IllegalStateException("tag store unavailable");
|
||||
}
|
||||
super.put(key, value);
|
||||
}
|
||||
});
|
||||
|
||||
assertThrows(IllegalStateException.class,
|
||||
() -> service.putConfigurationRecorder(REGION, recorder("default"), ENV_PROD));
|
||||
service.putConfigurationRecorder(REGION, recorder("default"), ENV_PROD);
|
||||
|
||||
assertEquals(ENV_PROD, service.listTagsForResource(REGION, recorderArn(service)));
|
||||
}
|
||||
|
||||
private static AwsConfigService serviceWithTagStore(StorageBackend<String, Map<String, String>> tagStore) {
|
||||
AwsConfigService service = new AwsConfigService(new RegionResolver(REGION, ACCOUNT),
|
||||
new InMemoryStorageFactory(ACCOUNT).withStore("config-tags.json", tagStore));
|
||||
@@ -232,9 +325,26 @@ class AwsConfigServiceTaggingTest {
|
||||
return service;
|
||||
}
|
||||
|
||||
private static AwsConfigService serviceWithARecorderSavedWithoutAnArn() {
|
||||
AccountAwareStorageBackend<ConfigurationRecorder> recorders = AccountAwareStorageBackend.inMemory(ACCOUNT);
|
||||
recorders.put(REGION, recorder("default"));
|
||||
AwsConfigService service = new AwsConfigService(new RegionResolver(REGION, ACCOUNT),
|
||||
new InMemoryStorageFactory(ACCOUNT).withStore("config-recorders.json", recorders));
|
||||
service.initializeStorage();
|
||||
return service;
|
||||
}
|
||||
|
||||
private static ConfigRule rule(String name) {
|
||||
return new ConfigRule(name, null, null, null, null,
|
||||
new ConfigRuleSource("AWS", "S3_BUCKET_VERSIONING_ENABLED", null, null),
|
||||
null, null, null, null, null);
|
||||
}
|
||||
|
||||
private static ConfigurationRecorder recorder(String name) {
|
||||
return new ConfigurationRecorder(null, name, "arn:aws:iam::000000000000:role/config", null, null);
|
||||
}
|
||||
|
||||
private static String recorderArn(AwsConfigService service) {
|
||||
return service.describeConfigurationRecorders(REGION, null).getFirst().arn();
|
||||
}
|
||||
}
|
||||
+105
@@ -431,4 +431,109 @@ class ConfigurationRecorderIntegrationTest {
|
||||
.body("ConfigurationRecorders[0].recordingGroup", not(hasKey("exclusionByResourceTypes")))
|
||||
.body("ConfigurationRecorders[0]", not(hasKey("recordingMode")));
|
||||
}
|
||||
|
||||
/** PutConfigurationRecorder's Tags is a TagsList, and the operation models ValidationException,
|
||||
* not the InvalidParameterValueException PutConfigRule answers. */
|
||||
@Test
|
||||
@Order(19)
|
||||
void putConfigurationRecorderRejectsAnInvalidTagWithoutStoringIt() {
|
||||
given()
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DeleteConfigurationRecorder")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ConfigurationRecorderName": "default"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "PutConfigurationRecorder")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ConfigurationRecorder": {"name": "default", "roleARN": "arn:aws:iam::123456789012:role/r"},
|
||||
"Tags": [{"Key": "", "Value": "red"}]}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DescribeConfigurationRecorders")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ConfigurationRecorders", hasSize(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
void recorderTagsAreListedUnderItsArnUntilItIsDeleted() {
|
||||
given()
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "PutConfigurationRecorder")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ConfigurationRecorder": {"name": "default", "roleARN": "arn:aws:iam::123456789012:role/r"},
|
||||
"Tags": [{"Key": "team", "Value": "red"}]}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
String arn = given()
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DescribeConfigurationRecorders")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ConfigurationRecorders[0].arn",
|
||||
matchesPattern("arn:aws:config:us-east-1:\\d{12}:configuration-recorder/default/\\w+"))
|
||||
.extract().path("ConfigurationRecorders[0].arn");
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "ListTagsForResource")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ResourceArn": "%s"}
|
||||
""".formatted(arn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags", hasSize(1))
|
||||
.body("Tags[0].Key", equalTo("team"))
|
||||
.body("Tags[0].Value", equalTo("red"));
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DeleteConfigurationRecorder")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ConfigurationRecorderName": "default"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "ListTagsForResource")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ResourceArn": "%s"}
|
||||
""".formatted(arn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user