Skip to content

[codex] OM-SEC-19: Protect migration and SSH setup authorization - #9474

Draft
AFOliveira wants to merge 144 commits into
omacom:quattrofrom
AFOliveira:codex/om-sec-19-cold-migration-queue
Draft

AFOliveira wants to merge 144 commits into
omacom:quattrofrom
AFOliveira:codex/om-sec-19-cold-migration-queue

Conversation

@AFOliveira

@AFOliveira AFOliveira commented Aug 31, 2026 •

Copy link
Copy Markdown
Member

Keep the ordered migration queue and SSH setup outside reusable sudo lifetime. Startup and source-root validation happen before selecting code; authentication is revoked before work, after each successful migration, and on failure or catchable signals. Completion is published only after both work and revocation succeed. Direct package-helper calls preserve the same boundary.

Finding: OM-SEC-19. Sean Huber reported inherited Bash-state authorization reuse in migrations and SSH setup. Afonso Oliveira independently disclosed the migration lifetime and direct package-helper paths as OM-SEC-19 and authored this remediation.

Order: #9457 → #9469 → #9467 → #9472 → this PR, together with #9463. This branch includes validated #9472 b9336ce8 through an ordinary merge and retains the published #9463 d72e607b SSH implementation. No unpublished SSH redesign or later local SSH follow-ups are included. #9473 remains closed. Reconcile separate AUR/migration work in #9795 and override handling in #10022 when integrating them.

Four machine repairs use a fixed installed transaction each: T2 defaults, Bluetooth power persistence, FIDO2 authfile ownership and CUPS hardening. Each has literal targets, closed machine arguments, a clean environment, root-side serialization/recheck and no nested sudo. Discovery errors and failed mutations remain retryable. Missing service units and an inactive Bluetooth daemon now complete safely rather than blocking every later migration. AUR helpers pin yay's sudo, flags, credential loop and pacman/configuration under the boundary; an update stops if its package transaction removes that boundary. Kernel migration tests now contain absolute sudo/pacman calls within their fixtures.

At cdaaeeb2, 18 focused suites pass locally and in a dedicated vanilla Arch VM: 149 groups plus 112 CLI checks. Package lifecycle checks use the current published #257 9b9a9c8e. Actual installed Bluetooth/CUPS migrations reproduce the old failure and pass with the fix, both before and after stock packages are installed. The two first-time repairs need two password prompts; replays and a second account with no sudo membership need none. Separate fixture queues using the real migration runner and real sudo verify cold entry, command-scoped authentication, failure/TERM cleanup and pending markers. Native yay 13.0.1 installs a small repository package through the exact AUR helper despite hostile yay configuration, without running configured decoys or leaving a ticket. This is not a claim about an AUR build or the complete historical queue.

Daybreak caught a failed-service state being mistaken for inactive. The fix now checks exact states; a real failed systemd unit reproduces the old error and confirms refusal/recovery. Daybreak reviewed the correction at exact cdaaeeb2, closed the finding and approved the scoped follow-ups. No remaining scoped findings.

Still draft. The SSH dependency/design discussion is unresolved, and later local SSH fixes are not part of this head. The historical 58-prompt migration queue has not been remeasured on a complete legacy upgrade; the earlier 163-prompt Quattro run is an unacceptable UX result. Native T2/initramfs, FIDO2, physical Bluetooth/printer behavior, full-queue cancellation/retry and the coordinated runtime/settings release still need validation. These targeted passes do not establish release readiness or justify restoring reusable authorization.

@AFOliveira
AFOliveira marked this pull request as draft September 1, 2026 09:50
Share the existing security helpers, propagate command-scoped sudo through the direct package helper boundary, and keep the regression focused on the reusable-credential defect.
@AFOliveira
AFOliveira force-pushed the codex/om-sec-19-cold-migration-queue branch from f66c372 to 94a84d7 Compare September 1, 2026 22:22
@AFOliveira

Copy link
Copy Markdown
Member Author

Reworked after the shared-helper review: force-pushed 94a84d7. The PR now excludes the rejected trusted-source-root proposal from closed #9351 and is limited to the real migration sudo-lifetime boundary. The shared libraries, package helper, and no-update wrapper are byte-identical prerequisite copies from #9457/#9470/#9469. Local verification was rerun on the audit baseline and after a clean cherry-pick onto current quattro b71dcad: exploit baseline succeeds/candidate blocks, focused 11/11, mutation detected, CLI 116/116, shell 224/225 with only the base-identical launch-about animation failure.

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

Failure and signal paths bypass final sudo revocation, while the direct package-helper boundary remains untested.

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

Pull request overview

Hardens migrations against reusable sudo authorization across mixed-trust execution.

Changes:

  • Adds command-scoped sudo and shared security helpers.
  • Sanitizes migration startup and sudo handling.
  • Adds isolated migration regressions.
File summaries
File Description
bin/omarchy-migrate Enforces hardened migration execution.
bin/omarchy-pkg-add Supports no-update sudo mode.
bin/omarchy-security-functions Adds shared security primitives.
bin/omarchy-install-security-functions Adds startup sanitization helpers.
default/omarchy/sudo-no-update/sudo Wraps sudo with -N.
test/shell.d/migrate-scope-test.sh Tests migration scope and ordering.
test/shell.d/migrate-wrapper-test.sh Tests the isolated wrapper environment.
Review details
  • Files reviewed: 3/7 changed files
  • Comments generated: 0
  • Review effort level: Balanced

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

