Skip to content

[codex] OM-SEC-14: Run update hooks without reusable sudo authority - #9469

Merged
ErikMelton merged 37 commits into
omacom:quattrofrom
AFOliveira:codex/om-sec-14-cold-update-hooks
Sep 25, 2026
Merged

ErikMelton merged 37 commits into
omacom:quattrofrom
AFOliveira:codex/om-sec-14-cold-update-hooks

Conversation

@AFOliveira

@AFOliveira AFOliveira commented Aug 31, 2026 •

Copy link
Copy Markdown
Member

Keeps update hooks, AUR builds, mise and channel hooks outside authorization created by the update workflow. It starts with canonical privileged-Bash/shared-helper validation and cold revocation, uses fixed no-update sudo dispatch, finishes privileged stages before user code, and revokes on errors, cancellation and completion. Finding: OM-SEC-14.

Reporter credit: Roger Piñol (R08) and Sean Huber reported earlier update/Pacman authorization-reuse cases; Afonso Oliveira independently disclosed OM-SEC-14 and authored this remediation. Sean also reported the separately tracked Stay Awake occurrence.

Candidate 75e58f03 builds on #9457's exact shared foundation and current Quattro. Earlier feedback about sudo option forwarding, unreachable tests, PATH preservation, hook timing and cleanup is reflected in the final implementation. The deferred pacman-refresh hook runs once after the completed channel transition.

The inhibitor identity protection is now a compatible child PR: #9467 is based on this exact candidate and preserves this updater/helper/wrapper while adding private state, full process identity and cancellation-safe launch. Order: #9457 → #9469 → #9467, then #9472/#9474. #9474 must also integrate #9463's SSH proof transaction. #9473 remains closed; its rejected 163-prompt legacy upgrade is not a successful validation or dependency.

Independent Daybreak review found no new defect in the update/channel authorization boundary. Thirteen focused suites (157 groups), CLI112, syntax and whitespace checks pass. The integrated inhibitor received separate reviews and tests in #9467.

Release gates remain: exact installed package-stack validation, measured normal update/channel prompt counts and cancellation, and #9474's migration security/UX integration. Command-scoped sudo can prompt for each privileged operation; -y does not bypass authentication. This source validation does not establish usable legacy upgrade authentication or account-wide isolation from unrelated concurrent sudo sessions.

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

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

Several required integrations are missing, leaving credential-reuse paths open while the relevant regression tests are unreachable.

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

Pull request overview

Hardens update hooks against reusable sudo credentials by introducing cold credential boundaries and reordering user-controlled stages.

Changes:

  • Adds a sudo -N wrapper and trusted source validation.
  • Moves hooks and mise after privileged update stages.
  • Adds security regression tests and updates documentation.
File summaries
File Description
bin/omarchy-update Reorders update stages and manages sudo boundaries.
bin/omarchy-refresh-pacman Moves or defers the legacy refresh hook.
default/omarchy/sudo-no-update/sudo Adds the no-update sudo wrapper.
test/shell.d/update-hook-security-test.sh Adds security regression scenarios.
test/shell.d/update-sequence-test.sh Updates expected stage ordering.
docs/update-process.md Documents the revised update process.
default/agents/skills/omarchy/hooks.md Documents hook timing and authorization.
config/omarchy/hooks/pre-refresh-pacman.d/add-custom-repo.sample Updates sample hook guidance.
Review details
  • Files reviewed: 6/8 changed files
  • Comments generated: 4
  • 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
Comment thread docs/update-process.md Resolved
Comment thread docs/update-process.md Resolved
@AFOliveira
AFOliveira marked this pull request as ready for review September 6, 2026 22:03
@sayem314

sayem314 commented Sep 7, 2026

Copy link
Copy Markdown

@robosayem review and audit this properly, and if you have any opinion or suggestions then share it.

AFOliveira and others added 2 commits September 8, 2026 15:28
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

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

A remaining caller exposes hook code to later sudo authentication, and grant cleanup can delete administrator-modified policy.

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

Review details
  • Files reviewed: 24/35 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread default/agents/skills/omarchy/hooks.md Resolved
@ErikMelton

Copy link
Copy Markdown
Member

LGTM, pending hook doc fix.

AFOliveira and others added 6 commits September 10, 2026 22:01
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>

@ErikMelton ErikMelton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  • [P2] Notification readiness blocks lock recovery — bin/omarchy-restart-shell:86–87
    if OMARCHY_PATH="$session_omarchy_path" OMARCHY_SHELL_IPC_TIMEOUT=0.5s omarchy-shell shell ping >/dev/null 2>&1 &&

When recovering a locked session whose lock client died, the new condition prevents relock_session from running unless notifications also become ready. If that plugin fails or takes longer than the polling window, the command exits and leaves the user stranded behind Hyprland’s failsafe—even when the lock service works. Run lock recovery independently of notification readiness. I reproduced this with isolated stubs: the PR exits without restoring the lock; the previous condition restores it successfully.

AFOliveira and others added 5 commits September 17, 2026 17:02
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>
@AFOliveira

Copy link
Copy Markdown
Member Author

Fixed in b34b117, now at 689771b. The restart waits for core IPC, re-secures the lock immediately, and only then waits for a previously running notification service, exiting 1 with its own message if that never returns; the restart suite covers the never-returning case.

Follow-up on the same head: cleanup traps are installed before the entry sudo -k, the notification probe is bounded to 1s instead of busctl's 25s default, and the branch carries the current #9457 head. All 15 owned suites and ./test/cli pass; independent review is CLEAR at 43b9116 plus the #9457 merge.

AFOliveira added a commit to AFOliveira/omarchy that referenced this pull request Sep 18, 2026
Bring in omacom#9469 at its current head, which carries current quattro and
the current omacom#9457 head, replacing this branch's stale copy of both.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@ErikMelton
ErikMelton merged commit 56ca654 into omacom:quattro Sep 25, 2026
@paralyses2193

Copy link
Copy Markdown

The PR lists "measured normal update/channel prompt counts" as remaining release work, so here is one measurement from a real edge install.

Setup: omarchy-dev and omarchy-settings-dev 4.0.0.r2304.g7b336b1-1, sudo 1.9.17.p2, a terminal omarchy update with no pending packages, AUR or migrations. It exited 0.

There were 9 password prompts, one per privileged command. I matched each against the sudo journal:

  1. paccache -rk2
  2. snapper --csvout list-configs
  3. snapper -c root create -c number ...
  4. snapper -c root cleanup number
  5. systemd-inhibit ... setpriv ... (update inhibitor)
  6. pacman-key --list-keys 40DFB630...
  7. pacman -Sy --noconfirm archlinux-keyring
  8. pacman-key --list-keys 40DFB630... (same check again)
  9. pacman -Syu --noconfirm --overwrite /usr/share/omarchy/*

AUR, hooks and mise did not prompt. An earlier run on the same machine hit the keyring recovery path after one aborted prompt (the first --list-keys failing sends it to recv-keys, lsign-key and pacman -Sy). That added 4 more prompts before the package step. A run with packages to upgrade or migrations would presumably add more.

Before r2304, one prompt covered the whole update. The user's first reaction to 9 prompts was that the update was broken, and they cancelled a run partway through because of it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants