Align discovery path matching with system:discovery and rebuild the result cache key #24
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.50) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 598 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.383
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #24"
general
weight: 0.35
stlaz
Summary
Aligns how Guard matches non-resource (discovery) paths with the upstream Kubernetes rule it mirrors, and rebuilds the CheckAccess result cache key so that two requests that are not identical cannot produce the same key.
Both changes now follow the upstream Kubernetes construct they mirror, per review feedback.
Changes
1. Match discovery paths against the upstream
system:discoveryruleAllowNonResPathDiscoveryAccessmatched with a short list ofstrings.HasPrefixroots that did not correspond to any upstream rule, so the set of exempted paths was wider in some places and narrower in others than the rule it was meant to represent.Matching now reproduces the non-resource URLs of the upstream
system:discoveryClusterRole (plugin/pkg/auth/authorizer/rbac/bootstrappolicy/policy.go, bound tosystem:authenticated) together with howrbacv1.NonResourceURLMatchesevaluates them: an entry ending inis a prefix with thetrimmed, every other entry is an exact string match./api,/apis,/healthz,/livez,/openapi,/readyz,/version,/version//api/,/apis/,/openapi/Behaviour changes against the previous revision:
/healthz/<anything>and/version/<anything>are no longer exempt, and/livezand/readyznow are, matching upstream. A path that is not discovery is not denied; it falls through to the regular Azure RBAC check.Guard is deliberately stricter than upstream on one point: a path containing a
..segment is never treated as discovery.nonResourceAttributes.pathon aSelfSubjectAccessReviewis set by the caller rather than derived by the API server's router, so unlike a routed path it is not already normalized.2. Build the result cache key with a length-prefixed hash
getResultCacheKeybuilt the key by joining fields withpath.Join. That leaves the boundaries between fields ambiguous, and appliespath.Cleanto the result, so the key was a function of the normalized join rather than of the fields themselves.It now follows
buildKeyfromk8s.io/apiserver/pkg/endpoints/filters/impersonation/cache.go: a fixed-width request-shape byte, then every field under auint32big-endian length prefix, hashed with SHA-256, with the un-hashed user name appended after the digest. No field value can shift a field boundary, so two requests share a key only when every field is byte equal, and because the digest is fixed width, two keys are equal only if their users are equal. Any digest collision is therefore confined to a single user's own keys, where it cannot yield a permission that user does not already hold.The shape byte distinguishes the three specs Guard can receive - resource attributes, non-resource attributes, or neither - so keys built from different attribute sets occupy disjoint spaces.
Two deviations from upstream: no
unsafe(itstoStringsaves one allocation in an apiserver hot path; this runs once perSubjectAccessReview), and a three-state shape byte instead ofaddBool(IsResourceRequest), because a spec can carry neither attribute set.The field set is unchanged, so cache hit rates are unaffected: the key still uses the derived action, so
get,listandwatchcontinue to share one entry.Tests
Test_AllowNonResPathDiscoveryAccess- all 11 upstream entries allowed; subpaths of the exact-match entries (/healthz/etcd,/version/foo,/livez/poststarthook/...,/readyz/shutdown) rejected; loose-prefix look-alikes (/apiz,/healthzz,/livezz,/readyzz,/versionx) rejected; traversal, verb and flag guards covered.Test_getResultCacheKey_distinctRequestsGetDistinctKeys- requests that must not share a decision do not share a key, including placeholder and field-boundary cases.Test_getResultCacheKey_isDeterministic,Test_getResultCacheKey_isUserNamespaced- key depends only on the request, and is a 64 character digest suffixed with the user name.Test_getResultCacheKey_readVerbsShareCacheKey- pins the preservedget/list/watchsharing, so keying on the raw verb fails the build.Test_getResultCacheKey_noResourceNonResourceCollision- keys built from resource and non-resource attributes stay in disjoint spaces.Literal-key assertions were replaced with invariant tests, since asserting a hardcoded digest would only restate the implementation. The distinctness table was checked against both a prefix-less encoding and the previous
path.Joinencoding to confirm it discriminates.Validation
go build ./...- OKgo vet ./...- OKgofmt -lon all non-vendor Go files - cleangolangci-lint runinghcr.io/appscode/golang-dev:1.25viamake lint- 0 issuesgo test ./authz/... ./auth/providers/azure/graph/...- all pass