Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions bin/omarchy-update
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,18 @@ unset OMARCHY_UPDATE_USER_PATH
# exits through the cleanup path.
omarchy_security_install_sudo_cleanup_traps
omarchy_security_revoke_sudo_timestamp || exit 1
omarchy_security_enable_no_update_sudo
# Fixed helpers below share one cached authorization, so a sudo without
# --no-update support must stop the update before any work. Channel switching
# has already installed the wrapper and exports OMARCHY_SUDO_NO_UPDATE; keep
# that boundary instead of opening a caching window inside it.
if ! omarchy_security_sudo_supports_no_update; then
echo "This sudo does not support --no-update; refusing mixed-trust work." >&2
exit 1
fi
if [[ ${OMARCHY_SUDO_NO_UPDATE:-0} != "1" ]]; then
PATH="$OMARCHY_PATH/bin:/usr/bin:/usr/sbin:/bin:/sbin"
export PATH
fi

update_stay_awake_stopped=0
cleanup_update() {
Expand Down Expand Up @@ -82,11 +93,13 @@ if [[ ${1:-} == "-y" ]] || omarchy-update-confirm; then
# takes the update with it rather than migrating against what is still on disk.
omarchy-update-system-pkgs

# Historical migrations are strictly ordered and mix user hooks/downloaded
# tooling with privileged repairs. The no-update sudo wrapper has covered the
# whole update, so neither the package transaction nor a later repair can
# publish a timestamp to a detached migration child.
# Historical migrations are strictly ordered and mix user hooks and
# downloaded tooling with later privileged repairs. Drop the cached timestamp
# here. Every later sudo — migrations, orphan removal, service restarts, AUR,
# hooks, and mise — goes through --no-update, so a migration child cannot
# wait for one of those repairs to publish a ticket.
omarchy_security_revoke_sudo_timestamp
omarchy_security_enable_no_update_sudo
omarchy-migrate
omarchy-update-orphan-pkgs

Expand Down
23 changes: 17 additions & 6 deletions bin/omarchy-update-stay-awake
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ omarchy_security_require_privileged_bash_startup || exit 126
set -e
omarchy_security_sanitize_bash_environment "$0" "$@"
omarchy_security_require_source_root "$0"
# Traps first, so a signal or failure during the entry revocation still
# exits through the cleanup path.
omarchy_security_install_sudo_cleanup_traps
omarchy_security_revoke_sudo_timestamp || exit 1
omarchy_security_enable_no_update_sudo
# A signal during start must still reach the launch rollback. start itself
# authenticates with sudo -N, which borrows a timestamp without publishing
# one, and must not clear a ticket the update's trusted phases still hold.
omarchy_security_install_signal_exit_traps

stay_awake_state="$HOME/.local/state/omarchy/indicators/stay-awake"
caller_uid=""
Expand Down Expand Up @@ -557,7 +556,10 @@ start_locked() {
fi
fi
launch_pending=0
omarchy_security_install_sudo_cleanup_traps
# The successful launch used sudo -N, so it did not create a timestamp.
# Drop the rollback trap without revoking the caller's cached authorization.
trap - EXIT
omarchy_security_install_signal_exit_traps
}

case "${1:-}" in
Expand All @@ -568,6 +570,15 @@ case "${1:-}" in
;;
esac

# stop is invoked on its own, including after the update has moved into
# untrusted phases. It revokes on entry and exit. start does not: its only
# sudo is `sudo -N`, and clearing here would throw away the update's ticket.
if [[ $1 == "stop" ]]; then
omarchy_security_install_sudo_cleanup_traps
omarchy_security_revoke_sudo_timestamp || exit 1
omarchy_security_enable_no_update_sudo
fi

initialize_state_boundary
exec {state_lock_fd}<"$state_base" || fail_state_boundary
flock -x "$state_lock_fd" || fail_state_boundary
Expand Down
6 changes: 3 additions & 3 deletions docs/update-process.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ omarchy-update

Important behavior:

- Protected update entrypoints require the session's canonical `OMARCHY_PATH` to match their own checkout or the packaged `/usr/bin` entrypoint before selecting commands or the sudo wrapper. This preserves intentionally trusted development checkouts while rejecting a command paired with a different source root. System phases use a fixed command search path; user PATH is restored behind the sudo wrapper for hooks and mise.
- Protected update entrypoints require the session's canonical `OMARCHY_PATH` to match their own checkout or the packaged `/usr/bin` entrypoint before selecting commands or the sudo wrapper. This preserves intentionally trusted development checkouts while rejecting a command paired with a different source root. Phases before migrations use a fixed command search path and caching sudo. From migrations on, the no-update wrapper is first, and user PATH is restored behind that wrapper for hooks and mise.
- Mixed-trust update entrypoints start Bash in privileged mode, discard `BASH_ENV`, `ENV`, and exported-function records before launching helpers, and reject an ordinary `bash path/to/command` invocation. Run them as executables (normally through the `omarchy` CLI); `/usr/bin/bash -p path/to/command` is the explicit interpreter form. This keeps shell startup injection from replacing the no-update sudo boundary.
- In dev-link mode, `omarchy update` fast-forwards the active checkout from its configured upstream before changing system packages or running migrations.
- Migrations remain in chronological order even though historical entries mix user-controlled code with later privileged repairs. Before entering that mixed-trust tail, Omarchy invalidates its timestamp and forces every later sudo call—including AUR's configurable sudo command—to use `--no-update`; prompts authorize one command without publishing a reusable timestamp. Yay's credential loop is disabled for the update.
- User-controlled post-update hooks and mise tools run only after every sudo-capable update stage. Omarchy invalidates its sudo timestamp before each boundary and on every exit; detached children therefore have no later reusable update authorization to wait for.
- This lifecycle controls authorization created by the protected workflow. `sudo -N` prevents cache updates but can use an existing valid credential, and `sudo -k` revokes the current session's timestamp. It does not isolate the account from unrelated concurrent authentication in another workflow.
- Sleep inhibition authenticates before detaching, drops the held command back to the caller, and closes both update lock descriptors before the persistent process starts. Cleanup accepts only caller-owned, mode-0600, single-link state and revalidates the recorded PID, process start time, owner, and random token immediately before every signal.
- Sleep inhibition authenticates with `sudo -N` before detaching, so it can borrow the update's cached timestamp without refreshing or clearing it. It drops the held command back to the caller and closes both update lock descriptors before the persistent process starts. A failed or cancelled launch still revokes. `stop` revokes on entry and exit. Cleanup accepts only caller-owned, mode-0600, single-link state and revalidates the recorded PID, process start time, owner, and random token immediately before every signal.
- Channel switching establishes the same boundary before dev link/unlink, refresh and package operations. It keeps the wrapper first when changing source roots, carries the original user PATH into update hooks and mise, and checks after each package transaction that the wrapper still exists before any further privileged step, since a transaction can replace the running tree with a release that predates it; when it is gone, or the destination otherwise lacks it, the switch stops after the package switch with instructions to run that release's update from a fresh session rather than letting a bare `sudo` or an updater that authenticates without `--no-update` publish a timestamp. Failed and interrupted channel switches revoke on exit.
- `-y` exports `OMARCHY_UPDATE_UNATTENDED=1` and suppresses Omarchy confirmation prompts. Interactive review steps (orphan removal, conflict handoff) report and skip instead of blocking. Privileged commands still require sudo authorization, and command-scoped authentication can prompt separately for each command.
- `-y` exports `OMARCHY_UPDATE_UNATTENDED=1` and suppresses Omarchy confirmation prompts. Interactive review steps (orphan removal, conflict handoff) report and skip instead of blocking. Privileged commands still require sudo authorization: one cached authorization covers the fixed helpers before migrations (prune, snapshot, keyring, pacman). From `omarchy-migrate` onward, each sudo uses `--no-update` and does not publish a timestamp. Orphan removal and service restarts sit in that cold section because they run after migrations, and a caching sudo there would republish a ticket for anything a migration started.
- The free-space requirement uses a 10 GiB threshold and stops the update before
confirmation when it is not met. If free space cannot be determined, the
check is silently skipped. Set `OMARCHY_UPDATE_FORCE=1` to bypass the check.
Expand Down
8 changes: 8 additions & 0 deletions test/shell.d/fixtures/sudo-boundary-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ else
fi
STUB
chmod +x "$SUDO_TEST_ROOT/mock/sudo"
# Trusted update phases call bare sudo. The wrapper is not on PATH until
# migrations, so this has to win over the host sudo. A real file, not a
# symlink: a later test replaces bin/sudo with a decoy via truncation.
cat >"$SUDO_TEST_ROOT/bin/sudo" <<'STUB'
#!/bin/bash
exec "$OMARCHY_PATH/mock/sudo" "$@"
STUB
chmod +x "$SUDO_TEST_ROOT/bin/sudo"

cat >"$SUDO_TEST_ROOT/bin/test-step" <<'STUB'
#!/bin/bash
Expand Down
14 changes: 10 additions & 4 deletions test/shell.d/update-hook-security-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,21 @@ for args in '-y' ''; do
touch "$SUDO_TEST_CACHE"
run_update $args || fail "update failed" "$(<"$boundary_tmp/output")"
assert_boundary_cold "successful update"
grep -q '^sudo -N /usr/bin/true$' "$SUDO_TEST_LOG" || fail "update package helpers must use no-update sudo"
grep -q '^sudo /usr/bin/true$' "$SUDO_TEST_LOG" || fail "trusted update phases must use caching sudo"
python3 - "$SUDO_TEST_LOG" <<'PY'
import sys
s=open(sys.argv[1]).read().splitlines()
positions=[next(i for i,line in enumerate(s) if line.startswith(prefix)) for prefix in ['step:omarchy-update-restart --services-only','step:yay','step:omarchy-hook post-update','step:omarchy-update-mise','step:omarchy-update-stay-awake stop','step:omarchy-update-restart --reboot-only']]
positions=[next(i for i,line in enumerate(s) if line.startswith(prefix)) for prefix in ['step:omarchy-migrate','step:omarchy-update-restart --services-only','step:yay','step:omarchy-hook post-update','step:omarchy-update-mise','step:omarchy-update-stay-awake stop','step:omarchy-update-restart --reboot-only']]
assert positions==sorted(positions), s
assert not any(line.startswith('sudo -N ') for line in s[positions[2]:]), s
migrate=positions[0]
cached=[i for i,line in enumerate(s) if line=='sudo /usr/bin/true']
assert cached and max(cached) < migrate, s
between=s[max(cached)+1:migrate]
assert between==['sudo -k','sudo -h'], s
assert all(line in ('sudo -h','sudo -k') or line.startswith('sudo -N ') for line in s[migrate:] if line.startswith('sudo ')), s
assert not any(line.startswith('sudo -N ') for line in s[positions[3]:]), s
PY
pass "update $args runs privileged phases before hooks and exits cold"
pass "update $args caches sudo before migrations, then stays cold"
done

for step in omarchy-update-system-pkgs yay omarchy-hook omarchy-update-mise; do
Expand Down
20 changes: 14 additions & 6 deletions test/shell.d/update-lock-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,17 @@ assert_boundary_cold "standalone inhibitor cleanup"
pass "standalone inhibitor cleanup revokes before and after session work"

reset_boundary
export SUDO_TEST_REVOKE_FAIL=1
if run_with_lock_env "$SUDO_TEST_ROOT/bin/omarchy-update-stay-awake" start; then
fail "inhibitor started after failed initial revocation"
fi
[[ ! -e $stay_awake_helper_state/inhibit-pid ]] || fail "failed revocation started an inhibitor"
pass "failed initial revocation prevents standalone inhibition"
touch "$SUDO_TEST_CACHE"
preserve_driver="$test_tmp/preserve-stay-awake"
cat >"$preserve_driver" <<'SH'
#!/bin/bash
set -euo pipefail
omarchy-update-stay-awake start
SH
chmod +x "$preserve_driver"
run_with_lock_env script -qefc "$preserve_driver" /dev/null >/dev/null
[[ -e $SUDO_TEST_CACHE ]] || fail "start cleared a timestamp it did not create" "$(<"$SUDO_TEST_LOG")"
grep -q -- '^sudo -N -b -- ' "$SUDO_TEST_LOG" || fail "start did not authenticate with sudo -N" "$(<"$SUDO_TEST_LOG")"
grep -qx 'sudo -k' "$SUDO_TEST_LOG" && fail "start revoked a timestamp it did not create" "$(<"$SUDO_TEST_LOG")"
run_with_lock_env "$SUDO_TEST_ROOT/bin/omarchy-update-stay-awake" stop
pass "start borrows a cached timestamp with sudo -N and leaves it in place"