Skip to content

Validate key-only SSH setup before exposing the service - #14910

Closed
thebytorsnowdog wants to merge 1 commit into
omacom:quattrofrom
thebytorsnowdog:codex/os-audit-ssh
Closed

thebytorsnowdog wants to merge 1 commit into
omacom:quattrofrom
thebytorsnowdog:codex/os-audit-ssh

Conversation

@thebytorsnowdog

Copy link
Copy Markdown
Contributor

SSH setup currently starts the service and opens the firewall before key collection and authentication configuration succeed. Validate every supplied or fetched key and the effective key-only defaults before activating SSH, then open UFW last.

The configuration update stages and validates the hardening drop-in, restoring the previous file on validation failure. Existing authorized keys, unrelated directives and administrator Match rules are preserved. Running servers reload the validated policy; stopped servers start afterward. A later service or firewall failure reports incomplete setup while retaining the validated keys and hardening.

Validation: all eight groups in test/shell.d/setup-security-sshd-test.sh pass, covering cancellation, failed/mixed key downloads, configuration rollback, existing/symlinked drop-ins, repeated execution, and service/firewall failures. Privileged operations use disposable paths and strict stubs; Bash syntax and command-style checks pass.

Before release, verify real SSH login, effective authentication policy, reload failures and firewall ordering in a disposable Omarchy VM. No live SSH daemon or firewall was changed during these tests.

@greptile-apps

greptile-apps Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[High impact] Rewrites SSH server setup and validation logic.

The PR appears safe to merge, with a non-blocking gap in tests for administrator Match rules.

Findings

  1. P2 `Match` rules lack test coverage ▶

Summary

SSH setup now collects and validates all keys before changing access. It checks the effective authentication defaults before starting or reloading SSH, then updates UFW last.

  • SSH setup checks keys and policy before exposing the service.

Acknowledged by thebytorsnowdog: retaining validated keys and policy after later failures is intentional. Administrator Match exceptions remain intentional. Real login, reload, and firewall checks in a disposable VM are deferred until before release.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Collect keys] --> B[Validate every key]
  B --> C[Install OpenSSH and generate missing host keys]
  C --> D[Back up and stage policy]
  D --> E[Check syntax and effective defaults]
  E -->|Failure| F[Restore previous policy and exit]
  E -->|Success| G[Save authorized keys]
  G --> H[Commit policy]
  H --> I[Reload running SSH or start stopped SSH]
  I --> J[Enable SSH]
  J --> K[Update UFW last]
  I -->|Failure| L[Keep saved keys and policy; report incomplete setup]
  J -->|Failure| L
  K -->|Failure| L
Loading

Reviews (1) · Last reviewed commit: "Validate key-only SSH setup before expos..." · Reviewed by Greptile


prepare_case preserve-customization
printf '%s' "$old_key" >"$case_home/.ssh/authorized_keys"
printf '# administrator additions\nPasswordAuthentication yes\nAllowUsers existing\n' >"$config"

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.

P2 Match rules lack test coverage

The new preservation test has no Match block, so it never checks that administrator-specific authentication rules survive setup. A future change could erase those rules without failing these tests. Add a fixture with global authentication settings followed by a Match User block. Check that setup changes the global settings, keeps the block unchanged, and does not duplicate settings on a second run.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@jandrusk

Copy link
Copy Markdown

Good fix for the #8363 class: validate keys + effective key-only policy before starting/enabling sshd and opening the firewall, with rollback of a rejected candidate config.

Overlapping open PRs aiming at the same bug: #14667 (omarchybot), #9463 (OM-SEC-08), #14781 (host-key generation tests on fix/issue-8363). Please pick one lineage (or rebase this on the winner) so we don’t merge two competing sshd setup flows.

Suggested labels: security, area:sshd, P1.

@omarchybot

Copy link
Copy Markdown
Collaborator

Read the diff at 67190dd against current quattro. Claude Opus 5.5 classifies it as a bug fix: on quattro, omarchy setup security sshd enables sshd and opens port 22 before any key is collected, so a cancelled prompt, a rejected key or a failed --gh-keys fetch leaves a password-accepting server reachable, and this change collects and validates the keys, writes and verifies the key-only policy, and only then starts or reloads sshd and opens the firewall.

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 a pass where both models can look at it.

Two things for whoever picks this up:

@ryanrhughes

Copy link
Copy Markdown
Collaborator

Closing this as #14667 merged today with the core ordering fix: sshd is only enabled, started and opened in ufw once a key is authorized and the key-only drop-in validates. It's on quattro and on v4-5-0 for RC3.

Two things this PR handles that #14667 doesn't, and I'd happily take them as a small follow-up on top of quattro:

  • A re-run that fails validation deletes an existing hardening drop-in, so passwords come back on the next restart. Restoring the previous file, like you do here, fixes that.
  • sshd -T runs without -C, so an admin Match block that turns passwords back on still passes the check.

Thanks @thebytorsnowdog. If you open that follow-up, keep it to those two so it's quick to review.

@ryanrhughes ryanrhughes closed this Nov 1, 2026
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.

4 participants