Skip to content

harden(keys): minting an API key requires an interactive session - #27536

Merged
objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/harden-keys-interactive-mint
Oct 29, 2026
Merged

objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/harden-keys-interactive-mint

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Dispatched by the W3-C3b QA run security path (detail withheld)

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么:创建 API key(POST /api/v1/keys)现在只接受登录会话发起的请求;用 API key 认证的请求一律 403 PERMISSION_DENIED,不写任何数据。
  • 为什么改:安全加固。创建凭据属于凭据生命周期操作,应当由账号本人登录后完成,不应由一把 key 代办。
  • 风险与回滚:风险在于曾用 API key 调用该接口的脚本会改为收到 403;控制台、Connect an Agent 页面和带会话的调用不受影响。回滚 = revert 本 PR。
  • 先看:packages/runtime/src/domains/keys.ts(新增的会话判定,紧跟匿名判定之后、读取请求体之前);packages/runtime/src/domains/keys-mint-interactive-session.pin.test.ts;packages/runtime/src/api-key-lifecycle.pin.test.ts 中改写的 control 用例。
  • 两分钟验证:pnpm --filter @objectstack/runtime exec vitest run --project local src/domains/keys-mint-interactive-session.pin.test.ts,预期 14 个用例全部通过。
  • 需要你做的:无,席位落地。

What changes

POST /api/v1/keys mints only for a principal that a signed-in session admitted.

  • packages/runtime/src/domains/keys.ts: right after the anonymous decision (ADR-0138 D2) and before the body is read, the domain asks HttpProtocolContext.admission.credential, which the dispatcher's identity step writes from the shared resolver (resolveAuthzContext's credential, via onAdmission). Anything other than 'session' is refused 403. That covers an API-key admission and also an absent admission, because a credential the door was never told about is not a session. The check is positive on purpose, so a credential kind added later is refused until it is admitted explicitly.
  • The refusal is domain-wide, so every verb from a key-admitted caller gets the 403 instead of the 405. A session-admitted caller still gets the 405 for a wrong verb.
  • Error code: the existing status-derived PERMISSION_DENIED. This route already answers it when the caller is not a member of their active organization. No new code, no ledger change.
  • The module header and one inline comment are updated to match. The comment had described the active organization as possibly coming from a minting key's stamp, and only a session reaches that line now.
  • Changeset: @objectstack/runtime patch. It names who is affected and tells embedders that call HttpDispatcher.handleKeys directly to record the admitting credential.

Tests

  • New: packages/runtime/src/domains/keys-mint-interactive-session.pin.test.ts (14 cases).
    • Through dispatch(): session mint is 201 with one row pinned to the session user. An API-key admission in each accepted header spelling (x-api-key, Authorization: ApiKey, Authorization: Bearer osk_…) is refused 403 PERMISSION_DENIED with nothing written. A cookie beside the key does not lift the refusal. Every verb gets the 403. Controls: a session wrong verb gets 405, anonymous gets 401 UNAUTHENTICATED.
    • At handleKeys: no admission, or an api_key admission, is refused with the body unread and no service resolved. A session admission mints.
  • Fixture triage. Hand-built "signed-in" contexts in seven runtime test files never said which credential admitted them. Each one now declares admission: { credential: 'session', authGate: undefined }. No assertion moved.
  • One assertion was rewritten: the control the same key, live, is served in api-key-lifecycle.pin.test.ts used a live key to mint. It now pins what it exists to prove. The live key passes the identity step: dispatch() resolves, the admission is api_key and the principal is the key's owner. The door then answers with its own rule (403 PERMISSION_DENIED), never a lifecycle code.
  • Ablation, run once on the committed fix (subject reached through relative src imports, so no dist rebuild was involved). node scripts/ablation-replace.mjs replaced the session condition with if (false): anchor 1 to 0, blob 2d6f7ad939f2 to 96dff2464c80. Result: 11 of the 28 cases across the new pin file and the lifecycle pin failed (every refusal case and the rewritten control), and every control stayed green. Restore: blob equal to HEAD and git diff HEAD empty.
Runtime suite readings
  • Before the fixture triage (first full run, fix only): Test Files 7 failed | 464 passed (471), Tests 32 failed | 7636 passed | 19 skipped. All 32 failures were hand-built signed-in fixtures without an admission, plus the live-key mint control.
  • Affected files after the triage (11 files, including the hono every-verb integration and the account-posture pin): Test Files 11 passed (11), Tests 502 passed (502), lock VERDICT command-exit 0.
  • pnpm --filter @objectstack/runtime typecheck: exit 0. check:test-typecheck OK: 27 files, 190 errors, 68 pinned signatures, unchanged ledger.
  • Full suite on the final head: at 11fff72f, pnpm --filter @objectstack/runtime exec vitest run --project local gave Test Files 472 passed (472) and Tests 7682 passed | 19 skipped (7701), lock VERDICT command-exit 0.

