Skip to content

fix(pr-verify): route the capture's outer leg through the key proxy and narrow its Bash - #13770

Merged
kyle-sexton merged 5 commits into
mainfrom
fix/13710-outer-leg-proxy
Nov 6, 2026
Merged

kyle-sexton merged 5 commits into
mainfrom
fix/13710-outer-leg-proxy

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Refs: #13710

Summary

The PR capture's outer leg, the key-holding Claude Code that drives the sandboxed app, no longer holds the real PR_VERIFY_CLAUDE_API_KEY. It runs on a per-run client key through the key proxy, and its Bash is narrowed to named commands. Owner decision Q7 (a) and Q9 (c): issuecomment-6686203326. It uses the loopback-base-url opt-in from melodic-software/ci-workflows#1000 (merged as 4aba9be).

Fix

  • Key proxy: an in-process second listener on 127.0.0.1:47101 for the driver legs, with its own budget. Every request must carry the per-run client key ccd-outer-<64 hex>, compared as SHA-256 digests with timingSafeEqual; a missing or wrong key gets 401. The key is generated and masked in "Start the key proxy" and reaches the proxy on stdin line 2. A socat bridge could not check a key, which is why the proxy listens directly. The driven sandbox listener is unchanged.
  • Workflow: run-claude-cli and apply-claude-managed-settings are pinned to 4aba9be with loopback-base-url: http://127.0.0.1:47101. The bump also brings in ci-workflows 17985f4, which gives the fallback leg an empty subscription token. PR_VERIFY_CLAUDE_API_KEY now reaches only "Start the key proxy". The managed env adds NO_PROXY, the nonessential-traffic switch, the output cap at the ceiling and the haiku model; on Claude Code 2.1.318 that removed the inline-tools and advisor betas, HEAD /api/hello and max_tokens 128000, measured locally. A new step, "Check the driver legs hold no real key", hashes every managed-settings value and every readable environ value against the real key, using the client key as a canary. The probe leg uses the same client key and port, because one /etc/claude-code/managed-settings.json serves every leg.
  • Bash narrowed (Q9): the driver verbs (plugins, launch, ready, screenshot, record, log, stop) for both path forms. git -C head with exact read commands (branch --show-current, status --porcelain, diff HEAD, diff --name-only <base>...HEAD, rev-parse --show-toplevel, worktree list --porcelain) and the exact network forms the e2e context names (ls-remote --symref origin HEAD, fetch origin main). Also the named skill commands: resolve-config.sh e2e *, check-browser-driver.sh --user *, claude plugin list --json and cmp *. dontAsk denies everything else.

Verification

  • key-proxy.test.mjs 45 pass, workflow.test.mjs 78 pass, pr-verify suites plus callers.test.mjs 636 pass. 10 new or changed tests fail on the old code. The workflow test checks that these stay refused: curl, wget, python -c, node -e, bash -c, a head copy of resolve-config.sh, claude -p, claude plugin install, a fetch from another branch or URL, and --upload-pack forms.
  • actionlint shows only the cache-mode warning that was already there. gitleaks over the diff is clean.

Remaining

Related

🤖 Generated with Claude Code

kyle-sexton and others added 4 commits November 6, 2026 11:53
The capture's driver legs ran Claude Code holding the real
PR_VERIFY_CLAUDE_API_KEY with unrestricted Bash. Owner decision Q7 (a)
and Q9 (c) on #12232: route them through the key proxy with a dummy key,
and narrow their Bash to the driver and git.

- key-proxy.mjs: --listen <port> adds a loopback TCP listener in the
  same process. It reads a per-run client key from stdin's second line,
  refuses any request without it with a 401 (SHA-256 digests compared
  with timingSafeEqual), keeps its own budget and state, and relays a
  non-200 count_tokens preflight answer as sent, so a credit stop or a
  refused key still reaches run-claude-cli's handoff classification.
  The socket listener is unchanged.
- pr-verify-capture.yml: run-claude-cli and apply-claude-managed-settings
  move to 4aba9be (loopback-base-url). The managed settings file is the
  machine's one, so both the probe and the capture leg take the client
  key, the loopback port 47101 and the Claude Code version the proxy's
  betas were measured on. The settings add NO_PROXY for the loopback and
  the nonessential-traffic switch, the output-token cap and the small
  model the driven session already pins: measured on 2.1.318, the leg
  otherwise sends two betas the proxy refuses and max_tokens 128000.
  The real key now reaches only "Start the key proxy"; a new step checks
  that the managed settings and every readable process environment hold
  no value hashing to it. The capture leg's bare Bash rule becomes
  per-verb rules for main's driver and named git commands on the head.
- callers.test.mjs: 4aba9be passes --permission-prompts none
  (lane.cjs:425-426).

