Files
Kamino/roles/sshd/tasks/validate.yml
T
Defame1297andClaude Opus 5.5 915f588533 feat(sshd): add the sshd role
Copied from the environment repository's local role. The files are
identical except: galaxy namespace mortis; comments, the README and the
guard failure messages scrubbed of environment references (issue numbers,
playbooks, inventory groups, the caller role's fallback, history of the
old vars/ files and of the variable renames), with the technical
explanation kept; the README's run order now asks for the ansible_user key
to be installed first instead of naming the environment's playbooks; the
molecule scenario calls the role by its FQCN (mortis.kamino.sshd), follows
the Kamino scenario conventions (kamino-molecule header,
scenario.test_sequence) and no longer sets ANSIBLE_COLLECTIONS_PATH or
ANSIBLE_ROLES_PATH. No variable, default, argument_specs type or task
logic changed; the test coverage is the same. The role uses
ansible.builtin only, so galaxy.yml's dependencies are unchanged.

The README Roadmap no longer lists sshd.

Not verified locally: the molecule scenario (it runs on the
kamino-molecule runner in CI) and ansible-test sanity (runs on push).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
2026-11-15 22:08:10 +00:00

63 lines
2.9 KiB
YAML

---
- name: Fail if sshd_profile is not set
ansible.builtin.fail:
msg: "sshd_profile must be set (pve, ubuntu_lxc, ubuntu_vm)"
when: sshd_profile is not defined
- name: Fail if sshd_profile is unknown
ansible.builtin.fail:
msg: "sshd_profile '{{ sshd_profile }}' is invalid. Must be: {{ sshd_profiles.keys() | sort | join(', ') }}."
when: sshd_profile not in sshd_profiles
- name: Fail if no sshd settings are defined
ansible.builtin.fail:
msg: "No sshd settings resolved after merging defaults and overrides."
when: sshd_settings_effective | length == 0
- name: Fail if SSH would be locked out
ansible.builtin.fail:
msg: >
SSH hardening would lock you out.
PasswordAuthentication is disabled and PubkeyAuthentication is not enabled.
when:
- sshd_settings_effective.PasswordAuthentication | default("yes") == "no"
- sshd_settings_effective.PubkeyAuthentication | default("no") != "yes"
- name: Fail if root key login is disabled on Proxmox
ansible.builtin.fail:
msg: >
Proxmox cluster SSH needs root public-key login. PermitRootLogin must be
prohibit-password, without-password or yes, not
'{{ sshd_settings_effective.PermitRootLogin }}'.
# forced-commands-only is refused too: the cluster's tunnels run arbitrary commands
# with keys that carry no command= option. An unset value keeps the OpenSSH default,
# prohibit-password. sshd matches the value case-insensitively, so the guard does too;
# a YAML boolean (unquoted yes) becomes "true" and is refused, as sshd would refuse it.
when:
- sshd_profile == "pve"
- >-
sshd_settings_effective.PermitRootLogin | default("prohibit-password") | string | lower
not in ["prohibit-password", "without-password", "yes"]
- name: Fail if RSA keys are refused on Proxmox
ansible.builtin.fail:
msg: >
Proxmox cluster SSH pins RSA host keys and logs in with root's RSA key.
HostKeyAlgorithms and PubkeyAcceptedAlgorithms must both include rsa-sha2-512.
# An unset directive keeps the OpenSSH default, which includes rsa-sha2-512. The
# +/-/^ list forms are not parsed, so they fail here: write the full list.
when:
- sshd_profile == "pve"
- >-
'rsa-sha2-512' not in (sshd_settings_effective.HostKeyAlgorithms | default('rsa-sha2-512') | split(',') | map('trim'))
or 'rsa-sha2-512' not in (sshd_settings_effective.PubkeyAcceptedAlgorithms | default('rsa-sha2-512') | split(',') | map('trim'))
- name: Fail if SHA-1 RSA (ssh-rsa) is allowed
ansible.builtin.fail:
msg: >
HostKeyAlgorithms and PubkeyAcceptedAlgorithms must not list ssh-rsa (RSA with SHA-1);
use rsa-sha2-512/rsa-sha2-256.
when: >-
'ssh-rsa' in (sshd_settings_effective.HostKeyAlgorithms | default('') | split(',') | map('trim'))
or 'ssh-rsa' in (sshd_settings_effective.PubkeyAcceptedAlgorithms | default('') | split(',') | map('trim'))