Skip to content

[codex] OM-SEC-17: Allowlist update restart markers and commands - #9472

Open
AFOliveira wants to merge 55 commits into
omacom:quattrofrom
AFOliveira:codex/om-sec-17-restart-marker-allowlist
Open

AFOliveira wants to merge 55 commits into
omacom:quattrofrom
AFOliveira:codex/om-sec-17-restart-marker-allowlist

Conversation

@AFOliveira

@AFOliveira AFOliveira commented Aug 31, 2026 •

Copy link
Copy Markdown
Member

Writable restart markers select only supported, zero-argument component commands through an explicit allowlist. Commands resolve inside the validated source tree, including matching packaged links to /usr/bin. Unsupported names, generic dispatchers and non-regular markers cannot select a command. Failed restarts keep their marker for retry; a shell marker causes only the single normal shell refresh.

Finding: OM-SEC-17, reported and remediated by Afonso Oliveira. The #9469 prerequisite retains Roger Piñol's and Sean Huber's credits for their update/Pacman and Stay Awake reports.

Order: #9457 → #9469 → #9467 → this PR. The integration includes the actual #9467 6af052fc commit through an ordinary merge, including first-upgrade compatibility and the isolated idle-toggle fixture. Shared authorization code, the updater, inhibitor and their tests are byte-identical to that prerequisite. Erik's hook-documentation feedback is addressed by the current foundation's manual, reference and sample hook timing. #9474 remains a separate downstream migration change; #9473 is closed.

At b9336ce8, this PR's own delta over #9467 is four files: the restart dispatcher, its documentation and two restart test files. Seven focused suites pass both locally and in a fresh vanilla Arch VM: 111 groups, plus 112 CLI checks, with no skipped cross-account coverage. The VM had no installed Omarchy commands when the suites ran.

Native tests on the same VM exercised the actual restart dispatcher and tmux in both checkout and packaged symlink layouts. Supported markers reload the real tmux configuration; malicious PATH commands and unsupported markers are not dispatched; failed reloads retain their marker and succeed on retry; non-regular markers are refused; cached sudo authorization is revoked. This headless guest also exercises the non-blocking missing-desktop path; it does not establish graphical shell or every hardware component restart.

Daybreak's final scoped review of exact b9336ce8 found no blocker; inherited SSH/AUR changes were excluded. Full historical update/migration prompt counts and the coordinated runtime/settings release remain separate validation work; earlier excessive prompt counts are not release-readiness evidence.

@AFOliveira
AFOliveira marked this pull request as draft September 1, 2026 09:49
@ErikMelton

Copy link
Copy Markdown
Member

2 Changes:

  1. The new sudo wrapper breaks option-bearing calls. default/omarchy/sudo-no-update/sudo executes:

exec /usr/bin/sudo -N -- "$@"

The -- makes subsequent arguments command arguments rather than sudo options. For example, omarchy-update-stay-awake calls sudo -v, which becomes:

/usr/bin/sudo -N -- -v

This attempts to execute a command named -v and aborts a normal terminal update under set -e. The wrapper needs to preserve supported sudo options, with regression coverage for sudo -v.

  1. The original user PATH is lost before hooks and mise run. omarchy-update saves user_path, replaces and exports PATH, and then re-executes itself through script. Because user_path is not preserved across that re-exec, the new process captures the already-sanitized path. The later PATH="$user_path" calls therefore do not restore paths such as ~/.local/bin. Post-update hooks can silently lose commands, and a user-installed mise may be skipped.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The sudo validation flow can break sleep inhibition, existing update tests bypass their stubs, and the claimed marker security regression test is absent.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Hardens update restart handling against attacker-controlled markers and reusable sudo authorization.

Changes:

  • Allowlists restart markers and resolves fixed command paths.
  • Adds non-reusable sudo and trusted-source boundaries.
  • Reorders privileged and user-controlled update phases.
File summaries
File Description
AGENTS.md Documents secure bash -p exceptions.
bin/omarchy-update Adds trust validation, sudo isolation, and sequencing.
bin/omarchy-update-restart Validates markers and separates restart phases.
default/omarchy/sudo-no-update/sudo Wraps sudo with --no-update.
test/shell.d/update-sequence-test.sh Extends update-order and boundary testing.
Review details
  • Files reviewed: 3/5 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread default/omarchy/sudo-no-update/sudo Resolved
