Repository navigation
fix(auth): keep the server error for reads allowed by object tags, and in GetObjectAttributes - #294
Merged
Merged
Conversation
…ct cannot be read Signed-off-by: Denis Babchuk <[email protected]>
…annot read the tags Signed-off-by: Denis Babchuk <[email protected]>
…ucket Signed-off-by: Denis Babchuk <[email protected]>
…ket on the bucket Signed-off-by: Denis Babchuk <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contribution Licensing (no CLA, inbound=outbound, DCO required)
This pull request contributes to PGSTY SILO (
pgsty/silo). Code contributionsare 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-bytrailer(
git commit -s) certifying theDeveloper 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:ExistingObjectTagcondition therefore gets403 AccessDeniedfor a server error such as lost read quorum, and clients do not retry it. GetObjectAttributes turns every read error into 403 unless the caller hass3:ListBucket, and it checkss3:ListBucketonbucket/objectinstead 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
TestExistingObjectTagAuthReadQuorumLostin the newcmd/auth-handler-unread-tags_test.gouses 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:StringEqualsonk=v;Null: false;Null: falsetogether withStringNotEquals;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;Null: truetogether withStringEquals;${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
Rangeby 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
cmd/auth-handler-unread-tags.gowithauthorizeRequestWithUnreadTags(ctx, r, action, readErr). It first callsauthorizeRequestas before. If that denies andreadErris a server error (5xx), it also tries the regular authorization with candidate tag sets frompolicyExistingObjectTags. If one passes, the caller gets the storage error; otherwise AccessDenied. For client errors, NoSuchKey among them, nothing changes.policyExistingObjectTagsbuilds 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,existingObjectTagsForgroups thes3:ExistingObjectTag/<key>functions by key. For each key it evaluates the functions with silo-pkg'scondition.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.combineExistingObjectTagsmerges one Allow per policy set, with and without the Deny-avoiding tags, deduplicates, and caps the result at 64 candidates.cmd/object-handlers.go:getObjectNInfoauthorizes with those tags when they are known, else withauthorizeRequestWithUnreadTags.authorizeRequestWithUnreadTagswhenGetObjectInfofailed and the request was not proxied.authorizeRequestWithUnreadTagswhenGetObjectInfofailed.TestExistingObjectTagsFor: 21 condition blocks, Allow and Deny, with the tags expected for each.test(api): cover GetObjectAttributes errors with and without s3:ListBucket
TestGetObjectAttributesReadQuorumLostin the newcmd/object-attributes-read-error_test.gohas two callers withs3:GetObjectands3:GetObjectAttributesonbucket/*; one also hass3:ListBucketonbucket. Expected: a missing key gets 403 withouts3:ListBucketand 404 with it, and lost read quorum gets 503 for both.fix(api): keep GetObjectAttributes server errors and check s3:ListBucket on the bucket
getObjectAttributesHandlersends a 5xx read error as it is. For 4xx it keeps the S3 rule (withouts3:ListBucket, AccessDenied instead of NoSuchKey), checkings3:ListBucketthrough the newauthorizeBucketRequestincmd/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?
At the two test commits, which add only the tests on top of main (
TestExistingObjectTagsForcomes with the fix, since it tests the new code):With the fix all three pass.
Live, with
repro.shfrom #293 (one native server, 4 drives, 3 moved away while it runs):On main every line after the drives go away is 403 except root's 503, and
attr/missingis 403 while healthy (output in #293).session GET privateis 503 now:privatecarries no tags, but once the tags cannot be read they could bek=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 ./...go testcommand of.github/workflows/go.yml: the race sets, theconsistency_strictcompile,go test ./internal/...andgo test ./cmd/(311 s):okgo test -race ./cmd -run '^(TestExistingObjectTag|TestGetObjectAttributesReadQuorumLost|TestAPIGetObjectAttributes|TestGetAndValidateAttributesOpts|TestAPIGetObjectHandler|TestAPIHeadObjectHandler|TestHeadObjectNoQuorum|TestGetObjectLambdaHandler|TestAPITagging)' -count=3:okmake buildCompatibility impact
No API, configuration, storage format, metric, route or dependency changes.
s3:ExistingObjectTagconditions do not reach the new code.Numeric*andDate*tag conditions; installations where more than 64 candidate tag sets apply. Candidates come from cached policies, in policy-name order.s3:ListBucketon the bucket now gets 404 NoSuchKey, as in S3, instead of 403. A caller withs3:ListBucketonly onbucket/*now gets 403; before, it got 404.Types of changes
Checklist:
git commit -s) per the DCOcommit-idorPR #here): no, the same code is in MinIORELEASE.2025-07-23T15-54-02Zmake verifierspassesgo test ./cmd, the CI race sets andmake buildpasspgsty/silo.pgsty.com, if needed (not needed)