fix(iam): authorize a virtual-hosted bucket request against the bucket ARN (#3942)

S3VirtualHostFilter rewrites a bucket-level virtual-hosted request (GET /)
to the path /bucket/, and ResourceArnBuilder.buildS3Arn turned that into
arn:aws:s3:::bucket/ with a trailing slash. A policy naming the bucket as
arn:aws:s3:::bucket then failed to match, so an allowed ListBucket was
denied for every SDK that defaults to virtual-hosted addressing while the
identical path-style call was allowed.

Drop the separator when nothing follows it. A key that itself ends in a
slash (a folder marker such as folder/) keeps it, because there the slash
is key data rather than a separator.

Refs lex00/floci#213

(cherry picked from commit 8624701021f2c6374b6e5d627218eeaa961ce751)
This commit is contained in:
lex00 authored and GitHub committed 2026-09-19 16:30:13 -04:00
1 parent 869589e932
commit 3c251b2343
3 files changed
+182 -3

No files matched your search

@@ -69,9 +69,14 @@ public class ResourceArnBuilder {
if (stripped.isEmpty()) {
return AwsArnUtils.Arn.of("s3", "", "", "*").toString();
}
int slash = stripped.indexOf('/');
if (slash < 0) {
return AwsArnUtils.Arn.of("s3", "", "", stripped).toString();
// S3VirtualHostFilter rewrites a bucket-level virtual-hosted request (GET /) to
// /bucket/, and the empty key after that separator is not part of the resource.
// A policy names the bucket as arn:aws:s3:::bucket, so the trailing slash has to
// go or a bucket-level ARN never matches. A key that itself ends in a slash
// (a folder marker such as folder/) keeps it, because there the slash is key data.
int firstSlash = stripped.indexOf('/');
if (firstSlash == stripped.length() - 1) {
stripped = stripped.substring(0, firstSlash);
}
return AwsArnUtils.Arn.of("s3", "", "", stripped).toString();
}