@AFOliveira
AFOliveira marked this pull request as ready for review September 7, 2026 13:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The refresh hook can precede later cache-populating sudo calls in omarchy-reinstall-pkgs, reopening the authorization-reuse window.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 26/37 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread default/agents/skills/omarchy/hooks.md Outdated
├── post-update.d/ # During `omarchy update`, after system packages and migrations
├── pre-refresh-pacman.d/ # Before `omarchy refresh pacman` re-syncs packages
├── post-update.d/ # At the end of `omarchy update`, after privileged work
├── pre-refresh-pacman.d/ # After `omarchy refresh pacman` finishes (legacy name)
@ErikMelton

Copy link
Copy Markdown
Member

LGTM, pending hook doc fix.

AFOliveira and others added 17 commits September 10, 2026 15:12
Upstream now runs every Omarchy-owned pacman transaction through the
hidden omarchy-update-pacman helper so a mid-transaction systemd reexec
cannot kill it. Keep the deferred pre-refresh-pacman hook and the
command-scoped sudo wrapper, and call the helper from the refresh and
channel commands; the wrapper still applies to the helper's own sudo.

The sudo boundary fixture copies the helper into its root and runs a
systemd-run stand-in that execs the wrapped pacman step in place.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The legacy command wrote the caller's unvalidated name into both the
sudoers filename and the rule. Cleanup applied the current lower-case
account pattern to that suffix, so an exact legacy grant for an account
such as Alice was classified as administrator policy, left active, and
the machine-wide migration marker was written anyway.

Match a legacy grant by its exact filename and rule relationship instead
of the account policy, and cover it in the lifecycle suite through both
the unit cleanup and the real migration runner.

The account pattern itself stays lower-case: sudoers reads an upper-case
word such as ALICE as a User_Alias reference, and ALL as every user, so
such names must never reach the generated rule. Pin that with a test.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Matching a legacy grant by its filename and rule relationship is not a
complete fingerprint: the legacy writer took the filename from $USER but
produced the rule with echo, and under BASH_ENV with xpg_echo a name such
as ali\0143e yields an alice rule in a mismatched file. Preserving that
as administrator policy let the migration certify success with an
unrestricted grant still live until the next boot.

The prefix is reserved anyway: boot cleanup and the package hook remove
everything under it. Move any file the classifier does not recognize
into a fresh root-only directory under /var/lib/omarchy/sudoers-quarantine/
as `policy`, with the original name stored beside it, so nothing there
stays live, the administrator keeps the content, and a legacy filename
already close to NAME_MAX still fits. An untrusted quarantine directory
keeps the migration pending. Cover the mismatched and maximum-length
legacy files in the unit cleanup and through the real migration runner.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Bring in the legacy-grant classifier fix and the reserved-prefix
quarantine from omacom#9457 so this branch no longer carries a stale copy of
that command.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…rough user work

Three review findings on the update-hook boundary:

The pre-refresh-pacman hook had been moved after the refresh transaction
and, during a channel switch, deferred to the very end. That defeated the
hook's purpose: custom repositories and IgnorePkg entries were not in
place when the downgrade-capable -Syyuu ran. Run the hook where it used
to run, after the package config is re-synced and before the transaction,
but cold: revoke the timestamp, run it behind the no-update wrapper with
the caller's original PATH, and revoke again before continuing. Every
later privileged command authenticates with --no-update, so a detached
child left by the hook has no reusable timestamp to wait for. Channel
switching hands the caller's PATH to the refresh the same way the updater
receives it, and no longer defers or re-runs the hook.

Stay Awake was released before AUR builds, hooks and mise, so the machine
could sleep during the longest part of an update. Releasing the inhibitor
needs no privilege because the held command already dropped to the user,
so stop it after mise and before the reboot prompt, as before.

A packaged channel destination cannot be inspected before its package is
installed, and a transaction can replace the running tree with a release
that predates the command-scoped wrapper; from then on a bare sudo would
resolve to /usr/bin/sudo and publish a timestamp, and the destination's
own updater authenticates the same way. The switch used to abort only
after the packages had changed, with generic rerun advice. Now it checks
for the wrapper after each transaction before any further privileged
step, completes what it safely can, and stops cold with instructions to
run that release's update from a fresh session instead of launching it.

