Skip to content

fix(hub): delete RefreshAgentToken dead code trap (#1337) - #1338

Open
ptone wants to merge 1 commit into
sn-metaauth-inv/entitlement-from-listingfrom
sn-metaauth-inv/delete-refresh-agent-token
Open

fix(hub): delete RefreshAgentToken dead code trap (#1337)#1338
ptone wants to merge 1 commit into
sn-metaauth-inv/entitlement-from-listingfrom
sn-metaauth-inv/delete-refresh-agent-token

Conversation

@ptone

@ptone ptone commented Aug 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • Delete RefreshAgentToken and GenerateAgentTokenWithExpiry — zero production callers, both are dead code traps
  • RefreshAgentToken mints credentials with NULL entitled_secret_keys and its generator returns no JTI hash, making it impossible for callers to record entitled keys
  • Also delete CredentialChecker interface, SetCredentialChecker, and mockCredentialChecker test double — all existed solely for RefreshAgentToken
  • The live refresh path is handleAgentTokenRefresh (handlers_agents_core.go), which uses GenerateAgentToken (with JTI hash) and already records entitled keys

Why now

The fetch endpoint (PR 4) will read entitled_secret_keys for authorization. A NULL value from a RefreshAgentToken-minted credential would fail closed by design, but the function looks correct and the failure mode is invisible until an operator reports it. Removing it before PR 4 eliminates the trap.

Caller search extent

grep -rn "RefreshAgentToken" --include="*.go" /workspace/
grep -rn "GenerateAgentTokenWithExpiry" --include="*.go" /workspace/

Searched: cmd/, internal/, all pkg/ packages, all test files. Zero production callers. GenerateAgentTokenWithExpiry called only by RefreshAgentToken (agenttoken.go:287) and one test.

Tracking issue

Fixes #1337

Test plan

  • go vet ./pkg/hub/ — clean
  • go build ./... — clean
  • TestAgentTokenService_* — all pass (7 remaining tests)
  • TestCredentialRecorderNilSafe — passes
  • TestCredentialStoreOperations — passes
  • TestComputeEntitledSecretKeys_* — all 8 pass (unaffected)

…1337)

RefreshAgentToken mints credentials with NULL entitled_secret_keys and
its underlying generator (GenerateAgentTokenWithExpiry) returns no JTI
hash, making it impossible for callers to record entitled keys even
knowing they should. This is a trap for any future caller: they get a
working token, a credential that looks fine, and a wall.

Both functions have zero production callers. The live token refresh
path is handleAgentTokenRefresh (handlers_agents_core.go), which uses
GenerateAgentToken (with JTI hash return) and records entitled keys.

Deleted:
- RefreshAgentToken (agenttoken.go)
- GenerateAgentTokenWithExpiry (agenttoken.go)
- CredentialChecker interface and SetCredentialChecker (agenttoken.go)
- GetAgentCredentialByJTIHash on storeCredentialRecorder (server.go)
- 6 RefreshAgentToken tests, 1 GenerateAgentTokenWithExpiry test
- mockCredentialChecker test double (agenttoken_test.go)

Callers searched: cmd/, internal/, all pkg/ packages, tests. Extent:
grep -rn across entire repo for both function names. Zero production
callers found.
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