This commit is contained in:
1 parent
b724a21a0d
commit
d73fa2c435
45 files changed
+2733
-226
No files matched your search
@@ -8,7 +8,7 @@ final class S3Access {
|
||||
private final ObjectStorage store;
|
||||
private final String owner;
|
||||
private final java.util.Map<String, BucketPolicy> configuredIdentityPolicies;
|
||||
private volatile java.util.Map<String, BucketPolicy> identityPolicies;
|
||||
private volatile ManagedCredentials managedCredentials;
|
||||
private final ConcurrentHashMap<String, CachedPolicy> policies = new ConcurrentHashMap<>();
|
||||
private record CachedPolicy(String source, BucketPolicy parsed) { }
|
||||
|
||||
@@ -20,15 +20,17 @@ final class S3Access {
|
||||
this.store = store;
|
||||
this.owner = owner;
|
||||
this.configuredIdentityPolicies = java.util.Map.copyOf(identityPolicies);
|
||||
this.identityPolicies = configuredIdentityPolicies;
|
||||
}
|
||||
|
||||
synchronized void setManagedPolicies(java.util.Map<String, BucketPolicy> managed) {
|
||||
var combined = new java.util.HashMap<>(configuredIdentityPolicies);
|
||||
for (var entry : managed.entrySet())
|
||||
if (combined.putIfAbsent(entry.getKey(), entry.getValue()) != null)
|
||||
throw new IllegalArgumentException("Managed policy conflicts with a configured identity");
|
||||
identityPolicies = java.util.Map.copyOf(combined);
|
||||
void setManagedCredentials(ManagedCredentials managed) { managedCredentials = managed; }
|
||||
|
||||
private BucketPolicy identityPolicy(String principal) {
|
||||
if (principal == null) return BucketPolicy.empty();
|
||||
BucketPolicy configured = configuredIdentityPolicies.get(principal);
|
||||
if (configured != null) return configured;
|
||||
ManagedCredentials managed = managedCredentials;
|
||||
return managed == null ? BucketPolicy.empty() :
|
||||
managed.policies().getOrDefault(principal, BucketPolicy.empty());
|
||||
}
|
||||
|
||||
String owner() {
|
||||
@@ -83,8 +85,7 @@ final class S3Access {
|
||||
String resource = "arn:aws:s3:::" + bucket.name() + (key == null ? "" : "/" + key);
|
||||
BucketPolicy policy = policy(bucket);
|
||||
int decision = policy.decide(principal, action, resource);
|
||||
int identityDecision = principal == null ? 0 :
|
||||
identityPolicies.getOrDefault(principal, BucketPolicy.empty()).decide(principal, action, resource);
|
||||
int identityDecision = identityPolicy(principal).decide(principal, action, resource);
|
||||
if (decision < 0) return new Decision(false, "Explicit bucket policy deny");
|
||||
if (identityDecision < 0) return new Decision(false, "Explicit identity policy deny");
|
||||
if (BucketSecurity.allowsAcl(bucket, acl, principal, owner, permission))
|
||||
|
||||
Reference in new issue
Block a user