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:
Priamo Germosen authored and GitHub committed 2026-11-15 17:45:24 -04:00
1 parent 9f7ac3b6a5
commit 160c45bf2d
6 files changed
+126 -7

No files matched your search

@@ -26,9 +26,10 @@ import java.util.Optional;
* permission sets are provisioned to; Resource Explorer, for its default view; OAM and RAM, for the sinks,
* invitations and shares of other accounts they act on; Secrets Manager, for the secret a name or an ARN names,
* random suffix included, and its tags; EventBridge Scheduler, for its default schedule group; CloudFormation, for
* the stack or the stack set a name names, whose id it minted); looked up lazily by {@code ResourceArnBuilder} and
* {@code IamConditionContextResolver} through {@code Instance<StoredResourceArns>} for the namespace a request or an
* ARN is of, so IAM never depends on that service directly.</p>
* the stack or the stack set a name names, whose id it minted; S3 Tables, for the table a request names by its table
* bucket, namespace and name, and the tags of a table bucket or a table); looked up lazily by
* {@code ResourceArnBuilder} and {@code IamConditionContextResolver} through {@code Instance<StoredResourceArns>} for
* the namespace a request or an ARN is of, so IAM never depends on that service directly.</p>
*
* <p>Each answer is a lookup of what the service holds, asked for by an entry of the generated table ({@code find},
* {@code through}, a default, {@code forwarded}, a type's {@code resourceTagKeys}): never a fact about what an operation acts on, which the table alone
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import io.floci.aws.core.common.AwsArnUtils;
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.StorageBackend;
import io.floci.aws.core.storage.StorageFactory;
import io.floci.aws.services.s3.S3Service;
@@ -187,6 +188,40 @@ public class S3TablesService {
}
}
/**
* The tags of the table bucket or the table stored under {@code arn}, in the account and Region the ARN names, by
* key, which IAM gives a resource-tag condition; empty when there is none. Reads that one bucket's entry, a
* pre-multi-account one of the default account in place, and matches the bucket, or a table of it, on the whole
* ARN, leaving both as they are.
*/
public synchronized Map<String, String> storedTags(String arn) {
if (!AwsArnUtils.isArnFor(arn, "s3tables")) {
return Map.of();
}
AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
if (!parsed.resource().startsWith(BUCKET_PREFIX)) {
return Map.of();
}
String rest = parsed.resource().substring(BUCKET_PREFIX.length());
String bucketName = rest.contains("/") ? rest.substring(0, rest.indexOf('/')) : rest;
TableBucket bucket = stored(parsed.accountId(), storageKey(parsed.region(), bucketName)).orElse(null);
if (bucket == null) {
return Map.of();
}
if (arn.equals(bucket.getArn())) {
return Map.copyOf(bucket.getTags());
}
if (!arn.startsWith(bucket.getArn() + TABLE_INFIX)) {
return Map.of();
}
return bucket.getNamespaces().values().stream()
.flatMap(namespace -> namespace.getTables().values().stream())
.filter(table -> arn.equals(table.getArn()))
.findFirst()
.<Map<String, String>>map(table -> Map.copyOf(table.getTags()))
.orElse(Map.of());
}
public synchronized List<S3Table> listTables(String tableBucketArn, String namespaceName, String prefix, String region) {
TableBucket bucket = getTableBucket(tableBucketArn, region);
List<S3Table> tables = new ArrayList<>();
@@ -442,6 +477,13 @@ public class S3TablesService {
return region + "::" + name;
}
/** 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
? aware.getForAccount(accountId, key).or(() -> aware.getLegacyForAccount(accountId, key))
: store.get(key);
}
private String resourceName(String arn, String prefix) {
// Guard and cut must use the same needle. Checking for ":" + prefix but cutting on prefix
// alone means a name that itself contains the prefix is cut at the wrong place.
@@ -5,12 +5,13 @@ import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* What IAM asks S3 Tables of the resources a request names: the table a request names by its table bucket's ARN, its
* namespace and its name, whose ARN AWS ends in an id the service mints and Floci in the table's name, so only the
* stored table gives it.
* namespace and its name, whose ARN ends in an id the service mints, so only the stored table gives it; and the tags
* of a table bucket or a table, which a resource-tag condition reads.
*/
@ApplicationScoped
public class S3TablesStoredResourceArns implements StoredResourceArns {
@@ -34,4 +35,10 @@ public class S3TablesStoredResourceArns implements StoredResourceArns {
}
return s3TablesService.tableArn(names.get(0), names.get(1), names.get(2), region);
}
/** The tags of the table bucket or the table {@code arn} names, which a resource-tag condition reads. */
@Override
public Map<String, String> storedTags(String arn) {
return s3TablesService.storedTags(arn);
}
}