2020-10-23 21:46:12 +02:00
|
|
|
---
|
|
|
|
- hosts: all
|
2020-11-20 23:12:04 +01:00
|
|
|
vars:
|
|
|
|
__sshd_test_backup_files:
|
|
|
|
- /etc/ssh/sshd_config
|
|
|
|
- /etc/ssh/sshd_config.d/00-ansible_system_role.conf
|
2020-12-08 14:20:39 +01:00
|
|
|
- /tmp/ssh_host_rsa_key2
|
2020-10-23 21:46:12 +02:00
|
|
|
tasks:
|
2020-11-20 23:12:04 +01:00
|
|
|
- name: "Backup configuration files"
|
|
|
|
include_tasks: tasks/backup.yml
|
|
|
|
|
2020-10-23 21:46:12 +02:00
|
|
|
- name: Remove host key before the test
|
|
|
|
file:
|
2020-12-08 14:20:39 +01:00
|
|
|
path: /tmp/ssh_host_rsa_key2
|
2020-10-23 21:46:12 +02:00
|
|
|
state: absent
|
|
|
|
|
2020-11-10 10:19:45 +01:00
|
|
|
- name: Ensure group 'nobody' exists
|
|
|
|
group:
|
|
|
|
name: nobody
|
|
|
|
|
|
|
|
- name: Ensure the user 'nobody' exists
|
|
|
|
user:
|
|
|
|
name: nobody
|
|
|
|
group: nobody
|
|
|
|
comment: nobody
|
|
|
|
create_home: no
|
|
|
|
shell: /sbin/nologin
|
|
|
|
|
2020-10-23 21:46:12 +02:00
|
|
|
- name: Configure sshd with alternative host keys
|
|
|
|
include_role:
|
|
|
|
name: ansible-sshd
|
|
|
|
vars:
|
|
|
|
# very BAD example
|
|
|
|
sshd_hostkey_owner: "nobody"
|
|
|
|
sshd_hostkey_group: "nobody"
|
|
|
|
sshd_hostkey_mode: "0664"
|
|
|
|
sshd:
|
|
|
|
HostKey:
|
2020-12-08 14:20:39 +01:00
|
|
|
- /tmp/ssh_host_rsa_key2
|
2020-10-23 21:46:12 +02:00
|
|
|
|
|
|
|
- name: Verify the options are correctly set
|
|
|
|
vars:
|
|
|
|
main_sshd_config: >-
|
|
|
|
{{
|
|
|
|
"/etc/ssh/sshd_config.d/00-ansible_system_role.conf"
|
|
|
|
if ansible_facts['distribution'] == 'Fedora'
|
|
|
|
else "/etc/ssh/sshd_config"
|
|
|
|
}}
|
|
|
|
block:
|
|
|
|
- meta: flush_handlers
|
|
|
|
|
|
|
|
- name: Print current configuration file
|
|
|
|
slurp:
|
|
|
|
src: "{{ main_sshd_config }}"
|
|
|
|
register: config
|
|
|
|
|
|
|
|
- stat:
|
2020-12-08 14:20:39 +01:00
|
|
|
path: /tmp/ssh_host_rsa_key2
|
2020-10-23 21:46:12 +02:00
|
|
|
register: privkey
|
|
|
|
|
|
|
|
- stat:
|
2020-12-08 14:20:39 +01:00
|
|
|
path: /tmp/ssh_host_rsa_key2.pub
|
2020-10-23 21:46:12 +02:00
|
|
|
register: pubkey
|
|
|
|
|
|
|
|
- name: Check the options are in configuration file
|
|
|
|
assert:
|
|
|
|
that:
|
2020-12-08 14:20:39 +01:00
|
|
|
- "'HostKey /tmp/ssh_host_rsa_key2' in config.content | b64decode"
|
2020-10-23 21:46:12 +02:00
|
|
|
|
|
|
|
- name: Check the generated host key has requested properties
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- privkey.stat.exists
|
|
|
|
- privkey.stat.gr_name == 'nobody'
|
|
|
|
- privkey.stat.pw_name == 'nobody'
|
|
|
|
- privkey.stat.mode == '0664'
|
|
|
|
- pubkey.stat.exists
|
|
|
|
tags: tests::verify
|
2020-11-20 23:12:04 +01:00
|
|
|
|
|
|
|
- name: "Restore configuration files"
|
|
|
|
include_tasks: tasks/restore.yml
|