Skip to content

secrets-collect: add --yes for agents without a terminal - #5

Merged
djbclark merged 6 commits into
sudo-mainfrom
fix/secrets-collect-yes
Oct 26, 2026
Merged

djbclark merged 6 commits into
sudo-mainfrom
fix/secrets-collect-yes

Conversation

@djbclark

@djbclark djbclark commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

What

skills/sudo-secretspec/scripts/secrets-collect.py gains --yes so an agent without a terminal can collect one secret per run from the clipboard, safely:

  1. --clipboard --yes requires an exact :LEN, refuses stale, sentinel or already-consumed copies, and clears the clipboard right after the read.
  2. The read-to-clear step runs under a per-user flock (~/Library/Caches/secrets-collect.lock), so parallel runs cannot store one copy twice. A loser is told which run consumed the copy and that both names need re-collecting, one at a time.
  3. Partial stores are reported (PARTIAL STORE ... not_stored=[..]), SIGINT/SIGTERM/SIGHUP are handled, and value characters never reach stdout, stderr or argv.
  4. Piped answers without --yes, and --yes without --clipboard, are refused.
  5. SKILL.md documents the protocol, including "never run two at once" and the --literal exception for /+= keys.

Tests: 44 in tests/sudo_postinstall/test_secrets_collect.py (stub sudo-secretspec/pbpaste/pbcopy, every run has a timeout); the adversary re-ran them, 44 passed.

Adversary reviews (four rounds)

Verdict: APPROVE on 68105c47807d44bd66fe77ff0b4b9b93b2c5a7d9 (round 4, delta review of the third repair; round 3 approved 6cb0341). Head f6e6208 adds only the CHANGELOG entry on top of that reviewed head.

Rounds 1 and 2 returned BLOCK (stale-clipboard store; then a parallel read-before-clear race storing one copy under two names); both are fixed and tested, with mutation checks.

Deferred low findings (round 4), to be fixed in a follow-up:

  1. The SKILL's follow-up printf 'cleared' | clip erases the consumer name when runs do not overlap.
  2. The production lock location is untested (tests use SECRETS_COLLECT_LOCK_DIR).
  3. If the winner's clear fails, the next run stores the same secret under its own name (documented); the script could exit non-zero.
  4. The sentinel has a time but no date, so a stale one can misattribute a copy.

🤖 Generated with Claude Code


Note

Medium Risk
Changes secret-ingestion semantics (partial stores, clipboard clearing, and locking) on a security-sensitive operator script; mistakes in parallel runs or wrong-name assignment are documented but not automatically recoverable.

Overview
Adds --yes to secrets-collect.py so agents without a TTY can ingest one secret per run from the clipboard (--clipboard --yes), with mandatory :LEN, sentinel-based stale/consumed detection, per-user flock around read→clear, and abort paths that never echo secret bytes (only lengths and character classes).

Behavior changes beyond the agent path: collection is no longer described as all-or-nothing once the store loop starts—failures and interrupts emit PARTIAL STORE with stored / not_stored / unknown and do not roll back prior writes. Interactive docs in SKILL.md and CHANGELOG.md spell out the no-terminal protocol (sequential runs, --literal for base64-style keys).

Tests: new tests/sudo_postinstall/test_secrets_collect.py (stub sudo-secretspec / pbpaste / pbcopy) covering locks, sentinels, signals, partial stores, and refusal modes.

Reviewed by Cursor Bugbot for commit f6e6208. Bugbot is set up for automated code reviews on this repo. Configure here.

…, self-clear), report partial stores, no value chars in transcript, tests with timeouts
…--yes protections on pty too, refuse piped answers, LEN required, clear in finally, SIGTERM/SIGHUP partial report, pbpaste locale, stronger tests
…ait, user-level lock path, signals blocked around the clear, tests for surviving mutants
@cursor

cursor Bot commented Oct 26, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: 8d93c2cb-3878-44e8-a345-e10fbab90a34)

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T05:34:55.695456Z f6e6208 PR opened
🔒 Security Review ✅ Completed 2026-10-26T05:37:22.923342Z f6e6208 PR opened
ℹ️ 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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f6e620892b

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +483 to +485
except StoreError as e:
print(str(e), file=sys.stderr)
report_partial(stored, [n for n, _ in collected if n not in stored])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve unknown outcomes when a store command fails

If sudo-secretspec set returns 125 or 126, this handler incorrectly lists the current name as not_stored and can even claim that nothing was stored. These are explicitly ambiguous outcomes: sudo-secretspec-cli/src/broker.rs returns 125 when rollback fails and 126 when recording the terminal audit event fails after the operation has already committed or rolled back; the client preserves these exit codes. Preserve the return code in StoreError and report the current name as unknown for these cases rather than telling the operator that its previous value is unchanged.

Useful? React with 👍 / 👎.

Comment on lines +1 to +3
"""secrets-collect.py with stub `sudo-secretspec`, `pbpaste`, `pbcopy` on PATH; no real vault or clipboard.

Every subprocess has a hard timeout: a mutant that loops must fail, not hang CI.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep stub-only tests outside the live-boundary skip gate

On a checkout without an installed privileged boundary, tests/sudo_postinstall/conftest.py:132-140 marks every collected test as skipped, including all 44 new tests in this file. Running python3 -m pytest tests/sudo_postinstall/test_secrets_collect.py -q here therefore exits successfully with 44 skips, even though these tests use stubs and require no live installation. Move this module outside the gated directory or exempt it from the collection hook so ordinary development and automated runs actually exercise the new safety checks.

Useful? React with 👍 / 👎.

@djbclark
djbclark merged commit 319172c into sudo-main Oct 26, 2026
60 of 63 checks passed
@linear-code

linear-code Bot commented Oct 26, 2026

Copy link
Copy Markdown

VIB-117

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