mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
feat(s3tables): expose bucket encryption configuration (#8523)
S3 Tables now serves GetTableBucketEncryption, returning the encryption configuration CreateTableBucket stored, a configured KMS key ARN included. A bucket created without one, or loaded from an older snapshot, reports AES256. It is configuration readback only: Floci does not encrypt table data or use the KMS key, and updating or deleting a bucket's encryption configuration is not implemented. Co-authored-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
1 parent
7a98f47742
commit
b0a4cc41cb
6 files changed
+254
-1
No files matched your search
@@ -20,7 +20,7 @@ metadata files there through Floci's S3 and commits each new metadata file
|
||||
with `UpdateTableMetadataLocation`. Deleting the table deletes its warehouse
|
||||
and everything in it, every object version included. A warehouse bucket is the
|
||||
table's storage, not a general purpose bucket, so `ListBuckets` leaves it out. Floci does not run an Iceberg engine itself: compaction,
|
||||
snapshot expiry, replication, encryption management, and metrics are outside
|
||||
snapshot expiry, replication, data encryption, and metrics are outside
|
||||
this implementation.
|
||||
|
||||
A table's ARN ends in an id Floci mints when it creates the table
|
||||
@@ -35,6 +35,7 @@ was stored with, which ends in its name.
|
||||
| Area | Operations |
|
||||
|---|---|
|
||||
| Table buckets | CreateTableBucket, GetTableBucket, ListTableBuckets, DeleteTableBucket |
|
||||
| Bucket encryption | GetTableBucketEncryption |
|
||||
| Bucket policy | PutTableBucketPolicy, GetTableBucketPolicy, DeleteTableBucketPolicy |
|
||||
| Bucket storage class | GetTableBucketStorageClass |
|
||||
| Bucket maintenance | PutTableBucketMaintenanceConfiguration, GetTableBucketMaintenanceConfiguration |
|
||||
@@ -48,6 +49,13 @@ Tables must use `ICEBERG` format. `UpdateTableMetadataLocation` implements
|
||||
optimistic concurrency: supply the table's current `versionToken`; a stale
|
||||
token returns `ConflictException`.
|
||||
|
||||
`GetTableBucketEncryption` returns the encryption configuration stored by
|
||||
`CreateTableBucket`, including a configured KMS key ARN. Buckets created
|
||||
without an explicit configuration, including those loaded from older
|
||||
snapshots, report `AES256`. This is configuration readback; Floci does not
|
||||
encrypt table data or perform KMS cryptographic operations. Updating or
|
||||
deleting a bucket's encryption configuration is not implemented.
|
||||
|
||||
## Example
|
||||
|
||||
```bash
|
||||
|
||||
@@ -61,6 +61,14 @@ public class S3TablesController {
|
||||
return Response.ok(bucketRepresentation(service.getTableBucket(decode(tableBucketArn), region(headers)))).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/buckets/{tableBucketARN}/encryption")
|
||||
public Response getTableBucketEncryption(@Context HttpHeaders headers,
|
||||
@Encoded @PathParam("tableBucketARN") String tableBucketArn) {
|
||||
return Response.ok(Map.of("encryptionConfiguration",
|
||||
service.getTableBucketEncryption(decode(tableBucketArn), region(headers)))).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/buckets/{tableBucketARN}")
|
||||
public Response deleteTableBucket(@Context HttpHeaders headers, @Encoded @PathParam("tableBucketARN") String tableBucketArn) {
|
||||
|
||||
@@ -67,6 +67,11 @@ public class S3TablesService {
|
||||
return bucket;
|
||||
}
|
||||
|
||||
public synchronized Object getTableBucketEncryption(String tableBucketArn, String region) {
|
||||
Object configuration = getTableBucket(tableBucketArn, region).getEncryptionConfiguration();
|
||||
return configuration == null ? Map.of("sseAlgorithm", "AES256") : configuration;
|
||||
}
|
||||
|
||||
public synchronized List<TableBucket> listTableBuckets(String prefix, String region) {
|
||||
return store.scan(key -> key.startsWith(region + "::")).stream()
|
||||
.filter(bucket -> prefix == null || bucket.getName().startsWith(prefix))
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package io.floci.aws.services.s3tables;
|
||||
|
||||
import io.floci.aws.testing.AwsTestClients;
|
||||
import io.quarkus.test.common.http.TestHTTPResource;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.s3tables.S3TablesClient;
|
||||
import software.amazon.awssdk.services.s3tables.model.EncryptionConfiguration;
|
||||
import software.amazon.awssdk.services.s3tables.model.NotFoundException;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@QuarkusTest
|
||||
class S3TablesEncryptionIntegrationTest {
|
||||
@TestHTTPResource
|
||||
URI endpoint;
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"us-east-1,aws", "us-gov-west-1,aws-us-gov", "cn-north-1,aws-cn"})
|
||||
void sdkReadsDefaultAndConfiguredBucketEncryption(String region, String partition) {
|
||||
try (S3TablesClient client = client(region, "111111111111")) {
|
||||
assertReadback(client, null, EncryptionConfiguration.builder().sseAlgorithm("AES256").build());
|
||||
EncryptionConfiguration aes = EncryptionConfiguration.builder().sseAlgorithm("AES256").build();
|
||||
assertReadback(client, aes, aes);
|
||||
EncryptionConfiguration kms = EncryptionConfiguration.builder().sseAlgorithm("aws:kms")
|
||||
.kmsKeyArn("arn:" + partition + ":kms:" + region + ":111111111111:key/"
|
||||
+ UUID.randomUUID()).build();
|
||||
assertReadback(client, kms, kms);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void readsUseTheRequestedAccountRegionAndExactBucketArn() {
|
||||
String name = name();
|
||||
try (S3TablesClient first = client("us-east-1", "111111111111");
|
||||
S3TablesClient second = client("us-east-1", "222222222222");
|
||||
S3TablesClient otherRegion = client("us-west-2", "111111111111")) {
|
||||
String firstArn = first.createTableBucket(request -> request.name(name)).arn();
|
||||
try {
|
||||
String secondArn = second.createTableBucket(request -> request.name(name)
|
||||
.encryptionConfiguration(config -> config.sseAlgorithm("aws:kms")
|
||||
.kmsKeyArn("arn:aws:kms:us-east-1:222222222222:key/" + UUID.randomUUID()))).arn();
|
||||
try {
|
||||
assertEquals("AES256", read(first, firstArn).sseAlgorithmAsString());
|
||||
assertEquals("aws:kms", read(second, secondArn).sseAlgorithmAsString());
|
||||
assertThrows(NotFoundException.class, () -> read(first, secondArn));
|
||||
assertThrows(NotFoundException.class, () -> read(second, firstArn));
|
||||
assertThrows(NotFoundException.class, () -> read(otherRegion, firstArn));
|
||||
assertEquals("aws:kms", read(second, secondArn).sseAlgorithmAsString());
|
||||
} finally {
|
||||
second.deleteTableBucket(request -> request.tableBucketARN(secondArn));
|
||||
}
|
||||
} finally {
|
||||
first.deleteTableBucket(request -> request.tableBucketARN(firstArn));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void missingAndDeletedBucketsUseModeledErrors() {
|
||||
try (S3TablesClient client = client("us-east-1", "test")) {
|
||||
String arn = client.createTableBucket(request -> request.name(name())).arn();
|
||||
try {
|
||||
assertThrows(NotFoundException.class, () -> read(client, arn + "-missing"));
|
||||
} finally {
|
||||
client.deleteTableBucket(request -> request.tableBucketARN(arn));
|
||||
}
|
||||
assertThrows(NotFoundException.class, () -> read(client, arn));
|
||||
}
|
||||
}
|
||||
|
||||
private void assertReadback(S3TablesClient client, EncryptionConfiguration configured,
|
||||
EncryptionConfiguration expected) {
|
||||
String arn = client.createTableBucket(request -> {
|
||||
request.name(name());
|
||||
if (configured != null) {
|
||||
request.encryptionConfiguration(configured);
|
||||
}
|
||||
}).arn();
|
||||
try {
|
||||
assertEquals(expected, read(client, arn));
|
||||
} finally {
|
||||
client.deleteTableBucket(request -> request.tableBucketARN(arn));
|
||||
}
|
||||
}
|
||||
|
||||
private EncryptionConfiguration read(S3TablesClient client, String arn) {
|
||||
return client.getTableBucketEncryption(request -> request.tableBucketARN(arn)).encryptionConfiguration();
|
||||
}
|
||||
|
||||
private String name() {
|
||||
return "encryption-read-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
}
|
||||
|
||||
private S3TablesClient client(String region, String account) {
|
||||
return AwsTestClients.create(S3TablesClient.builder(), account, Region.of(region), endpoint);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package io.floci.aws.services.s3tables;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.core.storage.StorageBackend;
|
||||
import io.floci.aws.core.storage.StorageFactory;
|
||||
import io.floci.aws.services.s3.S3Service;
|
||||
import io.floci.aws.services.s3tables.model.TableBucket;
|
||||
import io.floci.aws.testing.StorageTestBackends;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class S3TablesEncryptionPersistenceTest {
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String ACCOUNT = "000000000000";
|
||||
private static final Map<String, String> KMS = Map.of("sseAlgorithm", "aws:kms",
|
||||
"kmsKeyArn", "arn:aws:kms:us-east-1:000000000000:key/9f135f7d-d012-4be8-951a-e8517782f780");
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"persistent,false", "persistent,true", "hybrid,false", "hybrid,true", "wal,false", "wal,true"})
|
||||
void defaultAndConfiguredEncryptionReadBackAfterReload(String mode, boolean configured, @TempDir Path directory) {
|
||||
Path snapshot = directory.resolve("s3tables.json");
|
||||
String arn;
|
||||
Map<String, String> expected = configured ? KMS : Map.of("sseAlgorithm", "AES256");
|
||||
StorageBackend<String, TableBucket> first = open(mode, snapshot);
|
||||
try {
|
||||
S3TablesService service = service(first);
|
||||
arn = service.createTableBucket("warehouse", configured ? KMS : null, null, Map.of(), REGION).getArn();
|
||||
assertEquals(expected, service.getTableBucketEncryption(arn, REGION));
|
||||
} finally {
|
||||
StorageTestBackends.close(first);
|
||||
}
|
||||
|
||||
StorageBackend<String, TableBucket> second = open(mode, snapshot);
|
||||
try {
|
||||
assertEquals(expected, service(second).getTableBucketEncryption(arn, REGION));
|
||||
} finally {
|
||||
StorageTestBackends.close(second);
|
||||
}
|
||||
}
|
||||
|
||||
private static S3TablesService service(StorageBackend<String, TableBucket> backend) {
|
||||
StorageFactory factory = mock(StorageFactory.class);
|
||||
when(factory.<TableBucket>create(anyString(), anyString(), any()))
|
||||
.thenReturn(new AccountAwareStorageBackend<>(backend, null, ACCOUNT));
|
||||
return new S3TablesService(factory, new RegionResolver(REGION, ACCOUNT), mock(S3Service.class));
|
||||
}
|
||||
|
||||
private static StorageBackend<String, TableBucket> open(String mode, Path snapshot) {
|
||||
TypeReference<Map<String, TableBucket>> type = new TypeReference<>() {};
|
||||
StorageBackend<String, TableBucket> backend = StorageTestBackends.create(
|
||||
mode, snapshot, snapshot.resolveSibling("s3tables.wal"), type, 60_000);
|
||||
backend.load();
|
||||
return backend;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.floci.aws.services.s3tables;
|
||||
|
||||
import io.floci.aws.testing.AwsTestClients;
|
||||
import io.floci.aws.testing.SignedIamEnforcementProfile;
|
||||
import io.floci.aws.testing.SignedIamUsers;
|
||||
import io.floci.aws.testutil.AwsRequestSigner;
|
||||
@@ -9,6 +10,9 @@ import io.quarkus.test.junit.TestProfile;
|
||||
import io.restassured.response.Response;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.s3tables.S3TablesClient;
|
||||
import software.amazon.awssdk.services.s3tables.model.S3TablesException;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URLEncoder;
|
||||
@@ -21,6 +25,9 @@ import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* S3 Tables requests are checked against the caller's policies through its generated routes: a table bucket call on
|
||||
@@ -193,6 +200,63 @@ class S3TablesIamIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void encryptionReadbackRequiresPermissionOnTheRequestedBucket() throws Exception {
|
||||
String bucket = createBucket();
|
||||
try {
|
||||
try (SignedIamUsers.User user = SignedIamUsers.createUser(endpoint, "s3t-enc-");
|
||||
S3TablesClient client = encryptionClient(user)) {
|
||||
encryptionDenied(client, bucket);
|
||||
}
|
||||
String other = createBucket();
|
||||
try (SignedIamUsers.User user = SignedIamUsers.createUser(endpoint, "s3t-enc-", "read",
|
||||
allow("\"s3tables:GetTableBucketEncryption\"", bucket));
|
||||
S3TablesClient client = encryptionClient(user)) {
|
||||
assertEquals("AES256", client.getTableBucketEncryption(request -> request.tableBucketARN(bucket))
|
||||
.encryptionConfiguration().sseAlgorithmAsString());
|
||||
encryptionDenied(client, other);
|
||||
} finally {
|
||||
send(admin, "DELETE", "/buckets/" + encoded(other), null).then().statusCode(204);
|
||||
}
|
||||
String policy = """
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": "s3tables:GetTableBucketEncryption",
|
||||
"Resource": "*"
|
||||
},
|
||||
{
|
||||
"Effect": "Deny",
|
||||
"Action": "s3tables:GetTableBucketEncryption",
|
||||
"Resource": "%s"
|
||||
}
|
||||
]
|
||||
}
|
||||
""".formatted(bucket);
|
||||
try (SignedIamUsers.User user = SignedIamUsers.createUser(endpoint, "s3t-enc-", "deny", policy);
|
||||
S3TablesClient client = encryptionClient(user)) {
|
||||
encryptionDenied(client, bucket);
|
||||
}
|
||||
} finally {
|
||||
send(admin, "DELETE", "/buckets/" + encoded(bucket), null).then().statusCode(204);
|
||||
}
|
||||
}
|
||||
|
||||
private S3TablesClient encryptionClient(SignedIamUsers.User user) {
|
||||
return AwsTestClients.create(S3TablesClient.builder(), user.accessKeyId(), user.secretAccessKey(),
|
||||
Region.US_EAST_1, endpoint);
|
||||
}
|
||||
|
||||
private static void encryptionDenied(S3TablesClient client, String bucket) {
|
||||
S3TablesException error = assertThrows(S3TablesException.class,
|
||||
() -> client.getTableBucketEncryption(request -> request.tableBucketARN(bucket)));
|
||||
assertEquals(403, error.statusCode());
|
||||
assertTrue(error.getMessage().contains("not authorized to perform: s3tables:GetTableBucketEncryption"),
|
||||
error.getMessage());
|
||||
}
|
||||
|
||||
private String createTable(String bucket, String namespace, String name) throws Exception {
|
||||
send(admin, "PUT", "/namespaces/" + encoded(bucket), "{\"namespace\":[\"" + namespace + "\"]}");
|
||||
return send(admin, "PUT", "/tables/" + encoded(bucket) + "/" + namespace + "/",
|
||||
|
||||
Reference in new issue
Block a user