fix(system_baseline): refuse ICMP redirects on every interface
Build / build (pull_request) Successful in 28s
Molecule / select (pull_request) Successful in 8s
Lint / lint (pull_request) Successful in 2m23s
Molecule / scenarios (pull_request) Successful in 10m38s
Molecule / Result (pull_request) Successful in 1s

With forwarding off the kernel accepts redirects when either `all` or the
interface's own value is 1, and over IPv6 only the interface's value counts.
The profiles now also set `default` and, with a wildcard, every existing
interface, over IPv4 and IPv6.

Refs #511

Assisted-by: Claude Code:claude-opus-5-5
This commit is contained in:
Defame1297 committed 2026-12-03 17:44:02 +00:00
1 parent d88e5d237a
commit 74e574ee80
6 files changed
+163 -5

No files matched your search

@@ -865,7 +865,13 @@
- net.ipv4.tcp_syncookies=1
- net.ipv4.conf.all.accept_source_route=0
- net.ipv4.conf.all.accept_redirects=0
- net.ipv4.conf.default.accept_redirects=0
- net.ipv4.conf.*.accept_redirects=0
- net.ipv4.conf.all.secure_redirects=0
- net.ipv4.conf.default.secure_redirects=0
- net.ipv6.conf.all.accept_redirects=0
- net.ipv6.conf.default.accept_redirects=0
- net.ipv6.conf.*.accept_redirects=0
- net.ipv4.icmp_echo_ignore_broadcasts=1
- net.ipv4.icmp_ignore_bogus_error_responses=1
@@ -954,6 +960,85 @@
that: ansible_failed_task.name is search('Apply the sysctl hardening settings')
quiet: true
# The container can inherit the runner host's values. The interfaces share the value of `default`; `all` has its own.
- name: Read the live arp_accept values
ansible.builtin.command:
argv: [cat, /proc/sys/net/ipv4/conf/all/arp_accept, /proc/sys/net/ipv4/conf/default/arp_accept]
register: system_baseline_verify_sysctl_arp
changed_when: false
- name: Apply a wildcard value that every interface already has
ansible.builtin.include_role:
name: mortis.kamino.system_baseline
tasks_from: sysctl_apply
vars:
system_baseline_sysctl_hardening:
- { name: net.ipv4.conf.all.arp_accept, value: "{{ system_baseline_verify_sysctl_arp.stdout_lines[0] }}" }
- { name: "net.ipv4.conf.*.arp_accept", value: "{{ system_baseline_verify_sysctl_arp.stdout_lines[1] }}" }
- name: No interface was changed
ansible.builtin.assert:
that: __system_baseline_sysctl_wildcard_apply is not changed
quiet: true
- name: Preview a different wildcard value in check mode
check_mode: true
block:
- name: Include system_baseline, tasks_from sysctl_apply
ansible.builtin.include_role:
name: mortis.kamino.system_baseline
tasks_from: sysctl_apply
vars:
system_baseline_sysctl_hardening:
- { name: net.ipv4.conf.all.arp_accept, value: "{{ system_baseline_verify_sysctl_arp.stdout_lines[0] }}" }
- { name: "net.ipv4.conf.*.arp_accept", value: "{{ (system_baseline_verify_sysctl_arp.stdout_lines[1] == '0') | ternary(1, 0) }}" }
- name: The pending change covers the interfaces and not the key with its own entry
ansible.builtin.assert:
that:
- __system_baseline_sysctl_wildcard_apply is changed
- system_baseline_verify_sysctl_cmd is search('net.ipv4.conf.lo.arp_accept=')
- system_baseline_verify_sysctl_cmd is not search('net.ipv4.conf.all.arp_accept=')
quiet: true
vars:
system_baseline_verify_sysctl_cmd: "{{ __system_baseline_sysctl_wildcard_apply.results[0].cmd | join(' ') }}"
- name: Apply a wildcard value that cannot be set
block:
- name: Include system_baseline, tasks_from sysctl_apply
ansible.builtin.include_role:
name: mortis.kamino.system_baseline
tasks_from: sysctl_apply
vars:
system_baseline_sysctl_hardening:
- { name: "net.ipv4.conf.*.arp_accept", value: "{{ (system_baseline_verify_sysctl_arp.stdout_lines[1] == '0') | ternary(1, 0) }}" }
- name: Unreachable when a refused wildcard value fails
ansible.builtin.fail:
msg: system_baseline ignored a sysctl wildcard that could not be set
rescue:
- name: The refused wildcard write stopped the play
ansible.builtin.assert:
that: ansible_failed_task.name is search('Apply the sysctl wildcards')
quiet: true
- name: Apply a wildcard that matches no key
block:
- name: Include system_baseline, tasks_from sysctl_apply
ansible.builtin.include_role:
name: mortis.kamino.system_baseline
tasks_from: sysctl_apply
vars:
system_baseline_sysctl_hardening:
- { name: "net.ipv4.conf.*.accept_redirect", value: 0 }
- name: Unreachable when a wildcard without a match fails
ansible.builtin.fail:
msg: system_baseline ignored a sysctl wildcard that matches no key
rescue:
- name: The wildcard without a match stopped the play
ansible.builtin.assert:
that: ansible_failed_task.name is search('Read the live values a wildcard matches')
quiet: true
# An empty system_baseline_journal_max_use leaves journald alone: with the drop-in gone, the role neither writes it again nor restarts
# systemd-journald. It runs last, because it applies the role with its defaults (the converge's tmux autostart and apt-daily timeout are
# not set here) and the checks above read what the converge wrote.