Repository navigation
[Security] Set up SSH for keys only, and open nothing until a key is in place - #8365
chessing234 wants to merge 10 commits into
Conversation
omarchy-setup-security-sshd announces "key-based authentication" and then starts sshd with the distribution defaults. OpenSSH's own default is PasswordAuthentication yes, and Arch's 99-archlinux.conf drop-in only turns KbdInteractiveAuthentication off, so the machine was left taking password logins from whatever network it is attached to. Write an sshd_config.d drop-in that turns both off, and remove it again in omarchy-remove-security-sshd. Enabling the service and opening the firewall also ran before the key was authorized, so a cancelled prompt, an unparseable key or a GitHub user with no keys left a reachable password-only server behind. Install the package first (ssh-keygen validates the key), then configure, authorize, and only then start and open the port.
There was a problem hiding this comment.
Pull request overview
Hardens SSH setup by requiring authorized keys before exposing sshd and disabling password-based authentication.
Changes:
- Adds an OpenSSH key-only configuration drop-in.
- Reorders setup to authorize keys before starting sshd/opening UFW.
- Removes the drop-in during SSH teardown and adds shell tests.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Reviewed changes
Copilot reviewed 1 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
bin/omarchy-setup-security-sshd |
Configures key-only authentication and delays network exposure. |
bin/omarchy-remove-security-sshd |
Removes the managed sshd drop-in. |
test/shell.d/sshd-setup-test.sh |
Tests configuration, ordering, and invalid-key behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
`systemctl enable --now` does not touch an already-active unit, and sshd parses its configuration once at startup. On a machine an earlier run had already set up, the command wrote the drop-in, printed that password authentication was off, opened the port and reported success while the running daemon went on accepting passwords until the next reboot -- the exact state this branch exists to prevent, on every machine that had run the command before. Verified on an Omarchy worker against a live sshd: after a successful run without this, `ssh -v` still gets `Authentications that can continue: publickey,password`; with it, `publickey`. Reload re-execs sshd in place rather than restarting it, so a user running this over their existing SSH session keeps it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
errexit is disabled inside a function invoked on the left of `||`, and every caller of `authorize_key` invokes it that way. So a `~/.ssh` that could not be written -- root-owned, read-only, out of space -- let `mkdir`, `chmod` and the append fail while the closing `echo` returned zero. The function reported success, and the branch's whole contract rests on that return value: the command then started sshd, opened port 22, and printed "your key is authorized" with no `authorized_keys` on disk at all. That was survivable before this branch, because the server it left behind still took passwords. With them off it is a listening machine its owner cannot reach. Reproduced on an Omarchy worker with a root-owned `~/.ssh`: the command exited 0 and opened the port; it now stops at the failing `chmod`. The GitHub path is covered by the same change -- `added` no longer counts a key that was never stored, so a fetch whose keys all fail to write exits through the existing zero-key check. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-Authored-By: Codex XHigh <noreply@openai.com>
|
Reviewed, and the two things this fixes are real and correctly diagnosed. I verified the precedence claim on a disposable Omarchy worker (openssh 10.5p1-1, systemd 261.2-1) rather than taking it from the PKGBUILD: Two defects, both pushed to your branch. Both were found against a live sshd on the worker, not read off the diff.
Two things I did not change, for you or the maintainer to decide. The drop-in is written before the key is authorized, so a cancelled run leaves it behind. Your comment's claim is true as written — nothing is listening and no port is open — but the config file stays. On a machine that already had sshd running with password logins and no key (set up outside Omarchy), cancelling the prompt leaves Nothing checks that the drop-in actually took. The 50 prefix is the right call and it wins on a stock system, but a user's own lower-numbered drop-in setting Worth knowing: #7986 (opened two days before this) is a competing fix for the same issue, and the two are complementary rather than duplicates. It already has the reload, orders the drop-in write after the key, has the This closes #8363. It does not close #8248 — I confirmed on the worker that after this command runs sshd still binds Tests, all on a disposable worker and never locally: your test file (now 11 assertions, all passing), Second opinion from codex at xhigh reasoning. The Waiting on the maintainer for the choice between this and #7986, and on you for the two open items above if you want them in this branch. |
Two gaps a maintainer review found on a live worker, both now closed: Writing the key-only drop-in still ran before a key was authorized, so a cancelled prompt left PasswordAuthentication no on disk, unapplied, until the machine's next reboot silently turned it on. Move the write to after the key lands, alongside starting sshd -- both now wait on the thing that makes them safe to do. Nothing confirmed the drop-in actually won. Our own file is numbered to beat the one Arch ships, but a user's own lower-numbered drop-in can still set PasswordAuthentication yes and the command opened the firewall and reported success anyway. Ask sshd -T what it actually resolved to before opening the port, and refuse if it disagrees.
itz4blitz
left a comment
There was a problem hiding this comment.
Reviewed this end to end against issue #8363. The ordering is the strong part and I want to call it out: package → key authorized (fail-closed prompts) → drop-in written → enable+reload → verify with sshd -T → only then open the firewall. Gating reachability on what the daemon actually resolved, rather than on the file having been written, is exactly right — and the test that keeps the port closed when sshd -T doesn't confirm key-only proves the gate bites.
A few things I checked and can confirm:
- The Arch comment is accurate:
99-archlinux.confonly setsKbdInteractiveAuthentication off, soPasswordAuthentication yesfrom upstream defaults survives a bare install. The drop-in is the correct mechanism (sshd_config.disIncluded first on Arch, so50-beats99-). - The
authorize_key|| return 1additions are correct bash: errexit is suppressed inside a function invoked to the left of||, so each step does have to refuse for itself. The unwritable-~/.sshtest covers the case that would otherwise silently "authorize" a key that never landed. confirm_key_onlyfails closed on every path I can construct: malformed config makessshd -Terror, grep finds nothing, exit 1, port stays closed. A lower-numbered user drop-in overriding ours is also caught because the check asks the daemon, not the filesystem.systemctl reloadafterenable --nowcorrectly handles "sshd was already running from a previous setup" — without it the daemon would keep its pre-drop-in config until reboot. The test asserts reload happens after the config write.
Two non-blocking nits:
- On a machine where
sshd.servicefailed to start (missing host keys on a fresh container, say),systemctl reloaderrors andset -eexits before the confirm — which is the right end state (port closed), but the user sees the raw systemctl error rather than a diagnosis. A|| { echo hint; exit 1; }would save a support round-trip. confirm_key_onlymatchespasswordauthentication noexactly.sshd -Tprints lowercase on every OpenSSH I have, so this is fine today; if it ever changes, the failure mode is fail-closed (port stays shut), not open, which is the right way for it to break.
This supersedes #7986 in coverage — that one only turned password auth off, this one also fixes the "port open before any key exists" half of #8363.
|
the two ordering items are in. leaving the reload-error hint and the sshd -T case match. |
OpenSSH 10.5 prints `PasswordAuthentication no` from `sshd -T`, not the lowercase `passwordauthentication no` the check grepped for, so the confirmation never matched: on a stock Omarchy machine the command authorized the key, wrote the drop-in, reloaded sshd into a correct key-only state, and then refused with "a drop-in with a lower number still allows password authentication" and left the firewall closed. Verified against openssh 10.5p1-1 on an Omarchy worker, where `sshd -T` now reports `PasswordAuthentication no` and `ssh -v` offers publickey alone, and the command exits 0. The test stub printed the lowercase form, which is why the suite passed against a command that could not succeed on any machine it ships to. It now prints what OpenSSH prints, and reverting the case-insensitive match fails the suite on its first assertion. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The drop-in turns both PasswordAuthentication and KbdInteractiveAuthentication off, but the confirmation only read the first, so a user's own lower-numbered drop-in setting `KbdInteractiveAuthentication yes` passed the gate. With Arch's `UsePAM yes` that is a password prompt on the network however PasswordAuthentication resolved. Measured on an Omarchy worker with openssh 10.5p1-1: the command reported "Perfect!", opened port 22, and `ssh -v` offered `publickey,keyboard-interactive`. It now refuses and leaves the port closed, and the failure's Check hint names both keywords. The stub's sshd -T output is parameterized so the two overrides can be simulated. Without those assertions a confirmation that read no value at all -- `[[ -n $resolved ]]` -- passed the whole suite, which is how a check that matched nothing shipped in the first place. Co-Authored-By: Codex XHigh <noreply@openai.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Re-reviewed the two commits since my last pass. Both of the items I left open are in, and I confirmed each on a disposable Omarchy worker (openssh 10.5p1-1) rather than off the diff: the drop-in is now written after the key is authorized, so a cancelled prompt leaves nothing on disk for a later reboot to apply; and The new gate did not work, though, and it broke the command outright on any current machine. Two defects, both pushed.
This is the case match you decided to leave, and I want to be plain about why it looked safe: the review above says " The gate confirmed one of the two keywords the drop-in writes. It read Three things I did not change. A When the gate refuses, sshd has already been started. It has to be:
Two test gaps worth knowing about, neither of which changes behaviour: Worth knowing for whoever picks between this and #7986: that one carries the identical casing bug — Tests, all on a disposable worker and never locally: this file (now 15 assertions, passing), Second opinion from codex at xhigh reasoning. The keyboard-interactive hole is its find — I had not reasoned about it, and I reproduced it on the worker before fixing it. The mutation gap in the stub and the Waiting on the maintainer for the choice against #7986, the |
quattro now disables password auth after authorize, but still opens the firewall before a key exists. Keep the package → key → drop-in → start → confirm → firewall order from this branch, and clean the legacy 10-omarchy-hardening.conf on remove.
|
rebased onto quattro; kept the key-before-firewall order. also cleans the legacy 10-omarchy-hardening.conf on remove. |
|
Re-reviewed at What is still yours, and worth keeping. Upstream's But the merge resolved 1. A remote lockout, through the drop-in filename. 2. 3. Also in Tests, all on a disposable worker VM, never on the machine doing the review. A shape that would fix all of it. Every point above disappears if the branch stops reimplementing the hardening step and keeps only what upstream does not have: leave upstream's Reviewed by Claude Opus 5 in Claude Code, with an independent second opinion from Codex at xhigh reasoning pinned to Waiting on you for the reshape, and on the maintainer for whether to take the reduced version or close this in favour of what upstream already shipped. |
The previous branch reimplemented the drop-in and raced the v4.0.2 hardening. Leave disable_password_auth alone and only change call order so a cancelled prompt cannot enable sshd or open port 22.
|
folded into #12099 — same sshd setup script, one review is enough. |
Fold key-before-listen ordering from omacom#8365 onto the localhost bind from omacom#11513 so a rejected key never enables sshd.
Fixes #8363.
Two things, both in what the command leaves behind.
Password authentication was never turned off. Nothing in the repo writes
sshd_config, OpenSSH's own default isPasswordAuthentication yes, and Arch's/etc/ssh/sshd_config.d/99-archlinux.confonly setsKbdInteractiveAuthentication no/UsePAM yes/PrintMotd no. So a command that announces "key-based authentication" was starting a server that takes password logins from whatever network the machine is on. This writes ansshd_config.ddrop-in that turns both off — Arch prependsInclude /etc/ssh/sshd_config.d/*.conftosshd_configin its PKGBUILD, so a drop-in is read — andomarchy-remove-security-sshdtakes it away again.The service and the firewall came first.
setup_sshdandopen_firewallran before any key was authorized, so a cancelledgumprompt, a keyssh-keygen -lfrejects, or a--gh-keysuser with no keys all left a reachable password-only sshd behind with nothing to log in with. The package still has to be installed first becausessh-keygenvalidates the key and ships with it, so the order is now: install → configure key-only → authorize → start → open the port.I picked
50-omarchy-key-only.conffor the name: OpenSSH takes the first value it obtains, so a user's own lower-numbered drop-in still wins, and nothing in the shipped set claimsPasswordAuthenticationahead of it.Verification
New
test/shell.d/sshd-setup-test.shstubssudo,ufw,ssh-keygenandomarchy-pkg-addand runs the real command:On the unfixed script the first assertion fails — no drop-in is written at all.
What I could not run here: this is an Arch/OpenSSH path and I have no Arch machine, so the drop-in is verified through the stubs and against the Arch
opensshPKGBUILD (theIncludeline and the contents of99-archlinux.conf), not against a livesshd -T. Worth a maintainer confirmingsudo sshd -T | grep -i passwordauthenticationreportsnoafter the change.