mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(s3tables): give resource-tag conditions the tags of the bucket or table a request names (#8505)
The generated request resources give S3 Tables' TableBucket and Table types aws:ResourceTag/ keys, but S3TablesStoredResourceArns did not answer storedTags, so a condition on a table bucket's or a table's tags saw none. S3TablesService.storedTags now reads the one bucket entry in the account and Region the ARN names and gives the bucket's tags, or a table's, matched on the whole ARN, reading only, a bucket stored before storage was account-aware read in place for the default account, as Secrets Manager's lookup reads one; S3TablesStoredResourceArns answers it.
This commit is contained in:
1 parent
9f7ac3b6a5
commit
160c45bf2d
6 files changed
+126
-7
No files matched your search
@@ -166,6 +166,33 @@ class S3TablesIamIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
/** A resource-tag condition reads the tags S3 Tables holds on the bucket or the table a request names. */
|
||||
@Test
|
||||
void aResourceTagConditionReadsTheTagsOfTheBucketAndTheTable() throws Exception {
|
||||
String tagged = send(admin, "PUT", "/buckets", "{\"name\":\"iam-" + UUID.randomUUID().toString().substring(0, 8)
|
||||
+ "\",\"tags\":{\"team\":\"data\"}}").then().statusCode(200).extract().path("arn");
|
||||
String untagged = createBucket();
|
||||
String path = "/tables/" + encoded(tagged) + "/analytics/";
|
||||
send(admin, "PUT", "/namespaces/" + encoded(tagged), "{\"namespace\":[\"analytics\"]}").then().statusCode(200);
|
||||
send(admin, "PUT", path, "{\"name\":\"events\",\"format\":\"ICEBERG\",\"tags\":{\"team\":\"data\"}}")
|
||||
.then().statusCode(200);
|
||||
send(admin, "PUT", path, "{\"name\":\"orders\",\"format\":\"ICEBERG\"}").then().statusCode(200);
|
||||
String onTeamData = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":"
|
||||
+ "[\"s3tables:GetTableBucket\",\"s3tables:GetTable\"],\"Resource\":\"*\",\"Condition\":"
|
||||
+ "{\"StringEquals\":{\"aws:ResourceTag/team\":\"data\"}}}]}";
|
||||
try (SignedIamUsers.User user = SignedIamUsers.createUser(endpoint, "s3t-iam-", "tags", onTeamData)) {
|
||||
send(user.signer("s3tables"), "GET", "/buckets/" + encoded(tagged), null).then().statusCode(200);
|
||||
denied(send(user.signer("s3tables"), "GET", "/buckets/" + encoded(untagged), null),
|
||||
"s3tables:GetTableBucket");
|
||||
String query = "/get-table?tableBucketARN=" + encoded(tagged) + "&namespace=analytics&name=";
|
||||
send(user.signer("s3tables"), "GET", query + "events", null).then().statusCode(200);
|
||||
denied(send(user.signer("s3tables"), "GET", query + "orders", null), "s3tables:GetTable");
|
||||
} finally {
|
||||
deleteBucket(tagged, "analytics");
|
||||
send(admin, "DELETE", "/buckets/" + encoded(untagged), null).then().statusCode(204);
|
||||
}
|
||||
}
|
||||
|
||||
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 + "/",
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
||||
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.StorageFactory;
|
||||
import io.floci.aws.services.s3.S3Service;
|
||||
import io.floci.aws.services.s3tables.model.S3Table;
|
||||
@@ -56,6 +57,47 @@ class S3TablesServiceTest {
|
||||
service = new S3TablesService(storageFactory, new RegionResolver(REGION, ACCOUNT_ID), s3Service);
|
||||
}
|
||||
|
||||
/**
|
||||
* The tags IAM gives a resource-tag condition: the table bucket's or a table's, read on the whole ARN in the
|
||||
* account and Region it names, and none for anything else.
|
||||
*/
|
||||
@Test
|
||||
void storedTagsReadsTheBucketOrTheTableItsArnNames() {
|
||||
TableBucket bucket = service.createTableBucket(BUCKET, null, null, Map.of("team", "data"), REGION);
|
||||
service.createNamespace(bucket.getArn(), List.of("analytics"), REGION);
|
||||
S3Table table = service.createTable(bucket.getArn(), "analytics", "events", "ICEBERG", null, null, null,
|
||||
Map.of("owner", "alice"), REGION);
|
||||
|
||||
assertEquals(Map.of("team", "data"), service.storedTags(bucket.getArn()));
|
||||
assertEquals(Map.of("owner", "alice"), service.storedTags(table.getArn()));
|
||||
assertEquals(Map.of(), service.storedTags(bucket.getArn() + "/table/other"));
|
||||
assertEquals(Map.of(), service.storedTags(bucket.getArn().replace(":" + ACCOUNT_ID + ":", ":111122223333:")));
|
||||
assertEquals(Map.of(), service.storedTags(bucket.getArn().replace(REGION, "eu-west-1")));
|
||||
assertEquals(Map.of(), service.storedTags("arn:aws:s3:::" + BUCKET));
|
||||
}
|
||||
|
||||
/** A bucket stored before storage was account-aware is read in place for the default account, never migrated. */
|
||||
@Test
|
||||
void storedTagsReadsAPreMultiAccountBucketOfTheDefaultAccountInPlace() {
|
||||
InMemoryStorage<String, TableBucket> raw = new InMemoryStorage<>();
|
||||
StorageFactory legacyFactory = new StorageFactory(null, null) {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <V> AccountAwareStorageBackend<V> create(String serviceName, String fileName,
|
||||
TypeReference<Map<String, V>> typeReference) {
|
||||
return (AccountAwareStorageBackend<V>) new AccountAwareStorageBackend<>(raw, null, ACCOUNT_ID);
|
||||
}
|
||||
};
|
||||
S3TablesService legacy = new S3TablesService(legacyFactory, new RegionResolver(REGION, ACCOUNT_ID), s3Service);
|
||||
String arn = "arn:aws:s3tables:" + REGION + ":" + ACCOUNT_ID + ":bucket/" + BUCKET;
|
||||
raw.put(REGION + "::" + BUCKET, new TableBucket(BUCKET, arn, "2026-01-01T00:00:00Z", ACCOUNT_ID, null, null,
|
||||
Map.of("team", "data")));
|
||||
|
||||
assertEquals(Map.of("team", "data"), legacy.storedTags(arn));
|
||||
assertEquals(Map.of(), legacy.storedTags(arn.replace(":" + ACCOUNT_ID + ":", ":111122223333:")));
|
||||
assertTrue(raw.get(REGION + "::" + BUCKET).isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listingAndUpdatingATableFromBeforeWarehousesGiveItOne() {
|
||||
String arn = service.createTableBucket(BUCKET, null, null, Map.of(), REGION).getArn();
|
||||
|
||||
Reference in new issue
Block a user