mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(config): keep recording strategy, exclusions and recording mode on configuration recorders (#7178)
This commit is contained in:
1 parent
c8dec86997
commit
c024c8342c
10 files changed
+169
-7
No files matched your search
+2
-1
@@ -686,7 +686,8 @@ public class AwsConfigService {
|
||||
|
||||
public void putConfigurationRecorder(String region, ConfigurationRecorder recorder) {
|
||||
String name = (recorder.name() == null || recorder.name().isEmpty()) ? "default" : recorder.name();
|
||||
ConfigurationRecorder stored = new ConfigurationRecorder(name, recorder.roleARN(), recorder.recordingGroup());
|
||||
ConfigurationRecorder stored = new ConfigurationRecorder(name, recorder.roleARN(), recorder.recordingGroup(),
|
||||
recorder.recordingMode());
|
||||
configurationRecorders.put(region, stored);
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -11,5 +11,6 @@ import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
public record ConfigurationRecorder(
|
||||
@JsonProperty("name") String name,
|
||||
@JsonProperty("roleARN") String roleARN,
|
||||
@JsonProperty("recordingGroup") RecordingGroup recordingGroup) {
|
||||
@JsonProperty("recordingGroup") RecordingGroup recordingGroup,
|
||||
@JsonProperty("recordingMode") RecordingMode recordingMode) {
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package io.github.hectorvent.floci.services.configservice.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record ExclusionByResourceTypes(@JsonProperty("resourceTypes") List<String> resourceTypes) {
|
||||
}
|
||||
+3
-1
@@ -13,5 +13,7 @@ import java.util.List;
|
||||
public record RecordingGroup(
|
||||
@JsonProperty("allSupported") Boolean allSupported,
|
||||
@JsonProperty("includeGlobalResourceTypes") Boolean includeGlobalResourceTypes,
|
||||
@JsonProperty("resourceTypes") List<String> resourceTypes) {
|
||||
@JsonProperty("resourceTypes") List<String> resourceTypes,
|
||||
@JsonProperty("exclusionByResourceTypes") ExclusionByResourceTypes exclusionByResourceTypes,
|
||||
@JsonProperty("recordingStrategy") RecordingStrategy recordingStrategy) {
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package io.github.hectorvent.floci.services.configservice.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record RecordingMode(
|
||||
@JsonProperty("recordingFrequency") String recordingFrequency,
|
||||
@JsonProperty("recordingModeOverrides") List<RecordingModeOverride> recordingModeOverrides) {
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package io.github.hectorvent.floci.services.configservice.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record RecordingModeOverride(
|
||||
@JsonProperty("description") String description,
|
||||
@JsonProperty("resourceTypes") List<String> resourceTypes,
|
||||
@JsonProperty("recordingFrequency") String recordingFrequency) {
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package io.github.hectorvent.floci.services.configservice.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record RecordingStrategy(@JsonProperty("useOnly") String useOnly) {
|
||||
}
|
||||
+1
-1
@@ -46,7 +46,7 @@ class AwsConfigAccountIsolationTest {
|
||||
void recorderStartStopAndDeletionStayInTheirAccount() {
|
||||
for (String account : List.of(FIRST, SECOND)) {
|
||||
context.setAccountId(account);
|
||||
service.putConfigurationRecorder(REGION, new ConfigurationRecorder("default", "role", null));
|
||||
service.putConfigurationRecorder(REGION, new ConfigurationRecorder("default", "role", null, null));
|
||||
service.putDeliveryChannel(REGION, new DeliveryChannel("default", "bucket", null, null, null, null));
|
||||
}
|
||||
context.setAccountId(FIRST);
|
||||
|
||||
+3
-3
@@ -43,7 +43,7 @@ class AwsConfigServicePersistenceTest {
|
||||
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)));
|
||||
"arn:aws:iam::000000000000:role/config", new RecordingGroup(true, false, 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")));
|
||||
@@ -140,7 +140,7 @@ class AwsConfigServicePersistenceTest {
|
||||
void aStartedRecorderIsStillRecordingAfterRestart() {
|
||||
AwsConfigService first = restartedService();
|
||||
first.putConfigurationRecorder(REGION, new ConfigurationRecorder("default",
|
||||
"arn:aws:iam::000000000000:role/config", new RecordingGroup(true, false, null)));
|
||||
"arn:aws:iam::000000000000:role/config", new RecordingGroup(true, false, null, null, null), null));
|
||||
first.putDeliveryChannel(REGION,
|
||||
new DeliveryChannel("default", "config-bucket", null, null, null, null));
|
||||
first.startConfigurationRecorder(REGION, "default");
|
||||
@@ -169,7 +169,7 @@ class AwsConfigServicePersistenceTest {
|
||||
void aDeletedRecorderDoesNotComeBackRecordingAfterRestart() {
|
||||
AwsConfigService first = restartedService();
|
||||
ConfigurationRecorder recorder = new ConfigurationRecorder("default",
|
||||
"arn:aws:iam::000000000000:role/config", new RecordingGroup(true, false, null));
|
||||
"arn:aws:iam::000000000000:role/config", new RecordingGroup(true, false, null, null, null), null);
|
||||
first.putConfigurationRecorder(REGION, recorder);
|
||||
first.putDeliveryChannel(REGION,
|
||||
new DeliveryChannel("default", "config-bucket", null, null, null, null));
|
||||
|
||||
+99
@@ -332,4 +332,103 @@ class ConfigurationRecorderIntegrationTest {
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("NoSuchConfigurationRecorderException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(16)
|
||||
void recordingStrategyRoundTrips() {
|
||||
given()
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "PutConfigurationRecorder")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ConfigurationRecorder": {"name": "default", "roleARN": "arn:aws:iam::123456789012:role/r",
|
||||
"recordingGroup": {"allSupported": true, "includeGlobalResourceTypes": true,
|
||||
"recordingStrategy": {"useOnly": "ALL_SUPPORTED_RESOURCE_TYPES"}}}}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DescribeConfigurationRecorders")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ConfigurationRecorders[0].recordingGroup.recordingStrategy.useOnly",
|
||||
equalTo("ALL_SUPPORTED_RESOURCE_TYPES"))
|
||||
.body("ConfigurationRecorders[0].recordingGroup.allSupported", equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(17)
|
||||
void exclusionsAndRecordingModeRoundTrip() {
|
||||
given()
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "PutConfigurationRecorder")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ConfigurationRecorder": {"name": "default", "roleARN": "arn:aws:iam::123456789012:role/r",
|
||||
"recordingGroup": {"allSupported": false, "includeGlobalResourceTypes": false,
|
||||
"exclusionByResourceTypes": {"resourceTypes": ["AWS::EC2::Instance"]},
|
||||
"recordingStrategy": {"useOnly": "EXCLUSION_BY_RESOURCE_TYPES"}},
|
||||
"recordingMode": {"recordingFrequency": "DAILY",
|
||||
"recordingModeOverrides": [{"description": "continuous buckets",
|
||||
"resourceTypes": ["AWS::S3::Bucket"], "recordingFrequency": "CONTINUOUS"}]}}}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DescribeConfigurationRecorders")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ConfigurationRecorders[0].recordingGroup.exclusionByResourceTypes.resourceTypes",
|
||||
contains("AWS::EC2::Instance"))
|
||||
.body("ConfigurationRecorders[0].recordingGroup.recordingStrategy.useOnly",
|
||||
equalTo("EXCLUSION_BY_RESOURCE_TYPES"))
|
||||
.body("ConfigurationRecorders[0].recordingMode.recordingFrequency", equalTo("DAILY"))
|
||||
.body("ConfigurationRecorders[0].recordingMode.recordingModeOverrides", hasSize(1))
|
||||
.body("ConfigurationRecorders[0].recordingMode.recordingModeOverrides[0].description",
|
||||
equalTo("continuous buckets"))
|
||||
.body("ConfigurationRecorders[0].recordingMode.recordingModeOverrides[0].resourceTypes",
|
||||
contains("AWS::S3::Bucket"))
|
||||
.body("ConfigurationRecorders[0].recordingMode.recordingModeOverrides[0].recordingFrequency",
|
||||
equalTo("CONTINUOUS"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(18)
|
||||
void absentFieldsAreNotSynthesized() {
|
||||
given()
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "PutConfigurationRecorder")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("""
|
||||
{"ConfigurationRecorder": {"name": "default", "roleARN": "arn:aws:iam::123456789012:role/r",
|
||||
"recordingGroup": {"allSupported": true, "includeGlobalResourceTypes": false}}}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DescribeConfigurationRecorders")
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ConfigurationRecorders[0].recordingGroup", not(hasKey("recordingStrategy")))
|
||||
.body("ConfigurationRecorders[0].recordingGroup", not(hasKey("exclusionByResourceTypes")))
|
||||
.body("ConfigurationRecorders[0]", not(hasKey("recordingMode")));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user