Skip to content

Commit 2906aaf

Browse files
added os_immutable_fs to os_hardening and ssh_hardening and edited tasks to allow both roles to work with redhat and fedora immutable filesystem os's - next step to add support for ubuntu core
1 parent c5db757 commit 2906aaf

File tree

11 files changed

+55
-5
lines changed

11 files changed

+55
-5
lines changed

roles/os_hardening/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ We know that this is the case on Raspberry Pi.
116116

117117
### Using with ostree system, ie coreos/silverblue
118118

119-
If you are using os_hardening with a filesystem that has immutable directories in accordance with the ostree specification, then you can set the variable `os_immutable_fs: true`. It defaults to `ansible_facts.pkg_mgr == 'atomic_container'` and so should compensate for the immutable file system by default.
119+
If you are using os_hardening with a filesystem that has an immutable filesystem in accordance with the ostree specification, then you can set the variable `os_immutable_fs: True`, which defaults to `os_immutable_fs: "{{ (ansible_facts.pkg_mgr == 'atomic_container') | bool }} "` and so should compensate for the immutable file system by default.
120+
However, for os_hardening to work, you will need at least python-rpm package installed.
121+
Note that on Coreos systems, neither python nor python-rpm is installed as default.
120122

121123
## Variables
122124
=======
@@ -815,8 +817,8 @@ This role is mostly based on guides by:
815817
- Type: list of ''
816818
- Required: no
817819
- `os_immutable_fs`
818-
- Default: `ansible_facts.pkg_mgr == 'atomic_container'`
819-
- Description: Specify that file system is immutable in accordance with ostree system ie coreos/silverblue
820+
- Default: `"{{ (ansible_facts.pkg_mgr == 'atomic_container') | bool }} "`
821+
- Description: Specify that file system is immutable in accordance with ostree system ie coreos/silverblue. Default is boolean depending on ansible_facts.
820822
- `os_pam_enabled`
821823
- Default: `True`
822824
- Description: Set to false to disable installing and configuring pam.

roles/os_hardening/defaults/main.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ os_security_packages_list: [xinetd, inetd, ypserv, telnet-server, rsh-server, pr
5454
os_security_init_prompt: true
5555
# Require root password for single user mode. (rhel, centos)
5656
os_security_init_single: false
57-
# Set to true if filesystem is immutable (ie ostree or similar)
58-
os_immutable_fs: ansible_facts.pkg_mgr == 'atomic_container'
5957

6058
# Apply ufw defaults
6159
ufw_manage_defaults: true

roles/os_hardening/tasks/hardening.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
with_dict: "{{ os_vars }}"
2929
tags: always
3030

31+
# I am unable to get the above code to recognise os_immutable_fs
32+
# set in var/Fedora.yml so I set it explicitly here.
33+
- name: set fact
34+
ansible.builtin.set_fact:
35+
"os_immutable_fs": "{{ ansible_facts.pkg_mgr == 'atomic_container' }}"
36+
tags: always
37+
3138
- name: Import tasks for auditd
3239
ansible.builtin.import_tasks: auditd.yml
3340
tags: auditd
@@ -110,6 +117,13 @@
110117
- ansible_facts.os_family == 'RedHat'
111118
- os_yum_enabled | bool
112119

120+
- name: Import tasks to configure yum
121+
ansible.builtin.import_tasks: rpm_ostree.yml
122+
tags: yum
123+
when:
124+
- ansible_facts.os_family == 'RedHat'
125+
- os_immutable_fs | bool
126+
113127
- name: Import tasks to configure apt
114128
ansible.builtin.import_tasks: apt.yml
115129
tags: apt
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
# configuration tasks for rpm_ostree systems
3+
# selected when os_immutable_fs == true
4+
# basic tasks taken from ./yum.yml
5+
- name: Remove deprecated or insecure packages | package-01 - package-09
6+
community.general.rpm_ostree_pkg:
7+
name: "{{ os_security_packages_list }}"
8+
state: absent
9+
when: os_security_packages_clean | bool

roles/os_hardening/tasks/yum.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@
4949
name: "{{ os_security_packages_list }}"
5050
state: absent
5151
when: os_security_packages_clean | bool
52+
when: not os_immutable_fs

roles/os_hardening/vars/Fedora.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,5 @@ modprobe_package: module-init-tools
8282
auditd_package: audit
8383

8484
hidepid_option: "2" # allowed values: 0, 1, 2
85+
86+
os_immutable_fs: "{{ (ansible_facts.pkg_mgr == 'atomic_container') | bool }} "

roles/os_hardening/vars/RedHat.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,5 @@ modprobe_package: module-init-tools
8282
auditd_package: audit
8383

8484
hidepid_option: "2" # allowed values: 0, 1, 2
85+
86+
os_immutable_fs: "{{ (ansible_facts.pkg_mgr == 'atomic_container') | bool }} "

roles/ssh_hardening/tasks/hardening.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
with_dict: "{{ os_vars }}"
2323
tags: always
2424

25+
# I am unable to get the above code to recognise os_immutable_fs
26+
# set in var/Fedora.yml so I set it explicitly here.
27+
- name: set fact
28+
ansible.builtin.set_fact:
29+
"os_immutable_fs": "{{ ansible_facts.pkg_mgr == 'atomic_container' }}"
30+
tags: always
31+
2532
- name: Install openssh package and configure the service
2633
ansible.builtin.include_tasks: install.yml
2734

roles/ssh_hardening/tasks/install.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
---
22

3+
- name: set fact for os_immutable_fs
4+
set_fact:
5+
ansible_package_use: "community.general.rpm_ostree_pkg"
6+
when: os_immutable_fs | bool
7+
38
- name: Install openssh package(s)
49
ansible.builtin.package:
510
name: "{{ pkg }}"
@@ -8,6 +13,12 @@
813
loop_control:
914
loop_var: pkg
1015

16+
- name: reboot if ostree_immutable needs_reboot is true
17+
ansible.builtin.reboot:
18+
msg: "Rebooting to install packages"
19+
pre_reboot_delay: 0
20+
when: ssh_pkgs_installed.results[0].needs_reboot
21+
1122
# see https://github.com/dev-sec/ansible-collection-hardening/issues/763
1223
- name: Change Debian/Ubuntu systems so ssh starts traditionally instead of socket-activated
1324
ansible.builtin.include_tasks: disable-systemd-socket.yml

roles/ssh_hardening/vars/Fedora.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ sshd_moduli_file: /etc/ssh/moduli
2424
# disable CRYPTO_POLICY to take settings from sshd configuration
2525
# see: https://access.redhat.com/solutions/4410591
2626
sshd_disable_crypto_policy: true
27+
28+
os_immutable_fs: "{{ (ansible_facts.pkg_mgr == 'atomic_container') | bool }} "

0 commit comments

Comments
 (0)