Refs: #13710

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The capture leg's skills name commands beyond the driver and the head's
local git: run-e2e's resolve-config.sh and check-browser-driver.sh,
drive's `claude plugin list --json`, cmp for the revert proof, and the
default branch's ls-remote and fetch. Each gets a named rule, from main's
checkout only. ls-remote and fetch are exact (origin, HEAD, main), since
`fetch *` or `ls-remote *` would admit --upload-pack, which runs a
program. The workflow test checks each rule and that curl, wget, python,
node -e, bash -c and a head copy of a script stay refused.

Refs: #13710

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…roxy

# Conflicts:
#	.github/workflows/pr-verify-capture.yml
The capture prompt runs the leg from the head checkout, so a relative
.base/ or head path in a Bash allow rule named a file the pull request
can commit, and the rule then ran head code outside the sandbox.
run-claude-cli resolves every plugin-dirs entry to an absolute path, so
the skills already name the absolute forms; the relative rules go.
The key proxy comment now says the socket is reachable by any
runner-user process and the job can spend up to twice the cap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 6, 2026 17:31
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-06T17:31:22.317078Z
We couldn’t complete this review. Comment @codex review to try again.
3db0747 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

The runner worker runs as the runner user and holds the job's secrets
in memory; only Yama's ptrace_scope keeps its descendants from
attaching to it. "Check the driver legs hold no real key" now reads
the value, prints it for the run record, and fails before any driver
leg when it is below 1 or unreadable.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed abf5089f1ba1ada11e23a362d579549b96742c95: read 2 of 2 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #13770 (head abf5089), incremental since 3db0747

I found no security issues. This was an incremental review. I read every hunk of the 2 files changed since 3db0747: .github/workflows/pr-verify-capture.yml and .github/scripts/pr-verify/workflow.test.mjs. Neither file matches a TRUSTED PATHS glob. The prior-findings file says blocking only: yes, so I would have reported only CRITICAL and IMPORTANT findings. There were none.

critical-findings: 0

What I checked

  • The new check fails closed. "Check the driver legs hold no real key" now reads /proc/sys/kernel/yama/ptrace_scope (pr-verify-capture.yml#L797-L800). The step fails when the file can't be read, when the value isn't a plain integer (/^[0-9]+$/), or when the value is below 1. It prints only the scope value, never a secret.
  • The threshold is right for the threat it names. At scope 1, a process can attach only to its own descendants. The driver legs run below the runner worker, so they can't attach to it or read its /proc/<pid>/mem, which needs ptrace attach access. Values of 2 and 3 are stricter still, and the check accepts them.
  • The change only adds a check. It removes or relaxes no existing check. The real-key hash checks and the environ scan with its client-key canary are unchanged. The step's if: condition and timeout-minutes are unchanged.
  • The test covers each case. It swaps both paths for temporary files and checks five values: 1 and 2 pass; 0, x and a missing file each fail with the expected ::error:: line.
  • Trust controls: none changed. The trusted-trigger check, the lane-token request and broker, the kill switch, the merge holds, and the other .github/actions/ controls are not in this change.
  • Instruction surface and manifests: none in this change.
  • Spend: none new. This step makes no API calls.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed abf5089f1ba1ada11e23a362d579549b96742c95: read 2 of 2 changed file(s); 0 finding(s), 0 as inline comments.

Code review (incremental, blocking only): ptrace_scope gate in "Check the driver legs hold no real key"

This lane already reviewed an earlier head (3db0747), so this round reports blocking findings only. Scope: the push since 3db0747. That is two files, and I read every hunk of both: .github/workflows/pr-verify-capture.yml and .github/scripts/pr-verify/workflow.test.mjs. I also read the whole step at head (pr-verify-capture.yml:775-818). Whether ptrace_scope ≥ 1 is enough protection is a security question, and I leave it to the security lane.

What checks out

  • Workflow step:
    • readFileSync is already imported in the inline module (pr-verify-capture.yml:785).
    • The read is wrapped in try/catch, so an unreadable file gives "unreadable". That value fails the ^[0-9]+$ test and stops the step through fail (process.exit(1)).
    • Garbage, 0 and a missing file all fail. 1, 2 and 3 pass.
    • The check runs before the environment scan, so a low scope stops the job before any driver leg.
    • The printed value is only the scope number, never a key.
  • Test:
    • rmSync and writeFileSync are already imported (workflow.test.mjs:13).
    • The path occurs once in the step's code (the comment only says "Yama's ptrace_scope"), so a single .replace swaps the real read.
    • The assert.ok(block.includes(...)) guard stops the swap from silently matching nothing.
    • run's default "1\n" keeps the existing refused cases on the passing path.
    • The cases covered are 1 (with its printed line), 2, 0, x and a missing file.

Findings: none blocking in this push.

Prior findings: the earlier summary comment (the advisory about the driver model and the proxy's models allowlist being unlinked) is on code this push does not change. Under blocking-only it is not restated.

Verification: I ran nothing; this lane has no shell. Any pass counts or results for this push are the author's claims and unverified.

Closing issue: the PR closes no issue; it only references #13710.

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