Skip to content

fix(auth): keep the server error for reads allowed by object tags, and in GetObjectAttributes - #294

Merged
Vonng merged 4 commits into
pgsty:mainfrom
botdeniska:fix/tag-auth-server-error
Nov 10, 2026
Merged

Vonng merged 4 commits into
pgsty:mainfrom
botdeniska:fix/tag-auth-server-error

Conversation

@botdeniska

Copy link
Copy Markdown

Contribution Licensing (no CLA, inbound=outbound, DCO required)

This pull request contributes to PGSTY SILO (pgsty/silo). Code contributions
are accepted under AGPL-3.0-or-later, the same license as the server.
This project does not use a CLA or require a separate Apache-2.0 license grant.
By submitting this pull request I represent that I have the right to contribute
the code changes under this repository's
GNU Affero General Public License v3.0 or later
and retain copyright in my original work. Existing copyright and license
notices remain intact; separately licensed material keeps its applicable terms.
Every commit must carry a DCO Signed-off-by trailer
(git commit -s) certifying the
Developer Certificate of Origin — see
CONTRIBUTING.md.

Description

Fixes #293.

When reading an object fails, GET, HEAD and PutObjectTagging authorize again without the object's tags. A caller allowed to read only by an s3:ExistingObjectTag condition therefore gets 403 AccessDenied for a server error such as lost read quorum, and clients do not retry it. GetObjectAttributes turns every read error into 403 unless the caller has s3:ListBucket, and it checks s3:ListBucket on bucket/object instead of the bucket.

Four commits, a test and a fix for each part. Each test commit fails on main.

test(auth): cover reads allowed by s3:ExistingObjectTag when the object cannot be read

TestExistingObjectTagAuthReadQuorumLost in the new cmd/auth-handler-unread-tags_test.go uses one set of 16 drives. Ten of them fail the metadata reads of one tagged object; IAM and bucket metadata stay readable. The test sends GET, HEAD and PutObjectTagging as these callers:

  • callers that some tags let through. They should get 200 while the drives are healthy and 503 once read quorum is lost. They are allowed by: StringEquals on k=v; Null: false; Null: false together with StringNotEquals; ForAllValues:StringNotEquals; ${aws:username}; a plain Allow with a Deny unless tagged (StringNotEquals). One is a service account whose parent policy asks for one tag and whose own policy asks for another. A bucket policy statement covers the anonymous case;
  • a caller allowed only for another tag value. It gets 403 while healthy, but 503 once the tags cannot be read, since they could be the allowed value;
  • callers that no tags let through. They must get 403 in both states: Allow under another prefix only; Allow and Deny on the same tag; Null: true together with StringEquals; ${aws:username} under another prefix; Deny both with and without the tag; a service account whose parent and own policy ask for different values of one tag.

The test also checks two things with healthy drives: a GET with an unsatisfiable Range by an allowed caller gets 416, and a missing key gets 403, as before.

fix(auth): keep the server error when a read allowed by object tags cannot read the tags

  1. New cmd/auth-handler-unread-tags.go with authorizeRequestWithUnreadTags(ctx, r, action, readErr). It first calls authorizeRequest as before. If that denies and readErr is a server error (5xx), it also tries the regular authorization with candidate tag sets from policyExistingObjectTags. If one passes, the caller gets the storage error; otherwise AccessDenied. For client errors, NoSuchKey among them, nothing changes.
  2. policyExistingObjectTags builds the candidates. It looks at the statements that apply to the action and resource, whatever their conditions: the bucket policy for an anonymous caller, else the cached IAM policies (cache only, no drive reads) and, as a second policy set, the credential's session policy. For each statement, existingObjectTagsFor groups the s3:ExistingObjectTag/<key> functions by key. For each key it evaluates the functions with silo-pkg's condition.Functions.Evaluate, trying the tag absent, the values named in the condition (policy variables resolved, wildcards filled), and "" and _. An Allow statement contributes tags that pass all its tag tests. A Deny statement contributes tags that make one of its tag tests fail. combineExistingObjectTags merges one Allow per policy set, with and without the Deny-avoiding tags, deduplicates, and caps the result at 64 candidates.
  3. cmd/object-handlers.go:
    • GET: the precondition callback records the tags it read. The fallback after a failed getObjectNInfo authorizes with those tags when they are known, else with authorizeRequestWithUnreadTags.
    • HEAD: uses authorizeRequestWithUnreadTags when GetObjectInfo failed and the request was not proxied.
    • PutObjectTagging: uses authorizeRequestWithUnreadTags when GetObjectInfo failed.
  4. TestExistingObjectTagsFor: 21 condition blocks, Allow and Deny, with the tags expected for each.

test(api): cover GetObjectAttributes errors with and without s3:ListBucket

