2 Commits
Author SHA1 Message Date
Defame1297 422f5487d7 Merge branch 'main' into renovate/pip-compile-refresh
Build / build (pull_request) Successful in 16s
Lint / lint (pull_request) Failing after 56s
Molecule / molecule (pull_request) Successful in 1s
2026-11-23 07:49:00 +00:00
renovate-bot fa678ec13a chore(deps): refresh pip-compile outputs
renovate/stability-days Updates have met minimum release age requirement
Build / build (pull_request) Successful in 22s
Lint / lint (pull_request) Successful in 1m19s
Molecule / molecule (pull_request) Successful in 1s
2026-11-23 03:18:44 +00:00
17 changed files with 46 additions and 154 deletions

No files matched your search

-5
View File
@@ -1,8 +1,3 @@
{
"attribution": {
"commit": "Assisted-by: Claude Code",
"pr": "Assisted-by: Claude Code",
"sessionUrl": false
},
"disableSkillShellExecution": true
}
+1 -1
View File
@@ -87,7 +87,7 @@ jobs:
dockerfile: Dockerfile
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
- name: ci
version: 0.2.35
version: 0.2.34
subpath: ""
dockerfile: images/ci/Dockerfile
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
-16
View File
@@ -4,22 +4,6 @@ mortis.kamino Release Notes
.. contents:: Topics
v1.10.2
=======
Bugfixes
--------
- systemd_hardening - Disable and mask the socket of a listed service as well. A service whose socket stayed active was started again by the next connection to its port (``rpcbind`` listens on port 111 through ``rpcbind.socket``). Every name in the disable and mask lists is now looked up as a socket and as a service, with or without a ``.service`` or ``.socket`` suffix, and each installed unit is acted on, the socket first. A socket that belongs to a listed name, such as ``rpcbind.socket``, is now stopped and disabled, or masked, where before it was left alone.
v1.10.1
=======
Bugfixes
--------
- systemd_hardening - Look up the listed units with one ``systemctl show`` instead of listing every unit file. The listing can keep PID 1 busy for seconds on a host with slow storage, and the cost grows with the number of unit files. A unit is still skipped when it has no unit file. An instance name such as ``[email protected]`` is now matched when its template exists, and a template name such as ``[email protected]`` in the lists now makes the lookup fail instead of matching.
v1.10.0
=======
+2 -2
View File
@@ -4,7 +4,7 @@ An Ansible Collection of reusable, hardened roles for a self-hosted home lab:
Linux baseline, firewall, SSH, user management and, in later releases, Proxmox,
Gitea and Gitea Actions runner roles.
Status: roles arrive in waves. Release 1.10.2 holds the `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`, `sshd`, `system_baseline`, `systemd_hardening`, `traefik`, `ufw` and `user_management` roles (and the internal `_binary_update`, which `gitea`, `gitea_runner` and `traefik` call).
Status: roles arrive in waves. Release 1.10.0 holds the `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`, `sshd`, `system_baseline`, `systemd_hardening`, `traefik`, `ufw` and `user_management` roles (and the internal `_binary_update`, which `gitea`, `gitea_runner` and `traefik` call).
## Consuming
@@ -16,7 +16,7 @@ name (FQCN) only, `mortis.kamino.<role>`:
collections:
- name: https://git.rkdr.net/mortis/kamino.git
type: git
version: v1.10.2
version: v1.10.0
```
Its dependencies (`community.general`, `ansible.posix`) are declared in `galaxy.yml`, so
+1 -1
View File
@@ -66,4 +66,4 @@ plugins:
strategy: {}
test: {}
vars: {}
version: 1.10.2
version: 1.10.0
-27
View File
@@ -58,33 +58,6 @@ releases:
- gitea-release-key-check.yml
- gitea-runner-role.yml
release_date: '2026-11-22'
1.10.1:
changes:
bugfixes:
- systemd_hardening - Look up the listed units with one ``systemctl show`` instead
of listing every unit file. The listing can keep PID 1 busy for seconds on
a host with slow storage, and the cost grows with the number of unit files.
A unit is still skipped when it has no unit file. An instance name such as
``[email protected]`` is now matched when its template exists, and a template
name such as ``[email protected]`` in the lists now makes the lookup fail instead
of matching.
fragments:
- systemd-hardening-unit-lookup.yml
release_date: '2026-11-23'
1.10.2:
changes:
bugfixes:
- systemd_hardening - Disable and mask the socket of a listed service as well.
A service whose socket stayed active was started again by the next connection
to its port (``rpcbind`` listens on port 111 through ``rpcbind.socket``).
Every name in the disable and mask lists is now looked up as a socket and
as a service, with or without a ``.service`` or ``.socket`` suffix, and each
installed unit is acted on, the socket first. A socket that belongs to a listed
name, such as ``rpcbind.socket``, is now stopped and disabled, or masked,
where before it was left alone.
fragments:
- systemd-hardening-sockets.yml
release_date: '2026-11-23'
1.2.0:
changes:
minor_changes:
@@ -0,0 +1,8 @@
---
bugfixes:
- >-
systemd_hardening - Look up the listed units with one ``systemctl show`` instead of listing every unit
file. The listing can keep PID 1 busy for seconds on a host with slow storage, and the cost grows with
the number of unit files. A unit is still skipped when it has no unit file. An instance name such as
``[email protected]`` is now matched when its template exists, and a template name such as
``[email protected]`` in the lists now makes the lookup fail instead of matching.
+1 -1
View File
@@ -1,7 +1,7 @@
---
namespace: mortis
name: kamino
version: 1.10.2
version: 1.10.0
readme: README.md
authors:
- Defame1297
+2 -3
View File
@@ -4,7 +4,7 @@ Disables and masks risky services, writes a systemd manager hardening drop-in an
## Supported platforms
Hosts with systemd: Ubuntu 24.04 (noble) LXCs, Ubuntu 22.04 (jammy) VMs and Debian 13 (trixie) Proxmox hosts. The role is applied to the three system types in `systemd_hardening_profiles`: `pve` (Proxmox hosts), `ubuntu_lxc` and `ubuntu_vm`. The molecule scenario (`molecule/default/`, CI only) runs the `ubuntu_lxc` profile on Ubuntu 24.04 against stub unit files (a socket and a service for the ones that ship both, a service only and a socket only for the others), because the test image installs none of the services the role disables or masks. It checks that the stub sockets and services end up stopped and disabled or masked, that a listed unit that does not exist is skipped, the manager and service drop-ins (loaded by systemd after the reload) and the refusals; it cannot show that a real `rpcbind` or similar stops. The `pve` and `ubuntu_vm` profiles and Ubuntu 22.04 and Debian 13 are not verified by a test.
Hosts with systemd: Ubuntu 24.04 (noble) LXCs, Ubuntu 22.04 (jammy) VMs and Debian 13 (trixie) Proxmox hosts. The role is applied to the three system types in `systemd_hardening_profiles`: `pve` (Proxmox hosts), `ubuntu_lxc` and `ubuntu_vm`. The molecule scenario (`molecule/default/`, CI only) runs the `ubuntu_lxc` profile on Ubuntu 24.04 against stub unit files, because the test image installs none of the services the role disables or masks. It checks the disable and mask results, the manager and service drop-ins (loaded by systemd after the reload) and the refusals; it cannot show that a real `rpcbind` or similar stops. The `pve` and `ubuntu_vm` profiles and Ubuntu 22.04 and Debian 13 are not verified by a test.
## Requirements and run order
@@ -49,8 +49,7 @@ Only `always` (the `systemd_hardening_system_type` assert) works as intended. `d
## Notes
- Every name in `systemd_hardening_disable_services` and `systemd_hardening_mask_services` is looked up as a socket and as a service, with or without the `.service` or `.socket` suffix. Only units that systemd has a unit file for (`LoadState` is not `not-found`) are disabled or masked, the socket first: a stopped service whose socket still listens is started again by the next connection. A name with only a service, only a socket, or neither is fine. The role asks about the listed units only, with one `systemctl show`, and does not list every unit file. A template name such as `[email protected]` is not supported: that call fails.
- `systemctl disable` does nothing for a static unit (one with no `[Install]` section), so the systemd module can report `changed` on every run for it; list only names whose units can be enabled, and note that this now applies to a listed name's socket as well.
- Only units that systemd has a unit file for (`LoadState` is not `not-found`) are disabled or masked, with or without the `.service` suffix. The role asks about the listed units only, with one `systemctl show`, and does not list every unit file. A template name such as `[email protected]` is not supported: that call fails.
- The manager drop-in (`DefaultLimitNOFILE`, `DefaultLimitNPROC`, `DefaultLimitCORE`, and task, memory and CPU accounting) is written verbatim by `tasks/harden_manager.yml` and has no variable.
- Drop-in and manager changes notify `systemd reload`, which runs `daemon-reload`. Handlers are flushed at the end of the role.
- Policy lives in defaults, not `vars/`, so group_vars and host_vars can override it.
@@ -7,9 +7,7 @@ argument_specs:
Validates C(systemd_hardening_system_type) against C(systemd_hardening_profiles), then disables the unwanted services and masks the high-risk
services that have an installed unit file, writes C(/etc/systemd/system.conf.d/hardening.conf) and renders a drop-in for every
unit in C(systemd_hardening_services).
- >-
Every listed name is handled as a socket and as a service, the socket first; units that are not installed are skipped.
Handlers are flushed at the end of the role.
- Units that are not installed are skipped. Handlers are flushed at the end of the role.
- >-
The role also reads C(systemd_hardening_disable_services_extra) (default is the profile entry for C(systemd_hardening_system_type)) and the
derived C(systemd_hardening_disable_services_effective) (the base list plus the extra list, a result, do not set it). They are
@@ -37,17 +35,13 @@ argument_specs:
elements: str
default: [rpcbind, avahi-daemon, cups, bluetooth, nfs-server]
description:
- >-
Services stopped and disabled on every system type, with or without the C(.service) or C(.socket) suffix, together with the
socket of the same name. Only installed units are touched.
- Services stopped and disabled on every system type, with or without the C(.service) suffix. Only installed units are touched.
systemd_hardening_mask_services:
type: list
elements: str
default: [telnet, rsh, rlogin, xinetd]
description:
- >-
Services masked and stopped, with or without the C(.service) or C(.socket) suffix, together with the socket of the same name.
Only installed units are touched.
- Services masked and stopped. Only installed units are touched.
systemd_hardening_services:
type: dict
default: {}
@@ -1,12 +1,8 @@
---
# The image installs none of the services the role touches, so the units it acts on are
# stubs in /usr/lib/systemd/system (not /etc: `systemctl mask` refuses to replace a regular
# file there). rpcbind and telnet are a socket and a service each, as the real packages ship them;
# cups has only a service and bluetooth only a socket (its Service= is a stub of another name:
# systemd refuses to start a socket whose service is not loaded), so the role meets every shape. The sockets
# listen on a unix socket under /run and are started, so the role has something to stop. rpcbind,
# cups and bluetooth are enabled so the role has something to disable; telnet only needs to
# exist; testsvc receives the drop-in.
# file there). Nothing is started. rpcbind is enabled so the role has something to
# disable; telnet only needs to exist; testsvc receives the drop-in.
- name: Prepare
hosts: all
gather_facts: false
@@ -26,35 +22,10 @@
owner: root
group: root
mode: "0644"
loop: [rpcbind, telnet, cups, testsvc, molecule-bluetooth-target]
loop: [rpcbind, telnet, testsvc]
- name: Install the stub socket unit files
ansible.builtin.copy:
dest: "/usr/lib/systemd/system/{{ item }}.socket"
content: |
[Unit]
Description=molecule stub socket for {{ item }}
[Socket]
ListenStream=/run/molecule-{{ item }}.sock
{% if item == 'bluetooth' %}
Service=molecule-bluetooth-target.service
{% endif %}
[Install]
WantedBy=sockets.target
owner: root
group: root
mode: "0644"
loop: [rpcbind, telnet, bluetooth]
- name: Reload systemd
- name: Enable rpcbind and reload systemd
ansible.builtin.systemd:
daemon_reload: true
- name: Enable and start the stub sockets and services
ansible.builtin.systemd:
name: "{{ item }}"
name: rpcbind
enabled: true
state: started
loop: [rpcbind.socket, telnet.socket, bluetooth.socket, rpcbind.service, cups.service, telnet.service]
daemon_reload: true
@@ -8,45 +8,28 @@
tasks:
- name: Ask systemd about the stub units
ansible.builtin.systemd:
name: "{{ item }}"
loop: [rpcbind.socket, rpcbind.service, cups.service, bluetooth.socket, telnet.socket, telnet.service]
name: "{{ item }}.service"
loop: [rpcbind, telnet]
register: systemd_hardening_verify_units
check_mode: true
- name: The disabled units, sockets and services alike, are disabled and stopped
- name: The disabled unit is disabled and the masked unit is masked
ansible.builtin.assert:
that:
- item.status.UnitFileState == "disabled"
- item.status.ActiveState == "inactive"
- systemd_hardening_verify_units.results[0].status.UnitFileState == "disabled"
- systemd_hardening_verify_units.results[1].status.UnitFileState == "masked"
quiet: true
loop: "{{ systemd_hardening_verify_units.results | rejectattr('item', 'match', '^telnet[.]') | list }}"
loop_control:
label: "{{ item.item }}"
- 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
- 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
changed_when: false
- name: The missing units were skipped, not masked or created
- name: The missing unit was skipped, not masked
ansible.builtin.assert:
that:
- item.stdout == "LoadState=not-found"
- systemd_hardening_verify_missing.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:
@@ -1,12 +1,11 @@
---
# Every installed socket and service of a listed name is stopped and disabled, the socket first: a
# stopped service whose socket is still listening is started again by the next connection.
- name: Disable unwanted services if present
become: true
ansible.builtin.systemd:
name: "{{ item }}"
enabled: false
state: stopped
loop: >-
{{ systemd_hardening_disable_services_effective | map('regex_replace', '[.](service|socket)$', '') | unique
| product(['socket', 'service']) | map('join', '.') | select('in', systemd_hardening_installed_units) | list }}
loop: "{{ systemd_hardening_disable_services_effective }}"
# Only act on installed units; items may be given with or without the
# ".service" suffix.
when: (item | regex_replace('\.service$', '') ~ '.service') in systemd_hardening_installed_units
+5 -9
View File
@@ -25,18 +25,14 @@
# prints one block per argument in the order given, `LoadState=not-found` for a unit with no unit
# file, and keeps the order for an alias. Not service_facts: it sets a fact named `services`, which
# overrides an inventory variable of that name.
# Every listed name is looked up as a socket and as a service, socket first: stopping a service
# whose socket is still listening does not close the port, systemd starts the service again on the
# next connection. A name may be given with or without .service or .socket.
- name: Find which of the listed units are installed
- name: Find which of the listed service units are installed
tags: [disable, mask]
vars:
__systemd_hardening_probe_units: >-
{{ (systemd_hardening_disable_services_effective + systemd_hardening_mask_services)
| map('regex_replace', '[.](service|socket)$', '') | unique
| product(['socket', 'service']) | map('join', '.') | list }}
| map('regex_replace', '[.]service$', '') | unique | map('regex_replace', '$', '.service') | list }}
block:
- name: Look up the listed units # noqa: command-instead-of-module
- name: Look up the listed service units # noqa: command-instead-of-module
become: true
ansible.builtin.command:
argv: "{{ ['systemctl', 'show', '--property=LoadState', '--'] + __systemd_hardening_probe_units }}"
@@ -45,7 +41,7 @@
check_mode: false
when: __systemd_hardening_probe_units | length > 0
- name: Set installed units
- name: Set installed service units
ansible.builtin.set_fact:
systemd_hardening_installed_units: >-
{{ __systemd_hardening_probe_units | zip(__systemd_hardening_probe_states)
@@ -54,7 +50,7 @@
__systemd_hardening_probe_states: "{{ (__systemd_hardening_probe.stdout | default('')).strip().split('\n\n') }}"
when: __systemd_hardening_probe_units | length > 0
- name: Set no installed units
- name: Set no installed service units
ansible.builtin.set_fact:
systemd_hardening_installed_units: []
when: __systemd_hardening_probe_units | length == 0
@@ -1,12 +1,10 @@
---
# Same shape as disable_services.yml: every installed socket and service of a listed name is masked, the socket first.
# A unit that is not installed can't be started, so masking it is unnecessary.
- name: Mask high-risk services
become: true
ansible.builtin.systemd:
name: "{{ item }}"
masked: true
state: stopped
loop: >-
{{ systemd_hardening_mask_services | map('regex_replace', '[.](service|socket)$', '') | unique
| product(['socket', 'service']) | map('join', '.') | select('in', systemd_hardening_installed_units) | list }}
loop: "{{ systemd_hardening_mask_services }}"
# A unit that isn't installed can't be started, so masking it is unnecessary.
when: (item | regex_replace('\.service$', '') ~ '.service') in systemd_hardening_installed_units
-1
View File
@@ -85,7 +85,6 @@ IGNORED = (
"ruff.toml",
"apm.yml",
"apm.lock.yaml",
".claude/*",
"tests/sanity/*",
"tests/scripts/*",
"images/*",
@@ -172,13 +172,6 @@ class SelectTest(unittest.TestCase):
)
self.assertEqual(chosen, [])
def test_agent_tool_settings_select_nothing(self):
# Claude Code reads .claude/ on a contributor's machine; no scenario reads it.
chosen, _reason = self.select(
[".claude/settings.json", ".claude/hooks/guard.sh"],
)
self.assertEqual(chosen, [])
def test_role_readme_selects_nothing(self):
# A role's README is documentation; its scenarios and its users' do not read it.
chosen, _reason = self.select(["roles/docker/README.md"])