2020-10-08 18:10:05 +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-10-08 18:10:05 +02:00
|
|
|
tasks:
|
2020-11-20 23:12:04 +01:00
|
|
|
- name: "Backup configuration files"
|
|
|
|
include_tasks: tasks/backup.yml
|
|
|
|
|
2020-10-08 18:10:05 +02:00
|
|
|
- name: Configure sshd
|
|
|
|
include_role:
|
|
|
|
name: ansible-sshd
|
|
|
|
vars:
|
2020-11-06 09:47:43 +01:00
|
|
|
# For Fedora containers, we need to make sure we have keys for sshd -T below
|
|
|
|
sshd_verify_hostkeys:
|
|
|
|
- /etc/ssh/ssh_host_rsa_key
|
2020-10-08 18:10:05 +02:00
|
|
|
sshd:
|
|
|
|
Match:
|
2020-11-21 00:23:59 +01:00
|
|
|
Condition: "User xusers"
|
2020-10-08 18:10:05 +02:00
|
|
|
X11Forwarding: yes
|
|
|
|
Banner: /tmp/xusers-banner
|
|
|
|
sshd_match:
|
|
|
|
- Condition: "User bot"
|
|
|
|
AllowTcpForwarding: no
|
|
|
|
Banner: /tmp/bot-banner
|
|
|
|
sshd_match_1:
|
|
|
|
- Condition: "User sftponly"
|
|
|
|
ForceCommand: "internal-sftp"
|
|
|
|
ChrootDirectory: "/var/uploads/"
|
|
|
|
sshd_match_2:
|
|
|
|
- Condition: "User root"
|
|
|
|
PasswordAuthentication: no
|
2020-12-08 15:09:57 +01:00
|
|
|
AllowTcpForwarding: yes
|
2020-10-08 18:10:05 +02:00
|
|
|
|
|
|
|
- name: Verify the options are correctly set
|
2020-11-04 22:42:44 +01:00
|
|
|
vars:
|
|
|
|
main_sshd_config: >-
|
|
|
|
{{
|
|
|
|
"/etc/ssh/sshd_config.d/00-ansible_system_role.conf"
|
|
|
|
if ansible_facts['distribution'] == 'Fedora'
|
|
|
|
else "/etc/ssh/sshd_config"
|
|
|
|
}}
|
2020-10-08 18:10:05 +02:00
|
|
|
block:
|
|
|
|
- meta: flush_handlers
|
|
|
|
|
|
|
|
- name: List effective configuration using sshd -T for xusers
|
2020-11-06 16:20:21 +01:00
|
|
|
command: sshd -T -C user=xusers,addr=127.0.0.1,host=example.com
|
2020-10-08 18:10:05 +02:00
|
|
|
register: xusers_effective
|
|
|
|
|
|
|
|
- name: List effective configuration using sshd -T for bot
|
2020-11-06 16:20:21 +01:00
|
|
|
command: sshd -T -C user=bot,addr=127.0.0.1,host=example.com
|
2020-10-08 18:10:05 +02:00
|
|
|
register: bot_effective
|
|
|
|
|
|
|
|
- name: List effective configuration using sshd -T for sftponly
|
2020-11-06 16:20:21 +01:00
|
|
|
command: sshd -T -C user=sftponly,addr=127.0.0.1,host=example.com
|
2020-10-08 18:10:05 +02:00
|
|
|
register: sftponly_effective
|
|
|
|
|
|
|
|
- name: List effective configuration using sshd -T for root
|
2020-11-06 16:20:21 +01:00
|
|
|
command: sshd -T -C user=root,addr=127.0.0.1,host=example.com
|
2020-10-08 18:10:05 +02:00
|
|
|
register: root_effective
|
|
|
|
|
|
|
|
- name: Print current configuration file
|
2020-11-13 13:14:22 +01:00
|
|
|
slurp:
|
|
|
|
src: "{{ main_sshd_config }}"
|
2020-10-08 18:10:05 +02:00
|
|
|
register: config
|
|
|
|
|
|
|
|
- name: Check the options are effective
|
|
|
|
# note, the options are in lower-case here
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "'x11forwarding yes' in xusers_effective.stdout"
|
|
|
|
- "'banner /tmp/xusers-banner' in xusers_effective.stdout"
|
|
|
|
- "'allowtcpforwarding no' in bot_effective.stdout"
|
|
|
|
- "'banner /tmp/bot-banner' in bot_effective.stdout"
|
|
|
|
- "'forcecommand internal-sftp' in sftponly_effective.stdout"
|
|
|
|
- "'chrootdirectory /var/uploads/' in sftponly_effective.stdout"
|
|
|
|
- "'passwordauthentication no' in root_effective.stdout"
|
2020-12-08 15:09:57 +01:00
|
|
|
- "'allowtcpforwarding yes' in root_effective.stdout"
|
2020-10-08 18:10:05 +02:00
|
|
|
|
|
|
|
- name: Check the options are in configuration file
|
|
|
|
assert:
|
|
|
|
that:
|
2020-11-13 13:14:22 +01:00
|
|
|
- "'Match User xusers' in config.content | b64decode"
|
|
|
|
- "'Match User bot' in config.content | b64decode"
|
|
|
|
- "'Match User sftponly' in config.content | b64decode"
|
|
|
|
- "'Match User root' in config.content | b64decode"
|
2020-10-08 18:10:05 +02:00
|
|
|
tags: tests::verify
|
2020-11-20 23:12:04 +01:00
|
|
|
|
|
|
|
- name: "Restore configuration files"
|
|
|
|
include_tasks: tasks/restore.yml
|