Files
Kamino/roles/systemd_hardening/molecule/default/verify.yml
T
Defame1297andClaude Sonnet 5.5 cf8f4b5bf0
Build / build (pull_request) Successful in 10s
Lint / lint (pull_request) Successful in 17s
Molecule / molecule (pull_request) Successful in 4m43s
feat(roles): add the systemd_hardening and network_interfaces roles
Copied from the environment repository's roles and scrubbed for the
Collection: galaxy namespace mortis, molecule scenarios call the roles by
their FQCN and take their paths from the workflow, README examples use
mortis.kamino.* and documentation addresses, repository-local references
(issue numbers, ADRs, inventory paths) are dropped. network_interfaces
loses its Legacy name guard and the molecule play that tested it: the
guard only protected the in-repo rename, and a new consumer never had the
old names. mock_roles in .ansible-lint lists both FQCNs.

Not verified locally: the molecule scenarios (they run on the
kamino-molecule runner in CI) and ansible-test sanity.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
2026-11-10 15:09:48 +00:00

66 lines
2.5 KiB
YAML

---
# 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