Files
Kamino/roles/sshd/molecule/default/verify.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

92 lines
3.3 KiB
YAML

---
# Lock-out signals only: the drop-in is in place, the daemon accepts the config and
# runs, and the effective settings keep key authentication on and passwords and
# root login off. The remaining hardening values restate the role's own defaults
# and would only break on a policy change.
- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Stat the drop-in
ansible.builtin.stat:
path: /etc/ssh/sshd_config.d/99-ansible-hardening.conf
register: sshd_verify_dropin_stat
- name: The drop-in exists
ansible.builtin.assert:
that: sshd_verify_dropin_stat.stat.exists
quiet: true
- name: Test the configuration sshd will load
ansible.builtin.command: sshd -t
changed_when: false
- name: Ask systemd about the ssh unit
ansible.builtin.systemd:
name: ssh
register: sshd_verify_unit
check_mode: true
- name: The ssh unit is active
ansible.builtin.assert:
that: sshd_verify_unit.status.ActiveState == "active"
quiet: true
- name: Dump the effective configuration
ansible.builtin.command: sshd -T
register: sshd_verify_effective
changed_when: false
- name: Key login stays on, password and root login stay off
ansible.builtin.assert:
that:
- sshd_verify_effective.stdout_lines is contains('pubkeyauthentication yes')
- sshd_verify_effective.stdout_lines is contains('passwordauthentication no')
- sshd_verify_effective.stdout_lines is contains('permitrootlogin no')
quiet: true
# The pve profile cannot be converged here (it is not an LXC), so render its drop-in
# to a scratch file and let sshd parse it: proves sshd accepts the value and the
# profile's algorithm lists, and what it resolves them to.
- name: Verify the pve profile parses
hosts: all
gather_facts: false
vars:
sshd_profile: pve
tasks:
- name: Load the role defaults for the pve profile
ansible.builtin.include_role:
name: mortis.kamino.sshd
tasks_from: validate.yml
public: true
- name: Create a scratch file for the pve drop-in
ansible.builtin.tempfile:
suffix: .conf
register: sshd_verify_pve_file
- name: Render the pve drop-in
ansible.builtin.copy:
content: "{{ lookup('ansible.builtin.template', playbook_dir ~ '/../../templates/99-ansible-hardening.conf.j2') }}"
dest: "{{ sshd_verify_pve_file.path }}"
mode: "0600"
- name: Dump the effective pve configuration
ansible.builtin.command: sshd -T -f {{ sshd_verify_pve_file.path }}
register: sshd_verify_pve_effective
changed_when: false
- name: Root logs in with keys only, passwords stay off
ansible.builtin.assert:
that:
# sshd -T prints the first alias in its table for prohibit-password: without-password.
- sshd_verify_pve_effective.stdout_lines is contains('permitrootlogin without-password')
- sshd_verify_pve_effective.stdout_lines is contains('passwordauthentication no')
- sshd_verify_pve_effective.stdout_lines is contains('pubkeyauthentication yes')
quiet: true
- name: Remove the scratch file
ansible.builtin.file:
path: "{{ sshd_verify_pve_file.path }}"
state: absent