Skip to content

Commit 2ba40b0

Browse files
authored
move sysctls to debian specific vars (#524)
* fix ansible-lint issue ansible/ansible-lint#1795 Signed-off-by: rndmh3ro <[email protected]> * move 2 sysctls to debian specific Signed-off-by: rndmh3ro <[email protected]> * fix ansible-lint issue ansible/ansible-lint#1795 Signed-off-by: rndmh3ro <[email protected]> * add arch linux sysctls * simplify sysctl settings Signed-off-by: rndmh3ro <[email protected]> * ove overwrite to the bottom to let it acutally overwrite something Signed-off-by: rndmh3ro <[email protected]> * fix typo Signed-off-by: rndmh3ro <[email protected]>
1 parent 798f4b9 commit 2ba40b0

File tree

6 files changed

+26
-24
lines changed

6 files changed

+26
-24
lines changed

.github/workflows/ansible-lint.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ jobs:
3030
# override-deps: |
3131
# ansible==2.9
3232
# ansible-lint==4.2.0
33+
override-deps: |
34+
rich>=9.5.1,<11.0.0
3335
# [optional]
3436
# Arguments to be passed to the ansible-lint
3537

roles/os_hardening/defaults/main.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ sysctl_config:
6969
# filenames (generally seen as "/tmp file race" vulnerabilities).
7070
fs.protected_hardlinks: 1
7171
fs.protected_symlinks: 1
72-
72+
7373
# For more info on the following settings see: https://www.kernel.org/doc/html/latest/admin-guide/sysctl/fs.html
7474
# Restrict FIFO special device creation behavior
7575
fs.protected_fifos: 1
@@ -288,14 +288,6 @@ sysctl_config:
288288
vm.mmap_rnd_bits: 32
289289
vm.mmap_rnd_compat_bits: 16
290290

291-
# Disable unprivileged users from loading eBPF programs into the kernel.
292-
# One of mitigations against CVE-2021-33909. | Tail-2
293-
kernel.unprivileged_bpf_disabled: 1
294-
295-
# Reduce attack surface by disabling unprivileged user namespaces.
296-
# Mitigates CVE-2021-33909 and other exploits.
297-
kernel.unprivileged_userns_clone: 0
298-
299291
# Do not delete the following line or otherwise the playbook will fail
300292
# at task 'create a combined sysctl-dict if overwrites are defined'
301293
sysctl_overwrite:

roles/os_hardening/tasks/sysctl.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@
4343

4444
- name: Change sysctls
4545
block:
46+
- name: Create a combined sysctl-dict if os-dependent sysctls are defined
47+
set_fact:
48+
sysctl_config: '{{ sysctl_config | combine(sysctl_custom_config) }}'
49+
when: sysctl_custom_config | default()
50+
51+
# sysctl_rhel_config is kept for backwards-compatibility. use sysctl_custom_config instead
52+
- name: Create a combined sysctl-dict if os-dependent sysctls are defined
53+
set_fact:
54+
sysctl_config: '{{ sysctl_config | combine(sysctl_rhel_config) }}'
55+
when: sysctl_rhel_config | default()
56+
4657
- name: Create a combined sysctl-dict if overwrites are defined
4758
set_fact:
4859
sysctl_config: '{{ sysctl_config | combine(sysctl_overwrite) }}'
@@ -57,17 +68,6 @@
5768
reload: true
5869
ignoreerrors: true
5970
with_dict: '{{ sysctl_config }}'
60-
61-
- name: Change various sysctl-settings on Amazon Linux, look at the sysctl-vars file for documentation
62-
sysctl:
63-
name: '{{ item.key }}'
64-
value: '{{ item.value }}'
65-
state: present
66-
reload: true
67-
ignoreerrors: true
68-
with_dict: '{{ sysctl_rhel_config }}'
69-
when: ansible_facts.distribution == 'Amazon'
70-
7171
when: ansible_virtualization_type not in ['docker', 'lxc', 'openvz']
7272

7373
- name: Apply ufw defaults

roles/os_hardening/vars/Amazon.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,4 @@ auditd_package: 'audit'
4545
# system accounts that do not get their login disabled and pasword changed
4646
os_always_ignore_users: ['root', 'sync', 'shutdown', 'halt', 'ec2-user']
4747

48-
sysctl_rhel_config:
49-
# ExecShield protection against buffer overflows
50-
kernel.exec-shield: 1
51-
5248
hidepid_option: '2' # allowed values: 0, 1, 2

roles/os_hardening/vars/Archlinux.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ modprobe_package: 'kmod'
3333
auditd_package: 'audit'
3434

3535
hidepid_option: '2' # allowed values: 0, 1, 2
36+
37+
sysctl_custom_config:
38+
# Mitigation of vulnerability CVE-2021-33909
39+
kernel.unprivileged_userns_clone: 0
40+
# Mitigation of vulnerability CVE-2021-33910
41+
kernel.unprivileged_bpf_disabled: 1

roles/os_hardening/vars/Debian.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,9 @@ tally2_path: '/usr/share/pam-configs/tally2'
4343
passwdqc_path: '/usr/share/pam-configs/passwdqc'
4444

4545
hidepid_option: '2' # allowed values: 0, 1, 2
46+
47+
sysctl_custom_config:
48+
# Mitigation of vulnerability CVE-2021-33909
49+
kernel.unprivileged_userns_clone: 0
50+
# Mitigation of vulnerability CVE-2021-33910
51+
kernel.unprivileged_bpf_disabled: 1

0 commit comments

Comments
 (0)