omarchy icon indicating copy to clipboard operation
omarchy copied to clipboard

`omarchy-update` is annotated `omarchy:requires-sudo=true`, but running it as root makes the mise step write root-owned files into the user home

Open abdrumm opened this issue 2 months ago • 4 comments

What happened

omarchy-update carries this annotation in its header:

# omarchy:summary=Update Omarchy and system packages
# omarchy:args=[-y]
# omarchy:requires-sudo=true

Following it, I ran sudo omarchy update -y. The update itself succeeded, but omarchy-update-mise ran mise up as root, so mise wrote its tool installs as root:

$ find ~ -xdev ! -user "$USER" | wc -l
588

452 of those are mise state (~/.local/share/mise, ~/.cache/mise), including ~/.local/share/mise/installs/opencode/1.18.32/ and its latest/1/1.18 symlinks.

What was expected

mise up manages per-user tools, so omarchy-update-mise should either run strictly as the invoking user, or drop privileges before calling mise.

Why the outer sudo should not be needed

omarchy-update already escalates exactly the steps that need root, and only those — each prompts separately:

[sudo] password for <user>:      # paccache -rk2
[sudo] password for <user>:      # snapper -c root create ...
[sudo] password for <user>:      # pacman -Syu --noconfirm ...

The per-user steps (omarchy-update-mise, omarchy-update-aur-pkgs, omarchy-update-dev) are not wrapped in sudo at all, which means they are intended to run unprivileged. An outer sudo silently converts them.

Impact

Once the installs are root-owned, mise cannot update them as the user:

$ mise use -g opencode
mise ✗ [email protected]  3ms · failed: Permission denied (os error 13)
mise ERROR Failed to install aqua:anomalyco/opencode@latest: Permission denied (os error 13)

This breaks omarchy-default-agent, which calls mise use -g <agent> on every invocation, so Defaults -> Agent -> in the menu fails with "Could not set as the default coding agent" and launches nothing.

Confusingly, the agents themselves still run fine (already-installed binaries are still executable), and SUPER+SHIFT+CTRL+A (omarchy-agent --pick) still works, because that path skips mise use -g entirely. So it presents as a broken menu rather than a permissions problem.

Recovery is sudo chown -R "$USER:$USER" ~/.local/share/mise ~/.cache/mise.

Steps to reproduce

  1. mise install <some-tool> as your normal user.
  2. sudo omarchy update (any Omarchy version with a mise-managed tool that has an update available).
  3. find ~ -xdev ! -user "$USER" — note the mise installs.
  4. mise use -g <some-tool> — now fails with Permission denied (os error 13).

Possible fixes

Any one of these would close the trap:

  • Drop omarchy:requires-sudo=true from omarchy-update, since the script escalates its own root steps.
  • Re-exec mise as the original invoking user in omarchy-update-mise, e.g. sudo -u "${SUDO_USER:-$USER}" MISE_MINIMUM_RELEASE_AGE=0 mise up.
  • Have omarchy-update drop privileges for the steps that are not annotated requires-sudo.

System details

$ omarchy version --no-sudo
4.0.4-1

Arch Linux, Omarchy 4.0.4-1, mise 2026.9.12.

Filed by opencode/big-pickle via opencode.

abdrumm avatar Sep 26 '26 15:09 abdrumm

Confirmed this is still the case on current quattro: omarchy-update still carries omarchy:requires-sudo=true, and omarchy-update-mise runs mise up as whoever started it. That metadata goes into the command catalog, so agents and humans both read it as "run this with sudo".

The simplest fix might be to refuse root up front, since the script already escalates only the steps that need it:

if (( EUID == 0 )); then
  echo "Run omarchy update as your normal user; it asks for sudo when it needs it." >&2
  exit 1
fi

and/or change the annotation so it doesn't suggest a sudo prefix.

jandrusk avatar Oct 08 '26 13:10 jandrusk

Reproduced on current quattro (f5006bd41) on a disposable Omarchy worker. The package, snapshot and boot phases were stubbed and omarchy-update-mise was left real. sudo -E omarchy update -y exited 0 and left 70 root-owned files in the user's home, under ~/.local/share/mise/installs/codex/<new version>. It also left a root-owned $XDG_RUNTIME_DIR/omarchy-update.lock, and the next omarchy update run as the user then failed at omarchy-update-lock with Permission denied. Plain sudo resets HOME to /root on a stock install, so there mise writes into /root instead, but it still runs as root. Nothing in bin/omarchy-update drops privileges before the per-user steps (omarchy-update-dev, omarchy-hook post-update, omarchy-update-mise, omarchy-update-aur-pkgs), so any root launch runs all of them as root.

