mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(s3): expose bucket policy status (#6397)
* fix(s3): expose bucket policy status * fix(s3): align bucket policy status response * test(s3): verify policy status through SDK and IAM * refactor(s3): reuse bucket policy lookup for status
This commit is contained in:
1 parent
8ef9e1ddbf
commit
be7b0ed62b
10 files changed
+283
-3
No files matched your search
@@ -688,6 +688,7 @@ public class IamActionRegistry {
|
||||
sub("website", "s3:GetBucketWebsite"),
|
||||
sub("logging", "s3:GetBucketLogging"),
|
||||
sub("policy", "s3:GetBucketPolicy"),
|
||||
sub("policyStatus", "s3:GetBucketPolicyStatus"),
|
||||
sub("cors", "s3:GetBucketCORS"),
|
||||
sub("lifecycle", "s3:GetLifecycleConfiguration"),
|
||||
sub("acl", "s3:GetBucketAcl"),
|
||||
|
||||
@@ -644,6 +644,15 @@ public class S3Controller {
|
||||
.type("application/xml")
|
||||
.build();
|
||||
}
|
||||
if (hasQueryParam(uriInfo, "policyStatus")) {
|
||||
s3Service.authorizeBucketRead(bucket, "s3:GetBucketPolicyStatus", authorization);
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.raw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
|
||||
.start("PolicyStatus")
|
||||
.elem("IsPublic", s3Service.isBucketPolicyPublic(bucket))
|
||||
.end("PolicyStatus");
|
||||
return Response.ok(xml.build()).type(MediaType.APPLICATION_XML).build();
|
||||
}
|
||||
if (hasQueryParam(uriInfo, "policy")) {
|
||||
s3Service.authorizeBucketRead(bucket, "s3:GetBucketPolicy", authorization);
|
||||
return Response.ok(s3Service.getBucketPolicy(bucket)).build();
|
||||
|
||||
@@ -175,7 +175,8 @@ final class S3PublicAccessEvaluator {
|
||||
return hasPublicPrincipal(statement.path("Principal"));
|
||||
}
|
||||
// An Allow on NotPrincipal grants to everyone the statement does not name.
|
||||
return statement.hasNonNull("NotPrincipal");
|
||||
return statement.hasNonNull("NotPrincipal")
|
||||
&& !hasPublicPrincipal(statement.path("NotPrincipal"));
|
||||
}
|
||||
|
||||
private static boolean conditionPinsToFixedValues(JsonNode conditions) {
|
||||
|
||||
@@ -5451,6 +5451,11 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
return bucket.getPolicy();
|
||||
}
|
||||
|
||||
/** Returns whether the bucket policy grants public access according to S3 policy-status rules. */
|
||||
public boolean isBucketPolicyPublic(String bucketName) {
|
||||
return S3PublicAccessEvaluator.policyIsPublic(objectMapper, getBucketPolicy(bucketName));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code BlockPublicPolicy} rejects a bucket policy that grants public access. As on AWS the
|
||||
* check runs whoever the caller is, so it does not sit behind {@code enforce-auth}, and it
|
||||
|
||||
Reference in new issue
Block a user