Skip to content

Start sshd and open its port only once a key is authorized - #14667

Merged
ryanrhughes merged 3 commits into
quattrofrom
fix/issue-8363
Nov 1, 2026
Merged

ryanrhughes merged 3 commits into
quattrofrom
fix/issue-8363

Conversation

@omarchybot

@omarchybot omarchybot commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

omarchy setup security sshd enabled and started sshd and opened port 22 in ufw before it asked for a key. Every way the key step can fail comes after that: cancelling the gum prompt, a pasted key ssh-keygen rejects, or --gh-keys for a user with no public keys. Each one exited and left a reachable server accepting passwords with no key authorized, because the hardening drop-in is only written once a key exists.

The command now installs openssh, authorizes the key, writes and verifies the hardening drop-in, and only then enables sshd and opens the firewall. A failure anywhere before that leaves nothing listening and nothing opened. Host keys are generated with ssh-keygen -A right after the install, because sshd -t and sshd -T refuse to run without them, and on a fresh machine they would otherwise first appear when the server starts. A server that is already running is reloaded rather than restarted (systemctl reload-or-restart), so an administrator already connected keeps their session.

Machines that already ran the old command are covered by migrations/1788124236.sh, which hardens them or disables sshd when no usable key is authorized. The password half of the issue already shipped in v4.0.2.

The test's systemctl and ufw stubs now record any call made while the hardening drop-in is absent, and new cases for a rejected key and a cancelled prompt assert that nothing is started or opened. The sshd stub refuses -t and -T until ssh-keygen -A has run, so generating host keys too late fails the test (the same check as #14781).

Fixes #8363

The setup command enabled sshd and opened port 22 before asking for a key, so a cancelled prompt, a rejected key or a GitHub user with no keys left a reachable server accepting passwords. It now installs openssh and generates host keys, authorizes the key, writes and verifies the hardening drop-in, and only then enables sshd and opens the firewall. Host keys are generated up front because sshd -t refuses to validate without them, and on a fresh machine they would otherwise first appear when the server starts.

Co-Authored-By: Codex Medium <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with the previous test gap fixed and no new actionable issues found.

Summary

SSH setup now authorizes a key and checks password restrictions before starting sshd and opening the firewall.

  • SSH setup checks the key and password rules before exposing the server.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Install OpenSSH] --> B[Generate host keys]
  B --> C[Authorize a key]
  C --> D[Write and check password restrictions]
  D --> E[Enable and start or reload sshd]
  E --> F[Open firewall]
  C -->|Failure or cancellation| G[Exit without starting or opening]
  D -->|Check fails| G
Loading

Reviews (2) · Last reviewed commit: "Make the cancelled sshd test prove it re..." · Reviewed by Greptile

@jandrusk

Copy link
Copy Markdown

Heads-up on overlap: #14910 ("Validate key-only SSH setup before exposing the service") and the older #9463 both target #8363 with the same "nothing listens until a key is authorized" ordering, and #14781 is stacked on this branch for the host-key ordering test. It would help reviewers to agree on one of #14667/#14910 and fold #14781 into it. Greptile's point that the test checks ssh-keygen -A ran but not that it ran before sshd -t also seems worth closing in the same pass.

@omarchybot

Copy link
Copy Markdown
Collaborator Author

Read the diff at 4b0aedf against current quattro (it still merges cleanly, including over the i18n change to the same script in #15326). Claude Opus 5.5 classifies it as a bug fix: on the base branch, omarchy setup security sshd enables sshd and opens port 22 before a key is authorized, so a cancelled prompt or a rejected key leaves a password-accepting server reachable, and this change moves both steps after the hardening drop-in is written and verified.

The classification is not settled yet: the second model (Codex Medium) was not asked, because today's review budget is spent. So this pull request has no class label, and nothing was run on a worker; the reproduction and test suite wait for the next pass, when both models can look at it.

Related, for whoever picks between them: #14910 makes the same "nothing listens until a key is authorized" change with a larger rewrite (staged config with rollback, all-or-nothing GitHub key batches), and draft #9463 covers it as part of a much wider security change. #14781 is stacked on this branch and makes the test check that ssh-keygen -A runs before sshd -t and sshd -T, the gap Greptile pointed out here; that is a real gap in this test and worth folding in.

Waiting on the next review pass.

ryanrhughes and others added 2 commits November 1, 2026 01:38
sshd -t and sshd -T exit without host keys, so on a fresh install setup only works if ssh-keygen -A runs first. The test only checked that ssh-keygen ran at all. The sshd stub now refuses to run until it has.

Co-authored-by: Donald Dunsmore <215750096+thebytorsnowdog@users.noreply.github.com>
On quattro the prompt labels come from omarchy-i18n, and the test only found it through an installed Omarchy. Without one, setup exited before gum and the test still passed. Put the checkout's bin on PATH and check that gum was called.

Co-Authored-By: Codex gpt-6.1-sol <noreply@openai.com>
@ryanrhughes
ryanrhughes merged commit 0f2085b into quattro Nov 1, 2026
3 checks passed
ryanrhughes added a commit that referenced this pull request Nov 1, 2026
* Start sshd and open its port only once a key is authorized

The setup command enabled sshd and opened port 22 before asking for a key, so a cancelled prompt, a rejected key or a GitHub user with no keys left a reachable server accepting passwords. It now installs openssh and generates host keys, authorizes the key, writes and verifies the hardening drop-in, and only then enables sshd and opens the firewall. Host keys are generated up front because sshd -t refuses to validate without them, and on a fresh machine they would otherwise first appear when the server starts.

Co-Authored-By: Codex Medium <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Fail the sshd test when host keys come after validation

sshd -t and sshd -T exit without host keys, so on a fresh install setup only works if ssh-keygen -A runs first. The test only checked that ssh-keygen ran at all. The sshd stub now refuses to run until it has.

Co-authored-by: Donald Dunsmore <215750096+thebytorsnowdog@users.noreply.github.com>

* Make the cancelled sshd test prove it reached the prompt

On quattro the prompt labels come from omarchy-i18n, and the test only found it through an installed Omarchy. Without one, setup exited before gum and the test still passed. Put the checkout's bin on PATH and check that gum was called.

Co-Authored-By: Codex gpt-6.1-sol <noreply@openai.com>

---------

Co-authored-by: Omarchybot <317366263+omarchybot@users.noreply.github.com>
Co-authored-by: Codex Medium <noreply@openai.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Ryan Hughes <ryan@heyoodle.com>
Co-authored-by: Donald Dunsmore <215750096+thebytorsnowdog@users.noreply.github.com>
(cherry picked from commit 0f2085b)
@emirb emirb added this to the 4.5 milestone Nov 5, 2026
omarchybot added a commit to mark-groves/omarchy that referenced this pull request Nov 16, 2026
omacom#14667 reordered setup so sshd starts and ufw opens only after passwords are off, and replaced the test's reload assertions with assert_nothing_exposed. The loose-home case now uses it too, so a refused writable home is shown to start nothing and open nothing, not merely to skip a reload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
omarchybot added a commit to z23/omarchy-mac that referenced this pull request Nov 17, 2026
quattro's omacom#14667 rewrote the sshd setup test with its own gum stub for a cancelled prompt, which conflicted with this branch's stub. The test file is taken from quattro as is, dropping this branch's pasted-key case: its gum stub supplied the 400-character limit the case tested, and it grepped for the flag the fix adds, both against AGENTS.md's test rules. The fix itself, --char-limit=0 on the public-key prompt, merges cleanly onto quattro's reordered script.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

[Security] omarchy setup security sshd leaves password authentication on, and opens the port before any key is authorized

4 participants