Skip to content

refactor(hub): extract resolveAgentSecrets, return JTI hash from token gen (#127) - #1333

Open
ptone wants to merge 3 commits into
sn-metaauth-inv/credential-entitled-keysfrom
sn-metaauth-inv/extract-resolve-agent-secrets
Open

refactor(hub): extract resolveAgentSecrets, return JTI hash from token gen (#127)#1333
ptone wants to merge 3 commits into
sn-metaauth-inv/credential-entitled-keysfrom
sn-metaauth-inv/extract-resolve-agent-secrets

Conversation

@ptone

@ptone ptone commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • Extract resolveAgentSecrets as the single source of truth for entitled-set
    computation. Returns both forInjection (filtered by injection mode) and
    entitledKeys (all secret key names from backend resolution). The injection
    mode governs timing, not entitlement.
  • AgentTokenGenerator interface returns JTI hash alongside the token string,
    so the dispatcher can bind entitled keys to the correct AgentCredential row.
  • recordEntitledKeys helper wired at all three dispatch paths (create, start,
    restart). Best-effort — logs on failure, does not block agent start.
  • DispatchAgentResetAuth updated for new return value (no entitled key
    recording — reset-auth does not resolve secrets).
  • Legacy resolveSecrets wrapper preserved for call sites that don't need the
    entitled key set.
  • 20 test files updated for the new GenerateAgentToken signature
    (token, jtiHash, err).

Depends on

PR #1332 (schema: entitled_secret_keys field + UpdateAgentCredentialEntitledKeys)

Design notes

  • Resolver vs chooser separation (Rule 126): This PR moves the resolver.
    PR 3 changes the chooser (entitlement filtering at the secrets endpoint).
    Entitlement filtering is NOT folded into resolveAgentSecrets.
  • Three-state model: The credential's entitled_secret_keys column is
    NULL (never recorded), empty (entitled to nothing), or populated.
    resolveAgentSecrets always returns a non-nil slice (may be empty),
    so credentials written via this path will never have NULL.

Test plan

  • go build ./... — clean
  • Targeted tests pass: TestGenerateAgentToken, TestRefreshAgentToken,
    TestHTTPAgentDispatcher
  • Full pkg/hub suite (pre-existing 300s timeout, not caused by these changes)
  • Reviewer verifies all three dispatch paths (create, start, restart) record
    entitled keys after token generation

…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
ptone changed the base branch from main to sn-metaauth-inv/credential-entitled-keys August 28, 2026 23:29
Scion Agent (sn-metaauth-inv) 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).
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