Skip to content

AgentRequest and RequireAgentToken - #66

Open
dcmcand wants to merge 1 commit into
slice/agent-tokens-13-collectfrom
slice/agent-tokens-14-agent-request
Open

dcmcand wants to merge 1 commit into
slice/agent-tokens-13-collectfrom
slice/agent-tokens-14-agent-request

Conversation

@dcmcand

@dcmcand dcmcand commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Slice 14: AgentRequest and RequireAgentToken

Only a coding agent's own app token can make a broker request, for its owner, under /api/ and on a mount of its own, and the agent's token scope rides along.

Spec: nebari-dev/tapas/docs/superpowers/specs/2026-11-30-agent-token-broker-design.md
Plan: nebari-dev/tapas/docs/superpowers/plans/2026-12-01-agent-tokens-and-frames.md (Slice 14)
Contracts touched: authn.AgentRequest (the only constructor of agenttoken.Request), authn.Authenticator.RequireAgentToken (middleware for a mount outside /api/)
Depends on: #64

  • AgentRequest(ctx, service): only a private app token whose caps include Deploy, Model or Trusted (Q57), read per request; everything else is ErrNoAgent. TokenScope copied.
  • A source test fails on any agenttoken.Request literal outside internal/gateway/authn.
  • RequireAgentToken: bearer only, the same liveness checks and context as RequireUser (compared for 11 token kinds); a live non-agent token passes with no caps (Q71); missing or dead is 401 invalid_token.
  • Keycloak check C12 (live, int-hub-test): the sign-in session still refreshes after Slice 13's second prompt=none request.

Validation

Step Command / action Expected Result
unit go test -count=1 -race ./internal/gateway/authn/... ./internal/gateway/agenttoken/... ok ok
local make test-local ok exit 0

AgentRequest is the one constructor of agenttoken.Request. It builds a
request only for a call that came with a private app's token whose
agent caps, read on every request, include deploying, a model or trust;
the person and agent come from the token and its scope rides along. A
browser session, a personal token, a job, a shared or non-agent app, or
a request behind neither middleware gets ErrNoAgent. A source test fails
if any other code writes an agenttoken.Request literal (one end-to-end
broker test is exempt by its exact path).

RequireAgentToken lets a mount outside /api/ take API tokens: it reads
the bearer header only, checks the token as RequireUser does (known, not
expired, still wanted, owner's sign-in recent), records its use, and
gives the handler the same context RequireUser would, so AgentRequest
answers the same on both mounts. A live non-agent token is passed on
with no agent caps; a missing or dead one is 401 invalid_token.

The Keycloak checks gain C12: a sign-in's session still refreshes after
the second prompt=none request that collects the offline token. The
spec records the owner's decision on admin roles behind the new mount.
contracts.md, patterns.md and the plan's evidence, checkpoint review and
deviations are updated.

This branch has not been deployed

No deployments
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