Repository navigation
[codex] OM-SEC-08: Publish SSH only after proving key-only access - #9463
AFOliveira wants to merge 43 commits into
Conversation
…dex/portfolio-9457-20260907
…rtfolio-9463-20260907 # Conflicts: # manual/48-security.md
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
SSH setup cannot recover from a missing OpenSSH unit, and migration can disable SSH because of irrelevant non-login accounts.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Strengthens SSH publication and temporary sudo lifecycle security with fail-closed validation and rollback.
Changes:
- Validates key-only SSH access before exposing the daemon.
- Adds bounded, serialized passwordless-sudo grants and cleanup.
- Expands migration, rollback, and lifecycle coverage.
File summaries
| File | Description |
|---|---|
AGENTS.md |
Documents privileged shebang exception. |
bin/omarchy-migrate-sshd-key-only |
Adds machine-wide SSH migration. |
bin/omarchy-security-functions |
Adds shared security helpers. |
bin/omarchy-setup-security-sshd |
Reorders and validates SSH setup. |
bin/omarchy-sudo-passwordless |
Implements bounded sudo grants. |
default/libalpm/hooks/05-omarchy-passwordless-revoke.hook |
Revokes grants before package changes. |
docs/passwordless-sudo.md |
Documents grant lifecycle. |
etc/tmpfiles.d/omarchy-nopasswd-sudo.conf |
Defines boot-time cleanup. |
manual/48-security.md |
Updates user guidance. |
migrations/1788163635.sh |
Cleans legacy sudo grants. |
migrations/1788163637.sh |
Dispatches SSH migration. |
test/shell.d/nopasswd-sudo-expiry-test.sh |
Tests expiry and packaging behavior. |
test/shell.d/passwordless-grant-lifecycle-test.sh |
Tests grant lifecycle failures. |
test/shell.d/setup-security-sshd-test.sh |
Tests SSH setup and rollback. |
test/shell.d/sshd-key-only-migration-test.sh |
Tests SSH migration safety. |
Review details
- Files reviewed: 11/15 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.
|
|
||
| ## Package ownership | ||
|
|
||
| The packaging companion must put the publication/expiry command, `omarchy-security-functions` `omarchy-nopasswd-sudo.conf` and the pre-transaction revocation hook in the settings package together. Removing the desktop runtime alone must leave a working expiry command behind. Stable and development package pairs must transfer ownership in one transaction without duplicate files. |
|
[P1] Earlier per-user migration can disable an already-converted machine [P1] Restricted key records are incorrectly considered usable [P1] Irrelevant passwd entries can shut down SSH [P2] Setup cannot recover when the OpenSSH unit is absent |
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>
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>
Replace the stale copy of the omacom#9457 command, library, hook, migration and tests that this branch carried with that PR's current head. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…accounts Four review findings and one more from the same class: The older quattro migration treated its own 10-omarchy-hardening.conf as the machine-wide completion state. Setup and the key-only migration now write 00-omarchy-key-only.conf and remove the old file, so a second account with that migration still pending saw neither and disabled sshd when it had no key. Recognise the key-only file as completion too. ssh-keygen -lf ignores the options field, so cert-authority, command=, from=, an expired expiry-time=, restrict and no-pty lines all counted as a usable login. A shared helper now accepts only lines with no options or with flag options that keep an interactive public-key login, and both the migration's account check and setup's key collection use it. Every passwd entry had its name and home validated before the UID and login-shell filter, so a system entry such as svc.name with nologin shut SSH down. Filter first; only login accounts reach the strict checks. Setup recorded the service state before installing openssh, and a missing unit's not-found answer aborted it. Install first, and treat not-found as not enabled in both commands. The key-only migration always prompted for sudo, so a later account without sudo rights stayed pending and blocked its queue, and the root phase re-validated machines it never converted. Exit without privileges once the legacy file is gone. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A key that parses is not proof of a login. A later drop-in can remove its algorithm from PubkeyAcceptedAlgorithms, an RSA key can fall under RequiredRSASize, and RevokedKeys can list it; setup would then publish, and the migration preserve, a key-only server nobody can log into. Both now check keys against the account's effective sshd -T -C policy, and the key-type list gains the ML-DSA hybrid type OpenSSH 10 accepts. The older migration accepted a symlinked key-only config as a completed conversion. Only the regular file Omarchy writes counts now. Setup read an unanswered UFW query as "no rule", so rollback could delete a rule the administrator already had; it now refuses to continue. The firewall rollback is armed before the rule is added, and a backup taken just before a signal is removed, so an interrupted setup leaves neither behind. The key-only migration installed its cleanup traps after the entry sudo -k; a failure there exited without revoking again. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Setup installs the key-only file before validating and publishing it, so a kill or power loss in between left a file both migrations took as a completed conversion. Setup and the conversion helper now record a root-owned marker only after success; the older migration requires it, and the key-only migration validates any uncertified key-only file. An account that sshd refuses outright or forces into a command proves no login; both commands now require RefuseConnection no and ForceCommand none in its effective policy. RevokedKeys may be a text list of public keys, which ssh-keygen -Q cannot read, so every key was treated as revoked. Text lists are now matched by key type and data; KRLs still go through ssh-keygen -Q. A second signal during setup rollback or the migration's exit revocation could abort them; both now ignore further signals until they finish. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…tion lists Setup wrote its completion marker before marking itself complete, and rollback never removed it, so an interruption in between restored the previous configuration while still certifying the conversion. Setup now removes any earlier certificate before changing the configuration and rollback removes it first on every incomplete exit. sshd refuses every key when a text RevokedKeys file has a line that is not a bare public key, but such lines were skipped as non-matches. Any line that is not a key now counts as revoking the key under test. Cleanup ignored further signals, and ignored dispositions are inherited across exec, so a hung command it ran could no longer be interrupted. Cleanup handles them instead: they still cannot abort it, and the commands it runs keep their default dispositions. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A plain-text RevokedKeys line was accepted when its data merely looked like base64, although sshd refuses the whole list when a key does not parse, and a valid certificate line was refused because only login key types were recognised. Each line must now start with a type from ssh -Q key and parse with ssh-keygen, as sshd requires. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ists A signal sent only to setup, as kill of a backgrounded setup or timeout --foreground deliver it, waited behind a hung cleanup command, so the remaining rollback and the final revocation never ran. Cleanup now runs each command as a waited-on background child and forwards the signal to it, then continues; the migration's exit revocation does the same. A revocation list with CRLF endings left the carriage return on the key data, so a listed key was not matched although sshd revokes it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A signal forwarded to the final sudo -k could kill it before it revoked, one arriving before a cleanup child's PID was recorded was lost, and the migration launched its exit revocation before replacing the signal trap that aborts it. Authorized-key restoration also ran in the foreground, where a signal sent only to setup could not reach it. Once cleanup starts, signals are held until a child is running and then forwarded to it, and key restoration runs through the same helper. The final revocation is never forwarded a signal: it runs under timeout in its own process group, is retried when it fails, and is reported when it never succeeds. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ically Under timeout, the final sudo -k had timeout as its parent, and with timestamp_type=ppid or no terminal sudo keys the cached authorization by parent, so it revoked another record and still succeeded. It is again a direct child of the shell, bounded by a sibling watchdog. The EXIT trap now records the status and marks cleanup active in one assignment, so a signal between the two can no longer abandon cleanup. Tests kill only the processes they started. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A signal to the whole process group killed the watchdog wrapper and left a hung revocation unbounded, and a watchdog that outlived its revoker could later kill a process that reused the PID. The revoker's stdout is now a pipe only it holds, so its exit arrives as end-of-file and read's own timeout bounds it inside the shell. At the deadline it is killed only while /proc still shows it as the shell's live child. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
… kill If the pipe could not be allocated, the unset descriptor aborted cleanup before any revocation, and the deadline kill depended on reading /proc, which hidepid denies, then fell into an unbounded wait. Without the pipe the revocation now runs directly. At the deadline the still-open pipe shows its only holder is alive, so it is killed without a /proc lookup, and one that does not exit within a short grace is abandoned rather than waited on. Tests kill only processes that are still alive. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
An open pipe did not prove the recorded PID was still the revoker: once it exited and was reaped, a leftover descendant kept the pipe open and the deadline KILL went to a possibly reused PID. And running out of descriptors fell back to an unbounded revocation. The revoker now starts under job control in its own process group in the same session, still a direct child of the shell. The wait polls and kills that group, whose ID stays reserved while any member lives, pausing on a descriptor reserved before the first privileged call; if it cannot be reserved, setup refuses and the migration stays pending. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Bash reaps background children on its own, so the revoker's PID and group ID could be free, and reused, between the liveness probe and the deadline KILL; and the wait helpers probed a PID after wait had consumed its status, which loops forever if that PID was reused. The revoker now runs as sudo -k | keeper under job control. The keeper shares its group, reports it, detects the revoker's exit by probing its PID (which the group keeps reserved), and waits for the shell's release on a second reserved descriptor, so the group ID is never released before the shell is done with it. The job status is the revoker's. Waits repeat only when a trapped signal interrupted them. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A keeper that stalled before reporting could survive into a retry and consume that attempt's release on the shared channel, leaving the shell waiting forever, and cleanup still forwarded TERM to a recorded PID that Bash may already have reaped and the kernel reused. Every cleanup command and the final revocation now runs as a foreground job under job control, the command followed by a keeper in its process group. The command stays a direct child of the shell and its status comes from PIPESTATUS. The keeper polls the command's PID, which its group keeps reserved, and at its deadline kills its own group; it ignores job-control signals, so it bounds the step even if setup dies. Setup and the migration never signal a PID themselves, hold signals during cleanup, and check that bounded jobs work before anything privileged. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Setup made about twenty separate sudo calls on a cached timestamp and then had to guarantee a final sudo -k under every signal, hang and PID-reuse case, which Bash cannot supervise soundly; killing sudo does not even stop the root command beneath its pty monitor. The migration had the same revocation machinery. Setup now imports the keys into the account's authorized_keys as the user, under a lock, and restores the previous file until that commits; committed keys stay whatever happens next. It then makes one call, sudo -N to omarchy-migrate-sshd-key-only --setup UID -- KEYS. The root phase re-resolves the account, re-validates every key, reads authorized_keys as the account, checks every directory it writes under, and runs the install, proof, publication and rollback in one process with an EXIT trap. A marker carrying this run's token is the commit point. It shares the migration's lock, now non-blocking. sudo -N never creates or refreshes a timestamp, so neither setup nor the migration has anything to revoke, and all revocation, watchdog and bounded-job code is gone. There is deliberately no hard deadline. Drop-in precedence is now compared in byte order, as sshd reads it, whatever the caller's locale. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…come The root phase proved the key-only policy from configuration any account could still write, so a writable sshd_config or included file could turn passwords back on between the proof and the reload. The main file and every file it includes, recursively, must now be regular files only root can write, under trusted directories, as must the RevokedKeys list setup consults; setup refuses otherwise, and the migration disables sshd rather than trust such a configuration. After the commit is attempted, only a lookup that reports the marker absent means the commit did not happen; any other lookup error is now an unknown outcome that keeps everything and is reported, instead of rolling back beneath a committed marker. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
sshd reads double-quoted and escaped Include arguments and the "Include=path" form. The trust check split arguments on whitespace, so a quoted path matched nothing and the file it named, even a world-writable one adding an AuthorizedKeysCommand, went unchecked; the precedence check likewise missed an "Include=" read before the drop-in glob. Both now end the keyword at whitespace or "=", and an Include whose arguments are quoted, escaped, commented or start with "~" is refused outright. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
An Include pattern that matched nothing was accepted without checking its directory, so a world-writable, empty include directory could gain a file between the check and the reload. The directory a pattern points into, or its nearest existing ancestor, must now be trusted whether or not anything matches yet, and a wildcard in the directory part is refused. Reads through process substitution hid their producers' failures, so a failed or partial Include parse, drop-in listing, allow/deny list or stat could pass. Each is now captured synchronously and its status checked. 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>
…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>
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>
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>
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>
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>
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>
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>
Bring in omacom#9463 at its current local head, replacing this branch's older copy of that PR. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
hey, the sshd key-before-start / key-only publish part overlaps #12099. if that was the main goal here, mind closing this as a duplicate (or trimming to whatever is still unique)? |
|
Closing this draft. The OM-SEC-08 ordering fix landed through #14667 today: sshd is only enabled, started and opened in ufw after a key is authorized and the key-only policy validates. It's on quattro and on The passwordless sudo half doesn't apply anymore since #17000 moved us back to ordinary sudo with a ten-minute timestamp. The open question this raised is still real: machines where someone cancelled the old setup still have a password-auth sshd listening, and migration 1788124236 does nothing once the drop-in exists. We're deciding separately whether to close that with a migration, since it would also turn sshd off for people who chose password-only on purpose. Thanks @AFOliveira, the account-admission checks here are what I'd start from if we do. |
SSH setup now authorizes a valid key and proves effective key-only policy before starting/enabling the service or opening the firewall. Partial failure rolls back newly created state while preserving an existing daemon and administrator configuration. Finding: OM-SEC-08, part of the coordinated Omarchy security disclosure.
The fixed root migration validates machine-wide login accounts instead of treating the invoking user's missing key as evidence that nobody can log in. At least one account must have safe key files and be admitted by its effective user/group access controls. Setup proves admission for the specific account whose key it authorizes. Native policy checks cover global and matched authentication directives; service queries distinguish inactive/disabled from errors. Account names ending in
$are supported.Unknown administrator files remain untouched. An affected Omarchy-managed legacy service is disabled with recovery guidance when safe access cannot be proven. Exact AllowUsers/DenyUsers/AllowGroups/DenyGroups entries are supported; complex wildcard or host-qualified rules fail closed rather than being guessed. This is a deliberate compatibility limit, and custom PAM/account-expiry policy still needs administrator validation.
Order: #9457 → this PR; #9474 integrates this corrected implementation after #9467. Both branches retain the same key, policy, rollback and cold-authorization boundary.
At
1fc0511ca0637f6caa908deee61f7312eb759ddb, independent Daybreak review accepted the service-state and account-admission corrections. Focused setup/migration fixtures, 112 CLI checks, syntax and diff checks pass. A disposable 4.0.2 VM with the installed candidate, an already keyed account and a locked/keyless second account passed native key-only checks, one-prompt cold migration, replay, active/enabled service retention, and actual fixture-key SSH login. The fixture used the safe final policy; it did not reproduce a vulnerable baseline. Temporary files, account and policy were restored afterward.Keep draft until the full interactive setup, password-prompt cancellation, custom administrator policies and delivered package layout receive integration validation. The VM results establish the tested policy/replay path, not every possible SSH/PAM configuration.