diff --git a/roles/hardening-basic/README.md b/roles/hardening-basic/README.md index 95d63a1..dcfc840 100644 --- a/roles/hardening-basic/README.md +++ b/roles/hardening-basic/README.md @@ -19,6 +19,8 @@ Role Variables - **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 +- **hardening_journald_system_max_use** (string): Example 250M +- **hardening_journald_system_max_file_size** (string): Example 50M Dependencies ------------ diff --git a/roles/hardening-basic/defaults/main.yml b/roles/hardening-basic/defaults/main.yml index 7b3bbbe..8437d8f 100644 --- a/roles/hardening-basic/defaults/main.yml +++ b/roles/hardening-basic/defaults/main.yml @@ -16,3 +16,6 @@ hardening_modprobe_disable_list: rare_filesystems: [cramfs,freevxfs,jffs2,hfs,hfsplus,squashfs,udf] rare_protocols: [dccp,sctp,rds,tipc,n-hdlc,ax25,netrom,x25,rose,decnet,econet,af_802154,ipx,appletalk,psnap,p8023,p8022,can,atm] vivid: [vivid] + +hardening_journald_system_max_use: 250M +hardening_journald_system_max_file_size: 50M diff --git a/roles/hardening-basic/tasks/harden_systemd.yml b/roles/hardening-basic/tasks/harden_systemd.yml new file mode 100644 index 0000000..4e1a684 --- /dev/null +++ b/roles/hardening-basic/tasks/harden_systemd.yml @@ -0,0 +1,14 @@ +- name: Create directory tree if not exists + ansible.builtin.file: + path: '/etc/{{ item.path }}' + state: directory + mode: '{{ item.mode }}' + with_community.general.filetree: '../templates/systemd/etc/' + when: item.state == 'directory' + +- name: Create and copy hardening files + ansible.builtin.template: + src: '{{ item.src }}' + dest: '/etc/{{ item.path }}' + with_community.general.filetree: '../templates/systemd/etc/' + when: item.state == 'file' diff --git a/roles/hardening-basic/tasks/main.yml b/roles/hardening-basic/tasks/main.yml index 6a5c355..9754d8c 100644 --- a/roles/hardening-basic/tasks/main.yml +++ b/roles/hardening-basic/tasks/main.yml @@ -7,12 +7,18 @@ ansible.builtin.template: src: '{{ item.src }}' dest: '/etc/{{ item.path }}' - with_community.general.filetree: '../templates/etc/' + with_community.general.filetree: '../templates/basic/etc/' when: item.state == 'file' - name: Harden SSH Config when: 'hardening_sshd_enabled is true' block: + - name: Create and copy hardening files + ansible.builtin.template: + src: '{{ item.src }}' + dest: '/etc/{{ item.path }}' + with_community.general.filetree: '../templates/ssh/etc/' + when: item.state == 'file' - name: Give 1700 permissions to .ssh folder ansible.builtin.file: @@ -33,3 +39,7 @@ ansible.builtin.systemd: state: restarted name: sshd + + - name: Harden Service Manager (like Systemd) + block: + - include_tasks: "harden_{{ ansible_service_mgr }}.yml" diff --git a/roles/hardening-basic/templates/etc/modprobe.d/hardening.conf b/roles/hardening-basic/templates/basic/etc/modprobe.d/hardening.conf similarity index 100% rename from roles/hardening-basic/templates/etc/modprobe.d/hardening.conf rename to roles/hardening-basic/templates/basic/etc/modprobe.d/hardening.conf diff --git a/roles/hardening-basic/templates/etc/sysctl.d/99-hardening.conf b/roles/hardening-basic/templates/basic/etc/sysctl.d/99-hardening.conf similarity index 100% rename from roles/hardening-basic/templates/etc/sysctl.d/99-hardening.conf rename to roles/hardening-basic/templates/basic/etc/sysctl.d/99-hardening.conf diff --git a/roles/hardening-basic/templates/etc/ssh/sshd_config.d/99-hardening.conf b/roles/hardening-basic/templates/ssh/etc/ssh/sshd_config.d/99-hardening.conf similarity index 98% rename from roles/hardening-basic/templates/etc/ssh/sshd_config.d/99-hardening.conf rename to roles/hardening-basic/templates/ssh/etc/ssh/sshd_config.d/99-hardening.conf index 8692650..128a1a7 100644 --- a/roles/hardening-basic/templates/etc/ssh/sshd_config.d/99-hardening.conf +++ b/roles/hardening-basic/templates/ssh/etc/ssh/sshd_config.d/99-hardening.conf @@ -1,5 +1,3 @@ -{% if hardening_sshd_enabled %} - Protocol 2 # Protocol 1 is fundamentally broken StrictModes yes # Protects from misconfiguration @@ -54,5 +52,3 @@ MaxStartups 2 # Max concurrent TCPKeepAlive yes # Do not use TCP keep-alive AcceptEnv LANG LC_* # Allow client to pass locale environment variables - -{% endif %} diff --git a/roles/hardening-basic/templates/systemd/etc/systemd/journald.conf.d/size.conf b/roles/hardening-basic/templates/systemd/etc/systemd/journald.conf.d/size.conf new file mode 100644 index 0000000..2374c9c --- /dev/null +++ b/roles/hardening-basic/templates/systemd/etc/systemd/journald.conf.d/size.conf @@ -0,0 +1,3 @@ +[Journal] +SystemMaxUse={{ hardening_journald_system_max_use }} +SystemMaxFileSize={{ hardening_journald_system_max_file_size }}