Skip to content

Add hardened key-only SSH admin access over the mesh (keepadmin, mesh-only)#58

Merged
kwsantiago merged 2 commits into
mainfrom
mesh-admin-ssh
Jul 5, 2026
Merged

Add hardened key-only SSH admin access over the mesh (keepadmin, mesh-only)#58
kwsantiago merged 2 commits into
mainfrom
mesh-admin-ssh

Conversation

@kwsantiago

@kwsantiago kwsantiago commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Second onboarding increment (bead keep-node-xp4): give a HARDENED keepnode a secure way in, so the insecure debug profile (known root password, password SSH, open signups) is no longer the only access path. Retires that debug profile for the DECLARATIVE-deploy path; the generic-ISO first-boot key enrollment is a tracked follow-up (keep-node-4r4).

Design is research-backed (cited): the perimeter is the mesh, not the daemon. SSH is opened ONLY on the nvpn mesh interface (like the rsync replica receiver), so a hostile LAN never reaches sshd -- only rostered, WireGuard-authenticated peers. This mirrors how comparable appliances work (Start9 gates SSH behind Tor/web-console, Umbrel steers remote access to a WireGuard mesh).

  • nixos/admin-access.nix (new keepNode.adminAccess): key-only OpenSSH, a dedicated keepadmin (wheel + passwordless sudo, since a key-only account has no password to type -- still auditable, not root-by-default), PermitRootLogin=no (root is not a network username), KbdInteractiveAuthentication=false, AllowUsers=[keepadmin], MaxAuthTries=3, forwarding off, ed25519 host key only. Deliberately does NOT pin Ciphers/Kex/MACs -- the modern OpenSSH defaults are the curated strong set, and pinning freezes crypto policy / blocks the PQ-KEX upgrade path. No fail2ban (it does nothing for key-only auth; sshd's built-in PerSourcePenalties covers it). keepNode.adminAuthorizedKeys takes inline operator pubkeys (public keys, no secret manager). An anti-lockout assertion refuses to build with SSH password-off + zero keys (permanent remote lockout otherwise). openFirewall=false so OpenSSH's default global port-22 opening can't defeat the mesh-only rule.
  • nixos/keep-node.nix: import the module.
  • flake.nix: an adminKeyFixture (ed25519 operator keypair) + the mesh-admin-ssh check.
  • tests/mesh-admin-ssh.nix: two nodes onboarded onto the mesh; the "operator" (a mesh peer) keys into keepadmin OVER THE MESH with passwordless sudo, the SAME SSH is REFUSED on the LAN/underlay address (proving mesh-only), and sshd's effective config is the hardened posture. The negative test caught a real bug during development: OpenSSH's openFirewall default would have silently exposed SSH to the LAN.

Summary by CodeRabbit

  • New Features

    • Added optional admin SSH access for nodes, with a dedicated keepadmin account and mesh-only port 22 access.
    • Introduced a new end-to-end test covering admin SSH login over the mesh.
  • Bug Fixes

    • Hardened SSH access by disabling password and keyboard-interactive logins, blocking root login, and requiring authorized keys.
    • Restricted SSH exposure to the configured mesh interface, preventing access from the LAN/underlay.
  • Tests

    • Added coverage for successful mesh SSH access and failure over non-mesh addresses.

@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@kwsantiago, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 34 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cca44ed7-95a0-4627-b53f-7b5568a91d33

📥 Commits

Reviewing files that changed from the base of the PR and between c4dfc0e and 3948b27.

📒 Files selected for processing (2)
  • nixos/admin-access.nix
  • tests/mesh-admin-ssh.nix

Walkthrough

This PR adds a new NixOS module (admin-access.nix) providing hardened, key-only SSH admin access restricted to a mesh network interface, wires it into keep-node.nix, and adds a corresponding flake check with a VM test validating mesh-scoped access and LAN refusal.

Changes

Mesh Admin SSH Access

Layer / File(s) Summary
Module options and safety assertion
nixos/admin-access.nix
Defines keepNode.adminAccess.enable, authorizedKeys, and meshInterface options, plus an assertion requiring non-empty authorizedKeys to prevent lockout.
Admin user, hardened sshd, and firewall scoping
nixos/admin-access.nix
Creates the keepadmin user with passwordless sudo, hardens services.openssh (disables password/root login, restricts to keepadmin, ed25519 host keys only), and opens TCP/22 only on the mesh interface.
Module wiring
nixos/keep-node.nix
Adds ./admin-access.nix to the appliance's module imports.
Flake fixture, check, and VM test
flake.nix, tests/mesh-admin-ssh.nix
Adds an ed25519 test key fixture, a mesh-admin-ssh flake check, and a two-node NixOS test verifying hardened sshd config, mesh-based SSH/sudo access, and refusal of LAN-based SSH.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant NodeA
  participant Mesh
  participant NodeB_sshd
  NodeA->>Mesh: nvpn ip --peer --discover-secs 0
  Mesh-->>NodeA: resolved meshB IP
  NodeA->>NodeB_sshd: ssh keepadmin@meshB (mesh IP)
  NodeB_sshd-->>NodeA: connection succeeds
  NodeA->>NodeB_sshd: sudo -n (passwordless)
  NodeB_sshd-->>NodeA: sudo succeeds
  NodeA->>NodeB_sshd: ssh keepadmin@underlayB (LAN IP)
  NodeB_sshd-->>NodeA: connection refused
Loading

Poem

A tunnel dug through mesh so deep,
No password left for foes to keep,
keepadmin hops with key in paw,
Sudo granted without a flaw,
LAN doors shut, the mesh stands tall—
This bunny's proud of firewall! 🐇🔐

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: hardened key-only SSH admin access for keepadmin restricted to the mesh.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mesh-admin-ssh

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/mesh-admin-ssh.nix (1)

89-96: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Extend hardened-posture assertions to cover AllowUsers and forwarding.

The sshd -T checks verify password/kbd-interactive/root-login/maxauthtries, but the PR objectives also claim AllowUsers = [ "keepadmin" ] and forwarding disabled as part of the hardened posture — neither is asserted here, so a regression in those specific settings wouldn't be caught by this test.

♻️ Proposed additional assertions
       for prop in [
           "passwordauthentication no",
           "kbdinteractiveauthentication no",
           "permitrootlogin no",
           "maxauthtries 3",
+          "allowusers keepadmin",
+          "allowtcpforwarding no",
+          "x11forwarding no",
       ]:
           nodeB.succeed(f"sshd -T | grep -qx '{prop}'")
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/mesh-admin-ssh.nix` around lines 89 - 96, The hardened sshd posture
check in the sshd -T assertion block only verifies password, kbd-interactive,
root login, and maxauthtries, so it misses the claimed AllowUsers and forwarding
restrictions. Extend the existing loop or add adjacent assertions in the same
test to verify the effective sshd config also includes AllowUsers for keepadmin
and that forwarding is disabled, using the same nodeB.succeed("sshd -T | grep
-qx ...") pattern so regressions in those settings are caught.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/mesh-admin-ssh.nix`:
- Around line 89-96: The hardened sshd posture check in the sshd -T assertion
block only verifies password, kbd-interactive, root login, and maxauthtries, so
it misses the claimed AllowUsers and forwarding restrictions. Extend the
existing loop or add adjacent assertions in the same test to verify the
effective sshd config also includes AllowUsers for keepadmin and that forwarding
is disabled, using the same nodeB.succeed("sshd -T | grep -qx ...") pattern so
regressions in those settings are caught.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 97a8c7da-756a-43e9-acfc-f926715b009e

📥 Commits

Reviewing files that changed from the base of the PR and between 3459b77 and c4dfc0e.

📒 Files selected for processing (4)
  • flake.nix
  • nixos/admin-access.nix
  • nixos/keep-node.nix
  • tests/mesh-admin-ssh.nix

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.

1 participant