From 634ec86744bfb10df2012360dac07e10bccb2bd3 Mon Sep 17 00:00:00 2001 From: Claudio Maradonna Date: Mon, 21 Nov 2022 15:02:03 +0100 Subject: [PATCH] update README for hardening-basic --- roles/hardening-basic/README.md | 28 +++++++++++-------- roles/hardening-basic/defaults/main.yml | 3 ++ .../templates/etc/sysctl.d/99-hardening.conf | 12 ++++---- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/roles/hardening-basic/README.md b/roles/hardening-basic/README.md index 225dd44..1396f4a 100644 --- a/roles/hardening-basic/README.md +++ b/roles/hardening-basic/README.md @@ -1,38 +1,42 @@ -Role Name +hardening-basic ========= -A brief description of the role goes here. +This role harden a target with best practises for SSH, modprobe and sysctl Requirements ------------ -Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. +. Role Variables -------------- -A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. +- *hardening_sshd_enabled* (boolean): Enable or disable ssh hardening +- *hardening_sshd_port* (integer): Set the SSHD port +- *hardening_sshd_authorized_key_file* (string): Set the relative path for sshd authorized_key_file +- *hardening_sshd_tcp_forward* (boolean): Enable or disable sshd tcp forwarding +- *hardening_sshd_legal_banner* (boolean): Enable or disable sshd legal banner (/etc/issue.net) +- *hardening_sshd_permissions_set_sticky_bit* (boolean): Enable or disable the sticky bit for sshd directory and files (root) +- *hardening_sysctl_vm_swappiness* (integer): Set the value for sysctl vm.swappiness +- *hardening_sysctl_disable_ipv6* (boolean): Enable or disable ipv6 though sysctl +- *hardening_modprobe_disable_list* (dict): Array of sections. Each section contains an array of string: modules, protocols and so on that can be disabled through modprobe Dependencies ------------ -A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. +. Example Playbook ---------------- -Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: - - - hosts: servers - roles: - - { role: username.rolename, x: 42 } +`ansible-playbook -i inventory/example.yml handbook.yml --extra-vars="target=your_target" --tags hardening` License ------- -BSD +GPLv3 Author Information ------------------ -An optional section for the role authors to include contact information, or a website (HTML is not allowed). +- [Claudio Maradonna](https://social.unitoo.it/claudio) diff --git a/roles/hardening-basic/defaults/main.yml b/roles/hardening-basic/defaults/main.yml index 8445b7f..bd3fee2 100644 --- a/roles/hardening-basic/defaults/main.yml +++ b/roles/hardening-basic/defaults/main.yml @@ -8,6 +8,9 @@ hardening_sshd_tcp_forward: false hardening_sshd_legal_banner: false hardening_sshd_permissions_set_sticky_bit: true +hardening_sysctl_vm_swappiness: 15 +hardening_sysctl_disable_ipv6: false + hardening_modprobe_disable_list: ipv6: [ipv6] network_filesystems: [cifs,nfs,nfsv3,nfsv4,gfs2] diff --git a/roles/hardening-basic/templates/etc/sysctl.d/99-hardening.conf b/roles/hardening-basic/templates/etc/sysctl.d/99-hardening.conf index 2350204..e2167ff 100644 --- a/roles/hardening-basic/templates/etc/sysctl.d/99-hardening.conf +++ b/roles/hardening-basic/templates/etc/sysctl.d/99-hardening.conf @@ -14,7 +14,6 @@ kernel.randomize_va_space = 2 kernel.sysrq = 0 kernel.unprivileged_bpf_disabled = 1 - net.core.bpf_jit_harden = 2 net.ipv4.conf.all.accept_redirects = 0 net.ipv4.conf.all.accept_source_route = 0 @@ -52,10 +51,11 @@ kernel.yama.ptrace_scope=2 vm.mmap_rnd_bits=32 vm.mmap_rnd_compat_bits=16 -# Uncomment do disable ipv6 -#net.ipv6.conf.all.disable_ipv6=1 -#net.ipv6.conf.default.disable_ipv6=1 -#net.ipv6.conf.lo.disable_ipv6=1 +{% if hardening_sysctl_disable_ipv6 %} +net.ipv6.conf.all.disable_ipv6=1 +net.ipv6.conf.default.disable_ipv6=1 +net.ipv6.conf.lo.disable_ipv6=1 +{% endif %} net.ipv6.conf.all.accept_redirects = 0 net.ipv6.conf.all.accept_source_route = 0 @@ -63,4 +63,4 @@ net.ipv6.conf.all.accept_source_route = 0 net.ipv6.conf.default.accept_redirects = 0 net.ipv6.conf.default.accept_source_route = 0 -vm.swappiness = 15 +vm.swappiness = {{ hardening_sysctl_vm_swappiness }}