Skip to content
This repository was archived by the owner on Dec 26, 2020. It is now read-only.

Commit 760f120

Browse files
authored
rework CRYPTO_POLICY handling for fedora (#314)
* rework CRYPTO_POLICY handling for fedora the previous implementation did not handle fedora right. Now we check if a CRYPTO_POLICY is present regardless of the OS version. Signed-off-by: Martin Schurz <[email protected]> * improve tasks for CRYPTO_POLICY Signed-off-by: Martin Schurz <[email protected]> * add exception for Archlinux Signed-off-by: Martin Schurz <[email protected]> * swap conditions Signed-off-by: Martin Schurz <[email protected]>
1 parent e69f589 commit 760f120

File tree

6 files changed

+37
-10
lines changed

6 files changed

+37
-10
lines changed

.kitchen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ platforms:
111111
image: rndmh3ro/docker-fedora-ansible:latest
112112
platform: centos
113113
provision_command:
114-
- dnf install -y python
114+
- dnf install -y python procps-ng
115115
- sed -i '/nologin/d' /etc/pam.d/sshd
116116
- systemctl enable sshd.service
117117

files/sshd

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Configuration file for the sshd service.
2+
3+
# The server keys are automatically generated if they are missing.
4+
# To change the automatic creation, adjust sshd.service options for
5+
# example using systemctl enable [email protected] to allow creation
6+
# of DSA key or systemctl mask [email protected] to disable RSA key
7+
# creation.
8+
9+
# Do not change this option unless you have hardware random
10+
# generator and you REALLY know what you are doing
11+
12+
SSH_USE_STRONG_RNG=0
13+
# SSH_USE_STRONG_RNG=1
14+
15+
# System-wide crypto policy:
16+
# To opt-out, uncomment the following line
17+
CRYPTO_POLICY=

tasks/hardening.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,16 @@
9898
include_tasks: selinux.yml
9999
when: ansible_facts.selinux and ansible_facts.selinux.status == "enabled"
100100

101-
- name: disable system CRYPTO_POLICY for RHEL8+
102-
lineinfile:
103-
path: /etc/sysconfig/sshd
104-
regexp: 'CRYPTO_POLICY='
105-
line: CRYPTO_POLICY=
101+
- name: gather package facts
102+
package_facts:
103+
check_mode: no
104+
when:
105+
- sshd_disable_crypto_policy | bool
106+
107+
- name: disable SSH server CRYPTO_POLICY
108+
copy:
109+
src: sshd
110+
dest: /etc/sysconfig/sshd
106111
when:
107-
- ansible_facts.distribution in ['CentOS', 'OracleLinux', 'RedHat']
108-
- ansible_facts.distribution_version is version('8.0', '>=')
109-
- sshd_disable_crypto_policy | bool
112+
- sshd_disable_crypto_policy | bool
113+
- ('crypto-policies' in ansible_facts.packages)

tests/default.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
name:
2121
- openssh-clients
2222
- openssh-server
23+
- procps-ng
2324
state: present
2425
update_cache: true
2526
ignore_errors: true

tests/default_custom.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
name:
2121
- openssh-clients
2222
- openssh-server
23+
- procps-ng
2324
state: present
2425
update_cache: true
2526
ignore_errors: true

vars/Archlinux.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
sshd_service_name: sshd
22
ssh_owner: root
3-
ssh_group: root
3+
ssh_group: root
4+
5+
# CRYPTO_POLICY is not supported on Archlinux
6+
# and the package check only works in Ansible >2.10
7+
sshd_disable_crypto_policy: false

0 commit comments

Comments
 (0)