feat(sshd): add an sshd hardening role (proposal) #160

Open
opened 2026-11-15 12:33:00 +00:00 by Dragonish · 5 comments
Collaborator

What

An sshd role: a hardening drop-in for OpenSSH. Proposal first, because the README lists SSH as in scope and I do not know whether you already have this role queued for extraction from your own repository.

Why

SSH is the first thing a home lab exposes and the first thing that locks you out when it is configured badly. A reusable role that does the well-known things correctly saves every user from rediscovering them:

  • A drop-in file named 00-ansible-hardening.conf: sshd keeps the first value it reads and reads sshd_config.d/*.conf in name order, so a later-sorting file loses to cloud-init's 50-cloud-init.conf (PasswordAuthentication yes on Ubuntu cloud-image VMs). 00- makes the hardening win.
  • Sensible defaults (key-only authentication, MaxAuthTries, no forwarding, modern KEX/cipher/MAC lists), merged with consumer overrides.
  • The config validated with sshd -t before the service is reloaded, so a typo cannot lock the host out.
  • Profiles per system type, mirroring the system_type profiles of system_baseline, so a hypervisor and a container can differ.

Scope of what I would send

About 10 files, roughly 200 lines. Generic by construction; what I would strip before sending: references to my hosts and issue numbers in comments, the coupling to ansible_user, and a profile name that only makes sense in my inventory. Role vars would be sshd_-prefixed, typed in argument_specs.yml, with a molecule scenario on both Ubuntu images.

Questions for the maintainer

  • Is this role already queued from your environment repository? If so I will not duplicate it, and would rather review it.
  • Do you want profiles, or a flat sshd_settings mapping that consumers override?
## What An `sshd` role: a hardening drop-in for OpenSSH. Proposal first, because the README lists SSH as in scope and I do not know whether you already have this role queued for extraction from your own repository. ## Why SSH is the first thing a home lab exposes and the first thing that locks you out when it is configured badly. A reusable role that does the well-known things correctly saves every user from rediscovering them: - A drop-in file named `00-ansible-hardening.conf`: sshd keeps the **first** value it reads and reads `sshd_config.d/*.conf` in name order, so a later-sorting file loses to cloud-init's `50-cloud-init.conf` (`PasswordAuthentication yes` on Ubuntu cloud-image VMs). `00-` makes the hardening win. - Sensible defaults (key-only authentication, `MaxAuthTries`, no forwarding, modern KEX/cipher/MAC lists), merged with consumer overrides. - The config validated with `sshd -t` before the service is reloaded, so a typo cannot lock the host out. - Profiles per system type, mirroring the `system_type` profiles of `system_baseline`, so a hypervisor and a container can differ. ## Scope of what I would send About 10 files, roughly 200 lines. Generic by construction; what I would strip before sending: references to my hosts and issue numbers in comments, the coupling to `ansible_user`, and a profile name that only makes sense in my inventory. Role vars would be `sshd_`-prefixed, typed in `argument_specs.yml`, with a molecule scenario on both Ubuntu images. ## Questions for the maintainer - Is this role already queued from your environment repository? If so I will not duplicate it, and would rather review it. - Do you want profiles, or a flat `sshd_settings` mapping that consumers override?
Dragonish added the Kind/Feature label 2026-11-15 12:33:00 +00:00
Defame1297 added the
Priority
Low
4
Reviewed
Duplicate
2
Status
Ready for Human
labels 2026-11-15 12:44:27 +00:00
Owner

sshd role will first be migrated from my repo, see README

sshd role will first be migrated from my repo, see README
Author
Collaborator

Understood, and thanks for saying so before any code landed. I will not open a PR for this.

For reference only: I had already prepared a local, unpushed sshd role branch (a drop-in named 00- so it sorts before cloud-init's 50-cloud-init.conf, a settings mapping merged over defaults, sshd -t before the reload with restore on failure, validation that refuses Match/Include, and a Molecule scenario that has not run). If it helps your migration, say so and I will share it (as a branch or a diff); otherwise it stays local and I will delete it once your role lands. I would be glad to review your version instead.

Assisted-by: Claude Code

Understood, and thanks for saying so before any code landed. I will not open a PR for this. For reference only: I had already prepared a local, unpushed `sshd` role branch (a drop-in named `00-` so it sorts before cloud-init's `50-cloud-init.conf`, a settings mapping merged over defaults, `sshd -t` before the reload with restore on failure, validation that refuses `Match`/`Include`, and a Molecule scenario that has not run). If it helps your migration, say so and I will share it (as a branch or a diff); otherwise it stays local and I will delete it once your role lands. I would be glad to review your version instead. Assisted-by: Claude Code
Owner

Labelled Reviewed/Duplicate and withdrawn by the proposer, but still Status/Ready for Human. Recommend the maintainer closes it. (From Order of the implementation backlog, #198.)

Labelled Reviewed/Duplicate and withdrawn by the proposer, but still Status/Ready for Human. Recommend the maintainer closes it. (From Order of the implementation backlog, #198.)
Owner

Review of the map (2026-11-15): corrections to this issue.

  • The proposal is now moot, not only a duplicate. The sshd role has merged and shipped in release 1.6.0 (roles/sshd/; CHANGELOG.rst:13, "Adds the sshd role"). The labels still contradict each other: Reviewed/Duplicate says nothing is left to do, Status/Ready for Human says the maintainer has an action. The maintainer can close this issue as completed by the sshd role; the proposer has offered to review that version instead.
Review of the map (2026-11-15): corrections to this issue. - **The proposal is now moot, not only a duplicate.** The `sshd` role has merged and shipped in release 1.6.0 (`roles/sshd/`; `CHANGELOG.rst:13`, "Adds the sshd role"). The labels still contradict each other: `Reviewed/Duplicate` says nothing is left to do, `Status/Ready for Human` says the maintainer has an action. The maintainer can close this issue as completed by the `sshd` role; the proposer has offered to review that version instead.
Owner

@Dragonish pls check whether there sre things you added in your repo that we should migrate here.

@Dragonish pls check whether there sre things you added in your repo that we should migrate here.
Sign in to join this conversation.
3 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Kamino#160