Skip to content

--pkexec with a multi-leaf privileged plan skips the TUI prompt; dialogs show only /usr/bin/env per leaf - #94

Open
cuihtlauac wants to merge 5 commits into
mainfrom
fix/88-pkexec-multileaf
Open

cuihtlauac wants to merge 5 commits into
mainfrom
fix/88-pkexec-multileaf

Conversation

@cuihtlauac

@cuihtlauac cuihtlauac commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Under --pkexec, every privileged: true request went to pkexec, one dialog per escalated step. A pkexec dialog shows a single argv (named /usr/bin/env, since steps run as pkexec env -C DIR -- argv) and never the files the daemon opens for a redirection. So no dialog showed the whole plan, and with pkexec-cache the later steps ran with no dialog at all.

This PR implements the approved plan (issue #88, comment "Approved plan (Claude) — final"):

  • New pure predicate delegate_to_pkexec in src/server.rs: approval is delegated to pkexec only for a privileged: true request whose plan_display views are exactly one escalated leaf with no redirection. It reads the same views the prompt renders.
  • Every other privileged request (multi-step, redirected or with-stdin-from, or escalating only through run-as) takes the TUI prompt and runs through sudo, the existing path run-as-only plans already used.
  • --pkexec help text updated.
  • Docs: docs/pkexec.md routing paragraph; assurance case G5.4 / Sn5.4 and a separate --pkexec exception sentence on G5.1; threat-model leaf 4.5 and its residual bullet; changelog entry; backlog item 6 replaced (pkexec dialog names /usr/bin/env), new item 7 (does a single-leaf setenv reach the program under pkexec?), and a Done: #88. line appended after the Phase 0 paragraph (append-only, in the style of Approval prompt: bound Steps: lines (and every prompt line) so a long argument cannot push [y/N] off-screen #93).

Behaviour change for --pkexec users: privileged multi-step plans and redirected single steps now show the TUI prompt and run through sudo. A user without sudo rights gets a sudo failure after approving, as for run-as plans already. With no usable /dev/tty, these requests fail closed with prompt error. They are audited as approved / denied / timeout instead of pkexec.

Fixes #88
Part of #89

Test evidence

  • cargo clippy --all-targets: no warnings.
  • cargo fmt --check: reports drift, all pre-existing (it lists files this PR does not touch, e.g. src/audit.rs, src/executor.rs, src/gui.rs). The new tests/plan_exec.rs test now follows rustfmt (review nit C3); the new pty_e2e.rs test keeps that file's existing one-line style.
  • cargo test --no-fail-fast (debug), after the review fixes: first full run, every suite passes except concurrency::burst_connections_above_cap_get_busy_response, the known flaky burst test (other worktrees were building in parallel on the same machine). Second full run: 263 passed, 0 failed. cargo test --test concurrency alone: 13 passed. The burst test sends plain true requests to a server without pkexec_only, so it does not reach the changed code.
  • New tests:
    • server::tests::delegate_to_pkexec_only_for_a_single_plain_leaf: unit table (one Root / one User("nobody") leaf → true; 0 or 2 leaves, >, <, 2>&1, a Direct leaf, pkexec_only = false, Mode::Remote, privileged = false → false).
    • tests/plan_exec.rs pkexec_mode_prompts_for_multi_leaf_privileged_plans: run / seq / alt / pipe of two leaves, a stdout-redirected leaf, a with-stdin-from leaf. For each request: the prompt count goes up by exactly 1, the status is Denied, the record for that request id (audit_for) has outcome denied, and the record count equals the number of requests sent so far. At the end: no record is pkexec, and the redirect target was never created.
    • tests/pty_e2e.rs pkexec_flag_multi_step_plan_gets_the_tui_prompt: real binary with --pkexec and DISPLAY=:99 (new PtyOpts::env); asserts that the daemon log says mode: local (TUI + pkexec) (so the test is not vacuous), the prompt says Execute as root? and shows both steps, the response is Denied, and the sudo shim log is empty.
  • Regression check: with the old gate (pkexec_only && mode == Mode::Local && req.privileged) restored temporarily, the integration test fails with run: the TUI prompt was skipped.
  • Safety: every test leaf's argv[0] is a nonexistent program (sudo-proxy-test-88-no-such-cmd). If the gate regresses, check_pkexec_leaves runs its harmless env -C / -- true probe (plain env, not pkexec) once, then build_command fails with command not found before any pkexec spawn. The response is an error, the audit outcome is pkexec and the prompt count does not move, so the test fails and no polkit dialog ever names the test program.
  • Kani: not run. src/proofs.rs and the functions it proves are unchanged. As the plan says, the predicate is covered by the exhaustive unit table.
  • Goldens: unchanged (no rendering change); not regenerated.

Deviations from plan

  • The unit table also checks 2>&1, two leaves with different privileges, and an explicit Direct leaf. These are additions, not changes.
  • The pty test also asserts mode: local (TUI + pkexec) in the daemon log. That makes the plan's "not vacuous" requirement explicit.
  • docs/pkexec.md also lists with-stdin-from among the routed shapes. It compiles to a < redirection, which the plan already covers.
  • Backlog: the plan said "add a short new item right after it". I numbered it 7, the next free number after item 6 at the end of that list. No existing item is renumbered.
  • Otherwise none.

Nits

Plan review:

  • P3 (failure signature on a regressed gate): applied as guidance, stated in the integration test's doc comment and above.
  • P4 (help text "single-step, unredirected"): applied (src/bin/sudo-proxy.rs).
  • P5 (parameter naming): applied. The parameter is req_privileged, and its doc comment says it is the raw flag, not effective_privileged().
  • P6 (G5.1 TLC-pinned sentence byte-identical): applied as guidance. The sentence is unchanged; the --pkexec exception is a separate sentence pointing to G5.4.
  • P7 (backticks around --pkexec in the changelog heading): applied.
  • P8 (off-by-one backlog line references in the plan): dropped: it concerns line numbers in the plan text only; the edits were located by content.
  • P9 (sudo's password prompt appears on the daemon's terminal): applied in the manual test below.

Code review:

  • C3 (rustfmt the new test lines): applied in tests/plan_exec.rs (the set_response chain and the final assert!). The tests/pty_e2e.rs part is dropped: that file is not rustfmt-formatted, and the new test keeps its one-line style.
  • C4 (tests/common/pty.rs module doc clause order and width): applied.
  • C5 (changelog pins backlog numbers 6 and 7): applied; the entry names the two backlog items instead.

Follow-ups

None opened. The code review raised no follow-up items, and none of #90, #91, #92 concerns this issue. The plan's residuals are recorded as backlog items ("pkexec dialog names /usr/bin/env" and "Does a single-leaf plan's setenv reach the program under --pkexec?") rather than as issues, as the plan specifies.

Review

Manual test before merge

Run from a graphical terminal, so that DISPLAY or WAYLAND_DISPLAY is set. Build with cargo build --release on this branch.

Terminal A (the daemon; the TUI prompt and sudo's password prompt appear here):

./target/release/sudo-proxy -v --pkexec --socket "$XDG_RUNTIME_DIR/sp-test-88.sock"

Check that the startup lines include mode: local (TUI + pkexec).

Terminal B (the requester):

  1. Multi-step privileged plan → TUI and sudo:
    ./target/release/sudo-request --socket "$XDG_RUNTIME_DIR/sp-test-88.sock" --print \
      --plan '{"op":"run","steps":[{"op":"exec","argv":["id","-un"]},{"op":"exec","argv":["id","-u"]}]}'
    • Terminal A shows the TUI prompt Execute as root? with both steps. No polkit dialog appears.
    • Press y. If sudo has no cached credentials, its password prompt appears in terminal A. Terminal B prints root and 0.
    • Send it again and press n. Terminal B prints Request denied.; the audit line in terminal A says denied, not pkexec.
  2. Redirected single step → TUI and sudo:
    ./target/release/sudo-request --socket "$XDG_RUNTIME_DIR/sp-test-88.sock" --print \
      --plan '{"op":"redirect","stream":"stdout","target":{"to":"file","path":"/dev/null"},"do":{"op":"exec","argv":["id","-un"]}}'
    • The TUI prompt shows > /dev/null, and no polkit dialog appears. Answer n; expect Request denied.
  3. Single plain step → pkexec (unchanged behaviour):
    ./target/release/sudo-request --socket "$XDG_RUNTIME_DIR/sp-test-88.sock" --print id -un
    • No TUI prompt. A polkit dialog appears (naming /usr/bin/env). After authentication, terminal B prints root, and the audit line says pkexec.

Stop the daemon with Ctrl-C in terminal A.

🤖 Generated with Claude Code

@cuihtlauac cuihtlauac left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🤖 Code review (Fable) — round 1

Verdict: approve-with-nits

Reviewed the whole diff of PR #94 against the "Approved plan (Claude) — final" comment on #88. The predicate, its call site, the three new tests and the doc edits match the plan. No blocker.

What I checked myself, on the branch in a separate worktree:

  • cargo clippy --all-targets --all-features -- -D warnings (the CI invocation): clean.
  • cargo test --no-fail-fast (debug): every suite passes, including concurrency::burst_connections_above_cap_get_busy_response, which the PR description reports as flaky-only.
  • The three new tests pass. With the old gate (pkexec_only && mode == Mode::Local && req.privileged) restored temporarily, tests/plan_exec.rs pkexec_mode_prompts_for_multi_leaf_privileged_plans fails at the first call_count assertion (run: the TUI prompt was skipped) and tests/pty_e2e.rs pkexec_flag_multi_step_plan_gets_the_tui_prompt fails waiting for a prompt that never comes. No polkit dialog appeared (the argv is a nonexistent program, so build_command fails first, as the plan's safety argument says). Both tests are therefore the regression tests the issue asks for, not vacuous ones.
  • delegate_to_pkexec reads the plan_display views computed before the no_shell check, so the decision and the prompt see the same leaves; a flat single-stage pipeline, and a single chdir/setenv-wrapped leaf, still delegate, as the plan intends. with-stdin-from compiles to < path in summarize_redirects, so it is covered by the "no redirection" conjunct, and > /dev/null / 2>&1 likewise route to the TUI.
  • Audit: Outcome::Pkexec is tied to use_pkexec, so the routed shapes record approved/denied/timeout; the integration test checks the per-request record and that none is pkexec.
  • docs/assurance-case.md G5.1: the TLC-pinned sentence is byte-identical; the exception is a separate sentence pointing to G5.4 (P6 followed).
  • Kani: not run, and correctly not claimed. src/proofs.rs and the functions it proves are untouched.
  • Goldens: unchanged, consistent with no rendering change.

Deviations from plan (all accepted):

  1. Extra unit-table cases (2>&1, mixed-privilege pair, explicit Direct): additions only; they tighten the table.
  2. The pty test asserts mode: local (TUI + pkexec) in the daemon log: this is the non-vacuity check the plan asked for, made explicit. Good.
  3. docs/pkexec.md names with-stdin-from: accurate (it is a < redirection on the leaf).
  4. New backlog item numbered 7 after item 6, nothing renumbered: fine.

Nits handling: P3–P7 and P9 applied or followed as reported; P8 dropped with a valid reason (plan-text line references only).

should-fix

  • C1 — src/server.rs:1136-1138 — The doc comment /// --log-json prints request bytes before validation … must come out inert. belongs to escape_for_terminal_neutralises_control_and_bidi, but the new leaf_view helper and delegate_to_pkexec_only_for_a_single_plain_leaf were inserted between that comment and its test. The helper now carries a doc comment about --log-json, and the escape test has none. Move the two new items above that comment (or below the escape test).
  • C2 — backlog.md:155 — The Phase 0 paragraph was edited in place and reflowed into one 128-column line (… · ~~#88 \--pkexec` multi-leaf plans~~ (done) · #87 …). The batch instruction asks for minimal, append-only edits to backlog.md/changelog.md/docs/assurance-case.mdso the four PRs rebase cleanly in the order #86, #85, #88, #87. PR #93 (#85, merged before this one) leaves that paragraph untouched and appends aDone: #85.line right after it; this hunk is adjacent to that insertion and will conflict on rebase. Keep the two original lines unwrapped and either strike#88 … in place without reflowing, or follow #93's convention and append (Done: #88.`). The item-6 replacement in the Priority #1 list is what the plan prescribes and is fine.

follow-up

None.

nit

  • C3 — tests/plan_exec.rs:400 and :456, tests/pty_e2e.rs:190-208 — rustfmt would reshape these new lines (set_response chain, two assert!, the Plan::Exec/Plan::Run literals). The PR description says the new lines follow rustfmt except in pty_e2e.rs; the two plan_exec.rs spots do not. CI does not run cargo fmt --check and main already drifts, so cosmetic only. Apply if you touch those lines for C1/C2, otherwise drop.
  • C4 — tests/common/pty.rs:17 — The module doc now reads "no DISPLAY/WAYLAND_DISPLAY unless PtyOpts::env sets one (so Mode::Remote: TUI prompt + sudo)", which attaches the Mode::Remote consequence to the "unless" clause, and the line is now over 100 columns. Suggest: "no DISPLAY/WAYLAND_DISPLAY (so Mode::Remote: TUI prompt + sudo) unless PtyOpts::env sets one".
  • C5 — changelog.md:19 — "backlog items 6 and 7" pins backlog numbering that the plan itself says may shift (this PR already renumbered item 6's content). Naming them ("the /usr/bin/env dialog item and the setenv-under-pkexec item") would survive a reshuffle.

Manual test: the PR's three-step manual test (multi-step → TUI + sudo; redirected single step → TUI; single plain step → pkexec dialog) matches the plan's, with P9's note on where sudo's password prompt appears. Nothing to add.

cuihtlauac and others added 5 commits November 21, 2026 22:25
#88)

pkexec's dialog shows one argv (as `env -C DIR -- BIN args`) and never the
files the daemon opens for a redirection. Delegating a multi-step plan
meant no dialog showed the whole plan, and under `pkexec-cache` later
steps ran with no dialog at all.

New pure predicate `delegate_to_pkexec`: delegate only a `privileged:
true` request whose `plan_display` views are exactly one escalated leaf
with no redirection. Every other privileged request takes the TUI prompt
and sudo, as `run-as`-only plans already did. Unit table covers each
conjunct. `--pkexec` help text updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
…pkexec (#88)

tests/plan_exec.rs: run/seq/alt/pipe of two leaves, a redirected leaf
and a with-stdin-from leaf each prompt once, are denied, and leave one
`denied` audit record; no record is `pkexec` and the redirect target is
never created. Every argv[0] is a nonexistent program, so a regressed
gate fails at build_command and never raises a polkit dialog.

tests/pty_e2e.rs: the same through the real CLI (`--pkexec`, DISPLAY
set so Mode::detect is Local), with a new `PtyOpts::env`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
…log (#88)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
…backlog edit)

Move the --log-json doc comment back onto its escape test (the new
leaf_view helper had been inserted under it), and restore the Phase 0
backlog paragraph, appending 'Done: #88.' instead of reflowing it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
rustfmt the new pkexec test in tests/plan_exec.rs, reorder the
tests/common/pty.rs module doc so the Mode::Remote consequence sits on
the no-DISPLAY clause, and name the backlog items in the changelog
instead of pinning their numbers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
@cuihtlauac
cuihtlauac force-pushed the fix/88-pkexec-multileaf branch from f55bd77 to acfe99e Compare November 22, 2026 05:35
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.

--pkexec with a multi-leaf privileged plan skips the TUI prompt; dialogs show only /usr/bin/env per leaf

1 participant