Skip to content

Flag exec of a shell as opaque; add strict no_shell policy - #67

Merged
cuihtlauac merged 4 commits into
mainfrom
feat/no-shell
Nov 20, 2026
Merged

cuihtlauac merged 4 commits into
mainfrom
feat/no-shell

Conversation

@cuihtlauac

@cuihtlauac cuihtlauac commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Backlog item #1, sub-items 1 and 2 (plan-model follow-ups). Rebased onto main (after v1.2.1).

Problem

Only an explicit shell op was flagged opaque at the approval prompt. A plain {"op":"exec","argv":["sh","-c","…"]} (or a flat pipeline stage) put a whole shell on the path but rendered as a tame exec stage. And the "strict policy mode" promised in protocol.rs did not exist.

Changes

  • Opaque detection (src/executor.rs, push_leaf): a leaf whose program is a shell interpreter (sh, bash, dash, zsh, ksh, mksh, ash, fish, csh, tcsh, yash, posh) is opaque. It is matched by name, by path, or by the canonical resolved binary (catches a renamed symlink), with or without -c, since bash script.sh hides the script too. Because every leaf goes through push_leaf, plans and flat pipelines are covered, and the prompt and the policy read the same bit.
  • Strict no_shell policy: "policy": {"no_shell": true} in hosts.json, or --no-shell / --allow-shell on the daemon (same tri-state pattern as unattended_eligible). A request with any opaque stage is rejected before prompting, ahead of the TUI, --pkexec and unattended paths. The error names the stage and points to the structured ops. --no-shell is forwarded with --host; --allow-shell is refused there (edit the remote hosts.json to loosen it). The file is read through the same owner-private check as unattended_eligible (GHSA-xx2m-j9f7-gcmr). If the check fails, strict mode is on (fail closed), so a hosts.json another user can write cannot switch it off.
  • Docs: docs/usage.md "Strict no-shell mode"; MCP execute op docs and the Plan::Shell doc comment updated.

Not covered yet: wrappers (env sh -c, nice bash …) and other interpreters (python -c, perl -e).

Tests

  • tests/no_shell.rs: with no_shell, six opaque shapes (shell op, exec by name/path, shell without -c, a pipe stage, a flat pipeline) are rejected and the prompter is never called; structured requests still run; without no_shell, all are prompted.
  • tests/pty_no_shell.rs (pty harness, Automate the manual end-to-end tests by driving the daemon through a pty #68): with --no-shell, with policy.no_shell in a 0600 hosts.json, and with a 0666 file that says "no_shell": false, an exec sh -c request gets the policy error, and the next structured request is the first prompt drawn on the tty. Disabling the gate, or letting an untrusted file turn strict mode off, makes the tests fail.
  • Unit tests for the detection (including a renamed symlink), the TUI opaque render, and policy.no_shell serde defaults.
  • cargo test --release: all pass except burst_connections_above_cap_get_busy_response, which fails identically on main (already skipped in CI). cargo clippy --all-targets: clean.
  • Manual check, driven through a pty: the permissive daemon shows sh opaque — resolves only the shell: /usr/bin/sh and runs on y; --no-shell returns the policy error with no prompt.

🤖 Generated with Claude Code

cuihtlauac added a commit that referenced this pull request Nov 17, 2026
PR #67 closed plan-model follow-ups 1-2 (flag exec of a shell as opaque;
strict no_shell policy). Record them in the changelog, drop them from the
consolidated backlog item and the shell-hatch levers, and note that
wrapper-hidden shells (env/nice/timeout, python -c) remain under the
env-resolution follow-up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
cuihtlauac added a commit that referenced this pull request Nov 17, 2026
PR #67 closed plan-model follow-ups 1-2 (flag exec of a shell as opaque;
strict no_shell policy). Record them in the changelog, drop them from the
consolidated backlog item and the shell-hatch levers, and note that
wrapper-hidden shells (env/nice/timeout, python -c) remain under the
env-resolution follow-up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
cuihtlauac added a commit that referenced this pull request Nov 18, 2026
PR #67 closed plan-model follow-ups 1-2 (flag exec of a shell as opaque;
strict no_shell policy). Record them in the changelog, drop them from the
consolidated backlog item and the shell-hatch levers, and note that
wrapper-hidden shells (env/nice/timeout, python -c) remain under the
env-resolution follow-up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
@cuihtlauac
cuihtlauac marked this pull request as ready for review November 18, 2026 15:47
cuihtlauac added a commit that referenced this pull request Nov 20, 2026
Drive the real daemon through the pty harness for the scenarios left
from issue #68:

