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
2 changes: 2 additions & 0 deletions bin/omarchy-sudo-keepalive
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
sudo -v
while true; do sudo -n true; sleep 60; done 2>/dev/null &
SUDO_KEEPALIVE_PID=$!
# Disown so the sourcing script does not wait on the sleep loop at exit.
disown "$SUDO_KEEPALIVE_PID" 2>/dev/null || true
trap "kill $SUDO_KEEPALIVE_PID 2>/dev/null" EXIT
9 changes: 9 additions & 0 deletions bin/omarchy-update
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ omarchy-update-requires-free-space
[[ ${1:-} != "-y" ]] || export OMARCHY_UPDATE_UNATTENDED=1

if [[ ${1:-} == "-y" ]] || omarchy-update-confirm; then
# One sudo prompt covers prune, snapshot, keyring, pacman, migrations, and
# orphan removal instead of re-asking on every step (#13404).
# Re-install the stay-awake EXIT trap after sourcing: keepalive replaces it.
source omarchy-sudo-keepalive
trap 'if (( ${SUDO_KEEPALIVE_PID:-0} > 0 )); then kill "$SUDO_KEEPALIVE_PID" 2>/dev/null || true; fi; omarchy-update-stay-awake stop' EXIT

# Before the snapshot: the cache is on the snapshotted subvolume, so pruning
# after it frees nothing until that snapshot ages out.
omarchy-update-pkg-prune
Expand Down Expand Up @@ -58,6 +64,9 @@ if [[ ${1:-} == "-y" ]] || omarchy-update-confirm; then
# reboot can terminate this process before its EXIT trap gets a chance to
# remove the persistent Stay Awake marker.
omarchy-update-stay-awake stop
if (( ${SUDO_KEEPALIVE_PID:-0} > 0 )); then
kill "$SUDO_KEEPALIVE_PID" 2>/dev/null || true
fi
trap - EXIT