The fix is already open, twice: #11479 and #13660 both make omarchy-update refuse to run as root before it writes its log or takes the lock, and both close this issue. A guard of that shape, tried on the same worker, refused sudo -E omarchy update -y with nothing changed in the home directory, and an update run as the user still upgraded the mise tools normally. Each pull request is reviewed as its own item.

For anyone already hit, the recovery in the report holds: sudo chown -R "$USER:$USER" ~/.local/share/mise ~/.cache/mise, and remove a root-owned $XDG_RUNTIME_DIR/omarchy-update.lock or /tmp/omarchy-update.log if one is left.

Checked by Claude Opus 5.5, with Codex Medium as the second opinion. Codex agreed with the mechanism, and found that no caller in the repository runs the full update as root, so refusing root breaks nothing. It reads the same working notes, so its agreement is not guaranteed to be independent. Waiting on the maintainer to choose between #11479 and #13660.

omarchybot avatar Oct 13 '26 03:10 omarchybot

Reproduced on 4.5.0-3 (Arch, mise 2026.11.10). A single sudo-run mise left 68 root-owned paths, 58 under $HOME/.local/share/mise and 10 under $HOME/.cache/mise. Slightly fewer than the 70 in the report above, same shape: the whole installs/codex/<version> tree (bin/codex, bin/codex-code-mode-host, bin/codex-exec-server, codex-package.json, codex-path/rg, codex-resources/*), .mise.backend.toml and the latest/global/0.171/0 symlinks; on the cache side codex/<version>/bin_paths-<hex>.msgpack.z, three lockfiles/<hex>, both downloads-cas blobs, github/...msgpack.z and go/remote_versions-<hex>.msgpack.z.

The part worth a regression test is that the damage is silent. Reads still succeed, so the tool keeps working; only regeneration of the cache file fails, and it fails on every prompt and every mise-invoked command:

mise WARN failed to write cache file: $HOME/.cache/mise/codex/<version>/bin_paths-<hex>.msgpack.z Permission denied (os error 13)

mise doctor still prints No problems found. The directory is 755 and root-owned, so the user cannot replace the file inside it either. Nothing surfaces until the next install or upgrade, which cannot write into the version directory; by then the warning is old and the cause is several updates back.

On the cause: sudo preserves HOME only with -E (or where env_keep covers it). Plain sudo writes to /root; sudo -E writes into the user's tree. Either way the process is root, and the per-user steps (omarchy-update-dev, omarchy-update-mise, omarchy-update-aur-pkgs, post-update hooks) inherit it.

Repair, run and verified. Escalation is only needed for the chown:

find $HOME/.cache/mise $HOME/.local/share/mise -not -user "$(id -u)" -print0 \
  | xargs -0 sudo chown -h "$(id -u):$(id -g)"
rm $HOME/.cache/mise/codex/<version>/bin_paths-*.msgpack.z

Any mise command that resolves the tool then rewrites the file owned by the user: 0 paths not owned by the user, warning gone, no reinstall, no data loss. One ordering note: the find itself must be escalated. Unprivileged it returns Operation not permitted per path, which reads as a find bug rather than a missing privilege.

4lleviate avatar Nov 21 '26 01:11 4lleviate

Rechecked after @aChr0me's report on 4.5.0-3. Current quattro (fef8501d27) still runs omarchy-update-mise without changing the caller's UID. A root launch that reaches mise with the user's home or mise paths preserved can therefore still create root-owned user state. The requires-sudo annotation is catalog metadata; the command router does not automatically elevate the update.

#11479 already links this issue and proposes refusing root before update work, but its branch now conflicts with quattro and needs to be brought current and reverified in its own review. #13660 has closed without merging. No new worker tests were run in this issue session; the earlier reproduction was on a different revision. This issue remains waiting on the maintainer while the existing fixes are worked as separate items.

Checked by GPT-6 High in Codex, with Opus 5.5 High and muse-wonder via pi, thinking high, as the second-opinion panel. Both agreed with the source diagnosis and disposition; their agreement is not guaranteed to be independent.

omarchybot avatar Nov 21 '26 01:11 omarchybot