- `a` on a daemon that is not eligible: not offered, no hint, approves
  once, and the same session is prompted again.
- `a` on an eligible daemon: the hint names the session; a later request
  from that session runs unattended (audit line in the daemon log), while
  another session is still prompted, checked by ordering: the next prompt
  block carries that session's request ID. A privileged request from the
  granted session is still prompted, without `a`.
- `a` on a privileged request denies, and nothing reaches sudo.
- An unanswered prompt times out, the command does not run, and termios
  is restored. This waits the real 60 s, so it is #[ignore]d rather than
  adding a prompt-timeout setting to the human gate.

Harness: `expect_within` (expect with a caller-chosen deadline) and
`daemon_log`. A mutant that makes the grant daemon-wide fails
a_grant_is_keyed_by_session.

The --no-shell scenario goes with the feature in PR #67.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
cuihtlauac and others added 4 commits November 20, 2026 08:29
Close the `exec sh -c` loophole: an Exec leaf (or flat-pipeline stage)
whose program is a shell interpreter (sh/bash/dash/zsh/…, by name, path,
or canonical resolved binary, with or without -c) is now flagged opaque
at the prompt exactly like an explicit `shell` op. The decision lives in
`push_leaf`, the one place every leaf is created, so the prompt and the
policy read the same bit.

Add the strict mode `protocol.rs` already promised: `policy.no_shell` in
hosts.json, or `--no-shell` / `--allow-shell`, rejects any request with
an opaque stage before prompting (ahead of the TUI, --pkexec and
unattended paths). `--no-shell` is forwarded with `--host`;
`--allow-shell` is refused there.

Wrappers (env/nice/timeout) and other interpreters (python -c) are not
detected yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
PR #67 closed plan-model follow-ups 1-2 (flag exec of a shell as opaque;
strict no_shell policy). Record them in the changelog, drop them from the
consolidated backlog item and the shell-hatch levers, and note that
wrapper-hidden shells (env/nice/timeout, python -c) remain under the
env-resolution follow-up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
Through the pty harness, with the strict mode set by `--no-shell` or by
`policy.no_shell` in an owner-private hosts.json: an `exec sh -c` request
gets the policy error, and the next structured request is the first
prompt drawn on the tty (checked by ordering, not by "no prompt seen").
Disabling the gate makes both tests fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
After rebasing onto the GHSA-xx2m-j9f7-gcmr fix, `unattended_eligible` was
read from hosts.json through `load_trusted_policy`, but `no_shell` still
used the unchecked `HostsConfig::load()`. Anyone who could write the file
could then switch strict mode off without warning.

Read the policy once, through the trusted loader, for both settings. An
untrusted file fails closed for each: not unattended-eligible, and
no_shell on. The warning names both effects. An explicit CLI flag still
wins, and the file is read only if a flag is missing.

New pty test untrusted_policy_turns_no_shell_on: a 0666 hosts.json saying
`"no_shell": false` still gets the opaque request rejected. It fails when
an untrusted file leaves no_shell off. Docs: usage.md, changelog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
@cuihtlauac
cuihtlauac merged commit ca2bc86 into main Nov 20, 2026
17 checks passed
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