Skip to content

sn/object: reduce GET eACL allocations and restore EC GET rechecks - #4341

Draft
End-rey wants to merge 3 commits into
eacl-system-header-spoofingfrom
get-ec-eacl-recheck
Draft

End-rey wants to merge 3 commits into
eacl-system-header-spoofingfrom
get-ec-eacl-recheck

Conversation

@End-rey

@End-rey End-rey commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Ignore user attributes with the reserved `$Object:` prefix in both eACL header
builders, including parent headers.

Closes #4300.

Signed-off-by: Andrey Butusov <andrey@nspcc.io>
Match raw and decoded GET headers without building complete header lists.
Avoid protobuf round-trips for decoded headers and scan user attributes
linearly. Cache all system values on the first system filter to avoid
repeated header parsing. Preserve existing ACL behavior.

```
Benchmark                                                                                         ns/op       B/op  allocs/op
BenchmarkMessageHeaderValues/attrs=10/distinct5/same/binary=false/lazy=false-16                  8669.0     3407.0       34.0
BenchmarkMessageHeaderValues/attrs=10/distinct5/same/binary=false/lazy=true-16                   1209.0      608.0        6.0
BenchmarkMessageHeaderValues/attrs=10/distinct5/same/binary=true/lazy=false-16                   5061.0     1369.0       33.0
BenchmarkMessageHeaderValues/attrs=10/distinct5/same/binary=true/lazy=true-16                    3431.0      896.0        5.0
BenchmarkMessageHeaderValues/attrs=10/mixed5/same/binary=true/lazy=false-16                      6125.0     1369.0       33.0
BenchmarkMessageHeaderValues/attrs=10/mixed5/same/binary=true/lazy=true-16                       7203.0     1425.0       15.0
BenchmarkMessageHeaderValues/attrs=100/distinct5/same/binary=false/lazy=false-16                28768.0    19088.0      124.0
BenchmarkMessageHeaderValues/attrs=100/distinct5/same/binary=false/lazy=true-16                  1472.0      608.0        6.0
BenchmarkMessageHeaderValues/attrs=100/distinct5/same/binary=true/lazy=false-16                 39650.0     9729.0      216.0
BenchmarkMessageHeaderValues/attrs=100/distinct5/same/binary=true/lazy=true-16                  28009.0     4032.0        5.0
BenchmarkMessageHeaderValues/attrs=100/repeated20/same/binary=false/lazy=false-16               58922.0    19087.0      124.0
BenchmarkMessageHeaderValues/attrs=100/repeated20/same/binary=false/lazy=true-16                12581.0      608.0        6.0
BenchmarkMessageHeaderValues/attrs=100/repeated20/same/binary=true/lazy=false-16                67427.0     9729.0      216.0
BenchmarkMessageHeaderValues/attrs=100/repeated20/same/binary=true/lazy=true-16                 43242.0     4032.0        5.0
BenchmarkMessageHeaderValues/attrs=100/mixed5/same/binary=true/lazy=false-16                    44800.0     9729.0      216.0
BenchmarkMessageHeaderValues/attrs=100/mixed5/same/binary=true/lazy=true-16                     35214.0     4564.0       15.0
```

Ref nspcc-dev/neofs-sdk-go#913.

Signed-off-by: Andrey Butusov <andrey@nspcc.io>
Check the parent header before sending any object data through
the local and remote EC streaming paths.

Reuse binary header validation and skip it when no recheck is armed.
Add regression tests for filtered rules and reserved-key spoofing,
including owner and payload-size whitelists.

Reported-by: Fabian Wahle <fabian@nash.io>
Signed-off-by: Andrey Butusov <andrey@nspcc.io>
@End-rey End-rey self-assigned this Nov 17, 2026
@End-rey End-rey changed the title Get ec eacl recheck sn/object: reduce GET eACL allocations and restore EC GET rechecks Nov 17, 2026
@End-rey

End-rey commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

/hal please review this with nspcc-dev/neofs-sdk-go#913

@End-rey
End-rey force-pushed the eacl-system-header-spoofing branch from 7ce3613 to 43cdba3 Compare November 17, 2026 15:29

@hal0x9000 hal0x9000 Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR fits SDK nspcc-dev/neofs-sdk-go#913 (a60c2cfbeb1b): messageHeaderValues meets the HeaderValueSource contract, including the rule that an unavailable header type is reported only when the object header is incomplete. The new EC recheck still lets one kind of eACL Deny rule through, though. The EC fast paths pass the header as []byte, and that path never sees the request's X-headers. So a Deny rule that combines a request-header filter with an object filter does not match, and the object is streamed to the client.

What I checked

  • The changes, read against the SDK diff in #913: ValidationUnit.WithHeaderValueSource, matchHeaderValues and matchHeaderValue. I compared the node's value source with the legacy headerSource for each message type: binary, decoded, storage Head and address-only.
  • go test ./pkg/services/object/ ./pkg/services/object/acl/... passes at 7b27345.
  • go mod tidy -diff prints nothing. The otel/logr bumps in go.sum come in with the new SDK revision.
  • TestServer_Get_ECEACL fails in every recheck case (local and remote) once ecTransport.checkHeader is not set. The test does cover the fix.
  • I added one case to that test, in a scratch copy and not pushed: the request carries the X-header role=guest, and the table has Deny GET Others with two filters, NewRequestHeaderFilter("role", MatchStringEqual, "guest") and classified == secret. It fails for both remote=false and remote=true: the client gets the header and the payload instead of ObjectAccessDenied (the inline comments below have the details).

