refactor(hub): extract resolveAgentSecrets, return JTI hash from token gen (#127) - #1333
Open
ptone wants to merge 3 commits into
Open
Conversation
…oken generation (#127) Single source of truth for entitled-set computation. resolveAgentSecrets returns both the injection list (filtered by injection mode) and the full set of entitled secret key names. The dispatcher records entitled keys on the AgentCredential after token generation at all three dispatch paths (create, start, restart). AgentTokenGenerator interface now returns (token, jtiHash, err) so the dispatcher can bind entitled keys to the correct credential row. All call sites (production and test) updated for the new signature. Prepares for POST /api/v1/agent/secrets endpoint in PR 3.
ptone
changed the base branch from
main
to
sn-metaauth-inv/credential-entitled-keys
August 28, 2026 23:29
added 2 commits
August 28, 2026 23:49
…s bypass DispatchAgentResetAuth now calls resolveAgentSecrets and records entitled keys on the new credential. ResetAuth is operator-initiated; copying stale entitlement from the old credential would preserve an answer computed under conditions that no longer hold. Delete the resolveSecrets legacy wrapper — it is an unguarded secret-resolution path that skips entitled-key computation. Migrate all test callers to resolveAgentSecrets.
When secret resolution fails during DispatchAgentResetAuth, the log now fires at Error level (unconditionally, not behind debug flag) and states the operator-visible consequence: the agent will not be able to fetch secrets until it is restarted. A comment explains why the reset proceeds anyway (recovery path; failing outright is worse).
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
resolveAgentSecretsas the single source of truth for entitled-setcomputation. Returns both
forInjection(filtered by injection mode) andentitledKeys(all secret key names from backend resolution). The injectionmode governs timing, not entitlement.
AgentTokenGeneratorinterface returns JTI hash alongside the token string,so the dispatcher can bind entitled keys to the correct
AgentCredentialrow.recordEntitledKeyshelper wired at all three dispatch paths (create, start,restart). Best-effort — logs on failure, does not block agent start.
DispatchAgentResetAuthupdated for new return value (no entitled keyrecording — reset-auth does not resolve secrets).
resolveSecretswrapper preserved for call sites that don't need theentitled key set.
GenerateAgentTokensignature(token, jtiHash, err).Depends on
PR #1332 (schema:
entitled_secret_keysfield +UpdateAgentCredentialEntitledKeys)Design notes
PR 3 changes the chooser (entitlement filtering at the secrets endpoint).
Entitlement filtering is NOT folded into
resolveAgentSecrets.entitled_secret_keyscolumn isNULL (never recorded), empty (entitled to nothing), or populated.
resolveAgentSecretsalways returns a non-nil slice (may be empty),so credentials written via this path will never have NULL.
Test plan
go build ./...— cleanTestGenerateAgentToken,TestRefreshAgentToken,TestHTTPAgentDispatcherpkg/hubsuite (pre-existing 300s timeout, not caused by these changes)entitled keys after token generation