omarchy-update-restart
Expand Down
9 changes: 7 additions & 2 deletions bin/omarchy-windows-vm
Original file line number Diff line number Diff line change
Expand Up @@ -580,14 +580,18 @@ prepare_caller_mounts() {
# Privacy is an explicit preflight step for both already-pinned sources, not
# a side effect halfway through the two-mount transaction. Old umask-022
# installs are hardened together before either Docker-facing anchor changes.
chmod 0700 -- "/proc/$BASHPID/fd/$storage_fd" "/proc/$BASHPID/fd/$shared_fd" || {
# Use a leading 0 in the mode so GNU chmod clears setuid/setgid: the Windows
# container leaves ~/Windows at 2777, and `chmod 0700` would keep setgid
# (2700), which then fails the exact-700 check below on every relaunch.
chmod 00700 -- "/proc/$BASHPID/fd/$storage_fd" "/proc/$BASHPID/fd/$shared_fd" || {
exec {storage_fd}<&-
exec {shared_fd}<&-
return 1
}
storage_mode=$(stat -Lc '%a' "/proc/$BASHPID/fd/$storage_fd" 2>/dev/null) || storage_mode=""
shared_mode=$(stat -Lc '%a' "/proc/$BASHPID/fd/$shared_fd" 2>/dev/null) || shared_mode=""
if [[ $storage_mode != 700 || $shared_mode != 700 ]]; then
echo "omarchy-windows-vm: VM data folders must be mode 700 (storage=$storage_mode shared=$shared_mode)" >&2
exec {storage_fd}<&-
exec {shared_fd}<&-
return 1
Expand Down Expand Up @@ -1015,7 +1019,8 @@ prepare_user_mount_sources() {
echo "omarchy-windows-vm: storage and shared must be different directories" >&2
return 1
}
chmod 0700 -- "$storage" "$shared"
# Leading 0 clears setuid/setgid; see prepare_caller_mounts.
chmod 00700 -- "$storage" "$shared"
}

storage_space_path() {
Expand Down
2 changes: 2 additions & 0 deletions test/shell.d/update-disk-space-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ for command in \
done
write_stub omarchy-update-available 'exit 1'
write_stub pkexec 'exec "$@"'
write_stub omarchy-sudo-keepalive ':'
write_stub sudo 'exit 0'

set +e
TEST_AVAILABLE_BYTES=$((9 * 1024 * 1024 * 1024)) \
Expand Down
3 changes: 3 additions & 0 deletions test/shell.d/update-lock-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ for command in \
done
write_stub omarchy-update-available 'exit 1'
write_stub pkexec 'exec "$@"'
# Sourced by omarchy-update; keep the real helper's sleep loop out of tests.
write_stub omarchy-sudo-keepalive ':'
write_stub sudo 'exit 0'

# omarchy-update should hold the lock before snapshotting, so a second update
# cannot even enter its pre-update snapshot.
Expand Down
7 changes: 7 additions & 0 deletions test/shell.d/update-sequence-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ STUB
chmod +x "$stub_bin/$step"
done

# Sourced by omarchy-update before the step chain; keep sleep loops out of tests.
cat >"$stub_bin/omarchy-sudo-keepalive" <<'STUB'
#!/bin/bash
:
STUB
chmod +x "$stub_bin/omarchy-sudo-keepalive"

# OMARCHY_UPDATE_LOGGED stands in for the script(1) wrapper the update re-execs
# itself under; the stubbed lock reports itself already held.
run_update() {
Expand Down
9 changes: 9 additions & 0 deletions test/shell.d/windows-vm-compose-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ grep -q 'PROTECT: "Y"' "$COMPOSE" || fail "web console is not password protected
grep -q -- '- /:/' "$COMPOSE" && fail "compose contains host-root bind"
pass "writer emits fixed anchors bound to exact private source inodes"

# Container leaves setgid on ~/Windows; user prep must clear it on relaunch.
unmount_all
chmod 2777 "$HOME/Windows"
[[ $(stat -Lc '%a' "$HOME/Windows") == 2777 ]] || fail "could not seed setgid shared folder"
prepare_user_mount_sources || fail "user prep rejected a setgid shared folder"
[[ $(stat -Lc '%a' "$HOME/Windows") == 700 ]] || fail "user prep did not clear setgid from shared folder"
[[ $(stat -Lc '%a' "$HOME/.windows") == 700 ]] || fail "user prep left storage off 700"
pass "user mount prep clears setgid left by the Windows container"

# Input cannot widen a mount or compose field.
rm -f "$COMPOSE"
write 4G 2 64G 'x -v /:/h' p UTC 2>/dev/null && fail "malicious username accepted"
Expand Down
12 changes: 12 additions & 0 deletions test/shell.d/windows-vm-mount-boundary-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ if setpriv --reuid=1001 --regid=1001 --clear-groups cat "$EXPECTED_SHARED/shared
fi
pass "cross-filesystem symlink sources bind by identity and migrated 0700 leaves deny another account"

# The Windows container sets ~/Windows to 2777 (including setgid). GNU chmod
# with a 4-digit mode leaves an existing setgid bit alone, so a bare 0700
# would leave 2700 and the exact-700 check would reject every relaunch.
umount "$EXPECTED_SHARED"
umount "$EXPECTED_STORAGE"
chmod 2777 /home/shared-target
[[ $(command stat -Lc '%a' /home/shared-target) == 2777 ]] || fail "could not seed setgid shared folder"
with_vm_lock prepare_caller_mounts || fail "root could not clear setgid from the shared folder"
[[ $(command stat -Lc '%a' /home/shared-target) == 700 ]] || fail "setgid shared folder was not normalized to 700"
[[ $(command stat -Lc '%u:%a' "$EXPECTED_SHARED") == 1000:700 ]] || fail "shared anchor retained setgid after relaunch prep"
pass "prepare_caller_mounts clears setgid left by the Windows container"

# Existing production boundary components are never repaired in place when
# their ownership or write permissions are unsafe. Both the preparation path
# and the final pre-Docker guard must fail closed without disturbing the binds.
Expand Down
24 changes: 24 additions & 0 deletions test/shell.d/windows-vm-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,27 @@ rg -q 'tag = "-default-opacity"' "$windows_vm_rules" ||
rg -q 'opacity = "1 1"' "$windows_vm_rules" ||
fail "Windows VM stays fully opaque"
pass "Windows VM stays fully opaque"

# chmod 0700 leaves setgid on directories; the container sets ~/Windows to 2777,
# so relaunch prep must use 00700 to clear it before the exact-700 check.
rg -q 'chmod 00700 -- "/proc/\$BASHPID/fd/\$storage_fd" "/proc/\$BASHPID/fd/\$shared_fd"' "$windows_vm_command" ||
fail "caller-mount prep clears setgid when hardening VM folders"
rg -q 'chmod 00700 -- "\$storage" "\$shared"' "$windows_vm_command" ||
fail "user-mount prep clears setgid when hardening VM folders"
if rg -q 'chmod 0700 -- "/proc/\$BASHPID/fd/\$storage_fd"' "$windows_vm_command" ||
rg -q 'chmod 0700 -- "\$storage" "\$shared"' "$windows_vm_command"; then
fail "VM folder hardening still uses chmod 0700, which preserves setgid"
fi
pass "Windows VM folder hardening clears setgid on relaunch"

# Document the GNU chmod quirk the hardening sites rely on: a 4-digit mode
# leaves setgid on directories, while a leading 0 clears it.
setgid_dir=$(mktemp -d)
chmod 2777 "$setgid_dir"
[[ $(stat -c %a "$setgid_dir") == 2777 ]] || fail "could not seed setgid directory"
chmod 0700 -- "$setgid_dir"
[[ $(stat -c %a "$setgid_dir") == 2700 ]] || fail "chmod 0700 unexpectedly cleared setgid"
chmod 00700 -- "$setgid_dir"
[[ $(stat -c %a "$setgid_dir") == 700 ]] || fail "chmod 00700 did not clear setgid"
rmdir "$setgid_dir"
pass "GNU chmod 00700 clears directory setgid; 0700 does not"