Skip to content

Authorize omarchy-channel-set once for the whole switch - #13479

Open
AnPod wants to merge 1 commit into
omacom:quattrofrom
AnPod:fix/channel-set-sudo-auth
Open

AnPod wants to merge 1 commit into
omacom:quattrofrom
AnPod:fix/channel-set-sudo-auth

Conversation

@AnPod

@AnPod AnPod commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Channel switching still prompted for sudo on every privileged step after #13323 taught omarchy update to ask once (#13415).

This change:

  1. Establishes one authorization upfront in bin/omarchy-channel-set.
  2. Shares that authorization with bin/omarchy-refresh-pacman and the package swap (including pre-refresh-pacman hook).
  3. Revokes authorization before handing off to update so update asks once for its own phases.
  4. Adds test coverage in test/shell.d/channel-sudo-boundary-test.sh verifying single authorization, signal traps (HUP/INT/TERM), and failure handling.

Fixes #13415

Channel switching still prompted for sudo on every privileged step after
omacom#13323 taught omarchy update to ask once. Establish one authorization up
front, share it with refresh-pacman and the package swap (including the
pre-refresh hook), then revoke before handing off so the update asks once
for its own phases.

Fixes omacom#13415

Co-authored-by: AnPod <AnPod@users.noreply.github.com>
@llstrk

llstrk commented Sep 28, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Verified: at b19dfb1, a channel switch asks for one authorization for the switch itself and then hands off to the update's own single authorization. The keepalive refreshes the ticket through long pacman transactions and is stopped before the ticket is revoked at the hand-off. HUP, INT, TERM, step failures, a refused password and stop_for_older_destination all exit with the ticket revoked. Standalone omarchy-refresh-pacman behaves as before when OMARCHY_UPDATE_SUDO_SESSION is unset.

Prompts per switch, from a mock sudo modelled on sudo 1.9.17p2 source (default sudoers, a hook that does not call sudo, no AUR updates):

Path quattro 3faafba (switch + update) b19dfb1 (switch + update)
stable, rc, edge, leaving dev 8 + 1 1 + 1
dev (fresh clone or existing checkout) 8 + 1 1 + 1

The dev counts assume the ~/omarchy checkout includes this change. The dev path runs refresh-pacman from that checkout, so an older checkout that still revokes on entry would bring per-command prompts back (inferred from source, not run).

Four points follow: an existing test that now fails, a relaxed hook boundary that the docs still describe as cold, a session flag that also applies inside omarchy update, and the dev-path ordering.

test/shell.d/channel-test.sh fails on this branch

The dev case exits with not ok - dev activates the checkout before changing or updating packages at b19dfb1 and passes at 3faafba. The order check at test/shell.d/channel-test.sh:178 greps sudo lines too, and the new /usr/bin/sudo /usr/bin/true authorization is now logged first, before git clone. Because the file stops at its first failure, the later cases (dev to stable, switching back to dev, channel detection) no longer run.

Impact: the focused test for this command fails, and ./test/shell should fail with it (the full suite was not run). The changed channel-sudo-boundary-test.sh passes, so running only that file does not show it.

Suggested change: add sudo\t/usr/bin/true as the first expected line in that sequence. With only that edit, the whole file passes. If the dev-path reordering below is adopted, the sudo line moves after git clone instead.

The pre-refresh-pacman hook now runs with a live sudo ticket

During a switch, omarchy-refresh-pacman replaces omarchy_security_revoke_sudo_timestamp with a no-op (bin/omarchy-refresh-pacman:24-27), so the revocations on either side of the hook no longer run:

quattro:   sudo -k -> pre-refresh-pacman hook (no ticket) -> sudo -k -> pacman -Syyuu
b19dfb1:   channel ticket (kept alive every 60 s) -> hook -> pacman -Syyuu -> package swap -> sudo -k -> update

In sudo 1.9.17p2, -N only stops sudo from updating the ticket. It still uses an existing one (plugins/sudoers/check.c, src/parse_args.c). In the mock model, a bare sudo in the hook (through the no-update wrapper) and an absolute-path /usr/bin/sudo -n both succeed without a prompt at b19dfb1. Both needed a password at 3faafba.

The PR body does list the hook among the steps that share the authorization, and this extends the trade-off #13323 made for post-update. #13415 asked for that choice to be made explicitly. The new comment understates it, and three documents still describe the old cold boundary:

  • bin/omarchy-refresh-pacman:48-52: "the wrapper still prevents the hook from caching a credential of its own". That is true for bare sudo, but the hook's privileged commands now run without a prompt.
  • docs/update-process.md:273-275: "Channel switching runs the pre-refresh-pacman hook once … cold, behind the no-update wrapper".
  • manual/31-dotfiles.md:46: "a hook that uses sudo needs its own authorization and may ask for your password".
  • default/agents/skills/omarchy/hooks.md:30: "a detached child left behind by the hook has nothing to wait for". During a switch, a child on the same terminal can use the channel ticket until the hand-off, covering both pacman transactions.

