fix(systemd_hardening): disable and mask the socket of a listed service too
Look up every listed name as a socket and as a service and act on each installed unit, the socket first. A service whose socket stays active is started again by the next connection to its port. Assisted-by: Claude Code
This commit is contained in:
1 parent
545f2fe94a
commit
f256c1c7e5
8 files changed
+101
-33
No files matched your search
@@ -8,28 +8,45 @@
|
||||
tasks:
|
||||
- name: Ask systemd about the stub units
|
||||
ansible.builtin.systemd:
|
||||
name: "{{ item }}.service"
|
||||
loop: [rpcbind, telnet]
|
||||
name: "{{ item }}"
|
||||
loop: [rpcbind.socket, rpcbind.service, cups.service, bluetooth.socket, telnet.socket, telnet.service]
|
||||
register: systemd_hardening_verify_units
|
||||
check_mode: true
|
||||
|
||||
- name: The disabled unit is disabled and the masked unit is masked
|
||||
- name: The disabled units, sockets and services alike, are disabled and stopped
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- systemd_hardening_verify_units.results[0].status.UnitFileState == "disabled"
|
||||
- systemd_hardening_verify_units.results[1].status.UnitFileState == "masked"
|
||||
- item.status.UnitFileState == "disabled"
|
||||
- item.status.ActiveState == "inactive"
|
||||
quiet: true
|
||||
loop: "{{ systemd_hardening_verify_units.results | rejectattr('item', 'match', '^telnet[.]') | list }}"
|
||||
loop_control:
|
||||
label: "{{ item.item }}"
|
||||
|
||||
- name: Ask systemd about a listed unit that is not installed
|
||||
ansible.builtin.command: systemctl show --property=LoadState rsh.service # noqa: command-instead-of-module
|
||||
register: systemd_hardening_verify_missing
|
||||
- name: The masked units, socket and service, are masked and stopped
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- item.status.UnitFileState == "masked"
|
||||
- item.status.ActiveState == "inactive"
|
||||
quiet: true
|
||||
loop: "{{ systemd_hardening_verify_units.results | selectattr('item', 'match', '^telnet[.]') | list }}"
|
||||
loop_control:
|
||||
label: "{{ item.item }}"
|
||||
|
||||
- name: Ask systemd about the listed units that are not installed
|
||||
ansible.builtin.command: systemctl show --property=LoadState {{ item }} # noqa: command-instead-of-module
|
||||
loop: [cups.socket, bluetooth.service, rsh.service, rsh.socket]
|
||||
register: systemd_hardening_verify_absent
|
||||
changed_when: false
|
||||
|
||||
- name: The missing unit was skipped, not masked
|
||||
- name: The missing units were skipped, not masked or created
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- systemd_hardening_verify_missing.stdout == "LoadState=not-found"
|
||||
- item.stdout == "LoadState=not-found"
|
||||
quiet: true
|
||||
loop: "{{ systemd_hardening_verify_absent.results }}"
|
||||
loop_control:
|
||||
label: "{{ item.item }}"
|
||||
|
||||
- name: Read the manager drop-in
|
||||
ansible.builtin.slurp:
|
||||
|
||||
Reference in new issue
Block a user