Acceptance notes

  • packages/qa/dogfood/test/authz-conformance.matrix.ts: the anonymous-deny-keys row's note says "a signed-in caller reaches the mint exactly as before", which is still true for a session. This PR adds no row for the session requirement (outside this dispatch's file surface). Carrier: the dispatching seat.
  • The docs that teach minting (content/docs/api/index.mdx, content/docs/ai/connect-mcp.mdx, content/docs/api/client-sdk.mdx) already show session-based minting. None of them says a key cannot mint. A one-line mention there is a follow-up, outside this dispatch's file surface. Carrier: the dispatching seat.
  • No ui/ change: the Console's mint calls (AgentConnectSection.tsx, the create_api_key action) send the session cookie.

Verification

Local gate families (dispatch-gates, final head)
  • node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack derived 60 commands for the 10 changed paths. All 60 were run. 58 exited 0.
  • Two were NOT MEASURED (exit 3, prerequisite refusals unrelated to this diff):
    • node scripts/check-plugin-teardown-shape.mjs --self-test needs an unshallowed clone. It is checker health only.
    • pnpm check:dual-build-cjs-loads needs dist/ for seven packages outside this diff's build closure.
  • --ran reconciliation: 60 derived famil(ies) accounted for — 58 run, 2 NOT-MEASURED (2 DERIVED from a recorded exit 3).
  • Every CI-run family (Lint and Repo Gates, TypeScript Type Check, Test Core, Build Core and the rest) is CI's to report on this PR.

Generated by Claude Code

@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling labels Oct 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

2 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run.

What this run could not see
  • the SDK route bridge reached 58 of 210 client-bound route-ledger rows — the other 152 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 152: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 55 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 97 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 28 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 57c51aab4d2f63293676e9412daed8a5fc54c1bc → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 84cf8d055758861ff78fdeaf51d86dfc6479b625 — the merge of head 11fff72f9058bbb34358a7bb958786df07cd7e30 into base 57c51aab4d2f63293676e9412daed8a5fc54c1bc, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 84cf8d055758861ff78fdeaf51d86dfc6479b625 && git checkout 84cf8d055758861ff78fdeaf51d86dfc6479b625
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 57c51aab4d2f63293676e9412daed8a5fc54c1bc 11fff72f9058bbb34358a7bb958786df07cd7e30 && git checkout -B drift-repro 57c51aab4d2f63293676e9412daed8a5fc54c1bc && git merge --no-ff 11fff72f9058bbb34358a7bb958786df07cd7e30

node scripts/docs-audit/affected-docs.mjs --json 57c51aab4d2f63293676e9412daed8a5fc54c1bc

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:devx#1 · sunhaolin · session_017xRBcVkGJizGH7raJHhAvL

席位核对

ACCEPT at head 11fff72f9058bbb34358a7bb958786df07cd7e30. The maintainer instructed this session, verbatim: 「你应该使用 pm-dispatch 技能审核和落地 pr」.

  • Form: a draft against main. No card is referenced, because this is the security dispatch path, which carries no issue by the maintainer ruling of 2026-10-29. No closing keyword appears anywhere in the body.
  • Surface: check-governed-merges --pr 27536 reads NOT governed, 318 changed lines, below the 3000-line threshold. All 10 paths are in packages/runtime plus one changeset, matching the declared surface.
  • Contract faces: Clause-②: no. This is a runtime security-behaviour change (execution-duties: not a clause-② change). The PR touches no packages/spec/src/** and declares no narrowing arm, so no contract-tier review is owed.
  • Changeset: @objectstack/runtime patch. I checked it sentence by sentence against the diff: the 403 PERMISSION_DENIED on every verb for an API-key-admitted caller, a session cookie beside a key not lifting it, and the guidance for embedders calling handleKeys with admission. All match keys.ts.
  • Assertions: the refusal cases in keys-mint-interactive-session.pin.test.ts assert both the status and the envelope code (PERMISSION_DENIED, httpStatus 403), with controls (session 201, session wrong verb 405 METHOD_NOT_ALLOWED, anonymous 401 UNAUTHENTICATED). The check is positive (credential !== 'session'), it runs before the body read, and an absent admission fails closed.
  • Ablation: reported as 11 of 28 cases red with the condition disabled, restored to HEAD.
  • CI pinned to the head: 48 check-runs on 11fff72f, 34 success, 14 skipped, 0 failure. Lint & Repo Gates success, TypeScript Type Check success, Test Core 8/8 success, Build Core success. mergeable_state clean.
  • Deviations: none blocking. Two Acceptance-notes follow-ups (an authz-conformance matrix row and a docs one-liner) stay with the dispatching seat, per the notes.

Landing: pr_ready + automerge_enable through the relay.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant