fix(s3): verify header and presigned POST signatures under validate-signatures (#4786)

* fix(s3): verify header and presigned POST signatures under validate-signatures

floci.auth.validate-signatures verified only presigned URL signatures. A
header-signed request or a presigned POST with a forged signature or an
unknown access key was accepted unless enforce-auth was on, and enforce-auth
also turns on bucket-policy evaluation, so there was no way to authenticate
S3 requests without authorizing them.

S3 verifies a signature before, and independently of, deciding from policies
and ACLs whether the caller may act. validate-signatures now does the first
step for every placement: S3HeaderSignatureFilter runs under either flag, and
a browser POST that carries SigV4 form fields is verified. Bucket policies are
still not evaluated, and unsigned requests are still left to enforce-auth,
which decides anonymous access from policies and ACLs as AWS does.

docs/services/s3.md now says what each flag verifies.

* chore(s3): keep validatePresignedPostAuth's Javadoc on its method

* docs(s3): clarify multi-account credentials under signature verification

* docs(s3): update docs/configuration/multi-account.md

Signed-off-by: Abhigya <abhigyakrishna21@gmail.com>

---------

Signed-off-by: Abhigya <abhigyakrishna21@gmail.com>
This commit is contained in:
Abhigya authored and GitHub committed 2026-10-01 10:14:41 -04:00
1 parent fa4d4663a2
commit 8f904afa5a
9 files changed
+325 -21

No files matched your search

@@ -71,6 +71,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Stream;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
@@ -3502,7 +3503,7 @@ public class S3Controller {
S3PublicAccessEvaluator.objectArn(s3Service.bucketPartition(bucket), bucket, key));
}
if (s3Service.isAuthEnforced()) {
if (s3Service.isAuthEnforced() || (config.auth().validateSignatures() && isSignedPost(lcFields))) {
validatePresignedPostAuth(lcFields, bucket, key, fileData.length);
} else {
// Validate policy conditions if present
@@ -3571,6 +3572,17 @@ public class S3Controller {
}
}
/**
* Whether a browser POST carries any SigV4 form field. Under {@code floci.auth.validate-signatures}
* such a POST must verify, while one with none of them is anonymous and is left to
* {@code enforce-auth}, which decides anonymous access from the bucket policy and ACL.
*/
private static boolean isSignedPost(Map<String, String> fields) {
return Stream.of("x-amz-algorithm", "x-amz-credential", "x-amz-signature")
.map(fields::get)
.anyMatch(value -> value != null && !value.isEmpty());
}
/**
* Enforces real S3 presigned-POST auth: a {@code policy} field must be present and
* SigV4-signed by a known secret key referenced through {@code x-amz-credential}, matching
@@ -28,7 +28,7 @@ import java.util.Optional;
/**
* Verifies the SigV4 signature carried in the {@code Authorization} header of an S3 request when
* {@code floci.services.s3.enforce-auth} is enabled.
* {@code floci.services.s3.enforce-auth} or {@code floci.auth.validate-signatures} is enabled.
*
* <p>The presigned placements are already verified elsewhere ({@link PreSignedUrlFilter} for the
* query string, {@link S3PostPolicySigner} for a browser POST). This filter closes the remaining
@@ -59,7 +59,12 @@ import java.util.Optional;
* {@link PreSignedUrlFilter} and {@link S3PostPolicySigner}.</li>
* </ul>
*
* <p>Nothing here runs with the flag off: the filter returns before reading a single header, so
* <p>Signature verification is authentication only. Whether the verified caller, or an anonymous
* one, may perform the operation is authorization, which runs in {@link S3Service} under
* {@code enforce-auth} alone. {@code validate-signatures} therefore rejects a forged or unknown
* credential without evaluating bucket policies or ACLs, and lets unsigned requests through.
*
* <p>Nothing here runs with both flags off: the filter returns before reading a single header, so
* the default configuration keeps accepting any well-formed {@code Authorization} header exactly
* as before.
*/
@@ -77,6 +82,7 @@ public class S3HeaderSignatureFilter implements ContainerRequestFilter {
DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'").withZone(ZoneOffset.UTC);
private final S3Service s3Service;
private final PreSignedUrlGenerator presignGenerator;
private final IamService iamService;
private final CurrentVertxRequest currentVertxRequest;
@@ -84,16 +90,17 @@ public class S3HeaderSignatureFilter implements ContainerRequestFilter {
ResourceInfo resourceInfo;
@Inject
public S3HeaderSignatureFilter(S3Service s3Service, IamService iamService,
CurrentVertxRequest currentVertxRequest) {
public S3HeaderSignatureFilter(S3Service s3Service, PreSignedUrlGenerator presignGenerator,
IamService iamService, CurrentVertxRequest currentVertxRequest) {
this.s3Service = s3Service;
this.presignGenerator = presignGenerator;
this.iamService = iamService;
this.currentVertxRequest = currentVertxRequest;
}
@Override
public void filter(ContainerRequestContext ctx) throws IOException {
if (!s3Service.isAuthEnforced() || !routedToS3()) {
if (!verifiesSignatures() || !routedToS3()) {
return;
}
String authorization = ctx.getHeaderString("Authorization");
@@ -181,6 +188,10 @@ public class S3HeaderSignatureFilter implements ContainerRequestFilter {
}
}
private boolean verifiesSignatures() {
return s3Service.isAuthEnforced() || presignGenerator.shouldValidateSignatures();
}
private boolean routedToS3() {
return resourceInfo != null && S3Controller.class.equals(resourceInfo.getResourceClass());
}