Skip to content

feat(tokens): API keys that open one namespace alone - #415

Merged
adeelahmad merged 1 commit into
mainfrom
claude/project-thread-iq6ke4
Oct 15, 2026
Merged

adeelahmad merged 1 commit into
mainfrom
claude/project-thread-iq6ke4

Conversation

@adeelahmad

Copy link
Copy Markdown
Owner

Requested by Adeel · project thread

Description

Before: an app given a Lens API key to call one namespace's chat completions or MCP server could use that key anywhere in Lens, with every namespace its maker can read.

After: an API key can be made for one namespace. It opens that namespace's own MCP server (/mcp/<namespace>) and chat completions (/api/v1/namespaces/<namespace>/chat/completions and /models), with its maker's role there, and is refused (401) everywhere else, so an app given it can't read other namespaces or make keys. On the API tokens page it is the new Opens field (default: everything you can read, as before). Connect apps on the namespace page links to the form with the namespace filled in and the name suggested ("pods app key").

How:

  • POST /api/v1/tokens takes an optional namespace; the key stores the namespace's id. Token lists show namespace (empty when that namespace is gone).
  • deps._resolve sets Principal.space from the key. On any path other than that namespace's own servers (deps.serves), the key authenticates as no one, with the reason in the 401 (deps.signed_out). On those paths the person's roles are narrowed with deps.within, so a lost role or a deleted namespace opens nothing.
  • Making one needs a role in the namespace (Acl.namespace), and it is audited with the namespace.

This is PR 3 of 3 for the thread, after #401 (an MCP server for each namespace) and #413 (chat completions for one namespace).

Motivation and Context

Adeel asked for per-namespace scoped MCP servers and chat completions, so any general app can be integrated easily. A key that opens one namespace alone means the app is scoped too, not only the endpoint.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change; ! in the title)

Checklist:

  • The title is a Conventional Commit.
  • My code follows the code style of this project (make hooks checks it on commit).
  • I added or updated tests (tests/api/test_namespace_keys.py, __tests__/tokens-page.test.tsx, __tests__/connect-apps.test.tsx).
  • My change requires documentation updates, and I have updated docs/ accordingly (docs/authentication.md, docs/api.md, docs/mcp.md).
  • Users need more than the title to understand it, so I wrote it under ## Unreleased in CHANGELOG.md.

Done questions (AGENTS.md)

  • Goal: completes the ask (namespace MCP servers in feat(mcp): an MCP server for each namespace #401, chat completions in feat(api): chat completions for any app, from one namespace #413, keys scoped to them here). I'll merge it on green.
  • Agents: POST /api/v1/tokens with namespace.
  • Zero setup: nothing to install or configure.
  • Fewest clicks: Connect apps opens the form with the namespace and a name filled in; Enter makes the key.
  • Configurable: Opens defaults to everything you can read, as before.
  • Light: no new dependency or process.
  • Private and secure: it only narrows what a key opens. Threat model updated (§1.7 /mcp/<namespace> row, P-ROLE).
  • Cost: n/a, no model calls.
  • User decides: existing keys and the default are unchanged.
  • Upgrades: a new optional field on api_token (space). Its absence means every namespace, as before, so no upgrade step is needed.
  • Honest: docs describe only what's merged here.
  • Tests, docs and generated files: make openapi regenerated the client. The full backend suite (1108) and jest (892) pass locally.
  • Open standards: n/a, Lens's own API keys.
  • Reported in the thread. Refine later: an app key (lo_) chosen for one namespace at sign-in, not only by its resource.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LB2qrE7CENSd3G5h4FxFra


Generated by Claude Code

An API key can be made for one namespace (namespace on POST /api/v1/tokens,
or Opens on the API tokens page, which Connect apps fills in). It
authenticates only on that namespace's own MCP server and chat completions,
with its maker's role there, and is refused (401) everywhere else in Lens.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LB2qrE7CENSd3G5h4FxFra
@adeelahmad adeelahmad self-assigned this Oct 15, 2026
@adeelahmad
adeelahmad merged commit 6d43d8e into main Oct 15, 2026
11 checks passed
@adeelahmad
adeelahmad deleted the claude/project-thread-iq6ke4 branch October 15, 2026 14:01
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.

2 participants