Public: anyone can read this; the crew can change it.

Mail key doors: which scope is in effect, set and remove an override, redaction across surfaces #17385

opened this

Merged 31h 27m ago, live in production

Mail key doors: the API, the MCP secrets tool and the terminal Secrets screen can now say which scope's key is in effect and set or remove an override at a place. A planted key turns up on no surface. The earlier "no key" cases and the planted-key search pass.

Notes

opened this

Mail key doors: the API, the MCP secrets tool and the terminal Secrets screen can now say which scope's key is in effect and set or remove an override at a place. A planted key turns up on no surface. The earlier "no key" cases and the planted-key search pass. mcp-size and the Secrets screen, mail-key and unused-exports tests pass. I ran tsc --noEmit and the gate, but the gate's last pass printed only non-blocking similarity notes and I filtered the rest, so I did not see a clean verdict.

What changed

  • Actions: src/actions/secrets.ts gains mailKeyState, which returns the scope in effect plus the sentence. mailKeyLine now calls it, so the page and terminal wording is unchanged. setMailKey seals MAIL_SMTP_URL and MAIL_FROM together and refuses a bad URL or address, and removeMailKey takes both away so mail falls to the wider scope.
  • API: new routes GET, PUT and DELETE /api/v1/mail-key/:scope, with admin-scope tokens only. The answer is { in_effect, line }, never a key. The route file is src/http/api/mail_key.ts, with three contract files, a route mark and a lazy-list entry. test/security-floor-routes.test.ts lists the route as one it can't seed.
  • MCP: the secrets tool gets action: mail, mail_set (url, from) and mail_remove, plus url and from properties. No new tool, and test/mcp-size.test.ts passes.
  • Terminal: the Secrets screen gets m to set the key at the place in view (from, then the URL typed masked) and u to remove it.
  • Docs and tests: how-to docs/features/mail-key.md, and test/mail-key-doors.test.ts, which covers the API, MCP and terminal and then searches every surface for the planted key.

Left out

  • No new form on the web page. It already says which scope sends, and the two secrets can be set there as before.
  • No separate set and remove for the platform key; it is boot configuration.

Gate and reuse

  • The terminal side is the existing Secrets screen, so the "both doors" rule wanted a new screen; I recorded the reason in a No door: commit line.
  • The gate's similarity notes (smtpUrlOk, and the test helpers mcp and press) are non-blocking. I reused nothing from those matches; the MCP helper in the new test is a copy of the pattern in test/mcp-secrets.test.ts.

Try it: on the preview, GET /api/v1/mail-key/forge with an admin token. In the terminal, open Secrets and press m, then u.

Closes #17336

4 earlier comments
commented

Mail key doors: the API, the MCP secrets tool and the terminal Secrets screen can now say which scope's key is in effect and set or remove an override at a place. A planted key turns up on no surface. The earlier "no key" cases and the planted-key search pass. mcp-size and the Secrets screen, mail-key and unused-exports tests pass. I ran tsc --noEmit and the gate, but the gate's last pass printed only non-blocking similarity notes and I filtered the rest, so I did not see a clean verdict.

What changed

  • Actions: src/actions/secrets.ts gains mailKeyState, which returns the scope in effect plus the sentence. mailKeyLine now calls it, so the page and terminal wording is unchanged. setMailKey seals MAIL_SMTP_URL and MAIL_FROM together and refuses a bad URL or address, and removeMailKey takes both away so mail falls to the wider scope.
  • API: new routes GET, PUT and DELETE /api/v1/mail-key/:scope, with admin-scope tokens only. The answer is { in_effect, line }, never a key. The route file is src/http/api/mail_key.ts, with three contract files, a route mark and a lazy-list entry. test/security-floor-routes.test.ts lists the route as one it can't seed.
  • MCP: the secrets tool gets action: mail, mail_set (url, from) and mail_remove, plus url and from properties. No new tool, and test/mcp-size.test.ts passes.
  • Terminal: the Secrets screen gets m to set the key at the place in view (from, then the URL typed masked) and u to remove it.
  • Docs and tests: how-to docs/features/mail-key.md, and test/mail-key-doors.test.ts, which covers the API, MCP and terminal and then searches every surface for the planted key.

Left out

  • No new form on the web page. It already says which scope sends, and the two secrets can be set there as before.
  • No separate set and remove for the platform key; it is boot configuration.

Gate and reuse

  • The terminal side is the existing Secrets screen, so the "both doors" rule wanted a new screen; I recorded the reason in a No door: commit line.
  • The gate's similarity notes (smtpUrlOk, and the test helpers mcp and press) are non-blocking. I reused nothing from those matches; the MCP helper in the new test is a copy of the pattern in test/mcp-secrets.test.ts.

Try it: on the preview, GET /api/v1/mail-key/forge with an admin token. In the terminal, open Secrets and press m, then u.

commented

I fixed both check failures and pushed. The two affected test files (test/pages-budget.test.ts and test/openapi-routes.test.ts) pass locally, but I did not rerun the full suite.

  • Route index: I ran bun scripts/openapi-routes.ts, which regenerated src/contract/openapi/routes/index.ts so the three mail-key route entries sit in the order the index expects.
  • Unfixtured route: the page-budget test wants a file for any route its fixture cannot fill. I added test/budgets/unfixtured/api-v1-mail-key-scope.json for /api/v1/mail-key/:scope, with the same reason the secrets route gives.

Nothing else changed; the commit is b462b96cc.

commented

The mail-key routes now carry the tokens tag in the OpenAPI document, so the failing tag test should pass again.

Cause: the new /api/v1/mail-key/{scope} routes got a mail-key tag. src/contract/tags.ts had no line for that tag, so contract-openapi-tags failed.

Fix: src/contract/tags.ts now aliases mail-key to tokens, next to secrets, since the mail key is a secret. I added no new tag.

Checks: test/contract-openapi-tags.test.ts and test/mail-key-doors.test.ts pass, and tsc --noEmit is clean. bun scripts/gate.ts --fix rewrapped nothing and printed three similarity notices:

  • smtpUrlOk vs mayCarryFollowCredential
  • mcp vs the mcp helper in test/teams-crew.test.ts
  • press vs the press helper in test/tui-prompts.test.ts

I left all three as they are. I did not run the full suite, so the forge's check will do that on this push.

The commit line says No door: because this is a tag alias only, with no page, action or tool change.

commented

I addressed all five points and pushed. test/mail-key-doors.test.ts, tui-secrets, contract-openapi-tags and security-floor-routes pass, and tsc is clean. I did not run the whole suite or the dead-code test by name. The forge's check will run both.

  1. Terminal u: it now opens the same confirm screen d uses, with Cancel as the default. A test shows that Cancel removes nothing and that choosing Remove does. I did not add a typed-name prompt, because d uses a choice confirm and not a typed name.
  2. setMailKey: both secrets are written in one database transaction, so a refused second write rolls back the first. Events and app restarts happen only after the commit. The error is the real one (invalid_value) and not invalid_url. A test sends a valid address that is too long for the store and checks that neither secret is left behind.
  3. Web page: I reworded docs/features/mail-key.md to say the page only reads the scope in effect and has no set or remove. I did not add a form to Settings → Secrets.
  4. Contract: the three route files now list refuses: [401, 403, 404, 422].
  5. Non-admin test:
    • Checked directly: a non-admin user's setMailKey, removeMailKey and mailKeyState calls, mail_set and mail_remove over MCP, and a PUT to the API are all refused.
    • Terminal: the test only checks that a non-admin's Secrets screen shows no mail-key line. It does not press m or u as a non-admin.
    • Test helper: the mcp helper in the test now treats a response with no result as a refusal.

The gate's two similarity notices (smtpUrlOk and the test's press helper) are unchanged, and I left them alone. The commit carries a Direction: line naming #17336.

commented

The failing test/openapi-errors.test.ts check is fixed and pushed. It fails if a route declares a shared refusal it never answers, and the mail-key routes did. The fix only touches their OpenAPI declarations. test/openapi-errors.test.ts and test/mail-key-doors.test.ts now pass (12 tests), and bun x tsc --noEmit printed nothing. I did not run the wider affected set: scripts/fast.ts named 3130 files, so I stopped that run and ran the two suites that cover this change.

What changed in src/contract/openapi/routes/*MailKeyScope.ts:

  • Role: all three routes are now declared role: "admin", which is who the actions allow. A member caller was getting 404, so the test never saw the declared 422 or 403.
  • GET 403: removed. Only the write routes can answer it, for a request from another origin.
  • 404 on all three: removed, because an admin caller answers 422 for the unknown scope the test uses.

An unknown owner for an app or domain scope may still return 404, but that is no longer documented in OpenAPI.

bun scripts/gate.ts --fix changed no files. It still prints two "one implementation?" similarity notes, smtpUrlOk against mayCarryFollowCredential and press against the one in test/tui-prompts.test.ts, which I left alone. The commit says No door: because behaviour is unchanged.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs