systemd_hardening looked up and acted on <name>.service only. A service whose socket unit stays active is started again by the next connection to its port, so disabling or masking only the service does not make it unreachable (rpcbind listens on port 111 through rpcbind.socket). The role now looks up every listed name as a socket and as a service in the same single systemctl show, and acts on each installed unit, socket first. A name may carry a .service or .socket suffix.
Behaviour change: a socket that belongs to a listed name (with the default lists: rpcbind.socket, and avahi-daemon.socket and cups.socket where they exist) is now stopped and disabled, or masked, where before it was left alone. A name with only a service, only a socket, or neither is fine. The README notes that systemctl disable does nothing for a static unit.
Verified
The systemd behaviour the issue describes, on an Ubuntu 24.04 VM (systemd 255) with a throwaway socket and service pair: stopping the service alone leaves the port listening and the next connection restarts it; stopping the socket first closes the port (ConnectionRefused). This used systemctl directly, not the role.
The lookup and loop expressions, rendered with Ansible's own engine: suffix variants and duplicates fold into one name, the socket comes first, only installed units remain, and the positional pairing keeps the right names.
All commit-stage hooks pass (yamllint, ansible-lint, REUSE, changelog lint, Conventional Commit). --syntax-check passes on the converge, prepare and verify playbooks.
An independent review of the diff found one real problem (a stub socket with no loaded service cannot be started), fixed before this push.
Not verified
Molecule (CI only): the stub sockets and the new verify assertions have not run on the image. The stubs are a socket and service pair for rpcbind and telnet, a service only for cups, and a socket only for bluetooth.
The role itself against a real rpcbind, and whether enabled: false on a service also disables its socket for the next boot.
ansible-test sanity ran in the pre-push hook only.
I confirm third-party material is recorded in NOTICE and REUSE.toml, or there is none.
Assisted-by: Claude Code
## What and why
Closes #308
`systemd_hardening` looked up and acted on `<name>.service` only. A service whose socket unit stays active is started again by the next connection to its port, so disabling or masking only the service does not make it unreachable (`rpcbind` listens on port 111 through `rpcbind.socket`). The role now looks up every listed name as a socket and as a service in the same single `systemctl show`, and acts on each installed unit, socket first. A name may carry a `.service` or `.socket` suffix.
**Behaviour change:** a socket that belongs to a listed name (with the default lists: `rpcbind.socket`, and `avahi-daemon.socket` and `cups.socket` where they exist) is now stopped and disabled, or masked, where before it was left alone. A name with only a service, only a socket, or neither is fine. The README notes that `systemctl disable` does nothing for a static unit.
## Verified
- The systemd behaviour the issue describes, on an Ubuntu 24.04 VM (systemd 255) with a throwaway socket and service pair: stopping the service alone leaves the port listening and the next connection restarts it; stopping the socket first closes the port (ConnectionRefused). This used `systemctl` directly, not the role.
- The lookup and loop expressions, rendered with Ansible's own engine: suffix variants and duplicates fold into one name, the socket comes first, only installed units remain, and the positional pairing keeps the right names.
- All commit-stage hooks pass (yamllint, ansible-lint, REUSE, changelog lint, Conventional Commit). `--syntax-check` passes on the converge, prepare and verify playbooks.
- An independent review of the diff found one real problem (a stub socket with no loaded service cannot be started), fixed before this push.
## Not verified
- Molecule (CI only): the stub sockets and the new verify assertions have not run on the image. The stubs are a socket and service pair for `rpcbind` and `telnet`, a service only for `cups`, and a socket only for `bluetooth`.
- The role itself against a real `rpcbind`, and whether `enabled: false` on a service also disables its socket for the next boot.
- `ansible-test sanity` ran in the pre-push hook only.
---
- [x] I confirm third-party material is recorded in `NOTICE` and `REUSE.toml`, or there is none.
Assisted-by: Claude Code
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
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
What and why
Closes #308
systemd_hardeninglooked up and acted on<name>.serviceonly. A service whose socket unit stays active is started again by the next connection to its port, so disabling or masking only the service does not make it unreachable (rpcbindlistens on port 111 throughrpcbind.socket). The role now looks up every listed name as a socket and as a service in the same singlesystemctl show, and acts on each installed unit, socket first. A name may carry a.serviceor.socketsuffix.Behaviour change: a socket that belongs to a listed name (with the default lists:
rpcbind.socket, andavahi-daemon.socketandcups.socketwhere they exist) is now stopped and disabled, or masked, where before it was left alone. A name with only a service, only a socket, or neither is fine. The README notes thatsystemctl disabledoes nothing for a static unit.Verified
systemctldirectly, not the role.--syntax-checkpasses on the converge, prepare and verify playbooks.Not verified
rpcbindandtelnet, a service only forcups, and a socket only forbluetooth.rpcbind, and whetherenabled: falseon a service also disables its socket for the next boot.ansible-test sanityran in the pre-push hook only.NOTICEandREUSE.toml, or there is none.Assisted-by: Claude Code