TestGetObjectAttributesReadQuorumLost in the new cmd/object-attributes-read-error_test.go has two callers with s3:GetObject and s3:GetObjectAttributes on bucket/*; one also has s3:ListBucket on bucket. Expected: a missing key gets 403 without s3:ListBucket and 404 with it, and lost read quorum gets 503 for both.

fix(api): keep GetObjectAttributes server errors and check s3:ListBucket on the bucket

getObjectAttributesHandler sends a 5xx read error as it is. For 4xx it keeps the S3 rule (without s3:ListBucket, AccessDenied instead of NoSuchKey), checking s3:ListBucket through the new authorizeBucketRequest in cmd/auth-handler.go. That helper authorizes a bucket action with the request's object name cleared, then restores it.

Motivation and Context

During a partial outage, callers allowed by object tags see 403 and give up, while every other caller retries and recovers. Details and a reproduction are in #293.

How to test this PR?

go test ./cmd -count=1 -run '^(TestExistingObjectTagAuthReadQuorumLost|TestExistingObjectTagsFor|TestGetObjectAttributesReadQuorumLost)$' -v

At the two test commits, which add only the tests on top of main (TestExistingObjectTagsFor comes with the fix, since it tests the new code):

--- FAIL: TestExistingObjectTagAuthReadQuorumLost
    healthy: GET bytes=100-200 by tagged: status 403 AccessDenied, want 416
    read quorum lost: GET by tagged: status 403 AccessDenied, want 503
    ... the same for nullFalse, notEquals, forAllNotEquals, owner, denyUnlessTagged, serviceAccount, otherValue
    ... the same 8 for HEAD and for PutObjectTagging
    read quorum lost: GET by anonymous: status 403 AccessDenied, want 503
    read quorum lost: HEAD by anonymous: status 403 , want 503
--- FAIL: TestGetObjectAttributesReadQuorumLost
    healthy: GetObjectAttributes missing by withList: status 403 AccessDenied, want 404
    read quorum lost: GetObjectAttributes object by withoutList: status 403 AccessDenied, want 503
    read quorum lost: GetObjectAttributes object by withList: status 403 AccessDenied, want 503

With the fix all three pass.

Live, with repro.sh from #293 (one native server, 4 drives, 3 moved away while it runs):

silo-fix version DEVELOPMENT.2026-11-07T08-43-31Z (commit-id=a2ff3c2ecde8e71a5442340a82053273737acbaa)
healthy:
  root GET obj                                 200 
  anonymous GET obj (allowed by k=v)           200 
  anonymous HEAD obj (allowed by k=v)          200 
  anonymous PutObjectTagging obj (by k=v)      200 
  anonymous GET private (not allowed)          403 AccessDenied
  session GET obj (allowed by k=v)             200 
  session GET private (allowed by k=v)         403 AccessDenied
  anonymous GetObjectAttributes attr/obj       200 
  anonymous GetObjectAttributes attr/missing   404 NoSuchKey
3 of 4 drives away:
  root GET obj                                 503 SlowDownRead
  anonymous GET obj (allowed by k=v)           503 SlowDownRead
  anonymous HEAD obj (allowed by k=v)          503 
  anonymous PutObjectTagging obj (by k=v)      503 SlowDownRead
  anonymous GET private (not allowed)          403 AccessDenied
  session GET obj (allowed by k=v)             503 SlowDownRead
  session GET private (allowed by k=v)         503 SlowDownRead
  anonymous GetObjectAttributes attr/obj       503 SlowDownRead
  anonymous GetObjectAttributes attr/missing   503 SlowDownRead

On main every line after the drives go away is 403 except root's 503, and attr/missing is 403 while healthy (output in #293). session GET private is 503 now: private carries no tags, but once the tags cannot be read they could be k=v.

Run locally on Go 1.27.3 (darwin/arm64), on main 69fcf50cd:

  • make verifiers (golangci-lint v2.15.0: 0 issues, check-gen, rebrand checks), gofmt, go build ./..., go vet ./...
  • every go test command of .github/workflows/go.yml: the race sets, the consistency_strict compile, go test ./internal/... and go test ./cmd/ (311 s): ok
  • go test -race ./cmd -run '^(TestExistingObjectTag|TestGetObjectAttributesReadQuorumLost|TestAPIGetObjectAttributes|TestGetAndValidateAttributesOpts|TestAPIGetObjectHandler|TestAPIHeadObjectHandler|TestHeadObjectNoQuorum|TestGetObjectLambdaHandler|TestAPITagging)' -count=3: ok
  • make build

Compatibility impact

No API, configuration, storage format, metric, route or dependency changes.

  • Only error paths change. With readable tags, and for client errors such as NoSuchKey, decisions and error codes stay as they were. Policies without s3:ExistingObjectTag conditions do not reach the new code.
  • The candidates never grant access. They only pick between the storage error and AccessDenied, and the regular authorization picks. No object data or metadata is returned on these paths.
  • A caller allowed only for other tag values also gets the server error (503 instead of 403) while the tags cannot be read, because the decision depends on them.
  • Not covered, 403 as before: a configured authorization plugin (OPA), whose protocol cannot express unknown tags; Numeric* and Date* tag conditions; installations where more than 64 candidate tag sets apply. Candidates come from cached policies, in policy-name order.
  • GetObjectAttributes on a missing key: a caller with s3:ListBucket on the bucket now gets 404 NoSuchKey, as in S3, instead of 403. A caller with s3:ListBucket only on bucket/* now gets 403; before, it got 404.
  • Cost: only a denied request with a 5xx read error pays for the extra evaluation: one pass over the applicable cached statements and at most 64 authorizations.
  • Rollback restores the old behavior.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Optimization (provides speedup with no functional changes)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • All commits are signed off (git commit -s) per the DCO
  • Fixes a regression (If yes, please add commit-id or PR # here): no, the same code is in MinIO RELEASE.2025-07-23T15-54-02Z
  • Unit tests added/updated
  • make verifiers passes
  • go test ./cmd, the CI race sets and make build pass
  • Compatibility and rollback impact documented
  • Internal documentation updated (not needed)
  • Public documentation update opened in pgsty/silo.pgsty.com, if needed (not needed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A read allowed by s3:ExistingObjectTag gets 403 AccessDenied instead of the server error when the object cannot be read

2 participants