Skip to content

Commit

Permalink
rework CRYPTO_POLICY handling for fedora (#314)
Browse files Browse the repository at this point in the history
* 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 <Martin.Schurz@t-systems.com>

* improve tasks for CRYPTO_POLICY

Signed-off-by: Martin Schurz <Martin.Schurz@t-systems.com>

* add exception for Archlinux

Signed-off-by: Martin Schurz <Martin.Schurz@t-systems.com>

* swap conditions

Signed-off-by: Martin Schurz <Martin.Schurz@t-systems.com>
  • Loading branch information
schurzi committed Jul 22, 2020
1 parent e69f589 commit 760f120
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ platforms:
image: rndmh3ro/docker-fedora-ansible:latest
platform: centos
provision_command:
- dnf install -y python
- dnf install -y python procps-ng
- sed -i '/nologin/d' /etc/pam.d/sshd
- systemctl enable sshd.service

Expand Down
17 changes: 17 additions & 0 deletions files/sshd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Configuration file for the sshd service.

# The server keys are automatically generated if they are missing.
# To change the automatic creation, adjust sshd.service options for
# example using systemctl enable sshd-keygen@dsa.service to allow creation
# of DSA key or systemctl mask sshd-keygen@rsa.service to disable RSA key
# creation.

# Do not change this option unless you have hardware random
# generator and you REALLY know what you are doing

SSH_USE_STRONG_RNG=0
# SSH_USE_STRONG_RNG=1

# System-wide crypto policy:
# To opt-out, uncomment the following line
CRYPTO_POLICY=
20 changes: 12 additions & 8 deletions tasks/hardening.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,16 @@
include_tasks: selinux.yml
when: ansible_facts.selinux and ansible_facts.selinux.status == "enabled"

- name: disable system CRYPTO_POLICY for RHEL8+
lineinfile:
path: /etc/sysconfig/sshd
regexp: 'CRYPTO_POLICY='
line: CRYPTO_POLICY=
- name: gather package facts
package_facts:
check_mode: no
when:
- sshd_disable_crypto_policy | bool

- name: disable SSH server CRYPTO_POLICY
copy:
src: sshd
dest: /etc/sysconfig/sshd
when:
- ansible_facts.distribution in ['CentOS', 'OracleLinux', 'RedHat']
- ansible_facts.distribution_version is version('8.0', '>=')
- sshd_disable_crypto_policy | bool
- sshd_disable_crypto_policy | bool
- ('crypto-policies' in ansible_facts.packages)
1 change: 1 addition & 0 deletions tests/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
name:
- openssh-clients
- openssh-server
- procps-ng
state: present
update_cache: true
ignore_errors: true
Expand Down
1 change: 1 addition & 0 deletions tests/default_custom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
name:
- openssh-clients
- openssh-server
- procps-ng
state: present
update_cache: true
ignore_errors: true
Expand Down
6 changes: 5 additions & 1 deletion vars/Archlinux.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
sshd_service_name: sshd
ssh_owner: root
ssh_group: root
ssh_group: root

# CRYPTO_POLICY is not supported on Archlinux
# and the package check only works in Ansible >2.10
sshd_disable_crypto_policy: false

0 comments on commit 760f120

Please sign in to comment.