@ErikMelton

Copy link
Copy Markdown
Member

One issue I found:

The second revocation runs only after every migration succeeds. With set -e, a failed or interrupted migration exits before line 158. If migration code bypasses the PATH wrapper, for example through /usr/bin/sudo or another PATH-resetting helper, it can leave a reusable timestamp behind after the aborted queue. This preserves part of credential-leak scenario the PR is intended to close.

AFOliveira and others added 26 commits September 18, 2026 16:21
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A failed or interrupted glob enumeration came back as no matches, so a
writable file it never saw went unchecked. The wildcard-free directory an
Include points into is now listed with find, whose status is checked
after the listing, and a directory that exists but cannot be listed in
full is refused.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…he lock

A rollback whose disable failed still restored the previous, possibly
password-enabled, configuration beneath a unit left enabled for the next
boot; a failed disable now keeps the key-only policy like a failed stop.

The older hardening migration could act on a key-only file a concurrent
setup had installed but not yet committed, outside the machine lock. It
now leaves any key-only file to the key-only migration that follows it,
which validates it or disables sshd under that lock.

The Include-listing regression now reports a real, trusted file before
failing, so only the checked listing status can refuse it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The older hardening migration still checked for the key-only file and
then acted outside the machine lock, so a setup for another account could
install and certify between its check and its disable. Its whole job,
hardening or disabling a daemon old setup exposed, now belongs to the
key-only migration's machine phase, which already runs under the lock
setup holds: with no Omarchy file and sshd enabled or running, it installs
the validated key-only policy when a login account has a usable key and
disables sshd otherwise, and it stays pending on an unknown service
state. The older migration is kept as a no-op, and the key-only migration
reaches the machine phase for a daemon that may be exposed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A runtime mask hides a persistent enablement that returns at the next
boot, but masked-runtime counted as not enabled, so the migration
skipped a daemon that would start again unhardened after a reboot. It
now counts as possibly enabled in both the per-user check and the
machine phase, whose disable --now removes the persistent enablement
while leaving the mask.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
systemctl disable ignores a masked unit and still succeeds, so a keyless
daemon that was persistently enabled beneath a runtime mask was reported
disabled while its enablement stayed for the next boot. The machine
phase now lifts the runtime mask for the disable and restores it on every
exit, and after any disable asks systemd whether the unit is still
enabled, staying pending when it is. The test's systemctl stand-in now
ignores a disable of a masked unit the way systemctl does.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Restoring the runtime mask ran after its traps were removed, so a
signal or failure there left the mask off, and a SIGKILL while it was
lifted left a persistently enabled daemon free to start with its old
configuration at the next boot. The traps now stay armed until the mask
is back, retry a failed restore, and hold a further signal during it;
and before lifting the mask, a key-only guard is installed where no
key-only file exists, so a daemon started meanwhile takes no passwords.
The guard is removed once the mask is restored.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The key-only guard written before lifting a runtime mask only protects
when sshd reads it, and this path runs exactly when the configuration is
untrusted or unprovable, so a SIGKILL could still leave a password-capable
daemon free to start. The guard is now a systemd drop-in that fails every
start of sshd.service, loaded before the mask is lifted and removed once
the unit is disabled and masked again. One left by an interrupted run is
cleared by the next successful disable, and by setup before it starts sshd.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Lifting a runtime mask to disable the unit needed a guard for the time
it was lifted, and neither an SSH-configuration guard nor a systemd
drop-in could be proven to hold, while setup could strand one. A
persistently enabled, runtime-masked sshd with no usable key is now
masked persistently on top of the runtime mask and stopped, so it is
never unmasked and its enablement stays inert once a reboot clears the
runtime mask. After either path, systemd must report the unit unable to
start or the migration stays pending. The guard, its traps and setup's
cleanup of it are gone.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <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.
systemctl is-active exits 4 for a unit that does not exist, and the CUPS
repair took that as an inspection error, so on a default install, where
cups-browsed is not installed, the machine phase failed every run and
blocked every later migration. 4 now means inactive, like 3.

The Bluetooth repair asked bluetoothctl even when no bluetoothd runs, as
on a machine without an adapter or with the service off, timed out, and
stayed pending for good. With bluetooth.service inactive or absent the
adapter has been off, and it completes as off, as it did before; a
running daemon that cannot be asked, or an unknown service state, still
stays pending. The test stand-ins now report a missing unit the way
systemctl does.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Pin yay to the no-update sudo wrapper and packaged pacman configuration, clear configured sudo flags, and disable its credential loop. Refuse invalid boundary flags and missing or non-file wrappers before invoking yay.

Consolidates the previously reviewed local AUR fixes from 309d7772, 94f85dd4 and cc7b22f1.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Recheck the command-scoped authorization boundary before entering migrations or later privileged stages. Preserve a cold credential state and leave the remaining work for a fresh invocation.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Map absolute package-manager and sudo calls to harmless stand-ins while leaving the migration-specific commands visible. Both kernel migration suites remain isolated from the host.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants