Skip to content

feat: per-user secrets (API keys) for sessions#64

Merged
mrsimpson merged 7 commits into
mainfrom
feat/per-user-secrets
May 18, 2026
Merged

feat: per-user secrets (API keys) for sessions#64
mrsimpson merged 7 commits into
mainfrom
feat/per-user-secrets

Conversation

@mrsimpson
Copy link
Copy Markdown
Owner

@mrsimpson mrsimpson commented May 17, 2026

Summary

Allow users to maintain their own API keys as environment variables that are automatically injected into all their sessions.

Features

  • K8s Secret pattern: opencode-user-<email-hash> mirroring existing GitHub token pattern
  • Multi-key format: Users can set multiple env vars (e.g. OPENAI_API_KEY, ANTHROPIC_API_KEY) — keys map directly to environment variable names
  • API endpoints:
    • GET /api/user/secret — returns { hasSecret, keys[] } (keys only, no values exposed)
    • POST /api/user/secret — sets secrets via { secrets: { KEY: value } }
    • DELETE /api/user/secret — removes all user secrets
  • Settings UI: Gear icon (⚙️) opens settings dialog at /settings route
    • Add env var name + value pairs
    • View existing keys (masked)
    • Delete individual secrets or all at once
  • Auto-injection: User's secrets mounted via envFrom to all their session pods

Commits

  • b50332799 — wip: per-user secrets backend implementation
  • 3a08fd234 — feat: per-user secrets for session pods
  • 50dbb1d2f — docs: update development plan with completed commits
  • ab6d2b496 — feat: support multiple env vars in user secrets

Tests

  • Backend: 167 pass, 0 fail (pod-manager + api)
  • Frontend: 43 pass, 0 fail

mrsimpson and others added 7 commits May 18, 2026 11:34
- Add getUserSecretName, ensureUserSecret, deleteUserSecret, getUserSecret functions
- Add GET/POST/DELETE /api/user/secret API endpoints
- Update ensurePod to mount user secret via envFrom
- Update session creation to pass user secret to pods
Backend (opencode-router):
- Add getUserSecretName, ensureUserSecret, deleteUserSecret, getUserSecret functions in pod-manager.ts
- Add GET/POST/DELETE /api/user/secret API endpoints in api.ts
- Update ensurePod to mount user secret via envFrom
- Update startSession and resumeSession to pass userSecret to pods

Frontend (opencode-router-app):
- Add getUserSecret, setUserSecret, deleteUserSecret API functions
- Add settings button next to welcome heading
- Add settings dialog with API key management (set/update/delete)
- Add i18n translations for settings UI
- Change user secrets from single string to Record<string, string> format
- K8s secret keys map directly to env var names (e.g. OPENAI_API_KEY)
- Update API endpoints: POST accepts { secrets: { KEY: value } }, GET returns keys[]
- Add /settings route for navigating to settings dialog
- Update settings UI with env var name + value input fields
- Fix tests and mock to handle new multi-key format
- Fix: adding a new env var now merges with existing secrets instead of overwriting
- Fix: getUserSecret reads from K8s data (base64) not stringData
- Fix: GET /api/user/secret returns secrets object for frontend merging
- Fix: individual key deletion removes only that key, keeps others
- Fix: frontend properly loads existing keys on mount and in settings dialog
@mrsimpson mrsimpson force-pushed the feat/per-user-secrets branch from b189c14 to d97253f Compare May 18, 2026 09:48
@mrsimpson mrsimpson merged commit 03408e7 into main May 18, 2026
4 checks passed
@mrsimpson mrsimpson deleted the feat/per-user-secrets branch May 18, 2026 09:52
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