mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(glue): add security configuration CRUD (#3870)
* feat(glue): add security configuration CRUD Implement AWS Glue security configuration create, get, list, and delete operations with encrypted configuration round trips, account and region isolation, persistence, and integration coverage. * fix(glue): close catalog encryption handler case Close the PutDataCatalogEncryptionSettings switch arm so the merged security configuration cases compile. * test(glue): cover empty security configuration lists Restore coverage for the empty GetSecurityConfigurations response and keep the test setup aligned with the rebased GlueService constructor. * refactor(glue): name security configuration length limit Use a named constant for the documented 255-character security configuration name limit. * fix(glue): serialize security configuration timestamps
This commit is contained in:
1 parent
cde8f48084
commit
e8b03538e6
7 files changed
+341
-9
No files matched your search
+6
-6
@@ -22,9 +22,9 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Verifies the wire-accurate empty-list responses for the read-only Glue actions on resources
|
||||
* the emulator does not model (ListDataQualityRulesets, GetSecurityConfigurations).
|
||||
* Each must return HTTP 200, an empty list under its result key, and omit NextToken.
|
||||
* Verifies the wire-accurate empty-list responses for an unmodeled Glue action and an
|
||||
* empty newly modeled resource collection. Each must return HTTP 200, an empty list
|
||||
* under its result key, and omit NextToken.
|
||||
*/
|
||||
class GlueJsonHandlerEmptyListTest {
|
||||
|
||||
@@ -42,8 +42,8 @@ class GlueJsonHandlerEmptyListTest {
|
||||
GlueSchemaRegistryService schemaRegistryService =
|
||||
new GlueSchemaRegistryService(storageFactory, regionResolver);
|
||||
GlueService glueService = new GlueService(
|
||||
storageFactory, schemaRegistryService, regionResolver, new ResourceGroupsTaggingService(storageFactory),
|
||||
new KmsService(storageFactory, regionResolver));
|
||||
storageFactory, schemaRegistryService, regionResolver,
|
||||
new ResourceGroupsTaggingService(storageFactory), new KmsService(storageFactory, regionResolver));
|
||||
handler = new GlueJsonHandler(glueService, schemaRegistryService, mapper);
|
||||
}
|
||||
|
||||
@@ -82,4 +82,4 @@ class GlueJsonHandlerEmptyListTest {
|
||||
return AccountAwareStorageBackend.inMemory("000000000000");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
package io.github.hectorvent.floci.services.glue;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.core.storage.PersistentStorage;
|
||||
import io.github.hectorvent.floci.services.glue.model.SecurityConfiguration;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.QuarkusTestProfile;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@QuarkusTest
|
||||
@TestProfile(GlueSecurityConfigurationIntegrationTest.PersistentStorageProfile.class)
|
||||
class GlueSecurityConfigurationIntegrationTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String STORAGE_DIR = "target/glue-security-configuration-it";
|
||||
private static final Path STORAGE_FILE = Path.of(STORAGE_DIR, "security_configurations.json");
|
||||
private static final String NAME = "security-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
private static final String ENCRYPTION = """
|
||||
{"S3Encryption":[{"S3EncryptionMode":"SSE-KMS","KmsKeyArn":"arn:aws:kms:us-east-1:000000000000:key/test"}],
|
||||
"JobBookmarksEncryption":{"JobBookmarksEncryptionMode":"CSE-KMS"}}
|
||||
""";
|
||||
|
||||
@BeforeAll
|
||||
static void setup() throws Exception {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
Files.deleteIfExists(STORAGE_FILE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void securityConfigurationCrudAndEncryptionRoundTrip() {
|
||||
create(NAME, "us-east-1", "000000000000");
|
||||
|
||||
given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSGlue.GetSecurityConfiguration")
|
||||
.body("{\"Name\":\"" + NAME + "\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("SecurityConfiguration.Name", equalTo(NAME))
|
||||
.body("SecurityConfiguration.CreatedTimeStamp", instanceOf(Number.class))
|
||||
.body("SecurityConfiguration.EncryptionConfiguration.S3Encryption[0].S3EncryptionMode",
|
||||
equalTo("SSE-KMS"))
|
||||
.body("SecurityConfiguration.EncryptionConfiguration.JobBookmarksEncryption.JobBookmarksEncryptionMode",
|
||||
equalTo("CSE-KMS"));
|
||||
|
||||
given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSGlue.GetSecurityConfigurations")
|
||||
.body("{}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("SecurityConfigurations", hasSize(1))
|
||||
.body("SecurityConfigurations[0].Name", equalTo(NAME))
|
||||
.body("SecurityConfigurations[0].CreatedTimeStamp", instanceOf(Number.class));
|
||||
|
||||
given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSGlue.DeleteSecurityConfiguration")
|
||||
.body("{\"Name\":\"" + NAME + "\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void duplicateAndMissingConfigurationsUseAwsErrors() {
|
||||
create(NAME, "us-east-1", "000000000000");
|
||||
|
||||
given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSGlue.CreateSecurityConfiguration")
|
||||
.body("{\"Name\":\"" + NAME + "\",\"EncryptionConfiguration\":{} }")
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body("__type", containsString("AlreadyExistsException"));
|
||||
|
||||
delete(NAME, "us-east-1", "000000000000");
|
||||
|
||||
given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSGlue.GetSecurityConfiguration")
|
||||
.body("{\"Name\":\"" + NAME + "\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body("__type", containsString("EntityNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void accountAndRegionAreIsolatedAndConfigurationIsPersisted() throws Exception {
|
||||
create(NAME, "us-east-1", "000000000001");
|
||||
|
||||
given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSGlue.GetSecurityConfiguration")
|
||||
.header("Authorization", authorization("000000000002", "us-east-1"))
|
||||
.body("{\"Name\":\"" + NAME + "\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body("__type", containsString("EntityNotFoundException"));
|
||||
|
||||
given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSGlue.GetSecurityConfiguration")
|
||||
.header("Authorization", authorization("000000000001", "us-west-2"))
|
||||
.body("{\"Name\":\"" + NAME + "\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body("__type", containsString("EntityNotFoundException"));
|
||||
|
||||
PersistentStorage<String, SecurityConfiguration> store = new PersistentStorage<>(
|
||||
STORAGE_FILE, new TypeReference<Map<String, SecurityConfiguration>>() {});
|
||||
store.load();
|
||||
assertTrue(store.get("000000000001/us-east-1:" + NAME).isPresent());
|
||||
assertEquals(NAME, store.get("000000000001/us-east-1:" + NAME).orElseThrow().getName());
|
||||
}
|
||||
|
||||
private static void create(String name, String region, String account) {
|
||||
given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSGlue.CreateSecurityConfiguration")
|
||||
.header("Authorization", authorization(account, region))
|
||||
.body("{\"Name\":\"" + name + "\",\"EncryptionConfiguration\":" + ENCRYPTION + "}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("Name", equalTo(name))
|
||||
.body("CreatedTimestamp", instanceOf(Number.class));
|
||||
}
|
||||
|
||||
private static void delete(String name, String region, String account) {
|
||||
given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSGlue.DeleteSecurityConfiguration")
|
||||
.header("Authorization", authorization(account, region))
|
||||
.body("{\"Name\":\"" + name + "\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
}
|
||||
|
||||
private static String authorization(String account, String region) {
|
||||
return "AWS4-HMAC-SHA256 Credential=" + account
|
||||
+ "/20260918/" + region + "/glue/aws4_request, SignedHeaders=host, Signature=abc";
|
||||
}
|
||||
|
||||
public static final class PersistentStorageProfile implements QuarkusTestProfile {
|
||||
@Override
|
||||
public Map<String, String> getConfigOverrides() {
|
||||
return Map.of(
|
||||
"floci.storage.mode", "persistent",
|
||||
"floci.storage.persistent-path", STORAGE_DIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package io.github.hectorvent.floci.services.glue;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
@@ -28,6 +30,7 @@ import io.github.hectorvent.floci.services.glue.model.PartitionIndex;
|
||||
import io.github.hectorvent.floci.services.glue.model.PartitionIndexDescriptor;
|
||||
import io.github.hectorvent.floci.services.glue.model.S3Target;
|
||||
import io.github.hectorvent.floci.services.glue.model.SchemaReference;
|
||||
import io.github.hectorvent.floci.services.glue.model.SecurityConfiguration;
|
||||
import io.github.hectorvent.floci.services.glue.model.StorageDescriptor;
|
||||
import io.github.hectorvent.floci.services.glue.model.Table;
|
||||
import io.github.hectorvent.floci.services.glue.model.UserDefinedFunction;
|
||||
@@ -106,8 +109,8 @@ class GlueServiceTest {
|
||||
new InMemoryStorage<String, Connection>(),
|
||||
new InMemoryStorage<String, GluePolicy>(),
|
||||
new InMemoryStorage<String, DataCatalogEncryptionSettings>(),
|
||||
schemaRegistryService, regionResolver, new ResourceGroupsTaggingService(null),
|
||||
kmsService);
|
||||
new InMemoryStorage<String, SecurityConfiguration>(),
|
||||
schemaRegistryService, regionResolver, new ResourceGroupsTaggingService(null), kmsService);
|
||||
glueService.createDatabase(new Database("db1"));
|
||||
}
|
||||
|
||||
@@ -117,6 +120,43 @@ class GlueServiceTest {
|
||||
assertEquals(ACCOUNT_ID, glueService.getDatabase("db1").getCatalogId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void securityConfigurationCrudPreservesEncryptionAndIsRegionScoped() throws Exception {
|
||||
JsonNode encryption = new ObjectMapper().readTree("""
|
||||
{"S3Encryption":[{"S3EncryptionMode":"SSE-KMS","KmsKeyArn":"arn:aws:kms:us-east-1:000000000000:key/a"}],
|
||||
"CloudWatchEncryption":{"CloudWatchEncryptionMode":"SSE-KMS"}}
|
||||
""");
|
||||
|
||||
SecurityConfiguration created = glueService.createSecurityConfiguration("secure", encryption, REGION);
|
||||
|
||||
assertEquals(encryption, created.getEncryptionConfiguration());
|
||||
assertEquals(encryption, glueService.getSecurityConfiguration("secure", REGION).getEncryptionConfiguration());
|
||||
assertEquals(1, glueService.getSecurityConfigurations(REGION).size());
|
||||
assertTrue(glueService.getSecurityConfigurations("us-west-2").isEmpty());
|
||||
|
||||
AwsException duplicate = assertThrows(AwsException.class,
|
||||
() -> glueService.createSecurityConfiguration("secure", encryption, REGION));
|
||||
assertEquals("AlreadyExistsException", duplicate.getErrorCode());
|
||||
glueService.deleteSecurityConfiguration("secure", REGION);
|
||||
AwsException missingGet = assertThrows(AwsException.class,
|
||||
() -> glueService.getSecurityConfiguration("secure", REGION));
|
||||
assertEquals("EntityNotFoundException", missingGet.getErrorCode());
|
||||
AwsException missingDelete = assertThrows(AwsException.class,
|
||||
() -> glueService.deleteSecurityConfiguration("secure", REGION));
|
||||
assertEquals("EntityNotFoundException", missingDelete.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsSecurityConfigurationNamesLongerThan255Characters() throws Exception {
|
||||
JsonNode encryption = new ObjectMapper().readTree("{\"EncryptionConfiguration\":{}}");
|
||||
String name = "a".repeat(256);
|
||||
|
||||
AwsException exception = assertThrows(AwsException.class,
|
||||
() -> glueService.createSecurityConfiguration(name, encryption, REGION));
|
||||
|
||||
assertEquals("InvalidInputException", exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void databasePersistedBeforeCatalogIdWasModelledIsBackfilledOnRead() {
|
||||
Database legacy = new Database("legacy-db");
|
||||
|
||||
Reference in new issue
Block a user