Boundary tests pin the hook between the config copies and the transaction
with a cold timestamp on both sides, the older-destination stop with its
guidance and no launched updater, the new inhibitor position, and the
post-update hook staying unreached on failures and signals. Docs, the
manual and the sample hook describe the restored timing.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Restarting the shell waited for the notification bus name to reappear
before it would re-acquire a lock whose client had died. A slow or
failed notification plugin then left the user stranded behind
Hyprland's failsafe even though the lock service worked.

Wait for the shell's core IPC, re-secure the lock immediately, and only
then wait for a previously running notification service, reporting it
separately if it never returns. Cover the never-returning case: the lock
comes back and the restart still reports the missing service.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…robe

The protected entrypoints revoked the sudo timestamp before installing
their cleanup traps, so a signal or failure during that first sudo -k
exited without the cleanup path. Install the traps first.

The shell restart probed the notification bus name with busctl's
default 25 second timeout, so an unresponsive user bus could stall the
restart by that much per probe. Bound each probe to one second.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
pacman continues a transaction after a failed scriptlet. Model that in
the shared package-scriptlet contract: a failed pre_upgrade followed by
post_upgrade must keep the removal blocker while a rule remains, a
clean retry recovers, a stranded blocker with a live rule is cleaned by
the next completed installation, a fresh install that cannot remove a
leftover rule leaves publication refused, and the sweep does not depend
on inherited glob state.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The settings package's pre-transaction hook runs this command under
pacman's transaction. Its lock wait was unbounded, so a stalled grant
operation could hang pacman indefinitely before AbortOnFail ever saw a
result. Grant operations are short; wait at most 60 seconds.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Keep inhibitor state in validated private directories and verify the recorded owner, PID, start time and launch token before signaling. Authenticate the held command before detaching and drop it back to the invoking user.

Serialize launch and cancellation, identify the child before publishing its state, and preserve caller-owned idle choices. Cover cross-account fallback state, process identity, cancellation, retry, and update-lock handling with isolated regressions.
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at b9336ce8. The prerequisites #9457, #9469 and #9467 are merged, so what this pull request still adds is four files: bin/omarchy-update-restart, its doc bullets, and two restart tests. It no longer merges into quattro, and when merged by hand it breaks the update's single sudo authorization from #13323.

What changed underneath it. After this branched, #13323 (e1614f2bd) made omarchy update ask for the password once and keep that authorization alive with a keepalive for the whole run, deliberately including the service restarts, the post-update hook and mise. The new omarchy-update-restart calls omarchy_security_revoke_sudo_timestamp (sudo -k) when it starts (line 22) and again after the restarts (line 100). omarchy-update runs omarchy-update-restart --services-only before the post-update hook and mise, so that revocation ends the update's authorization partway through. The keepalive then exits, and the hook, mise and anything else after that point either prompt again or, without a terminal, fail.

What was run, on a disposable Omarchy worker, against a local merge of quattro into this head. The only textual conflict, in docs/update-process.md, was resolved by keeping both sides; nothing was pushed.

  • A reproduction with real sudo set to require a password. After an authorized sudo true, quattro's omarchy-update-restart --services-only leaves the authorization in place, and this branch's version leaves it revoked.
  • test/shell.d/update-restart-security-test.sh from this PR fails on the merge: the updater could not complete with real restart handling. The update stops with "Something went wrong" right after "Restarting shell", which is the step that follows the revocation. update-restart-phases, update-sequence, update-hook-security, restart-shell, update-stay-awake-security and channel-sudo-boundary pass.
  • ./test/cli has one failure, vscode generated theme references current theme file, which is unrelated to this change.

Whether the restriction is still worth its size on quattro. The old dispatcher resolves omarchy-restart-$service on the update's fixed PATH, and a marker filename cannot contain a slash, so a marker can only pick one of the shipped omarchy-restart-* commands. Under #13323 the user-writable ~/.config/omarchy/hooks/post-update runs moments later under the same authorization and can run anything. Whether a marker allowlist still buys anything, given that, is a decision for the maintainer. The smaller parts (keeping a marker when its restart fails, not dispatching restart-app with no arguments) stand on their own and would be a much smaller change.

Second opinion: none. omabot review refused because today's limit of 500 reviews is used up, so this is one model's review (Claude Opus 5.5).

Nothing was pushed to the branch. This waits on the maintainer to decide whether the pull request is still wanted after #13323. If it is, the author needs to merge quattro and have the restart script leave the update's authorization alone when it runs inside an update (OMARCHY_UPDATE_SUDO_SESSION=1), as omarchy-update-stay-awake already does.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants