2016-12-27 14:03:35 +01:00
|
|
|
---
|
2017-09-14 14:26:00 +02:00
|
|
|
- debug:
|
|
|
|
msg: "Warning: empty 'evolinux_ssh_password_auth_addresses' variable, tasks will be skipped!"
|
2017-08-18 04:13:56 +02:00
|
|
|
when: evolinux_ssh_password_auth_addresses == []
|
|
|
|
|
2017-10-17 10:26:55 +02:00
|
|
|
# From 'man sshd_config' :
|
|
|
|
# « If all of the criteria on the Match line are satisfied, the keywords
|
|
|
|
# on the following lines override those set in the global section of the config
|
|
|
|
# file, until either another Match line or the end of the file.
|
|
|
|
# If a keyword appears in multiple Match blocks that are satisfied,
|
|
|
|
# only the first instance of the keyword is applied. »
|
|
|
|
#
|
|
|
|
# We want to allow any user from a list of IP addresses to login with password,
|
|
|
|
# but users of the "evolix" group can't login with password from other IP addresses
|
|
|
|
|
2018-04-20 14:38:45 +02:00
|
|
|
- name: Security directives for Evolinux (Debian 10 or later)"
|
2017-08-05 18:13:24 +02:00
|
|
|
blockinfile:
|
2016-12-27 14:03:35 +01:00
|
|
|
dest: /etc/ssh/sshd_config
|
2017-08-05 18:13:24 +02:00
|
|
|
block: |
|
2017-10-17 10:26:55 +02:00
|
|
|
Match Address {{ evolinux_ssh_password_auth_addresses | join(',') }}
|
|
|
|
PasswordAuthentication yes
|
2017-10-08 12:49:55 +02:00
|
|
|
Match Group evolix
|
2017-08-05 18:13:24 +02:00
|
|
|
PasswordAuthentication no
|
2017-10-17 10:26:55 +02:00
|
|
|
marker: "# {mark} EVOLINUX PASSWORD RESTRICTIONS"
|
|
|
|
insertafter: EOF
|
|
|
|
validate: '/usr/sbin/sshd -T -f %s'
|
|
|
|
notify: reload sshd
|
|
|
|
when:
|
|
|
|
- evolinux_ssh_password_auth_addresses != []
|
2018-04-20 14:38:45 +02:00
|
|
|
- ansible_distribution_major_version | version_compare('10', '>=')
|
2017-10-17 10:26:55 +02:00
|
|
|
|
2018-04-20 14:38:45 +02:00
|
|
|
- name: Security directives for Evolinux (Jessie/Stretch)
|
2017-10-17 10:26:55 +02:00
|
|
|
blockinfile:
|
|
|
|
dest: /etc/ssh/sshd_config
|
|
|
|
block: |
|
2017-08-05 18:13:24 +02:00
|
|
|
Match Address {{ evolinux_ssh_password_auth_addresses | join(',') }}
|
|
|
|
PasswordAuthentication yes
|
2017-10-17 10:26:55 +02:00
|
|
|
marker: "# {mark} EVOLINUX PASSWORD RESTRICTIONS BY ADDRESS"
|
2017-08-05 18:13:24 +02:00
|
|
|
insertafter: EOF
|
2016-12-27 14:03:35 +01:00
|
|
|
validate: '/usr/sbin/sshd -T -f %s'
|
2017-01-03 11:44:20 +01:00
|
|
|
notify: reload sshd
|
2017-10-17 10:26:55 +02:00
|
|
|
when:
|
|
|
|
- evolinux_ssh_password_auth_addresses != []
|
2018-04-20 14:38:45 +02:00
|
|
|
- ansible_distribution_major_version | version_compare('10', '<')
|
2016-12-27 14:03:35 +01:00
|
|
|
|
2017-08-18 14:37:18 +02:00
|
|
|
# We disable AcceptEnv because it can be a security issue, but also because we
|
|
|
|
# do not want clients to push their environment variables like LANG.
|
2016-12-27 14:03:35 +01:00
|
|
|
- name: disable AcceptEnv in ssh config
|
|
|
|
replace:
|
|
|
|
dest: /etc/ssh/sshd_config
|
|
|
|
regexp: '^AcceptEnv'
|
|
|
|
replace: "#AcceptEnv"
|
2017-06-14 15:53:15 +02:00
|
|
|
notify: reload sshd
|
2017-01-03 16:37:23 +01:00
|
|
|
when: evolinux_ssh_disable_acceptenv
|
2017-01-03 17:02:23 +01:00
|
|
|
|
2017-06-14 15:53:15 +02:00
|
|
|
- name: Set log level to verbose (for Debian >= 9)
|
|
|
|
replace:
|
|
|
|
dest: /etc/ssh/sshd_config
|
2017-07-19 13:49:08 +02:00
|
|
|
regexp: '^#?LogLevel [A-Z]+'
|
2017-06-14 15:53:15 +02:00
|
|
|
replace: "LogLevel VERBOSE"
|
|
|
|
notify: reload sshd
|
2017-08-22 00:42:14 +02:00
|
|
|
when: ansible_distribution_major_version | version_compare('9', '>=')
|
2017-06-14 15:53:15 +02:00
|
|
|
|
2017-10-07 12:59:35 +02:00
|
|
|
- name: "Get current user"
|
|
|
|
command: logname
|
2018-03-01 11:07:43 +01:00
|
|
|
changed_when: False
|
2017-10-07 12:59:35 +02:00
|
|
|
register: logname
|
|
|
|
check_mode: no
|
|
|
|
when: evolinux_ssh_allow_current_user
|
|
|
|
|
2017-10-07 22:15:51 +02:00
|
|
|
# we must double-escape caracters, because python
|
|
|
|
- name: verify AllowUsers directive
|
2018-04-04 23:22:46 +02:00
|
|
|
command: "grep -E '^AllowUsers' /etc/ssh/sshd_config"
|
2017-10-07 22:15:51 +02:00
|
|
|
failed_when: False
|
2018-03-01 11:07:43 +01:00
|
|
|
changed_when: False
|
2017-10-07 22:15:51 +02:00
|
|
|
register: grep_allowusers_ssh
|
|
|
|
check_mode: no
|
|
|
|
when: evolinux_ssh_allow_current_user
|
|
|
|
|
|
|
|
- name: "Add AllowUsers sshd directive for current user"
|
2017-10-07 12:59:35 +02:00
|
|
|
lineinfile:
|
|
|
|
dest: /etc/ssh/sshd_config
|
2017-10-07 22:15:51 +02:00
|
|
|
line: "\nAllowUsers {{ logname.stdout }}"
|
2017-10-07 12:59:35 +02:00
|
|
|
insertafter: 'Subsystem'
|
2017-10-07 22:15:51 +02:00
|
|
|
validate: '/usr/sbin/sshd -T -f %s'
|
|
|
|
notify: reload sshd
|
|
|
|
when: evolinux_ssh_allow_current_user and grep_allowusers_ssh.rc != 0
|
|
|
|
|
|
|
|
- name: "Modify AllowUsers sshd directive for current user"
|
|
|
|
replace:
|
|
|
|
dest: /etc/ssh/sshd_config
|
|
|
|
regexp: '^(AllowUsers ((?!{{ logname.stdout }}).)*)$'
|
|
|
|
replace: '\1 {{ logname.stdout }}'
|
|
|
|
validate: '/usr/sbin/sshd -T -f %s'
|
|
|
|
notify: reload sshd
|
|
|
|
when: evolinux_ssh_allow_current_user and grep_allowusers_ssh.rc == 0
|
2017-10-07 12:59:35 +02:00
|
|
|
|
2017-01-03 17:02:23 +01:00
|
|
|
- meta: flush_handlers
|