Findings

  1. The binary recheck drops the request's X-headers (inline on acl.go and values.go). This gap already existed on the non-EC buffer path. It is not a regression for EC, which had no recheck at all before this PR. But it means the restored EC recheck is weaker than the ValidateHeader path it stands in for. Open PR #4305 (closes #4297) fixes the binary path by adding a request parameter to WithObjectHeaderBinary. Whichever of the two PRs merges second has to extend the HeaderFromRequest branch in values.go to read the request from the binary message too. Otherwise the lazy source keeps the gap even after #4305 lands.
  2. checkBinaryHeader returns ErrNotMatched unchanged (inline). As far as I can tell this is not reachable today: a binary header never sets incompleteObjectHeaders. If it ever were reached, it would turn a basic-ACL fallback into an error status.

Smaller points (profile conventions)

  • pkg/services/object/acl/eacl/v2/object.go:47-85: dst.wantsSystemValues() cannot change while collectObjectHeaders runs, so a single check around the system-value block would replace the nine identical guards. collectBinaryObjectHeadersAt repeats the pattern at its end.
  • values_test.go builds the same protobuf header fixture (header slice, size, MarshalStable) about ten times, and builds the binary/decoded/response source table in several tests. The profile asks for one shared constructor.
  • pkg/services/object/server.go:2223 still spells "$Object:" as a literal, next to the new reservedAttributePrefix.
  • The first commit (sn/object: prevent system eACL property spoofing) says Closes #4300, but its CHANGELOG line cites #4338, which is the separate open PR carrying the same fix. Per the profile, the line should end with the issue number. Also worth deciding whether that commit lands through #4338 or through this PR.
  • go.mod pins an unmerged SDK PR commit. It will need re-pinning once #913 merges, and moving again if #913 changes in review.

Not determined: I did not build a live EC placement for the split-object range entry points (copySplitECObjectRangeByInfo/ByLinker/ByParts combined with payload-only), so I cannot confirm that none of them sends a header without the recheck. The other EC transports either reject an init part or write only payload.


Generated review by hal0x9000 for commit 7b27345.

} else if b, ok := msg.([]byte); ok {
hdrSrcOpts = append(hdrSrcOpts, eaclV2.WithObjectHeaderBinary(b))
} else if hdr, ok := msg.(*object.Object); ok {
req, _ := reqInfo.SrcRequest.(eaclV2.Request)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On this path the request is never handed to the header source. WithObjectHeaderBinary(b) (L172) carries only the bytes, unlike the *object.Object case on these lines. The EC fast paths this PR adds (getECTransport.checkHeader) and the existing buffer callback both reach CheckEACL with []byte. So every HeaderFromRequest filter sees no values during the deferred recheck.

How it fails: a client sends a GET with X-header role=guest, and the table has Deny GET Others with filters role == guest (request) and classified == secret (object). The initial check cannot read the object, so it defers. The binary recheck then finds no role value, the record does not match, and the EC object is streamed. I added this case to TestServer_Get_ECEACL in a scratch copy: it fails for both remote=false and remote=true (2 responses instead of the 1 ObjectAccessDenied).

Open PR #4305 fixes this for the binary path (WithObjectHeaderBinary(b, reqInfo.SrcRequest.(eaclV2.Request))). Either rebase onto it, or pass the request here the same way you do for *object.Object.

req = m.req
case responseXHeaderSource:
req = m.req.req
case decodedHeader:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This switch takes the request from requestXHeaderSource, responseXHeaderSource and decodedHeader, but not from binaryHeader, so binary messages always get req == nil. Once the binary option carries the request (see the comment on acl.go, and #4305), this branch needs a matching case. Otherwise the lazy source keeps the gap while the legacy HeadersOfType gets fixed. Whichever PR merges second should add a test for a request-header filter with a []byte message.

if err != nil && !errors.Is(err, aclsvc.ErrNotMatched) {
return eACLErr(s.reqInfo, err)
}
return err

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ErrNotMatched goes back to the caller unchanged here, while ValidateHeader just above treats it as "follow basic ACL" and returns nil. With a binary header I could not make it happen: incompleteObjectHeaders is never set, so CalculateAction always gives a final answer. If it ever did happen, the EC path would abort and Get would send it through sendStatusGetResponse as a failure. Returning nil would match ValidateHeader:

Suggested change
return err
return nil

)

// headerValueSet borrows user attributes and caches system values on first use.
// Linear scans avoid per-key indexes for small headers.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The profile asks that implementation rationale not go into code comments and that an explanation not appear twice. The caching rule is stated here and again in the NewMessageHeaderValueSource doc (L42-45), and "Linear scans avoid per-key indexes" is rationale that belongs in the commit message. Suggest one line saying what the type holds, and a one- or two-sentence doc on the constructor.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant