Skip to content

feat(secrets): mediate Custom-secret API calls from member chats - #23843

Closed
RohanK6 wants to merge 2 commits into
mainfrom
feat/mediated-secret-egress-v3
Closed

RohanK6 wants to merge 2 commits into
mainfrom
feat/mediated-secret-egress-v3

Conversation

@RohanK6

@RohanK6 RohanK6 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: An agent in a member conversation can call an owner-approved HTTPS API with a stored Custom secret, without the secret ever entering the sandbox.

Today a Custom secret can only reach a tool by being injected into an MCP server's environment at launch (secret://NAME). An agent in chat has no way to make a single authenticated call to, say, a webhook or a ticketing API with a key the owner stored, short of the owner wiring a whole MCP server for it. Issue #8628 asks for a mediated path: the agent names the secret and the request, the host injects the value and sends it.

This replaces #23756 (same change; a review round would have taken it past two commits, so it is one fresh commit on current main) and, before it, #10383, which was built on the member-proof model that #11780 removed (member_proof_header_value, issue_member_session_proof) and could no longer merge. This PR is a rebuild on the current caller-identity model, not a port of that one.

Why it matters

Without it, owners either hand the raw key to the agent (it lands in the transcript and the sandbox) or build an MCP server per API. A host-mediated call keeps the key in the vault, keeps the destination under the owner's control, and keeps each call behind an approval.

Not a goal

  • Reading API responses. The tool is write-only (POST/PUT/PATCH/DELETE) and every call returns the same fixed result, so a reflected credential has no channel back into the sandbox. Returning bodies is a separate decision.
  • Windows support. The trust argument depends on an attested Unix socket that Windows does not have; there the tool refuses explicitly.
  • Making the tool available by default. kirocrew-secrets is opt-in like the other assignable sets.

What changed (motivation → approach → change)

End-to-end flow:

owner:  kirocrew secrets authorize NAME https://api.example.com [--header X-Api-Key]
          -> signed policy in <data home>/secret-request-policy/ (masked in every sandbox)

agent (member chat) -> call_api_with_secret(secret_name, method, url, headers, query, json_body)
  -> ACP permission prompt -> owner approves
       -> under the ACP write lock, after the withdrawal / liveness / grant-deadline
          checks: mint a single-use capability bound to (session, tool_call_id, exact args),
          then write the answer frame (an undelivered answer revokes it, pending or claimed)
  -> kirocrew-secrets MCP stub (in sandbox)
       -> owner-only dashboard Unix socket; checks the answering peer is the gateway
          (SO_PEERCRED principal + published pid/start-token) before sending anything
       -> POST /api/mediated-secret-capability   (claim the capability for this call)
       -> POST /api/mediated-secret-request      (consume it; X-Mediated-Secret-Capability)
  -> gateway: internal secret + attested member scope (member_request_scope) required;
       Global chat (no member store) refused 403
       -> verify signed policy, exact-origin match, link_unfurl.vet_unfurl_url
          (public-address vet) + pinned_connector (connect only to vetted IPs),
          inject secret, send over aiohttp, cap redirects/timeouts
       -> fixed withheld result back to the agent

Caller identity. Main's current model is member_request_scope: the internal secret plus a transport attestation of X-Session-Key (session_key_is_attested: peer ancestry, or the signed per-session token on pooled backends). Both new routes are strict internal paths and use it, so a process that only read the loopback secret and a session key is refused. That answers the earlier GPT finding that the documented member path could not mint the proof it needed: there is no separate proof to mint now; the approval-minted capability is the per-call binding, and it is only issued when the call goes through hooks.on_tool_call, which is why the server has no autoApprove and doctor never blanket-allows it.

Policy integrity. The policy is signed with a gateway-certified key minted after bind (secrets_mediation/signing_root.py, kicked off in both gateway entrypoints so the listener never waits). The key, policy and authorize lock live in one directory that every sandbox tier masks whole and that is precreated before any spawn, so publications rename inside it and never over a mount point.

Windows. #10383 used unix_socket_urlopen unconditionally, which fails opaquely on Windows. The stub now returns an explicit unsupported-platform error there, gated on platform_compat.IS_WINDOWS (not hasattr(socket, "AF_UNIX"), which modern Windows Python passes).

Other pieces: the secrets authorize CLI (cli_commands_secrets.py, parser in cli_parser_admin.py), capability registry (mediated_request_capability.py), mint/revoke wired into both approval transports (acp/client_permissions.py, acp/session_handle_permissions.py), registry/discovery/cleanup entries for the new opt-in server, secret-request-policy added to the agent file-tool deny list, a short two-sentence Custom-secrets card copy in all 13 catalogs that labels kirocrew secrets authorize as a terminal command, and docs in docs/system-specs/modules/security.md.

SSRF and transport. Dispatch has no URL vet or transport of its own: it calls link_unfurl.vet_unfurl_url (the same vet link previews, the remote MCP probe and calendar use) and sends through pinned_connector, so the connection can only reach an address the vet approved. No new HTTP dependency.

Approval ordering. Both approval transports (acp/client_permissions.py, acp/session_handle_permissions.py) mint the capability as the last check under the ACP write lock, after the withdrawal, the runtime's liveness check and the grant deadline (ApprovalMint in mediated_request_capability.py). So no grant exists while an approval waits for the lock, and stopping the member during that wait leaves nothing to claim. If the answer frame is not delivered, revoke_minted removes the grant whether it is still pending or already claimed. An approval for any other tool hands the transport no extra write check and is sent exactly as before. Cancelling a turn on either ACP path (AcpSessionHandle.cancel, AcpClient.cancel_session) calls invalidate_session first, so a call the operator stopped cannot claim or consume an approval it already received. Other sessions' grants are untouched.

Key recovery. A signing key document that no longer certifies (for example after token_signing.key was recreated) is never repaired by the gateway, so a restart alone reproduces the failure. provenance.host_key_problem separates the two cases. A missing key tells the operator to start the gateway. An unusable key gives the remedy in both the secrets authorize error and the gateway's degradation audit: remove secret-request-policy/key.json, restart, then re-authorize.

Grant lifetime. An approved grant waits for its call to reach the shared kirocrew-secrets backend, which runs calls one at a time with each padded to its deadline. So a pending (approved, unclaimed) grant lives for the bounded queue depth times the per-call budget, and a claimed grant gets the short 30 s redemption lifetime. A call queued behind a 60 s call is no longer refused. Cancellation and single use still hold.

Backwards compatibility

Compatible: the server is opt-in and new, the CLI subcommand and routes are new, and the existing secret:// launch injection is untouched.

Removes nothing: the diff only adds a server, routes, a CLI subcommand, a masked directory and copy; no existing key, path or behavior is narrowed.

Tests

  • test/test_mediated_request_dispatch.py: method allowlist, exact-origin match, userinfo/redirect/timeout handling, vault read only after policy checks, and the withheld constant for every post-send outcome.
  • test/test_mediated_request_dispatch.py also covers the shared vet: a private/loopback target is refused through vet_unfurl_url, and the send uses pinned_connector for the vetted address.
  • test/test_mediated_request_policy.py, test/test_mediated_request_provenance.py, test/test_mediated_signing_root.py: signature verification, torn/unsigned policy refusal, post-bind key mint.
  • test/test_secrets_authorize_cli.py: add/remove/reset, refusal without the gateway-owned directory, publication only inside the hidden directory.
  • test/test_mediated_secret_request_handler.py: internal-auth, attested member scope, Global refusal, capability claim/consume/replay, bounded body read across multiple chunks, and a pending grant that outlives a queued 60 s call while a claimed grant keeps the short TTL.
  • test/test_mcp_secrets.py: stub peer verification, payload caps, Windows refusal.
  • test/test_transport_permission_floor.py: approval mints the capability under the write lock and revokes it when the answer write fails; nothing is minted when the member is withdrawn while the approval waits for the lock; a grant claimed during a failed write is revoked and cannot be consumed (both transports); cancelling a turn on either transport revokes that session's pending and claimed grants and leaves another session's alone.
  • test/test_mediated_request_provenance.py / test/test_mediated_signing_root.py: an uncertifiable key's error and degradation audit name the remedy; a missing key says to start the gateway.
  • Clock-dependent tests use ManualClock().install(...) on the module under test and a module-local asyncio stand-in, never the stdlib time module or real-time ceilings.
  • test/test_cli_mcp_doctor.py::test_auto_fix_never_blanket_allows_mediated_secret: doctor never pre-approves @kirocrew-secrets.
  • Contract updates: composition lazy-import table, dashboard composition census (+2 MCP routes, the signing-root kick in both boots, +1 lazy import), sandbox leaf-only counts (+1 per tier for the masked directory), security package line budget (+3 for one deny-list entry), MCP registry/shared-dispatch tests.
  • website/src/pages/settings/SecretsPanel.test.tsx: new card copy.

Local run: 2172 passed on the first commit across the feature, ACP transport, session-handle bindings, CLI, doctor, link-unfurl, secrets and composition-contract suites. On the second commit, a further 2086 passed across the feature, ACP client/session, transport floor, stop/cancel and composition suites (SecretsPanel.test.tsx passed 63 on the same card copy before this rebase; it cannot load locally right now because current main added a vite plugin the shared node_modules lacks); mypy src/kiro_crew/ clean; flake8, black, isort clean on changed files; file-line-cap, agent-SDK boundary, sync-IO-in-async, ACP fixture and lockdown gates pass; i18n check and parity pass.

Manual verification

Not run end to end against a live upstream API on this host. The dispatch, handler and stub paths are covered by the tests above with the network and vault faked.

Screenshots / video

Custom secrets card with the updated copy:

Custom secrets card, light

Dark

Custom secrets card, dark

Related Issues

Fixes #8628

Supersedes #23756 and #10383.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license.

Add an opt-in kirocrew-secrets MCP server whose call_api_with_secret
tool lets an agent in a member conversation make one owner-authorized
HTTPS write call with a stored Custom secret. The gateway injects the
value host-side, so the plaintext never enters the sandbox, and every
call returns the same fixed result.

- `kirocrew secrets authorize NAME ORIGIN` binds a secret to one exact
  https origin in a policy signed with a gateway-certified key. The
  key, policy and lock live in secret-request-policy/, which every
  sandbox tier hides whole and which is precreated before any spawn.
- Approving the tool mints a single-use capability bound to the call
  id and its exact arguments. Both approval transports mint it as the
  last check under the ACP write lock, after the withdrawal, liveness
  and grant-deadline checks, and revoke it, pending or claimed, when
  the answer is not delivered.
- The host routes require the internal secret plus an attested member
  scope (member_request_scope), then claim and consume the capability.
- Dispatch vets every hop with link_unfurl.vet_unfurl_url and sends
  through pinned_connector, pads completion to the request deadline,
  and refuses outbound values the redactors would change.
- The stub verifies the gateway peer on the owner-only socket and
  refuses explicitly on Windows.

Fixes #8628
@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 8653c3f2c002ee5d893305be2e2453269b75e184 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the feature is opt-in, it fails closed, and the take-aways only touch a brand-new masked directory that nothing else reads.

Notes

  • Approval and execution are linked by assuming the harness's progressToken equals the ACP toolCallId (backend_wire._carry_tool_call_id: "kiro-cli sends that id as the tools/call _meta.progressToken"). On any other selectable harness that assumption is unverified, so every claim would be refused (closed, but silently broken). Either state which backends the tool supports, or have the tool refuse explicitly on the others, as it already does on Windows.

[DESIGN-REVIEWED] 8653c3f

Description read

[DESCRIPTION-READ] e5f48536210ccc5624538dd3a2c731dba2e23aff0e2e813e3701bc226b524718

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🔴 BLOCK

Premise-level review of 8653c3f2c002ee5d893305be2e2453269b75e184 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: BLOCK

The policy-signing key (key.json, its boot-time mint and its recovery path) is a second, stored copy of a purpose key the repo already derives from token_signing.key without any file.

Notes

  • Item 9 — zero consumers: _secret_policy_key(..., create=False) says "retained for caller compatibility but deliberately ignored" in a brand-new module, and both of its 2 callers pass False. outstanding_overflow_refusals() has 0 non-test consumers. Subtraction: delete the create parameter and outstanding_overflow_refusals.

What this change ships

Inventory (9 items) — 7 justified

Intent: let a member-chat agent make an owner-approved HTTPS call with a stored Custom secret it never sees (an ADDITION).

  1. New opt-in kirocrew-secrets MCP server with the call_api_with_secret tool — justified
  2. New kirocrew secrets authorize NAME ORIGIN CLI command — justified
  3. Two new gateway routes that claim and consume a mediated request — justified
  4. Single-use, approval-bound capability minted under both ACP approval paths — justified
  5. Cancelling a turn revokes its grants — justified
  6. New secret-request-policy/ directory, masked in every sandbox tier and on the file-tool deny list — justified
  7. Signed policy key minted after the listener binds, plus its degradation audit and key-remedy text — duplicate of mirror_admission._purpose_key
  8. Custom-secrets card copy reworded in 13 catalogs — justified
  9. Dead create parameter and an unused overflow counter getter — zero consumers

Blockers

Stored certified key re-implements an existing derived purpose key — duplicate of src/kiro_crew/mirror_admission.py:_purpose_key
Trigger: provenance.py mints key.json, whose only authenticity comes from hmac.new(_token_root(), _HOST_KEY_CERT_DOMAIN + key, …). The CLI reads _get_secret() anyway. mirror_admission._purpose_key already does the same job with hmac.new(token_secret._get_secret(), _ADMISSION_KEY_DOMAIN, …). A grep for _get_secret() across src found 7 call sites, and one of them (mirror_admission) is already this file-less shape.
Outcome: you carry signing_root.py, _kick_mediation_signing_root_mint in both entrypoints, host_key_problem, UNUSABLE_KEY_REMEDY and a permanently broken state after a token-key rotation. The HEAD commit's "name the key remedy" is a patch for that self-made failure.
Subtraction: derive the policy MAC key as hmac(token_secret._get_secret(), <domain>). Then delete key.json, signing_root.py, both boot kicks and the remedy/problem text.
Clears when: the policy MAC key is derived from token_signing.key with no stored key document, or a maintainer records /ai-review override first-principles 8653c3f2c002ee5d893305be2e2453269b75e184 duplicate: <decision>.

[FIRST-PRINCIPLES-REVIEWED] 8653c3f

Description read

[DESCRIPTION-READ] ad65e34324d1f7cb4c2585571e76e1c9a0c424dbf21108610ae3a1203ea73d81

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS (a BLOCK with no Trigger and no Outcome does not block)

UX-level review of 8653c3f2c002ee5d893305be2e2453269b75e184 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

cannot evaluate: missing a screenshot of the Custom secrets description as this commit ships it. Both committed screenshots show an older, longer paragraph, so nobody has cold-read the new copy.

Evidence gaps

  • The Custom secrets card's description (settings…custom_description). The diff ships "Encrypted keys for MCP servers and .env settings. Reference one as secret://YOUR_KEY; the value is never shown in chat. To let the agent call one approved API with a secret, run the terminal command kirocrew secrets authorize." Both secrets-custom-description-dark.png and -light.png show a different paragraph instead: "…gateway-proxied member conversation… every call returns the same fixed result… (a default Global chat is refused)." The blind reader rated that old paragraph "no idea". To close the gap, recapture both themes with website/scripts/capture-secrets-custom-description.mjs against this HEAD.

Notes

  • The new copy still opens on jargon a first-time user won't know ("MCP servers", ".env", secret://). The blind reader already stalled on exactly these words. Lead with the task, e.g. "Encrypted keys the agent can use without seeing them," and keep the mechanism words for after.
  • "run the terminal command kirocrew secrets authorize" gives no format for the arguments. Show the full form inline (kirocrew secrets authorize NAME https://api.example.com), or link the setup guide that is already on this page.

[UX-REVIEWED] 8653c3f

Description read

[DESCRIPTION-READ] f5ac7343dd7b10e43fecdbe8f5395c2b72631943cee46ca10c95d32ed2b7dba4

That sha256 names everything this verdict read: the PR description, plus the 5 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@RohanK6

RohanK6 commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 14b8cb4
  • What rule changed: One new data-home directory, secret-request-policy/, is added to the crew hidden leaves (sandbox_leaves.py), precreated as a hidden directory before every spawn (sandbox_precreate.py), and added to the agent file-tool secret deny list (security/paths_lists.py). secrets_mediation/dispatch.py is registered in NON_EGRESS_REDACTION_MODULES (security_posture.py) as a refusal gate.
  • Before -> after (what was allowed/blocked, now): Before, the directory did not exist and nothing read it. After, every sandbox tier masks the whole directory (not readable or writable by agent processes), and the agent file tools refuse it. Only the host gateway and the owner kirocrew secrets authorize CLI open it. No existing path gains or loses access. The posture entry only classifies the dispatcher: it runs both redactors over agent-supplied URL/body/headers/query only to refuse the request when either would change a value, before any vault read, and returns a fixed constant, never redacted text.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): If the mask failed, an agent process could read the policy-signing key or rewrite the policy, so it could authorize its own origin for a Custom secret. If the precreate failed, a key or policy published after a sandbox started would sit outside the mask. A wrong posture classification would only mislabel a module that returns no redacted text. No existing command or user path is touched, so nothing existing breaks and no one is locked out.
  • Evidence checked (which sandbox result proves it): The sandbox leaf-only census tests count one more hidden leaf per tier, and test/test_sandbox_precreate_secret_dirs.py passes with the new directory precreated before spawn. test/test_secrets_authorize_cli.py proves the CLI refuses to publish without the gateway-owned directory and only publishes inside it. test/test_mediated_request_provenance.py and test/test_mediated_signing_root.py prove a tampered or unsigned policy is refused.
  • No regression:
    • Tools still work (which tools/commands were run, result): The full targeted suites ran on this head (CLI, doctor, MCP secrets stub, secrets handler, link unfurl, dashboard composition contract): 2172 passed, including the ACP approval transports and session-handle bindings. SecretsPanel.test.tsx passed 63 on the same copy before the rebase (it cannot load locally now, because current main added a vite plugin the shared node_modules lacks). flake8, black, isort and mypy are clean on the changed files, and the feature-map gate passes.
    • Backward compatible (old config / old data / old callers still work, how checked): The directory is new and the opt-in kirocrew-secrets server is new. secret:// launch injection and every existing deny or mask entry are unchanged (the diff only adds entries). Existing secrets handler and secret:// resolution tests pass unchanged.
    • Existing tests (which suites passed on this head): test_mediated_, test_mcp_secrets, test_transport_permission_floor, test_session_handle_bindings, test_acp_client, test_secrets_authorize_cli, test_secrets_handler, test_link_unfurl*, test_check_feature_map, test_cli, test_cli_doctor, test_dashboard_server_composition_contract*, test_sandbox_precreate_secret_dirs, SecretsPanel.test.tsx.
  • How to undo: Revert this PR's commit. That removes the leaf, precreate, deny-list and posture entries together with the feature. Any leftover secret-request-policy/ directory in a data home is inert once nothing reads it, and can be deleted by hand.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 8653c3f2c002ee5d893305be2e2453269b75e184 — this comment is updated in place on each push.

Review details

No findings.

Notes:

  • docs/architecture/mcp.md:1548: the new kirocrew-secrets row sits directly under a prose paragraph, so it renders as stray text. The managed-server table near line 1738 still has no entry for it.

[OPUS-REVIEWED] 8653c3f

Verdict parsed from the review's SHA-scoped output markers for commit 8653c3f2c002ee5d893305be2e2453269b75e184.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 8653c3f2c002ee5d893305be2e2453269b75e184 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — 🔴 changes requested (blocking)

GPT 6.1 found at least one blocking issue that must be resolved before merging 8653c3f2c002ee5d893305be2e2453269b75e184. 1 of 1 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands.

This comment is updated in place on each push.

BLOCKING -- src/kiro_crew/secrets_mediation/provenance.py:251 -- Non-ASCII signatures crash policy recovery

return hmac.compare_digest(signature, expected)
Trigger: With a valid signing key and a nonempty policy containing "sig": "é", kirocrew secrets authorize KEY https://api.example.com --reset reaches _authorize_txn → verify_secret_authorizations.
Outcome: compare_digest raises an uncaught TypeError before the reset branch, preventing recovery. A non-ASCII cert at line 116 likewise escapes the signing-key error handlers.
Anchor: residual/crash-data-loss-corruption
Fix: Reject non-ASCII MAC strings before both comparisons; return False for an invalid policy signature and raise the existing RuntimeError for an invalid key certificate.

[BLOCK-MERGE] 8653c3f
[GPT-REVIEWED] 8653c3f

Adjudication (Opus 5.5) — is blocking on each finding proportionate?

F1 (fenced): I'm flagging it. The defect is real, but it fails closed and nothing leaks.

  • Conditions:
    • The policy has to carry a non-ASCII sig. sign_secret_authorizations (src/kiro_crew/secrets_mediation/provenance.py:238) only ever writes hex, so the gateway's own writer can't produce one.
    • That leaves a file planted where the sandbox mask doesn't apply (the off tier, or a host with no sandbox backend; see src/kiro_crew/secrets_mediation/policy.py:72), or a hand edit.
    • The cert variant needs a non-ASCII value in the gateway-only key file, which _load_secret_host_root (provenance.py:108-116) reads. The gateway only writes hex certs there.
  • What happens:
    • At runtime, the TypeError escapes load_authorization (policy.py:236) before the secret is read, inside dispatch.py:263. The request is refused and nothing is exposed.

    • In the CLI, _authorize_txn (src/kiro_crew/cli_commands_secrets.py:213) raises before the --reset branch. That branch is the only CLI recovery path. The exception is a TypeError, so the (RuntimeError, OSError) handler at cli_commands_secrets.py:124 doesn't catch it.

    • Recovery is manual: the owner deletes the planted policy file. The harm is losing the recovery path on a file the system never writes itself, not losing credentials or the governance ceiling.

      [ADJUDICATION] 8653c3f total=0 uphold=0 downgrade=0
      [GPT-ADJUDICATED] 8653c3f

      [ADJUDICATION-FENCED] 8653c3f fenced=1 flagged=1
      FLAG F1 src/kiro_crew/secrets_mediation/provenance.py:251 -- Fails closed: only a planted or hand-edited non-hex sig/cert (never written by the gateway's own writer) reaches it, the TypeError raises before any secret read so nothing leaks, and the only cost is a CLI traceback on --reset that the owner clears by deleting the planted policy file.
      [GPT-ADJUDICATED-FENCED] 8653c3f

🏷️ Fenced finding(s) machine-flagged as likely edge case

The security fence keeps these findings blocking regardless of adjudication; the only clearance path is a human override. The annotate-only pass judged the condition combination each one requires extreme, and pre-drafted the override rationale below. A repository writer must independently verify a rationale before posting it — it is machine-authored, and a wrong override on a security-class finding ships exactly the class the fence exists to stop.

  • F1 src/kiro_crew/secrets_mediation/provenance.py:251 — Fails closed: only a planted or hand-edited non-hex sig/cert (never written by the gateway's own writer) reaches it, the TypeError raises before any secret read so nothing leaks, and the only cost is a CLI traceback on --reset that the owner clears by deleting the planted policy file.

    /ai-review override gpt 8653c3f2c002ee5d893305be2e2453269b75e184 <class>: Fails closed: only a planted or hand-edited non-hex sig/cert (never written by the gateway's own writer) reaches it, the TypeError raises before any secret read so nothing leaks, and the only cost is a CLI traceback on --reset that the owner clears by deleting the planted policy file.
    

Replace <class> with the class that records what you did. These findings are real, so for an accepted risk use owner-decision (link the decision comment in the reason) or deferred #<N> (a tracked follow-up issue); false-positive only if you verified the finding is wrong. Not not-applicable: that class files the override as a rule mismatch in the audit.

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 8653c3f2c002ee5d893305be2e2453269b75e184 false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Oct 24, 2026
- Cancelling a turn on either ACP path (AcpSessionHandle.cancel,
  AcpClient.cancel_session) now revokes that session's pending and
  claimed mediated-secret grants before the cancel goes out, so a call
  the operator stopped cannot claim and send on an approval it already
  received. Other sessions' grants are untouched.
- A present signing key that no longer certifies is never repaired by
  the gateway, so `secrets authorize` and the degradation audit now say
  how to recover (remove secret-request-policy/key.json, restart, then
  re-authorize) instead of "start the gateway". A missing key still
  says to start the gateway.
@RohanK6

RohanK6 commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 8653c3f
  • What rule changed: One new data-home directory, secret-request-policy/, is added to the crew hidden leaves (sandbox_leaves.py), precreated as a hidden directory before every spawn (sandbox_precreate.py), and added to the agent file-tool secret deny list (security/paths_lists.py). secrets_mediation/dispatch.py is registered in NON_EGRESS_REDACTION_MODULES (security_posture.py) as a refusal gate.
  • Before -> after (what was allowed/blocked, now): Before, the directory did not exist and nothing read it. After, every sandbox tier masks the whole directory (not readable or writable by agent processes), and the agent file tools refuse it. Only the host gateway and the owner kirocrew secrets authorize CLI open it. No existing path gains or loses access. The posture entry only classifies the dispatcher: it runs both redactors over agent-supplied URL/body/headers/query only to refuse the request when either would change a value, before any vault read, and returns a fixed constant, never redacted text.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): If the mask failed, an agent process could read the policy-signing key or rewrite the policy, so it could authorize its own origin for a Custom secret. If the precreate failed, a key or policy published after a sandbox started would sit outside the mask. A wrong posture classification would only mislabel a module that returns no redacted text. No existing command or user path is touched, so nothing existing breaks and no one is locked out.
  • Evidence checked (which sandbox result proves it): The sandbox leaf-only census tests count one more hidden leaf per tier, and test/test_sandbox_precreate_secret_dirs.py passes with the new directory precreated before spawn. test/test_secrets_authorize_cli.py proves the CLI refuses to publish without the gateway-owned directory and only publishes inside it. test/test_mediated_request_provenance.py and test/test_mediated_signing_root.py prove a tampered or unsigned policy is refused.
  • No regression:
    • Tools still work (which tools/commands were run, result): The full targeted suites ran on this head (CLI, doctor, MCP secrets stub, secrets handler, link unfurl, dashboard composition contract): 2172 passed, including the ACP approval transports and session-handle bindings. SecretsPanel.test.tsx passed 63 on the same copy before the rebase (it cannot load locally now, because current main added a vite plugin the shared node_modules lacks). flake8, black, isort and mypy are clean on the changed files, and the feature-map gate passes.
    • Backward compatible (old config / old data / old callers still work, how checked): The directory is new and the opt-in kirocrew-secrets server is new. secret:// launch injection and every existing deny or mask entry are unchanged (the diff only adds entries). Existing secrets handler and secret:// resolution tests pass unchanged.
    • Existing tests (which suites passed on this head): test_mediated_, test_mcp_secrets, test_transport_permission_floor, test_session_handle_bindings, test_acp_client, test_secrets_authorize_cli, test_secrets_handler, test_link_unfurl*, test_check_feature_map, test_cli, test_cli_doctor, test_dashboard_server_composition_contract*, test_sandbox_precreate_secret_dirs, SecretsPanel.test.tsx.
  • How to undo: Revert this PR's two commits. That removes the leaf, precreate, deny-list and posture entries together with the feature. Any leftover secret-request-policy/ directory in a data home is inert once nothing reads it, and can be deleted by hand.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ PASS

Which legitimate operations does 8653c3f2c002ee5d893305be2e2453269b75e184 newly refuse? Updated in place on each push. A script-confirmed regression blocks; the model proposes candidates and never decides a refusal.

Verdict basis: adjudicated, zero confirmed regressions.

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 13 classified, 0 newly refused, 13 still allowed.
  • ubuntu-latest (platform posix): 13 classified, 0 newly refused, 13 still allowed.
  • windows-latest (platform windows): 12 classified, 0 newly refused, 12 still allowed.

No candidate flipped from allowed to refused.

Scope-Verdict: PASS

Reason: The only part of this change that refuses more is a new secret-request-policy keystone leaf on the file-tool floor and the sandbox mask. None of the three shell deny tiers reads _SENSITIVE_HOME_DIRS (see is_sensitive_bash_command's docstring, paths.py:628-637), so the shell classifier should see no change from it. There are no confirmed regressions. Three guards outside the classifier's reach are named under UNADJUDICATED: the file-path floor, the in-sandbox mask, and the capability gate on the new mediated-secret routes.

TIGHTENING: _CREW_SECRET_LEAVES gains "secret-request-policy". This puts it on _SENSITIVE_HOME_DIRS, _CREW_HIDDEN_LEAVES and _CREW_PRECREATE_HIDDEN_DIR_LEAVES. The one threat it refuses is an agent reading the signing key or writing its own egress allowlist. From the paths_lists.py hunk: "Mediated-secret signing key + owner-signed egress policy: writable, it would let an agent authorize its own origin." Along with it come new gates on /api/mediated-secret-capability and /api/mediated-secret-request. Each request there must be internal-auth, attested member scope, and a single-use capability minted at ACP approval.

ADJUDICATED: 17 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE: The new leaf is a bare directory name joined under _CREW_HOME_PREFIXES, so the platform assumption it adds is how the data-home path is spelled.

  • posix: ~/.kiro/crew/secret-request-policy listing, grep, git log and pytest rows.
  • windows: %USERPROFILE%\.kiro\crew\... in cmd, $env:USERPROFILE\... in PowerShell, py with backslash test paths, and a curl.exe neighbour with cmd-style quote escaping.
  • any: the new kirocrew secrets authorize forms (bearer, --header, --remove), secrets import, doctor, --help and mcp-secrets.

mcp_secrets.py refuses outright on platform_compat.IS_WINDOWS. That is a refusal at the tool layer, not a shell command, so no shell row on any platform can probe it.

UNADJUDICATED:

  • File-path floor (is_sensitive_path / is_sensitive_write_path through _SENSITIVE_HOME_DIRS).
    • Call path: agent file tool → hooks.on_tool_call → path gate.
    • Inputs I would have submitted: an fs_read of ~/.kiro/crew/config.json and ~/.kiro/crew/sessions.db, which sit beside the leaf and must stay readable.
    • Because the leaf is a directory, _KEYSTONE_ARTIFACT_PARENTS gains no new parent; the crew home root is already there. So *.tmp and *.lock at the data-home root should be no more fenced than before.
    • The same list also feeds skills_script_validator.py and mcp_cron_shell_scan.py. A cron job or skill script whose text names secret-request-policy, for example a backup job, is now refused by those scanners. Neither scanner is in the classifier's composite.
  • Sandbox mask and precreate. The directory is hidden whole in every agent namespace. A legitimate in-sandbox read of it, such as an operator asking the agent to check whether key.json exists while following UNUSABLE_KEY_REMEDY, now sees an empty mount. That is the intended result, and the classifier cannot measure it.
  • Mediated-route gate (_admit plus the capability claim/consume in handlers/mediated_secrets.py).
    • Call path: call_api_with_secret → unix-socket POST → member_request_scope → claim(session_key, tool_call_id, intent) → consume.
    • These are legitimate inputs that I argue would be refused but cannot confirm:
      • a tools/call with no _meta.progressToken, which is refused fail-closed by design;
      • a default Global chat with no member binding;
      • a call approved through allowedTools or autoApprove, which mints no capability;
      • a Codex-wrapped call whose inner arguments differ in timeout_s default normalization between approval and claim.
    • All four are new routes, not narrowed existing behaviour, so none of them is a regression of an operation that previously worked.

[SCOPE-REVIEWED] 8653c3f

@RohanK6

RohanK6 commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #23855: the same change as one commit on current main. It takes the round-3 fixes: the policy MAC key is now derived from token_signing.key under its own purpose label, so there is no stored key, boot-time mint or recovery path, and only 64-char lowercase hex is accepted as a signature. A third commit here would have broken the two-commit limit.

@RohanK6 RohanK6 closed this Oct 24, 2026
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Oct 24, 2026
@bolichen97
bolichen97 deleted the feat/mediated-secret-egress-v3 branch November 6, 2026 07:18
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.

feat(secrets): mediate custom-secret API calls from chat

1 participant