Optionally allow support for resource in Admin actions#224
Optionally allow support for resource in Admin actions#224harshavardhana merged 9 commits intominio:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates IAM policy evaluation to optionally enforce Resource / NotResource matching for admin actions, enabling per-bucket scoping for bucket-level admin APIs while keeping existing behavior when Resource is omitted.
Changes:
- Update
Statement.IsAllowedPtrto ignore resource matching for admin statements only when neitherResourcenorNotResourceis specified. - Add validation for admin statement
Resource/NotResourcewhen present. - Add test coverage for admin resource scoping behavior (allow/deny cases, wildcard, invalid ARN).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
policy/statement.go |
Makes admin resource matching conditional on explicit Resource/NotResource and adds validation for these fields when provided. |
policy/policy_test.go |
Adds a new test suite verifying bucket-scoped admin policy behavior and backward compatibility when no resource is specified. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
This PR updates IAM policy evaluation to optionally enforce Resource/NotResource matching for a subset of bucket-scoped admin actions (e.g., bucket quota operations), enabling bucket-level scoping where it previously wasn’t possible.
Changes:
- Make resource matching conditional for admin actions based on membership in
AdminActionsResourceSupported. - Add
AdminActionsResourceSupportedto enumerate which admin actions support bucket-level resource scoping. - Add tests covering allow/deny outcomes for scoped vs unscoped admin statements and validation behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
policy/statement.go |
Implements per-action admin resource matching and adds admin Resource-support validation logic plus a helper for Resource/NotResource conflict detection. |
policy/admin-action.go |
Adds AdminActionsResourceSupported allowlist for admin actions that support Resource/NotResource scoping. |
policy/policy_test.go |
Adds TestAdminPolicyResourceScoping covering resource-scoped admin actions and parse-time validation expectations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
taran-p
left a comment
There was a problem hiding this comment.
I still think having a condition key, (i.e. admin:QuotaBucket or quota:Bucket) rather than using resource, would help avoid any backwards compatibility issues and make it clear which actions are being affected.
That said if we go down the resource route, this looks fine to me.
|
@taran-p We don't want that key to be different for every type. |
|
@klauspost @taran-p If we want to, we can introduce a new |
|
@rraulinio I don't have any particular problem with that. So you mean it will transfer internally to that if it is a new admin request? It ofc isn't optimal, but it would guarantee that no existing policies are suddenly broken. (if I understand your sugg correctly). |
|
@klauspost Somehow correct. EOS will tell |
|
Sure, that makes sense, though I don't think the current implementation will lead to too many issues either |
|
@taran-p It wouldn't, most likely. If we feel like we shouldn't attempt the hacky way, then fine by me. Let's maybe also hear from @harshavardhana and/or @kannappanr. For now, I'll just leave it as is. cc @klauspost |
Instead of checking args.BucketName == "" at eval time to decide whether resource matching applies, declare which admin actions are bucket-scoped via AdminActionsWithResource map. The map is the single source of truth. Add ParseConfigStrict/ValidateStrict for new policy creation that rejects Resource+NotResource in the same admin statement and validates Resource ARNs on bucket-scoped admin actions. The permissive ParseConfig/Validate path is unchanged for backward compatibility when loading existing policies. Also reject statements that mix action namespaces (e.g. s3 + admin) with a clear error message.
|
@rraulinio I pushed a commit to your branch that shows the idiomatic way to handle this in The key idea: don't check Changes:
|
|
@harshavardhana That's more or less what we had before. But then agreed with @klauspost and @taran-p on the |
Certain admin actions like
admin:GetBucketQuotaandadmin:SetBucketQuotaoperate at a bucket level, but previously there was no way to restrict them to specific buckets via IAM policies, granting the action allowed it across all buckets.This change makes resource matching conditional for admin policy statements: when a
Resourcefield is specified, it is enforced against the target bucket; when omitted, behavior is unchanged (backward compatible).