Move plans from doc/plan/ into doc/plans/ and add YYYY-MM-DD date prefixes to all undated plan files based on document headers or earliest git commit dates. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2.7 KiB
2.7 KiB
Agent Authentication — P0 Local Adapter JWT Implementation
Scope
- In-scope adapters:
claude_local,codex_local. - Goal: zero-configuration auth for local adapters while preserving static keys for all other call paths.
- Out-of-scope for P0: rotation UX, per-device revocation list, and CLI onboarding.
1) Token format and config
- Use HS256 JWTs with claims:
sub(agent id)company_idadapter_typerun_idiatexp- optional
jti(run token id)
- New config/env settings:
PAPERCLIP_AGENT_JWT_SECRETPAPERCLIP_AGENT_JWT_TTL_SECONDS(default:172800)PAPERCLIP_AGENT_JWT_ISSUER(default:paperclip)PAPERCLIP_AGENT_JWT_AUDIENCE(default:paperclip-api)
2) Dual authentication path in actorMiddleware
- Keep the existing DB key lookup path unchanged (
agent_api_keyshash lookup). - If no DB key matches, add JWT verification in
server/src/middleware/auth.ts. - On JWT success:
- set
req.actor = { type: "agent", agentId, companyId }. - optionally guard against terminated agents.
- set
- Continue board fallback for requests without valid authentication.
3) Opt-in adapter capability
- Extend
ServerAdapterModule(likelypackages/adapter-utils/src/types.ts) with a capability flag:supportsLocalAgentJwt?: true.
- Enable it on:
server/src/adapters/registry.tsforclaude_localandcodex_local.
- Keep
process/httpadapters unset for P0. - In
server/src/services/heartbeat.ts, when adapter supports JWT:- mint JWT per heartbeat run before execute.
- include token in adapter execution context.
4) Local env injection behavior
-
In:
packages/adapters/claude-local/src/server/execute.tspackages/adapters/codex-local/src/server/execute.ts
inject
PAPERCLIP_API_KEYfrom context token.
- Preserve existing behavior for explicit user-defined env vars in
adapterConfig.env:- if user already sets
PAPERCLIP_API_KEY, do not overwrite it.
- if user already sets
- Continue injecting:
PAPERCLIP_AGENT_IDPAPERCLIP_COMPANY_IDPAPERCLIP_API_URL
5) Documentation updates
- Update operator-facing docs to remove manual key setup expectation for local adapters:
skills/paperclip/SKILL.mdcli/src/commands/heartbeat-run.tsoutput/help examples if they mention manual API key setup.
6) P0 acceptance criteria
- Local adapters authenticate without manual
PAPERCLIP_API_KEYconfig. - Existing static keys (
agent_api_keys) still work unchanged. - Auth remains company-scoped (
req.actor.companyIdused by existing checks). - JWT generation and verification errors are logged as non-leaking structured events.
- Scope remains local-only (
claude_local,codex_local) while adapter capability model is generic.