mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(s3tables): validate legacy bucket ownership before migration (#8534)
S3 Tables now migrates an unprefixed legacy table bucket only when the caller is the configured default account and the bucket's ARN matches the stored one, on a lookup and on CreateTableBucket's existence check. A lookup from another account, or with a mismatched ARN, answers NotFoundException and leaves the legacy record in place, and another account creating a bucket of the same name gets its own.
This commit is contained in:
1 parent
8ec2c184f1
commit
8625f09f4c
2 files changed
+126
-3
No files matched your search
@@ -47,10 +47,11 @@ public class S3TablesService {
|
||||
Object storageClassConfiguration, Map<String, String> tags, String region) {
|
||||
validateBucketName(name);
|
||||
String key = storageKey(region, name);
|
||||
if (store.get(key).isPresent()) {
|
||||
String arn = bucketArn(region, name);
|
||||
if (findTableBucket(key, arn).isPresent()) {
|
||||
throw conflict("The table bucket " + name + " already exists.");
|
||||
}
|
||||
TableBucket bucket = new TableBucket(name, bucketArn(region, name), now(), regionResolver.getAccountId(),
|
||||
TableBucket bucket = new TableBucket(name, arn, now(), regionResolver.getAccountId(),
|
||||
encryptionConfiguration, storageClassConfiguration, tags);
|
||||
store.put(key, bucket);
|
||||
LOG.infov("Created S3 Tables bucket {0} in region {1}", name, region);
|
||||
@@ -59,7 +60,8 @@ public class S3TablesService {
|
||||
|
||||
public synchronized TableBucket getTableBucket(String tableBucketArn, String region) {
|
||||
String name = resourceName(tableBucketArn, BUCKET_PREFIX);
|
||||
TableBucket bucket = store.get(storageKey(region, name))
|
||||
String key = storageKey(region, name);
|
||||
TableBucket bucket = findTableBucket(key, tableBucketArn)
|
||||
.orElseThrow(() -> notFound("The table bucket does not exist."));
|
||||
if (!bucket.getArn().equals(tableBucketArn)) {
|
||||
throw notFound("The table bucket does not exist.");
|
||||
@@ -487,6 +489,15 @@ public class S3TablesService {
|
||||
return region + "::" + name;
|
||||
}
|
||||
|
||||
private Optional<TableBucket> findTableBucket(String key, String tableBucketArn) {
|
||||
if (store instanceof AccountAwareStorageBackend<TableBucket> aware) {
|
||||
String accountId = regionResolver.getAccountId();
|
||||
return aware.getForAccountMigratingLegacy(accountId, key,
|
||||
legacy -> accountId.equals(aware.defaultAccountId()) && tableBucketArn.equals(legacy.getArn()));
|
||||
}
|
||||
return store.get(key);
|
||||
}
|
||||
|
||||
/** The bucket stored under {@code key} in the account, or the default account's legacy one, read only. */
|
||||
private Optional<TableBucket> stored(String accountId, String key) {
|
||||
return store instanceof AccountAwareStorageBackend<TableBucket> aware
|
||||
|
||||
Reference in new issue
Block a user