One difference from #13323: omarchy-update creates its ticket inside its own script(1) pty, but the channel ticket lives on the caller's terminal. Other processes in that terminal session can also use it while the switch runs.

Impact: hook authors and users relying on the documented cold boundary get a different privilege model during channel switches than the docs describe.

Suggested change: state the relaxation plainly in the comment at bin/omarchy-refresh-pacman:48-52, and update the three documents to distinguish a standalone refresh from a channel switch.

OMARCHY_UPDATE_SUDO_SESSION=1 also disables refresh-pacman's revocations inside omarchy update

bin/omarchy-update:35 already exports OMARCHY_UPDATE_SUDO_SESSION=1 for the whole update. With this PR, an omarchy-refresh-pacman run from a post-update hook matches the same check and drops every revocation, not just the channel case:

Nested refresh from a post-update hook (mock model) 3faafba b19dfb1
sudo -k during the refresh 4 0
Ticket at its pre-refresh-pacman hook none live
Ticket after the refresh returns revoked live

Impact: this contradicts docs/update-process.md:156 ("Standalone commands that keep their own cold boundary, such as omarchy-refresh-pacman, still revoke if a post-update hook calls them"). The flag is also an ordinary inherited variable. These entrypoints strip shell-startup variables such as BASH_ENV and exported functions, but not this one. omarchy-update-stay-awake already honours it, but there it guards no user code. A standalone run with the variable set and an existing ticket issues no sudo -k at all. Setting it already requires running as the user, so this part is low severity.

Suggested change: use a channel-specific variable passed only on the refresh call from omarchy-channel-set, instead of exporting the update's flag for the whole switch. That fixes the overlap with omarchy update; any caller could still set a channel-only variable, which is the low-severity part above. Alternatively, keep the shared flag and update docs/update-process.md:156. channel_sudo_session (bin/omarchy-refresh-pacman:23,25) is set but never read.

Dev path asks for the password before cloning and validating the checkout

authorize_channel (bin/omarchy-channel-set:172) now runs before link_dev_checkout, which clones ~/omarchy if needed and then checks the required files. In the mock run with a stale checkout, b19dfb1 prompts for the password and then fails with "Update the checkout before switching to dev…". 3faafba rejected it with no prompt. The existing test "a stale dev checkout is rejected before linking or privileged work" still passes, because its check looks for sudo -N calls and dev-link/state steps, not the direct sudo /usr/bin/true. A fresh git clone also now runs while the ticket is live. Git runs a post-checkout hook after a clone, which can come from the user's template directory or core.hooksPath; this was taken from git's documentation and not executed.

Impact: a user with an outdated ~/omarchy enters a password for a switch that is then rejected, and the existing stale-checkout test does not detect the new prompt. On a fresh clone, any post-checkout hook from the user's git configuration runs while the ticket is live.

Suggested change: clone and validate the checkout first (no sudo needed), then call authorize_channel just before omarchy-dev-link.

Optional test improvement: these mutants still pass all 19 checks in channel-sudo-boundary-test.sh:

  • Removing end_channel_authorization || exit 1 before the hand-off still passes. The "revokes before the update starts" assertion is satisfied by omarchy-update's own entry sudo -k (bin/omarchy-update:28), which is logged before step:omarchy-update-lock.
  • Removing trap cleanup_channel EXIT, or the kill and wait in end_channel_authorization, also passes. Nothing observes the keepalive, whose 60 s sleep never elapses in a test run.

The HUP/INT/TERM and failure blocks the PR body lists are unchanged from 3faafba. They now run through cleanup_channel but still check only the end state (no ticket, a final revocation, post-update not reached), not the keepalive.

Coordination: open #13444 changes the same omarchy-update -y hand-off line that this PR inserts the revocation above. Whichever merges second needs a small manual resolution that keeps both changes.


Review information

Test scope: source review of b19dfb1 against quattro 3faafba, plus sandboxed runs of the seven repository shell test files that exercise the changed scripts and of diagnostic scenarios on both revisions. Sudo was always a mock: the repository's own in its tests, and one modelled on sudo 1.9.17p2 source (check.c, timestamp.c, parse_args.c) in the diagnostic runs. No real sudo, pacman or channel switch ran. Prompt counts assume default sudoers (tty tickets). With timestamp_type=ppid or timestamp_timeout=0, the shared ticket may not reach child sudo calls; this was inferred from source and not tested. Merge conflicts with other open PRs were checked by text merge only.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

omarchy-channel-set asks for the sudo password on every step; the switch never establishes its own authorization

4 participants