fix(hub): derive entitlement from key listing, not resolved values (#127) - #1336
Open
ptone wants to merge 3 commits into
Open
Conversation
added 3 commits
August 29, 2026 00:15
R7/R8/R9/R10) Entitlement was computed from Resolve()'s best-effort output: a secret that failed to decrypt was silently excluded, permanently narrowing what the agent could fetch. A transient storage fault became a durable, invisible entitlement reduction. Change 1 — computeEntitledSecretKeys (R7/R8): New package-level function derives entitled keys from ListSecrets and ListProgenySecrets (what exists and is scoped to the agent), not from resolved values. One function, called by all five credential writers (create, start, restart, resetAuth, refresh). No copy-forward anywhere. Change 2 — resolveAgentSecrets returns (forInjection, err) (R9): Remove the entitled-keys return value. Entitlement comes from computeEntitledSecretKeys and from nowhere else. Two sources of truth for one field is the defect, not the mismatch between them. Change 3 — fifth writer: handleAgentTokenRefresh (R8): Refresh now recomputes entitled keys from the listing via computeEntitledSecretKeys, same as every other writer. No special case. Authz scoping (R10): progeny secrets in computeEntitledSecretKeys go through the same authzService.CheckAccess path that Resolve() uses (same inputs: agent ID, project ID, ancestry, secret ID, ActionRead).
Add TestComputeEntitledSecretKeys_EqualsResolvedWhenAllSucceed: when every secret resolves cleanly, the entitled set must equal the resolved set. This test goes red if the two implementations (listing-based entitlement and resolution-based injection) drift on scope selection, internal-secret exclusion, or any other filtering rule. Fix fakeSecretBackendForEntitlement.Resolve to exclude internal secrets, matching real backend behavior (localbackend.go:173). The drift test itself caught this gap.
… resolution (R11) Two secrets with different keys but the same injection target: - Resolution applies DeduplicateByTarget → one survives - Entitlement does NOT apply that filter → both keys in entitled set This divergence is intentional. Target dedup is injection mechanics (env var collision), not authorization. The fetch-by-key channel has no target collision, so there is nothing for target dedup to resolve. Also makes the fake backend's Resolve() apply DeduplicateByTarget and default Target/SecretType, matching localbackend.go behavior. The fake was created in commit 5f2f52e as part of this PR — zero blast radius, no pre-existing test uses it.
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.
Summary
ListSecrets/ListProgenySecrets(what exists),not from
Resolve()output (what happened to decrypt). A secret that exists butfails to resolve is still entitled.
computeEntitledSecretKeysis a single package-level function called byall five credential writers. No copy-forward anywhere, no special case.
resolveAgentSecretsreturns(forInjection, err)— entitled-keys returnvalue removed. One source of truth, not two.
authzService.CheckAccesswith the same inputs as
Resolve()(agent ID, project ID, ancestry, secret ID,ActionRead). Entitlement is not wider than resolution.
handleAgentTokenRefreshnow recomputes entitled keys.Credential writer enumeration
Extent of search:
grep -rn 'GenerateAgentToken\|RecordAgentCredential\|UpdateAgentCredentialEntitledKeys\|AgentCredential{' pkg/hub/ --include='*.go', excluding test files and interface/type declarations.buildCreateRequestcomputeEntitledSecretKeysDispatchAgentStartcomputeEntitledSecretKeysDispatchAgentRestartcomputeEntitledSecretKeysDispatchAgentResetAuthcomputeEntitledSecretKeyshandleAgentTokenRefreshcomputeEntitledSecretKeysAll five call
computeEntitledSecretKeys. Zero call sites derive entitlement fromresolveAgentSecretsoutput (R9 enforced by removing the return value).Depends on
PR #1333 (refactor: extract resolveAgentSecrets, return JTI hash)
Test plan
go build ./...— cleango vet ./...— cleanTestComputeEntitledSecretKeys_ListingNotResolution— the R7 distinguishing testTestComputeEntitledSecretKeys_NilBackendTestComputeEntitledSecretKeys_EmptyProjectTestComputeEntitledSecretKeys_ListingErrorTestComputeEntitledSecretKeys_ExcludesInternalTestComputeEntitledSecretKeys_MultiScopeTestResolveSecrets*(4 test files updated for new signature)TestHTTPAgentDispatcher*,TestGenerateAgentToken,TestRefreshAgentToken