--- # What the role is for: the installed risky units are disabled or masked, the manager # drop-in is in place, and the opt-in drop-in renders and is loaded by systemd. The # directives restate the converge vars, not the role's whole policy. - name: Verify hosts: all gather_facts: false tasks: - name: Ask systemd about the stub units ansible.builtin.systemd: name: "{{ item }}.service" loop: [rpcbind, telnet] register: systemd_hardening_verify_units check_mode: true - name: The disabled unit is disabled and the masked unit is masked ansible.builtin.assert: that: - systemd_hardening_verify_units.results[0].status.UnitFileState == "disabled" - systemd_hardening_verify_units.results[1].status.UnitFileState == "masked" quiet: true - name: Read the manager drop-in ansible.builtin.slurp: src: /etc/systemd/system.conf.d/hardening.conf register: systemd_hardening_verify_manager - name: The manager drop-in holds the limits ansible.builtin.assert: that: - (systemd_hardening_verify_manager.content | b64decode).split('\n') is contains('[Manager]') - (systemd_hardening_verify_manager.content | b64decode).split('\n') is contains('DefaultLimitNOFILE=65535') - (systemd_hardening_verify_manager.content | b64decode).split('\n') is contains('DefaultLimitCORE=0') quiet: true - name: Read the service drop-in ansible.builtin.slurp: src: /etc/systemd/system/testsvc.service.d/hardening.conf register: systemd_hardening_verify_dropin - name: The drop-in renders booleans, lists and plain values ansible.builtin.assert: that: - (systemd_hardening_verify_dropin.content | b64decode).split('\n') | select | list == systemd_hardening_verify_expected quiet: true vars: systemd_hardening_verify_expected: - "[Service]" - ProtectSystem=strict - NoNewPrivileges=yes - ReadWritePaths=/var/tmp /run - LimitNOFILE=1024 - name: Ask systemd about the drop-in service ansible.builtin.systemd: name: testsvc.service register: systemd_hardening_verify_testsvc check_mode: true - name: The daemon reload made systemd load the drop-in ansible.builtin.assert: that: - systemd_hardening_verify_testsvc.status.NoNewPrivileges == "yes" - systemd_hardening_verify_testsvc.status.ProtectSystem == "strict" quiet: true