Compare commits
54
Commits
fee8ec1ff6
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b3aaf9062d | ||
|
|
f32e6930f5 | ||
|
|
704a5d9389 | ||
|
|
a6e1657363 | ||
|
|
e5a56b61d9 | ||
|
|
08078324c9 | ||
|
|
c2a2a1ea0e | ||
|
|
27f6635cc1 | ||
|
|
e8eee3be55 | ||
|
|
37fc48275d | ||
|
|
cc9cc6d34f | ||
|
|
975beccf50 | ||
|
|
3290d843cc | ||
|
|
4abfea352c | ||
|
|
b74598d265 | ||
|
|
483f3890e5 | ||
|
|
79943e0389 | ||
|
|
252c703afd | ||
|
|
1d10f2be39 | ||
|
|
6a1e7b77e7 | ||
|
|
ce851f59c6 | ||
|
|
6334820750 | ||
|
|
f60a2c7e1f | ||
|
|
b23466f588 | ||
|
|
74a0af2d32 | ||
|
|
c30b3d1f0a | ||
|
|
e5922692f6 | ||
|
|
bacb16b7b2 | ||
|
|
c7c9f6d5d1 | ||
|
|
0267db247e | ||
|
|
add568a242 | ||
|
|
ca34bd8363 | ||
|
|
f92b36ceaa | ||
|
|
32651402c6 | ||
|
|
0abc9fb1c3 | ||
|
|
c1c71194c6 | ||
|
|
66657f3917 | ||
|
|
e1b5639d65 | ||
|
|
7a260afe39 | ||
|
|
78a370dbd1 | ||
|
|
f67edd7a07 | ||
|
|
7464f4da0a | ||
|
|
923cd85020 | ||
|
|
61db0ed55e | ||
|
|
03fc22daf7 | ||
|
|
7604bc4dac | ||
|
|
46fd6a4c40 | ||
|
|
ec64ace8f4 | ||
|
|
5318997b73 | ||
|
|
4fbc4ad317 | ||
|
|
470d856332 | ||
|
|
589f899bae | ||
|
|
c2c8934ec9 | ||
|
|
5c0783cf86 |
@@ -0,0 +1,2 @@
|
|||||||
|
# Directory the node exporter reads textfile metrics from (the Debian default).
|
||||||
|
apt_updates_textfile_dir: /var/lib/prometheus/node-exporter
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
# The metrics run after apt-daily (update) and apt-daily-upgrade (upgrade), so they show the state apt
|
||||||
|
# just reached without a timer of their own. The "-" lets a failing metrics run leave apt's units green.
|
||||||
|
- name: Create the textfile directory
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ apt_updates_textfile_dir }}"
|
||||||
|
state: directory
|
||||||
|
mode: "0755"
|
||||||
|
|
||||||
|
- name: Install the apt metrics script
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: apt-updates-metrics.j2
|
||||||
|
dest: /usr/local/sbin/apt-updates-metrics
|
||||||
|
mode: "0755"
|
||||||
|
register: apt_updates_script
|
||||||
|
|
||||||
|
- name: Create the apt timers' drop-in directories
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /etc/systemd/system/{{ item }}.service.d
|
||||||
|
state: directory
|
||||||
|
mode: "0755"
|
||||||
|
loop:
|
||||||
|
- apt-daily
|
||||||
|
- apt-daily-upgrade
|
||||||
|
|
||||||
|
- name: Run the apt metrics after the apt timers' services
|
||||||
|
ansible.builtin.copy:
|
||||||
|
dest: /etc/systemd/system/{{ item }}.service.d/apt-updates-metrics.conf
|
||||||
|
mode: "0644"
|
||||||
|
content: |
|
||||||
|
[Service]
|
||||||
|
ExecStartPost=-/usr/local/sbin/apt-updates-metrics
|
||||||
|
loop:
|
||||||
|
- apt-daily
|
||||||
|
- apt-daily-upgrade
|
||||||
|
register: apt_updates_dropins
|
||||||
|
|
||||||
|
- name: Reload systemd after the apt metrics drop-ins
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
daemon_reload: true
|
||||||
|
when: apt_updates_dropins.changed
|
||||||
|
# Check mode does not write the drop-ins.
|
||||||
|
ignore_errors: "{{ ansible_check_mode }}"
|
||||||
|
|
||||||
|
# Debian's prometheus-node-exporter-apt collector writes apt.prom with the same metric families as this role under
|
||||||
|
# other HELP texts; node_exporter drops the rows of both files then. This role owns the apt metrics, so the
|
||||||
|
# collector stays off and its file, also a stale leftover of a removed collector, goes away.
|
||||||
|
- name: Look for the Debian apt metrics collector
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: /lib/systemd/system/prometheus-node-exporter-apt.timer
|
||||||
|
register: apt_updates_debian_collector
|
||||||
|
|
||||||
|
- name: Stop and disable the Debian apt metrics collector timer
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
name: prometheus-node-exporter-apt.timer
|
||||||
|
enabled: false
|
||||||
|
state: stopped
|
||||||
|
when: apt_updates_debian_collector.stat.exists
|
||||||
|
|
||||||
|
- name: Stop the Debian apt metrics collector service
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
name: prometheus-node-exporter-apt.service
|
||||||
|
state: stopped
|
||||||
|
when: apt_updates_debian_collector.stat.exists
|
||||||
|
|
||||||
|
- name: Remove the Debian apt metrics collector output
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ apt_updates_textfile_dir }}/apt.prom"
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
# The timers' drop-ins write the metrics after the next apt run; this gives a new host and a changed script
|
||||||
|
# current metrics at once.
|
||||||
|
- name: Look for the apt metrics file
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: "{{ apt_updates_textfile_dir }}/apt_updates.prom"
|
||||||
|
register: apt_updates_prom
|
||||||
|
|
||||||
|
- name: Write the apt metrics
|
||||||
|
ansible.builtin.command: /usr/local/sbin/apt-updates-metrics
|
||||||
|
when: apt_updates_script.changed or not apt_updates_prom.stat.exists
|
||||||
|
changed_when: true
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Pending upgrades, held packages, reboot flag and age of the package lists as node exporter textfile
|
||||||
|
# metrics. apt-daily and apt-daily-upgrade run it after their update and upgrade (drop-ins).
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
host={{ inventory_hostname }}
|
||||||
|
textfile_dir={{ apt_updates_textfile_dir }}
|
||||||
|
out=$textfile_dir/apt_updates.prom
|
||||||
|
tmp=$(mktemp "$textfile_dir/.apt_updates.XXXXXX")
|
||||||
|
trap 'rm -f "$tmp"' EXIT
|
||||||
|
|
||||||
|
# Architectures a pending package can have: the native and foreign ones, plus "all" for architecture-independent
|
||||||
|
# packages. Each gets a row per kind even at 0, so a resolved backlog reads as 0 and not as a vanished series.
|
||||||
|
archs="$(dpkg --print-architecture) $(dpkg --print-foreign-architectures | tr '\n' ' ') all"
|
||||||
|
|
||||||
|
# The simulated upgrade lists "Inst <package> [<installed>] (<candidate> <origins> [<arch>])" per package. The candidate
|
||||||
|
# is the newest version, which can come from regular updates while an older, still newer-than-installed version came
|
||||||
|
# from the security archive. So a package counts as security when any version above the installed one in its
|
||||||
|
# "apt-cache policy" table (newest first, installed marked with ***) has a security origin, everything else as regular.
|
||||||
|
sim=$(apt-get -s upgrade)
|
||||||
|
names=$(awk '/^Inst / { print $2 }' <<< "$sim")
|
||||||
|
security=""
|
||||||
|
if [[ -n $names ]]; then
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
security=$(apt-cache policy $names | awk '
|
||||||
|
/^[^ ]/ { pkg = $1; sub(/:$/, "", pkg); newer = 1; next }
|
||||||
|
/^ \*\*\* / { newer = 0; next }
|
||||||
|
/^ [0-9]+ / { if (newer && tolower($0) ~ /security/) print pkg }
|
||||||
|
')
|
||||||
|
fi
|
||||||
|
|
||||||
|
pending=$(SECURITY="$security" awk -v host="$host" -v archs="$archs" '
|
||||||
|
BEGIN {
|
||||||
|
n = split(ENVIRON["SECURITY"], s, "\n")
|
||||||
|
for (i = 1; i <= n; i++) sec[s[i]] = 1
|
||||||
|
}
|
||||||
|
/^Inst / {
|
||||||
|
line = $0
|
||||||
|
sub(/^[^(]*\(/, "", line)
|
||||||
|
sub(/\).*$/, "", line)
|
||||||
|
n = split(line, f, " ")
|
||||||
|
pkg_arch = f[n]
|
||||||
|
gsub(/\[|\]/, "", pkg_arch)
|
||||||
|
kind = ($2 in sec) ? "security" : "regular"
|
||||||
|
count[kind, pkg_arch]++
|
||||||
|
}
|
||||||
|
END {
|
||||||
|
split(archs, a, " ")
|
||||||
|
for (i in a) {
|
||||||
|
if (!(("security", a[i]) in count)) count["security", a[i]] = 0
|
||||||
|
if (!(("regular", a[i]) in count)) count["regular", a[i]] = 0
|
||||||
|
}
|
||||||
|
for (key in count) {
|
||||||
|
split(key, k, SUBSEP)
|
||||||
|
printf "apt_upgrades_pending{host=\"%s\",origin=\"%s\",arch=\"%s\"} %d\n", host, k[1], k[2], count[key]
|
||||||
|
}
|
||||||
|
}' <<< "$sim")
|
||||||
|
|
||||||
|
held=$(apt-mark showhold | wc -l)
|
||||||
|
|
||||||
|
reboot=0
|
||||||
|
if [[ -e /run/reboot-required ]]; then
|
||||||
|
reboot=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Debian writes update-stamp, Ubuntu update-success-stamp; both are touched by a successful update. Both are missing
|
||||||
|
# until apt.systemd.daily has run an update, then the package cache stands in.
|
||||||
|
stamp=/var/lib/apt/periodic/update-success-stamp
|
||||||
|
if [[ ! -e $stamp ]]; then
|
||||||
|
stamp=/var/lib/apt/periodic/update-stamp
|
||||||
|
fi
|
||||||
|
if [[ ! -e $stamp ]]; then
|
||||||
|
stamp=/var/cache/apt/pkgcache.bin
|
||||||
|
fi
|
||||||
|
cache=$(stat -c %Y "$stamp")
|
||||||
|
|
||||||
|
{
|
||||||
|
echo '# TYPE apt_upgrades_pending gauge'
|
||||||
|
echo "$pending"
|
||||||
|
echo '# TYPE apt_upgrades_held gauge'
|
||||||
|
echo "apt_upgrades_held{host=\"$host\"} $held"
|
||||||
|
echo '# TYPE node_reboot_required gauge'
|
||||||
|
echo "node_reboot_required{host=\"$host\"} $reboot"
|
||||||
|
echo '# TYPE apt_package_cache_timestamp_seconds gauge'
|
||||||
|
echo "apt_package_cache_timestamp_seconds{host=\"$host\"} $cache"
|
||||||
|
} > "$tmp"
|
||||||
|
|
||||||
|
chmod 0644 "$tmp"
|
||||||
|
mv -f "$tmp" "$out"
|
||||||
@@ -8,6 +8,8 @@ ipv6_accept_ra_interfaces: []
|
|||||||
disk_maintenance:
|
disk_maintenance:
|
||||||
# systemd OnCalendar for fstrim.timer; unset keeps the distribution schedule.
|
# systemd OnCalendar for fstrim.timer; unset keeps the distribution schedule.
|
||||||
fstrim_on_calendar:
|
fstrim_on_calendar:
|
||||||
|
# Mountpoints fstrim.service trims; unset trims every fstab filesystem.
|
||||||
|
fstrim_mountpoints:
|
||||||
# Cron "minute hour" of the monthly ZFS trim and scrub from zfsutils-linux; unset keeps 00:24.
|
# Cron "minute hour" of the monthly ZFS trim and scrub from zfsutils-linux; unset keeps 00:24.
|
||||||
zfs_cron_time:
|
zfs_cron_time:
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
|
# Only the files of this role that exist: in a container the distribution files hold keys that
|
||||||
|
# are not writable there, and sysctl --system fails on them; -e skips keys a container lacks.
|
||||||
- name: reload_sysctl
|
- name: reload_sysctl
|
||||||
command: sysctl --system
|
shell: >-
|
||||||
|
cd /etc/sysctl.d && sysctl -e -p $(ls
|
||||||
|
ip-forwarding.conf
|
||||||
|
ipv6-slaac-address-generation.conf
|
||||||
|
ipv6-slaac-override.conf
|
||||||
|
tcp-bbr.conf 2>/dev/null)
|
||||||
|
|
||||||
- name: restart_journald
|
- name: restart_journald
|
||||||
systemd:
|
systemd:
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
# With manage_etc_hosts in the user-data (Proxmox sets it) cloud-init rewrites /etc/hosts from its
|
||||||
|
# template on every boot and drops the blocks other roles add; user-data outranks cloud.cfg.d, so
|
||||||
|
# the module is taken out of the boot stage instead.
|
||||||
|
- name: Read the cloud-init configuration
|
||||||
|
slurp:
|
||||||
|
path: /etc/cloud/cloud.cfg
|
||||||
|
register: cloud_cfg
|
||||||
|
failed_when: false
|
||||||
|
|
||||||
|
- name: Keep cloud-init from rewriting /etc/hosts
|
||||||
|
when: cloud_cfg.content is defined
|
||||||
|
copy:
|
||||||
|
dest: /etc/cloud/cloud.cfg.d/99-ansible-etc-hosts.cfg
|
||||||
|
content: |
|
||||||
|
cloud_init_modules: {{ (cloud_cfg.content | b64decode | from_yaml).cloud_init_modules | reject('equalto', 'update_etc_hosts') | list | to_json }}
|
||||||
@@ -25,6 +25,36 @@
|
|||||||
daemon_reload: yes
|
daemon_reload: yes
|
||||||
state: restarted
|
state: restarted
|
||||||
|
|
||||||
|
- name: Create the fstrim service drop-in directory
|
||||||
|
when: disk_maintenance.fstrim_mountpoints | default(none) is not none
|
||||||
|
file:
|
||||||
|
path: /etc/systemd/system/fstrim.service.d
|
||||||
|
state: directory
|
||||||
|
|
||||||
|
- name: Set the fstrim mountpoints
|
||||||
|
when: disk_maintenance.fstrim_mountpoints | default(none) is not none
|
||||||
|
copy:
|
||||||
|
dest: /etc/systemd/system/fstrim.service.d/mountpoints.conf
|
||||||
|
content: |
|
||||||
|
[Service]
|
||||||
|
ExecStart=
|
||||||
|
{% for m in disk_maintenance.fstrim_mountpoints %}
|
||||||
|
ExecStart=/sbin/fstrim --verbose --quiet-unsupported {{ m }}
|
||||||
|
{% endfor %}
|
||||||
|
register: fstrim_mountpoints
|
||||||
|
|
||||||
|
- name: Trim every fstab filesystem
|
||||||
|
when: disk_maintenance.fstrim_mountpoints | default(none) is none
|
||||||
|
file:
|
||||||
|
path: /etc/systemd/system/fstrim.service.d/mountpoints.conf
|
||||||
|
state: absent
|
||||||
|
register: fstrim_mountpoints_removed
|
||||||
|
|
||||||
|
- name: Reload systemd for the fstrim mountpoints
|
||||||
|
when: fstrim_mountpoints.changed or fstrim_mountpoints_removed.changed
|
||||||
|
systemd:
|
||||||
|
daemon_reload: yes
|
||||||
|
|
||||||
- name: Schedule the monthly ZFS trim and scrub
|
- name: Schedule the monthly ZFS trim and scrub
|
||||||
when: disk_maintenance.zfs_cron_time | default(none) is not none
|
when: disk_maintenance.zfs_cron_time | default(none) is not none
|
||||||
lineinfile:
|
lineinfile:
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
- import_tasks: ./timesync.yml
|
- import_tasks: ./timesync.yml
|
||||||
|
|
||||||
|
- import_tasks: ./cloud_init.yml
|
||||||
|
|
||||||
- import_tasks: ./aliases.yml
|
- import_tasks: ./aliases.yml
|
||||||
|
|
||||||
- import_tasks: ./networking.yml
|
- import_tasks: ./networking.yml
|
||||||
|
|||||||
@@ -23,19 +23,16 @@
|
|||||||
|
|
||||||
- name: Generate random IPv6 stable-secret
|
- name: Generate random IPv6 stable-secret
|
||||||
set_fact:
|
set_fact:
|
||||||
ipv6_stable_secret: "{{ 'fd' + (lookup('password', '/dev/null length=30 chars=hex')).split('.')[0][:7] + '::' + (lookup('password', '/dev/null length=4 chars=hex')) }}"
|
ipv6_stable_secret: "{{ lookup('password', '/dev/null length=32 chars=hexdigits') | lower | regex_replace('(.{4})(?!$)', '\\1:') }}"
|
||||||
|
|
||||||
|
# The secret goes first: addr_gen_mode 2 is rejected while the interface has no secret.
|
||||||
- name: Set sysctl settings for ipv6-address-generation
|
- name: Set sysctl settings for ipv6-address-generation
|
||||||
copy:
|
copy:
|
||||||
dest: "/etc/sysctl.d/ipv6-slaac-address-generation.conf"
|
dest: "/etc/sysctl.d/ipv6-slaac-address-generation.conf"
|
||||||
content: |
|
content: |
|
||||||
{% if ansible_facts.default_ipv6.interface is defined %}
|
{% set iface = ansible_facts.default_ipv6.interface | default(ansible_facts.default_ipv4.interface) %}
|
||||||
net.ipv6.conf.{{ ansible_facts.default_ipv6.interface }}.addr_gen_mode = 2
|
net.ipv6.conf.{{ iface }}.stable_secret = {{ ipv6_stable_secret }}
|
||||||
net.ipv6.conf.{{ ansible_facts.default_ipv6.interface }}.stable_secret = {{ ipv6_stable_secret }}
|
net.ipv6.conf.{{ iface }}.addr_gen_mode = 2
|
||||||
{% else %}
|
|
||||||
net.ipv6.conf.{{ ansible_facts.default_ipv4.interface }}.addr_gen_mode = 2
|
|
||||||
net.ipv6.conf.{{ ansible_facts.default_ipv4.interface }}.stable_secret = {{ ipv6_stable_secret }}
|
|
||||||
{% endif %}
|
|
||||||
notify: reload_sysctl
|
notify: reload_sysctl
|
||||||
when:
|
when:
|
||||||
- ansible_facts.default_ipv6 is defined
|
- ansible_facts.default_ipv6 is defined
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
- name: Check if SSH daemon is active
|
- name: Check if SSH daemon is active
|
||||||
systemd:
|
systemd:
|
||||||
name: sshd
|
name: ssh
|
||||||
state: started
|
state: started
|
||||||
register: sshd_status
|
register: sshd_status
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
- name: Restart SSH daemon
|
- name: Restart SSH daemon
|
||||||
service:
|
service:
|
||||||
name: sshd
|
name: ssh
|
||||||
state: restarted
|
state: restarted
|
||||||
when: sshd_config.changed
|
when: sshd_config.changed
|
||||||
when: sshd_status.status.ActiveState == 'active'
|
when: sshd_status.status.ActiveState == 'active'
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ crowdsec:
|
|||||||
scenarios: {}
|
scenarios: {}
|
||||||
# path below /etc/crowdsec -> content, for local parsers and scenarios.
|
# path below /etc/crowdsec -> content, for local parsers and scenarios.
|
||||||
local_files: {}
|
local_files: {}
|
||||||
|
# name -> installed hub scenario removed from the agent (null drops one); needed where a local scenario replaces it.
|
||||||
|
disabled_scenarios: {}
|
||||||
|
# name -> path below /etc/crowdsec of a retired local file, removed when present (null drops one).
|
||||||
|
absent_files: {}
|
||||||
# name -> CIDR (single addresses as /32 or /128) never acted upon. Joined by
|
# name -> CIDR (single addresses as /32 or /128) never acted upon. Joined by
|
||||||
# the public_ips (same format) of every inventory host, then whitelisted by
|
# the public_ips (same format) of every inventory host, then whitelisted by
|
||||||
# this agent and, when lapi_allowlist is set, allowlisted on the LAPI.
|
# this agent and, when lapi_allowlist is set, allowlisted on the LAPI.
|
||||||
|
|||||||
@@ -19,6 +19,14 @@
|
|||||||
dest: /etc/apt/keyrings/crowdsec.asc
|
dest: /etc/apt/keyrings/crowdsec.asc
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
|
|
||||||
|
# A deb822 crowdsec.sources (written by the package or by hand) already
|
||||||
|
# defines the repository; a second crowdsec.list makes apt warn about
|
||||||
|
# duplicate targets.
|
||||||
|
- name: Check for an existing deb822 CrowdSec apt source
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: /etc/apt/sources.list.d/crowdsec.sources
|
||||||
|
register: crowdsec_sources
|
||||||
|
|
||||||
- name: Add the CrowdSec apt repository
|
- name: Add the CrowdSec apt repository
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
dest: /etc/apt/sources.list.d/crowdsec.list
|
dest: /etc/apt/sources.list.d/crowdsec.list
|
||||||
@@ -28,6 +36,7 @@
|
|||||||
https://packagecloud.io/crowdsec/crowdsec/{{ ansible_distribution | lower }}/
|
https://packagecloud.io/crowdsec/crowdsec/{{ ansible_distribution | lower }}/
|
||||||
{{ crowdsec.apt_suite_map[ansible_distribution_release] | default(ansible_distribution_release) }} main
|
{{ crowdsec.apt_suite_map[ansible_distribution_release] | default(ansible_distribution_release) }} main
|
||||||
register: crowdsec_repo
|
register: crowdsec_repo
|
||||||
|
when: not crowdsec_sources.stat.exists
|
||||||
|
|
||||||
# The postinst asks these; without them it registers a local machine for a
|
# The postinst asks these; without them it registers a local machine for a
|
||||||
# local LAPI and enrols in the central CAPI.
|
# local LAPI and enrols in the central CAPI.
|
||||||
@@ -53,6 +62,7 @@
|
|||||||
- /etc/crowdsec/bouncers
|
- /etc/crowdsec/bouncers
|
||||||
- /etc/crowdsec/parsers/s02-enrich
|
- /etc/crowdsec/parsers/s02-enrich
|
||||||
- /etc/systemd/system/crowdsec.service.d
|
- /etc/systemd/system/crowdsec.service.d
|
||||||
|
- /etc/systemd/system/crowdsec-hubupdate.service.d
|
||||||
- /etc/systemd/system/crowdsec-firewall-bouncer.service.d
|
- /etc/systemd/system/crowdsec-firewall-bouncer.service.d
|
||||||
- /etc/systemd/system/nftables.service.d
|
- /etc/systemd/system/nftables.service.d
|
||||||
|
|
||||||
@@ -171,6 +181,37 @@
|
|||||||
when: crowdsec_missing | length > 0
|
when: crowdsec_missing | length > 0
|
||||||
notify: Restart crowdsec
|
notify: Restart crowdsec
|
||||||
|
|
||||||
|
# The script upgrades every hub item with --force (a scenario removed with --force taints its collection, and a plain upgrade skips
|
||||||
|
# tainted collections) and removes the disabled scenarios again. It runs here once and daily as crowdsec-hubupdate.service.
|
||||||
|
- name: Install the hub update script
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: crowdsec-hubupdate.sh.j2
|
||||||
|
dest: /usr/local/sbin/crowdsec-hubupdate
|
||||||
|
mode: "0755"
|
||||||
|
|
||||||
|
- name: Run the hub update script instead of the package one
|
||||||
|
ansible.builtin.copy:
|
||||||
|
dest: /etc/systemd/system/crowdsec-hubupdate.service.d/override.conf
|
||||||
|
mode: "0644"
|
||||||
|
content: |
|
||||||
|
[Service]
|
||||||
|
ExecStart=
|
||||||
|
ExecStart=/usr/local/sbin/crowdsec-hubupdate
|
||||||
|
register: crowdsec_hubupdate_dropin
|
||||||
|
|
||||||
|
- name: Reload systemd for the hub update unit
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
daemon_reload: true
|
||||||
|
when: crowdsec_hubupdate_dropin is changed
|
||||||
|
|
||||||
|
- name: Upgrade the hub items and remove the disabled scenarios
|
||||||
|
ansible.builtin.command: /usr/local/sbin/crowdsec-hubupdate
|
||||||
|
environment:
|
||||||
|
NO_RELOAD: "1"
|
||||||
|
register: crowdsec_hubupdate
|
||||||
|
changed_when: "'changed' in crowdsec_hubupdate.stdout"
|
||||||
|
notify: Restart crowdsec
|
||||||
|
|
||||||
- name: Install the local parsers and scenarios
|
- name: Install the local parsers and scenarios
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
dest: "/etc/crowdsec/{{ item.key }}"
|
dest: "/etc/crowdsec/{{ item.key }}"
|
||||||
@@ -181,6 +222,15 @@
|
|||||||
label: "{{ item.key }}"
|
label: "{{ item.key }}"
|
||||||
notify: Restart crowdsec
|
notify: Restart crowdsec
|
||||||
|
|
||||||
|
- name: Remove retired local files
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "/etc/crowdsec/{{ item.value }}"
|
||||||
|
state: absent
|
||||||
|
loop: "{{ crowdsec.absent_files | dict2items | rejectattr('value', 'none') }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.value }}"
|
||||||
|
notify: Restart crowdsec
|
||||||
|
|
||||||
- name: Enable the agent and the bouncer
|
- name: Enable the agent and the bouncer
|
||||||
ansible.builtin.systemd:
|
ansible.builtin.systemd:
|
||||||
name: "{{ item }}"
|
name: "{{ item }}"
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Managed by Ansible. crowdsec-hubupdate.service runs this script instead of /usr/libexec/crowdsec/hubupdate.sh.
|
||||||
|
#
|
||||||
|
# "cscli scenarios remove --force" taints the collection that holds the scenario, and a plain "cscli hub upgrade" skips tainted
|
||||||
|
# collections for good. The upgrade therefore runs with --force, which also brings the removed scenarios back, and the removal is
|
||||||
|
# applied again. crowdsec is reloaded only when the installed hub files or the data files differ afterwards; with NO_RELOAD=1
|
||||||
|
# the script prints "changed" instead, for the role, which restarts crowdsec once at the end of its run. A failed step does not skip
|
||||||
|
# the later ones, so the removal of the disabled scenarios always runs; the script then exits non-zero.
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
test -x /usr/bin/cscli || exit 0
|
||||||
|
|
||||||
|
fingerprint() {
|
||||||
|
{
|
||||||
|
find -L /etc/crowdsec -path /etc/crowdsec/hub -prune -o -type f -exec sha256sum {} +
|
||||||
|
find /var/lib/crowdsec/data -maxdepth 1 -type f ! -name 'crowdsec.db*' ! -name trace -exec sha256sum {} +
|
||||||
|
} 2>/dev/null | sort -k2 | sha256sum
|
||||||
|
}
|
||||||
|
|
||||||
|
before="$(fingerprint)"
|
||||||
|
|
||||||
|
failed=0
|
||||||
|
|
||||||
|
# A failed list command does not skip the removal: the scenario is then removed without knowing whether it is installed.
|
||||||
|
remove_scenario() {
|
||||||
|
if list="$(/usr/bin/cscli scenarios list -o raw)"; then
|
||||||
|
printf '%s\n' "$list" | cut -d, -f1 | grep -qxF "$1" || return 0
|
||||||
|
else
|
||||||
|
failed=1
|
||||||
|
fi
|
||||||
|
/usr/bin/cscli --error scenarios remove "$1" --force >/dev/null || failed=1
|
||||||
|
}
|
||||||
|
|
||||||
|
/usr/bin/cscli --error hub update >/dev/null || failed=1
|
||||||
|
/usr/bin/cscli --error hub upgrade --force >/dev/null || failed=1
|
||||||
|
|
||||||
|
{% for scenario in crowdsec.disabled_scenarios.values() | reject('none') | unique | sort %}
|
||||||
|
remove_scenario '{{ scenario }}'
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
if [ "$before" != "$(fingerprint)" ]; then
|
||||||
|
if [ -n "${NO_RELOAD:-}" ]; then
|
||||||
|
echo changed
|
||||||
|
else
|
||||||
|
systemctl reload crowdsec.service
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit "$failed"
|
||||||
@@ -20,6 +20,8 @@ STATE_DIR = os.environ.get("STATE_DIRECTORY", "/var/lib/crowdsec-range-bouncer")
|
|||||||
HASH_FILE = os.path.join(STATE_DIR, "last.sha256")
|
HASH_FILE = os.path.join(STATE_DIR, "last.sha256")
|
||||||
NFT = "/usr/sbin/nft"
|
NFT = "/usr/sbin/nft"
|
||||||
TABLE = "crowdsec_ranges"
|
TABLE = "crowdsec_ranges"
|
||||||
|
# A prefix this wide is a poisoned decision, not a bad network.
|
||||||
|
MIN_DECISION_PREFIXLEN = {4: 8, 6: 16}
|
||||||
|
|
||||||
|
|
||||||
def fetch_ranges(lapi_url, api_key):
|
def fetch_ranges(lapi_url, api_key):
|
||||||
@@ -35,11 +37,16 @@ def fetch_ranges(lapi_url, api_key):
|
|||||||
return []
|
return []
|
||||||
if not isinstance(decisions, list):
|
if not isinstance(decisions, list):
|
||||||
raise ValueError("unexpected LAPI answer: %s" % type(decisions).__name__)
|
raise ValueError("unexpected LAPI answer: %s" % type(decisions).__name__)
|
||||||
return [
|
networks = []
|
||||||
ipaddress.ip_network(d["value"], strict=False)
|
for d in decisions:
|
||||||
for d in decisions
|
if d["type"] != "ban" or d["scope"].lower() != "range":
|
||||||
if d["type"] == "ban" and d["scope"].lower() == "range"
|
continue
|
||||||
]
|
network = ipaddress.ip_network(d["value"], strict=False)
|
||||||
|
if network.prefixlen < MIN_DECISION_PREFIXLEN[network.version]:
|
||||||
|
print("skipping suspiciously wide range decision %s" % network)
|
||||||
|
continue
|
||||||
|
networks.append(network)
|
||||||
|
return networks
|
||||||
|
|
||||||
|
|
||||||
def collapse(networks, version):
|
def collapse(networks, version):
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
docker:
|
||||||
|
# Merged into /etc/docker/daemon.json; keys not listed here keep their host value.
|
||||||
|
daemon:
|
||||||
|
# Containers keep running while dockerd restarts or upgrades.
|
||||||
|
live-restore: true
|
||||||
@@ -2,3 +2,9 @@
|
|||||||
service:
|
service:
|
||||||
name: "docker"
|
name: "docker"
|
||||||
state: restarted
|
state: restarted
|
||||||
|
|
||||||
|
# SIGHUP applies the reloadable daemon.json options without stopping containers.
|
||||||
|
- name: reload_docker
|
||||||
|
service:
|
||||||
|
name: "docker"
|
||||||
|
state: reloaded
|
||||||
|
|||||||
+24
-1
@@ -59,11 +59,34 @@
|
|||||||
- pass
|
- pass
|
||||||
state: latest
|
state: latest
|
||||||
|
|
||||||
|
- name: Read daemon.json
|
||||||
|
ansible.builtin.slurp:
|
||||||
|
path: /etc/docker/daemon.json
|
||||||
|
register: docker_daemon_json
|
||||||
|
failed_when: false
|
||||||
|
tags: docker_daemon
|
||||||
|
|
||||||
|
- name: Merge daemon options into daemon.json
|
||||||
|
vars:
|
||||||
|
docker_daemon_current: "{{ (docker_daemon_json.content | b64decode | from_json) if docker_daemon_json.content is defined else {} }}"
|
||||||
|
docker_daemon_merged: "{{ docker_daemon_current | combine(docker.daemon) }}"
|
||||||
|
ansible.builtin.copy:
|
||||||
|
content: "{{ docker_daemon_merged | to_nice_json(indent=4, sort_keys=False) }}\n"
|
||||||
|
dest: /etc/docker/daemon.json
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0644"
|
||||||
|
validate: dockerd --validate --config-file=%s
|
||||||
|
# Rewritten only on a value change, so hand-written formatting survives otherwise.
|
||||||
|
when: docker_daemon_merged != docker_daemon_current
|
||||||
|
notify: reload_docker
|
||||||
|
tags: docker_daemon
|
||||||
|
|
||||||
- name: Deploy docker-compose command to new docker compose plugin
|
- name: Deploy docker-compose command to new docker compose plugin
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
src: docker-compose
|
src: docker-compose
|
||||||
dest: "/usr/local/bin/docker-compose"
|
dest: "/usr/local/bin/docker-compose"
|
||||||
mode: preserve
|
mode: "0755"
|
||||||
|
|
||||||
- name: Check for docker binary
|
- name: Check for docker binary
|
||||||
ansible.builtin.stat:
|
ansible.builtin.stat:
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
---
|
---
|
||||||
|
# Address the node exporter binds to; empty = all addresses. For hosts without host_firewall: the NetBird
|
||||||
|
# address keeps the port off the LAN, and the mesh ACL decides who reaches it.
|
||||||
|
host_exporters_listen_address: ""
|
||||||
|
|
||||||
# Adds prometheus-smartctl-exporter (trixie-backports) next to the node exporter
|
# Adds prometheus-smartctl-exporter (trixie-backports) next to the node exporter
|
||||||
# on hosts with physical disks.
|
# on hosts with physical disks.
|
||||||
host_exporters_smart: false
|
host_exporters_smart: false
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
---
|
---
|
||||||
# Both exporters listen on all addresses; host_firewall limits who reaches them.
|
# Both exporters listen on all addresses (the node exporter on host_exporters_listen_address if set); host_firewall
|
||||||
|
# limits who reaches them.
|
||||||
# Its recommends (smartmontools, nvme-cli, ipmitool) start units that fail on hosts without such hardware.
|
# Its recommends (smartmontools, nvme-cli, ipmitool) start units that fail on hosts without such hardware.
|
||||||
- name: Install the node exporter
|
- name: Install the node exporter
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
@@ -7,11 +8,53 @@
|
|||||||
install_recommends: false
|
install_recommends: false
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
|
# Left over from installs with recommends; its init script fails at boot without a BMC.
|
||||||
|
# Purge also removes the init script a plain removal keeps.
|
||||||
|
- name: Purge OpenIPMI on hosts without a BMC
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name: openipmi
|
||||||
|
state: absent
|
||||||
|
purge: true
|
||||||
|
when: not host_exporters_ipmi
|
||||||
|
|
||||||
|
- name: Bind the node exporter to one address
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
path: /etc/default/prometheus-node-exporter
|
||||||
|
regexp: '^ARGS='
|
||||||
|
line: 'ARGS="--web.listen-address={{ host_exporters_listen_address }}:9100"'
|
||||||
|
when: host_exporters_listen_address | length > 0
|
||||||
|
register: host_exporters_listen
|
||||||
|
# Check mode does not install the package.
|
||||||
|
ignore_errors: "{{ ansible_check_mode }}"
|
||||||
|
|
||||||
|
- name: Create the node exporter unit drop-in directory
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /etc/systemd/system/prometheus-node-exporter.service.d
|
||||||
|
state: directory
|
||||||
|
mode: "0755"
|
||||||
|
when: host_exporters_listen_address | length > 0
|
||||||
|
|
||||||
|
# The NetBird address exists only after the daemon is up, and a failed bind must not exhaust the start limit.
|
||||||
|
- name: Start the bound node exporter after NetBird and retry
|
||||||
|
ansible.builtin.copy:
|
||||||
|
dest: /etc/systemd/system/prometheus-node-exporter.service.d/listen-address.conf
|
||||||
|
mode: "0644"
|
||||||
|
content: |
|
||||||
|
[Unit]
|
||||||
|
After=netbird.service
|
||||||
|
StartLimitIntervalSec=0
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
RestartSec=5s
|
||||||
|
when: host_exporters_listen_address | length > 0
|
||||||
|
register: host_exporters_listen_unit
|
||||||
|
|
||||||
- name: Enable the node exporter
|
- name: Enable the node exporter
|
||||||
ansible.builtin.systemd:
|
ansible.builtin.systemd:
|
||||||
name: prometheus-node-exporter
|
name: prometheus-node-exporter
|
||||||
enabled: true
|
enabled: true
|
||||||
state: started
|
state: "{{ 'restarted' if (host_exporters_listen.changed or host_exporters_listen_unit.changed) else 'started' }}"
|
||||||
|
daemon_reload: "{{ host_exporters_listen_unit.changed }}"
|
||||||
# Check mode does not install the package.
|
# Check mode does not install the package.
|
||||||
ignore_errors: "{{ ansible_check_mode }}"
|
ignore_errors: "{{ ansible_check_mode }}"
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,16 @@ firewall:
|
|||||||
ifaces: {}
|
ifaces: {}
|
||||||
v4: {}
|
v4: {}
|
||||||
v6: {}
|
v6: {}
|
||||||
|
# Hosts outside the ring that reach a NodePort service (CrowdSec LAPI) over wt0, and the port of its pods: Cilium
|
||||||
|
# translates the NodePort before netfilter, so the flows arrive as client -> pod:port.
|
||||||
|
lapi:
|
||||||
|
port: null
|
||||||
|
clients: {}
|
||||||
|
# Hosts outside the ring that upload their journal through Traefik over wt0, and the Traefik container port; as
|
||||||
|
# with lapi, the flows arrive as client -> pod:port.
|
||||||
|
journal:
|
||||||
|
port: null
|
||||||
|
clients: {}
|
||||||
# IPv4 port forwards: name -> {daddr, to, tcp: ports, udp: ports}, ports as in
|
# IPv4 port forwards: name -> {daddr, to, tcp: ports, udp: ports}, ports as in
|
||||||
# the maps above. Forwarded traffic passes the forward hook, not input.
|
# the maps above. Forwarded traffic passes the forward hook, not input.
|
||||||
dnat: {}
|
dnat: {}
|
||||||
@@ -44,26 +54,57 @@ firewall:
|
|||||||
# in on ifaces pass, the listed ports and types pass, the rest to daddr drops;
|
# in on ifaces pass, the listed ports and types pass, the rest to daddr drops;
|
||||||
# traffic to other addresses is not filtered.
|
# traffic to other addresses is not filtered.
|
||||||
forward_guard: {}
|
forward_guard: {}
|
||||||
ssh_rate_limit: "10/minute burst 5 packets"
|
# Limits on new inbound TCP connections per service, applied to the public and geo ports the host serves (input) and to
|
||||||
# Kernel log of dropped inbound packets (fw-in-drop: ) and of rejected
|
# DNATed traffic (forward: port forwards and Docker-published ports), after the admin, cluster, VPN, guest and internal
|
||||||
|
# sources and the public_ips of every inventory host (IPv4 per address, IPv6 per /64) are exempted. The rate and burst
|
||||||
|
# below are the service limit, enforced by the handshake meter per source: it counts the packet that completes a TCP
|
||||||
|
# handshake, which a spoofed source cannot send, and logs the excess with fw-rl-hs: and resets the connection. Each service
|
||||||
|
# also has a SYN meter at twice the rate and burst, as a flood cap above the service limit so that a real client reaches the
|
||||||
|
# handshake meter first: a tier per source (IPv4 /32, IPv6 /64) and a tier per range (IPv4 /24, IPv6 /48) at
|
||||||
|
# rate * range_factor. Its excess drops with the log prefix fw-rl-syn-addr: (source tier) or fw-rl-syn-range: (range tier);
|
||||||
|
# a spoofed source can trigger both, so they are evidence only. Log limit: log.ratelimit_rate.
|
||||||
|
# name -> {ports: port or list, rate: connections per `per`, per: second|minute (minute), burst: connections (2 * rate),
|
||||||
|
# range_factor_v4, range_factor_v6: override the factors below}; null drops a service, a service is idle unless a port is served.
|
||||||
|
# Values are 3x the highest legitimate rate seen, with a floor of 12 per minute (3x four connections per minute) where
|
||||||
|
# there is no or too little history; the measurement is noted at each service.
|
||||||
|
ratelimit:
|
||||||
|
range_factor:
|
||||||
|
v4: 6
|
||||||
|
v6: 3
|
||||||
|
services:
|
||||||
|
# 14 days of sshd Accepted lines in VictoriaLogs (all hosts, per host and source, /64 and /24 grouped): at most 8 per
|
||||||
|
# minute and 4 per 10 seconds from one address or /64 (Ansible runs), 22 per 10 minutes.
|
||||||
|
ssh:
|
||||||
|
ports: 22
|
||||||
|
rate: 24
|
||||||
|
# 14 days of Traefik access logs of the cluster: distinct client ports of one source within a minute, which bounds the
|
||||||
|
# new connections, at most 51 (IPv4) and 58 (IPv6 /64); 16 per second at most. Applies to the host ports 80 and 443.
|
||||||
|
web:
|
||||||
|
ports: [80, 443]
|
||||||
|
rate: 180
|
||||||
|
# Kernel log of dropped inbound packets (fw-in-drop: ), rate-limited connections (fw-rl-syn-addr: , fw-rl-syn-range: , fw-rl-hs: ) and of rejected
|
||||||
# outbound mail (fw-out-reject: ), read from the journal by CrowdSec. Each
|
# outbound mail (fw-out-reject: ), read from the journal by CrowdSec. Each
|
||||||
# rate is one limit shared by all matching packets.
|
# rate is one limit shared by all matching packets.
|
||||||
log:
|
log:
|
||||||
in_rate: "5/second burst 30 packets"
|
in_rate: "5/second burst 30 packets"
|
||||||
|
# One limit each for fw-rl-syn-addr: , fw-rl-syn-range: and fw-rl-hs: , shared by all services.
|
||||||
|
ratelimit_rate: "5/second burst 30 packets"
|
||||||
out_rate: "6/minute burst 5 packets"
|
out_rate: "6/minute burst 5 packets"
|
||||||
# Lets the kernel log the nft log statements of container network
|
# Lets the kernel log the nft log statements of container network
|
||||||
# namespaces (LXC guests) into the host kernel log.
|
# namespaces (LXC guests) into the host kernel log.
|
||||||
all_netns: false
|
all_netns: false
|
||||||
# Shared by the Spamhaus (fw-spamhaus-in: , fw-spamhaus-out: ), FireHOL (fw-firehol-in: , fw-firehol-out: ) and scanner (fw-scanners-in: ) chains, one limit each.
|
# Shared by the Spamhaus (fw-spamhaus-in: , fw-spamhaus-out: ), FireHOL level1 (fw-firehol1-in: , fw-firehol1-out: ),
|
||||||
|
# FireHOL level2 (fw-firehol2-in: , fw-firehol2-out: ) and scanner (fw-scanners-in: ) chains, one limit each.
|
||||||
spamhaus_rate: "6/minute burst 10 packets"
|
spamhaus_rate: "6/minute burst 10 packets"
|
||||||
# Spamhaus DROP, DROPv6 and ASN-DROP: traffic from the listed networks drops
|
# Spamhaus DROP, DROPv6 and ASN-DROP: traffic from the listed networks drops
|
||||||
# (input, forward), traffic to them is rejected (output, forward). The sets
|
# (input, forward), traffic to them is rejected (output, forward). The sets
|
||||||
# are refreshed daily by nft-host-spamhaus.
|
# are refreshed daily by nft-host-spamhaus.
|
||||||
spamhaus: true
|
spamhaus: true
|
||||||
# FireHOL level1 (IPv4): treated like the Spamhaus lists, with the prefixes
|
# FireHOL lists (IPv4 only, FireHOL has no IPv6 lists), from github.com/firehol/blocklist-ipsets:
|
||||||
# fw-firehol-in: and fw-firehol-out: and the same log limit. Entries in
|
# level1 and level2 (level2 includes GreenSnow): treated like the Spamhaus lists, with the prefixes fw-firehol1-in: ,
|
||||||
# private or reserved space and ones holding an address of the host are left
|
# fw-firehol1-out: (level1) and fw-firehol2-in: , fw-firehol2-out: (level2) and the same log limit.
|
||||||
# out. Refreshed daily by nft-host-firehol.
|
# Entries in private or reserved space and ones holding an address of the host are left out. Both sets are refreshed
|
||||||
|
# daily by nft-host-firehol.
|
||||||
firehol: true
|
firehol: true
|
||||||
# Internet-wide scanners (Censys, Shodan, ONYPHE, Shadowserver, ...), IPv4
|
# Internet-wide scanners (Censys, Shodan, ONYPHE, Shadowserver, ...), IPv4
|
||||||
# and IPv6: the cidr files of github.com/OpenFilters/internet-scanners
|
# and IPv6: the cidr files of github.com/OpenFilters/internet-scanners
|
||||||
@@ -75,6 +116,28 @@ firewall:
|
|||||||
# of any host, and ones holding an address of the host are left out
|
# of any host, and ones holding an address of the host are left out
|
||||||
# (/etc/nft-host-scanners.allowlist). Refreshed daily by nft-host-scanners.
|
# (/etc/nft-host-scanners.allowlist). Refreshed daily by nft-host-scanners.
|
||||||
scanners: true
|
scanners: true
|
||||||
|
# Uplink interfaces (name -> interface). New forwarded connections that arrive on one are dropped unless they were
|
||||||
|
# DNATed here or a forward_guard zone admits the destination. The datacenter gateway routes packets for foreign
|
||||||
|
# addresses of the subnet to the host; with ip_forward they would be forwarded and masqueraded with the host address.
|
||||||
|
# Not for hosts whose forwarded inbound traffic is not DNATed in netfilter (Cilium NodePorts are DNATed in BPF).
|
||||||
|
uplinks: {}
|
||||||
|
# Guest bridges (name -> interface) that IPv6 traffic from an uplink may be routed out of; IPv6 has no DNAT. New forwarded
|
||||||
|
# IPv6 connections that arrive on an uplink pass the uplink drop only when they leave through one of them, so the host
|
||||||
|
# never routes foreign destinations back out of the uplink or into the mesh and other interfaces. The kernel routes the
|
||||||
|
# prefix of the guest bridge, so no address is listed. The guest firewalls decide about the ports. IPv4 stays DNAT only.
|
||||||
|
routed_v6: {}
|
||||||
|
# Interfaces (name -> interface) whose forwarded traffic must not leave through the interface it arrived on, added to the
|
||||||
|
# interfaces of the default routes (IPv4 and IPv6) that every host gets. New connections that would be reflected drop;
|
||||||
|
# forwarding hosts (Kubernetes with Cilium, Docker, routing peers) otherwise route packets for foreign destinations that
|
||||||
|
# the datacenter sends to them back out. An uplink (see above) is already covered and left out.
|
||||||
|
no_reflect: {}
|
||||||
|
# Forward chain default. drop: forwarded traffic that no rule admits (replies, DNATed connections, trusted interfaces:
|
||||||
|
# wt0, cluster, internal and guest ifaces, routed_v6 bridges, forward_ifaces, pod interfaces) is logged with fw-fwd-drop:
|
||||||
|
# and dropped. log: the same, but nothing is dropped. accept: no tail, forwarded traffic passes unless a rule above drops it.
|
||||||
|
forward_policy: drop
|
||||||
|
# Interfaces (name -> interface, wildcards allowed) whose forwarded traffic is accepted without trusting their input,
|
||||||
|
# e.g. a transit bridge to a guest that only needs routing.
|
||||||
|
forward_ifaces: {}
|
||||||
# Reject outbound TCP 25; the mail group turns it off.
|
# Reject outbound TCP 25; the mail group turns it off.
|
||||||
block_smtp_out: true
|
block_smtp_out: true
|
||||||
# EU-27 plus CH, NO, GB, IS, LI (ipdeny country codes). Empty leaves the geo
|
# EU-27 plus CH, NO, GB, IS, LI (ipdeny country codes). Empty leaves the geo
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
# Managed by Ansible (role host_firewall), do not edit.
|
# Managed by Ansible (role host_firewall), do not edit.
|
||||||
"""Rebuilds the FireHOL level1 set firehol_v4 of table inet host.
|
"""Rebuilds the FireHOL sets of table inet host (IPv4 only, FireHOL has no IPv6 lists).
|
||||||
|
|
||||||
A failed download or sanity check exits non-zero before anything changes, so
|
Every set is built from one or more lists of the FireHOL blocklist-ipsets
|
||||||
the previous set stays in place.
|
(single addresses or CIDR networks, comment lines start with #). All sets go
|
||||||
|
into one file, so one reload replaces them together. A failed download or
|
||||||
|
sanity check of any list exits non-zero before anything changes, so the
|
||||||
|
previous sets stay in place.
|
||||||
"""
|
"""
|
||||||
import ipaddress
|
import ipaddress
|
||||||
import json
|
import json
|
||||||
@@ -16,11 +19,16 @@ import time
|
|||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
PERSISTED = "/etc/nftables.d/host-firehol.nft"
|
PERSISTED = "/etc/nftables.d/host-firehol.nft"
|
||||||
URL = "https://raw.githubusercontent.com/firehol/blocklist-ipsets/master/firehol_level1.netset"
|
BASE_URL = "https://raw.githubusercontent.com/firehol/blocklist-ipsets/master/"
|
||||||
USER_AGENT = "ruekov-host-firewall (nft-host-firehol)"
|
USER_AGENT = "ruekov-host-firewall (nft-host-firehol)"
|
||||||
|
|
||||||
# Lower bound that catches an empty or truncated answer.
|
# set name -> (lists merged into it, lower bound for their entries together that
|
||||||
MIN_ENTRIES = 1000
|
# catches an empty or truncated answer; the lists hold about 4700 (level1) and
|
||||||
|
# 18700 (level2)).
|
||||||
|
SETS = {
|
||||||
|
"firehol_v4": (["firehol_level1.netset"], 1000),
|
||||||
|
"firehol_level2_v4": (["firehol_level2.netset"], 5000),
|
||||||
|
}
|
||||||
# A prefix this wide is a parse error, not a bad network.
|
# A prefix this wide is a parse error, not a bad network.
|
||||||
MIN_PREFIXLEN = 8
|
MIN_PREFIXLEN = 8
|
||||||
# Private, CGNAT (NetBird), loopback, link-local and multicast/reserved space:
|
# Private, CGNAT (NetBird), loopback, link-local and multicast/reserved space:
|
||||||
@@ -36,17 +44,18 @@ def fail(message):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def fetch():
|
def fetch(name):
|
||||||
|
url = BASE_URL + name
|
||||||
error = None
|
error = None
|
||||||
for attempt in range(3):
|
for attempt in range(3):
|
||||||
try:
|
try:
|
||||||
request = urllib.request.Request(URL, headers={"User-Agent": USER_AGENT})
|
request = urllib.request.Request(url, headers={"User-Agent": USER_AGENT})
|
||||||
with urllib.request.urlopen(request, timeout=120) as response:
|
with urllib.request.urlopen(request, timeout=120) as response:
|
||||||
return response.read().decode("utf-8")
|
return response.read().decode("utf-8")
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
error = e
|
error = e
|
||||||
time.sleep(5 * (attempt + 1))
|
time.sleep(5 * (attempt + 1))
|
||||||
fail(f"download of {URL} failed: {error}")
|
fail(f"download of {url} failed: {error}")
|
||||||
|
|
||||||
|
|
||||||
def own_addresses():
|
def own_addresses():
|
||||||
@@ -57,20 +66,20 @@ def own_addresses():
|
|||||||
for a in link.get("addr_info", []) if a.get("family") == "inet"]
|
for a in link.get("addr_info", []) if a.get("family") == "inet"]
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def build_set(lists, minimum, own):
|
||||||
networks = []
|
networks = []
|
||||||
for line in fetch().splitlines():
|
for name in lists:
|
||||||
line = line.strip()
|
for line in fetch(name).splitlines():
|
||||||
if not line or line.startswith("#"):
|
line = line.strip()
|
||||||
continue
|
if not line or line.startswith("#"):
|
||||||
try:
|
continue
|
||||||
networks.append(ipaddress.IPv4Network(line))
|
try:
|
||||||
except ValueError:
|
networks.append(ipaddress.IPv4Network(line))
|
||||||
fail(f"unparsable line: {line!r}")
|
except ValueError:
|
||||||
if len(networks) < MIN_ENTRIES:
|
fail(f"unparsable line in {name}: {line!r}")
|
||||||
fail(f"only {len(networks)} entries")
|
if len(networks) < minimum:
|
||||||
|
fail(f"only {len(networks)} entries in {', '.join(lists)}")
|
||||||
|
|
||||||
own = own_addresses()
|
|
||||||
kept, excluded, own_skipped = [], 0, 0
|
kept, excluded, own_skipped = [], 0, 0
|
||||||
for network in networks:
|
for network in networks:
|
||||||
if any(network.overlaps(e) for e in EXCLUDED):
|
if any(network.overlaps(e) for e in EXCLUDED):
|
||||||
@@ -82,21 +91,28 @@ def main():
|
|||||||
fail(f"suspiciously wide prefix {network}")
|
fail(f"suspiciously wide prefix {network}")
|
||||||
kept.append(network)
|
kept.append(network)
|
||||||
merged = list(ipaddress.collapse_addresses(kept))
|
merged = list(ipaddress.collapse_addresses(kept))
|
||||||
print(f"firehol_v4: {len(networks)} entries, {excluded} in private or reserved space and "
|
return networks, excluded, own_skipped, merged
|
||||||
f"{own_skipped} holding an own address skipped -> {len(merged)} merged")
|
|
||||||
|
|
||||||
elements = ",\n\t\t".join(str(n) for n in merged) + ","
|
|
||||||
|
def main():
|
||||||
|
own = own_addresses()
|
||||||
|
definitions = []
|
||||||
|
for set_name, (lists, minimum) in SETS.items():
|
||||||
|
networks, excluded, own_skipped, merged = build_set(lists, minimum, own)
|
||||||
|
print(f"{set_name}: {len(networks)} entries, {excluded} in private or reserved space and "
|
||||||
|
f"{own_skipped} holding an own address skipped -> {len(merged)} merged")
|
||||||
|
elements = ",\n\t\t".join(str(n) for n in merged) + ","
|
||||||
|
definitions.append(f"\tset {set_name} {{ type ipv4_addr; flags interval; auto-merge; elements = {{\n"
|
||||||
|
f"\t\t{elements}\n\t}} }}\n")
|
||||||
persisted = ("# Generated by nft-host-firehol, do not edit.\n"
|
persisted = ("# Generated by nft-host-firehol, do not edit.\n"
|
||||||
"table inet host {\n"
|
"table inet host {\n" + "".join(definitions) + "}\n")
|
||||||
"\tset firehol_v4 { type ipv4_addr; flags interval; auto-merge; elements = {\n"
|
|
||||||
f"\t\t{elements}\n\t}} }}\n}}\n")
|
|
||||||
|
|
||||||
# Checked under another table name: a dry run against the live table
|
# Checked under another table name: a dry run against the live table
|
||||||
# name changes the live sets for its duration and unlisted addresses match.
|
# name changes the live sets for its duration and unlisted addresses match.
|
||||||
check_rules = persisted.replace("table inet host {", "table inet host_firehol_check {")
|
check_rules = persisted.replace("table inet host {", "table inet host_firehol_check {")
|
||||||
checked = subprocess.run(["nft", "-c", "-f", "-"], input=check_rules, capture_output=True, text=True)
|
checked = subprocess.run(["nft", "-c", "-f", "-"], input=check_rules, capture_output=True, text=True)
|
||||||
if checked.returncode != 0:
|
if checked.returncode != 0:
|
||||||
fail(f"nft rejects the set: {checked.stderr.strip()}")
|
fail(f"nft rejects the sets: {checked.stderr.strip()}")
|
||||||
|
|
||||||
with tempfile.TemporaryDirectory() as tmp:
|
with tempfile.TemporaryDirectory() as tmp:
|
||||||
previous = None
|
previous = None
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=Refresh the FireHOL set of the host firewall
|
Description=Refresh the FireHOL sets of the host firewall
|
||||||
Wants=network-online.target
|
Wants=network-online.target
|
||||||
After=network-online.target
|
After=network-online.target
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=Daily refresh of the host firewall FireHOL set
|
Description=Daily refresh of the host firewall FireHOL sets
|
||||||
|
|
||||||
[Timer]
|
[Timer]
|
||||||
OnCalendar=daily
|
OnCalendar=daily
|
||||||
|
|||||||
@@ -10,6 +10,11 @@
|
|||||||
fail_msg: "wt0 address {{ ansible_wt0.ipv4.address }} is missing from firewall.cluster.v4"
|
fail_msg: "wt0 address {{ ansible_wt0.ipv4.address }} is missing from firewall.cluster.v4"
|
||||||
when: firewall.cluster.v4 | default({}, true) | length > 0 and ansible_wt0.ipv4.address is defined
|
when: firewall.cluster.v4 | default({}, true) | length > 0 and ansible_wt0.ipv4.address is defined
|
||||||
|
|
||||||
|
- name: Check the forward policy
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: firewall.forward_policy | default('drop', true) in ['accept', 'log', 'drop']
|
||||||
|
fail_msg: "firewall.forward_policy is {{ firewall.forward_policy }}, expected accept, log or drop"
|
||||||
|
|
||||||
- name: Remove the include block of the old nftables role
|
- name: Remove the include block of the old nftables role
|
||||||
ansible.builtin.blockinfile:
|
ansible.builtin.blockinfile:
|
||||||
path: /etc/nftables.conf
|
path: /etc/nftables.conf
|
||||||
@@ -38,6 +43,22 @@
|
|||||||
reload: false
|
reload: false
|
||||||
when: firewall.log.all_netns
|
when: firewall.log.all_netns
|
||||||
|
|
||||||
|
# The handshake meters match `ct original packets 2`, which counts only with conntrack accounting (off by default).
|
||||||
|
# The module is loaded at boot so that systemd-sysctl finds the key.
|
||||||
|
- name: Load nf_conntrack at boot
|
||||||
|
ansible.builtin.copy:
|
||||||
|
dest: /etc/modules-load.d/nf_conntrack.conf
|
||||||
|
content: "nf_conntrack\n"
|
||||||
|
mode: "0644"
|
||||||
|
|
||||||
|
- name: Count packets per connection in conntrack
|
||||||
|
ansible.posix.sysctl:
|
||||||
|
name: net.netfilter.nf_conntrack_acct
|
||||||
|
value: "1"
|
||||||
|
sysctl_file: /etc/sysctl.d/90-nf-conntrack-acct.conf
|
||||||
|
sysctl_set: true
|
||||||
|
reload: false
|
||||||
|
|
||||||
- name: Install the systemd units
|
- name: Install the systemd units
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
src: "{{ item }}"
|
src: "{{ item }}"
|
||||||
@@ -158,7 +179,7 @@
|
|||||||
path: /etc/nftables.d/host-spamhaus.nft
|
path: /etc/nftables.d/host-spamhaus.nft
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
- name: FireHOL set
|
- name: FireHOL sets
|
||||||
when: firewall.firehol
|
when: firewall.firehol
|
||||||
block:
|
block:
|
||||||
- name: Install the FireHOL set updater
|
- name: Install the FireHOL set updater
|
||||||
@@ -167,25 +188,40 @@
|
|||||||
dest: /usr/local/sbin/nft-host-firehol
|
dest: /usr/local/sbin/nft-host-firehol
|
||||||
mode: "0755"
|
mode: "0755"
|
||||||
|
|
||||||
# The rule set includes this file, so a missing one would fail the load at boot.
|
# The rule set includes this file and uses both sets, so a missing file or set would fail the load at boot.
|
||||||
- name: Build the FireHOL set on first run
|
- name: Look for the FireHOL sets
|
||||||
ansible.builtin.command: /usr/local/sbin/nft-host-firehol
|
ansible.builtin.command: grep -cE 'set (firehol_v4|firehol_level2_v4) ' /etc/nftables.d/host-firehol.nft
|
||||||
args:
|
register: firewall_firehol_sets
|
||||||
creates: /etc/nftables.d/host-firehol.nft
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
check_mode: false
|
||||||
|
|
||||||
- name: Read the FireHOL set file
|
# Sets of removed lists are unused by the new rule set, which nft accepts, but the deployed one still uses them:
|
||||||
|
# a rebuild before the new rule set is confirmed would fail its reload. The rebuild at the end of the role drops them.
|
||||||
|
- name: Look for sets of removed FireHOL lists
|
||||||
|
ansible.builtin.command: grep -cE 'set (bruteforceblocker_v4|malware_v4) ' /etc/nftables.d/host-firehol.nft
|
||||||
|
register: firewall_firehol_stale
|
||||||
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
check_mode: false
|
||||||
|
|
||||||
|
- name: Build the FireHOL sets when missing
|
||||||
|
ansible.builtin.command: /usr/local/sbin/nft-host-firehol
|
||||||
|
when: firewall_firehol_sets.stdout != '2'
|
||||||
|
|
||||||
|
- name: Read the FireHOL sets file
|
||||||
ansible.builtin.stat:
|
ansible.builtin.stat:
|
||||||
path: /etc/nftables.d/host-firehol.nft
|
path: /etc/nftables.d/host-firehol.nft
|
||||||
register: firewall_firehol
|
register: firewall_firehol
|
||||||
|
|
||||||
- name: Require non-empty FireHOL set
|
- name: Require non-empty FireHOL sets
|
||||||
ansible.builtin.assert:
|
ansible.builtin.assert:
|
||||||
that: firewall_firehol.stat.exists and firewall_firehol.stat.size > 0
|
that: firewall_firehol.stat.exists and firewall_firehol.stat.size > 0
|
||||||
fail_msg: /etc/nftables.d/host-firehol.nft is missing or empty, refusing to apply the firewall
|
fail_msg: /etc/nftables.d/host-firehol.nft is missing or empty, refusing to apply the firewall
|
||||||
# Check mode neither installs the updater nor builds the sets.
|
# Check mode neither installs the updater nor builds the sets.
|
||||||
when: not ansible_check_mode
|
when: not ansible_check_mode
|
||||||
|
|
||||||
- name: Enable the FireHOL set timer
|
- name: Enable the FireHOL sets timer
|
||||||
ansible.builtin.systemd:
|
ansible.builtin.systemd:
|
||||||
name: nft-host-firehol.timer
|
name: nft-host-firehol.timer
|
||||||
enabled: true
|
enabled: true
|
||||||
@@ -194,10 +230,10 @@
|
|||||||
# Check mode does not install the unit.
|
# Check mode does not install the unit.
|
||||||
ignore_errors: "{{ ansible_check_mode }}"
|
ignore_errors: "{{ ansible_check_mode }}"
|
||||||
|
|
||||||
- name: Stop the FireHOL set refresh
|
- name: Stop the FireHOL sets refresh
|
||||||
when: not firewall.firehol
|
when: not firewall.firehol
|
||||||
block:
|
block:
|
||||||
- name: Disable the FireHOL set timer
|
- name: Disable the FireHOL sets timer
|
||||||
ansible.builtin.systemd:
|
ansible.builtin.systemd:
|
||||||
name: nft-host-firehol.timer
|
name: nft-host-firehol.timer
|
||||||
enabled: false
|
enabled: false
|
||||||
@@ -206,7 +242,7 @@
|
|||||||
# Check mode does not install the unit.
|
# Check mode does not install the unit.
|
||||||
ignore_errors: "{{ ansible_check_mode }}"
|
ignore_errors: "{{ ansible_check_mode }}"
|
||||||
|
|
||||||
- name: Remove the FireHOL set file
|
- name: Remove the FireHOL sets file
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: /etc/nftables.d/host-firehol.nft
|
path: /etc/nftables.d/host-firehol.nft
|
||||||
state: absent
|
state: absent
|
||||||
@@ -345,3 +381,45 @@
|
|||||||
dest: /etc/nftables.d/host.nft.good
|
dest: /etc/nftables.d/host.nft.good
|
||||||
remote_src: true
|
remote_src: true
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
|
|
||||||
|
# GreenSnow is part of FireHOL level2. The rule file goes last: the last confirmed rule set (host.nft.good) and a
|
||||||
|
# reload by a refresh service still include it until the new rule set is confirmed. The set itself leaves the live
|
||||||
|
# table with the reload of the new rule set.
|
||||||
|
- name: Look for the GreenSnow timer
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: /etc/systemd/system/nft-host-greensnow.timer
|
||||||
|
register: firewall_greensnow_timer
|
||||||
|
|
||||||
|
- name: Stop the GreenSnow refresh
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
name: nft-host-greensnow.timer
|
||||||
|
enabled: false
|
||||||
|
state: stopped
|
||||||
|
when: firewall_greensnow_timer.stat.exists
|
||||||
|
# Check mode does not stop the timer.
|
||||||
|
ignore_errors: "{{ ansible_check_mode }}"
|
||||||
|
|
||||||
|
- name: Remove the GreenSnow files
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ item }}"
|
||||||
|
state: absent
|
||||||
|
loop:
|
||||||
|
- /etc/systemd/system/nft-host-greensnow.service
|
||||||
|
- /etc/systemd/system/nft-host-greensnow.timer
|
||||||
|
- /usr/local/sbin/nft-host-greensnow
|
||||||
|
- /etc/nftables.d/host-greensnow.nft
|
||||||
|
register: firewall_greensnow_files
|
||||||
|
|
||||||
|
- name: Reload systemd after removing the GreenSnow units
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
daemon_reload: true
|
||||||
|
when: firewall_greensnow_files is changed
|
||||||
|
|
||||||
|
# The sets file keeps sets of removed FireHOL lists until the rule set without them is confirmed (see above).
|
||||||
|
- name: Drop sets of removed FireHOL lists
|
||||||
|
ansible.builtin.command: /usr/local/sbin/nft-host-firehol
|
||||||
|
when:
|
||||||
|
- firewall.firehol
|
||||||
|
- firewall_firehol_sets.stdout == '2'
|
||||||
|
- (firewall_firehol_stale.stdout | default('0') | int) > 0
|
||||||
|
- not ansible_check_mode
|
||||||
|
|||||||
@@ -11,16 +11,64 @@ set {{ name }} {
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
}
|
}
|
||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
|
{% macro addr_list_set(name, type, items) -%}
|
||||||
|
set {{ name }} {
|
||||||
|
type {{ type }}; flags interval; auto-merge;
|
||||||
|
{% if items %}
|
||||||
|
elements = { {{ items | join(', ') }} }
|
||||||
|
{% endif %}
|
||||||
|
}
|
||||||
|
{%- endmacro %}
|
||||||
{% set cluster = firewall.cluster | default({}, true) %}
|
{% set cluster = firewall.cluster | default({}, true) %}
|
||||||
|
{# public_ips of every inventory host: IPv4 per address, IPv6 per /64 (a longer prefix is widened, nft masks the host bits) #}
|
||||||
|
{% set public_ips = groups['all'] | map('extract', hostvars, 'public_ips') | select('defined') | flatten | map('string') | unique | list %}
|
||||||
|
{% set exempt_v4 = public_ips | reject('search', ':') | map('regex_replace', '^([^/]+)$', '\\1/32') | list %}
|
||||||
|
{% set exempt_v6 = public_ips | select('search', ':') | map('regex_replace', '^([^/]+)$', '\\1/128') | map('regex_replace', '/(6[5-9]|[7-9][0-9]|1[01][0-9]|12[0-8])$', '/64') | list %}
|
||||||
{% set cluster_ifaces = cluster.ifaces | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | unique | list %}
|
{% set cluster_ifaces = cluster.ifaces | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | unique | list %}
|
||||||
{% set internal_ifaces = firewall.internal_ifaces | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | unique | list %}
|
{% set internal_ifaces = firewall.internal_ifaces | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | unique | list %}
|
||||||
{% set guest_ifaces = firewall.guest_ifaces | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | unique | list %}
|
{% set guest_ifaces = firewall.guest_ifaces | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | unique | list %}
|
||||||
{% set guest_match = 'iifname { "' ~ (guest_ifaces | join('", "')) ~ '" }' %}
|
{% set guest_match = 'iifname { "' ~ (guest_ifaces | join('", "')) ~ '" }' %}
|
||||||
{% set dnat = firewall.dnat | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | list %}
|
{% set dnat = firewall.dnat | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | list %}
|
||||||
{% set masquerade = firewall.masquerade | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | unique | list %}
|
{% set masquerade = firewall.masquerade | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | unique | list %}
|
||||||
|
{% set lapi = cluster.lapi | default({}, true) %}
|
||||||
|
{% set lapi_rule = list(lapi.clients) and lapi.port %}
|
||||||
|
{% set journal = cluster.journal | default({}, true) %}
|
||||||
|
{% set journal_rule = list(journal.clients) and journal.port %}
|
||||||
{% set scrapers = firewall.scrapers | default({}, true) %}
|
{% set scrapers = firewall.scrapers | default({}, true) %}
|
||||||
{% set forward_guard = firewall.forward_guard | default({}, true) | dict2items | rejectattr('value', 'none') | list %}
|
{% set forward_guard = firewall.forward_guard | default({}, true) | dict2items | rejectattr('value', 'none') | list %}
|
||||||
|
{% set routed_v6 = firewall.routed_v6 | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | unique | list %}
|
||||||
|
{% set uplink_ifaces = firewall.uplinks | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | list %}
|
||||||
|
{% set no_reflect = ((firewall.no_reflect | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | list) + ([ansible_default_ipv4.interface | default(none), ansible_default_ipv6.interface | default(none)] | select | list)) | unique | difference(uplink_ifaces) | list %}
|
||||||
{% set blocklists = firewall.spamhaus or firewall.firehol %}
|
{% set blocklists = firewall.spamhaus or firewall.firehol %}
|
||||||
|
{% macro port_values(map) -%}
|
||||||
|
{{ map | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | map('string') | unique | join(' ') }}
|
||||||
|
{%- endmacro %}
|
||||||
|
{# Per-service limits apply only to ports the host serves: input for the public and geo ports, forward for DNATed traffic (port forwards of the host and Docker-published ports). #}
|
||||||
|
{% set served_input = (port_values(firewall.public.tcp) ~ ' ' ~ port_values(firewall.geo.tcp)).split() %}
|
||||||
|
{% set served_forward = (port_values(firewall.public.tcp) ~ ' ' ~ port_values(firewall.geo.tcp) ~ ' ' ~ (dnat | map(attribute='tcp') | map('default', {}, true) | map('dict2items') | sum(start=[]) | rejectattr('value', 'none') | map(attribute='value') | map('string') | join(' '))).split() %}
|
||||||
|
{% set rl = firewall.ratelimit | default({}, true) %}
|
||||||
|
{% set rl_factor = rl.range_factor | default({}, true) %}
|
||||||
|
{% set rl_services = [] %}
|
||||||
|
{% for svc in rl.services | default({}, true) | dict2items | rejectattr('value', 'none') %}
|
||||||
|
{% set ports = [svc.value.ports] | flatten | map('string') | list %}
|
||||||
|
{% set per = svc.value.per | default('minute', true) %}
|
||||||
|
{% set burst = svc.value.burst | default(svc.value.rate * 2, true) %}
|
||||||
|
{% set _ = rl_services.append({
|
||||||
|
'name': svc.key | replace('-', '_'),
|
||||||
|
'ports': ports | join(', '),
|
||||||
|
'rate': svc.value.rate,
|
||||||
|
'burst': burst,
|
||||||
|
'syn_rate': svc.value.rate * 2,
|
||||||
|
'syn_burst': burst * 2,
|
||||||
|
'per': per,
|
||||||
|
'f4': svc.value.range_factor_v4 | default(rl_factor.v4 | default(6), true),
|
||||||
|
'f6': svc.value.range_factor_v6 | default(rl_factor.v6 | default(3), true),
|
||||||
|
'input': (ports | select('in', served_input) | list | length) > 0,
|
||||||
|
'forward': (ports | select('in', served_forward) | list | length) > 0,
|
||||||
|
}) %}
|
||||||
|
{% endfor %}
|
||||||
|
{% set rl_input = rl_services | selectattr('input') | list %}
|
||||||
|
{% set rl_forward = rl_services | selectattr('forward') | list %}
|
||||||
|
|
||||||
# Declare-then-delete makes every load one atomic transaction that replaces
|
# Declare-then-delete makes every load one atomic transaction that replaces
|
||||||
# only these tables; Cilium, Docker, NetBird and CrowdSec tables stay untouched.
|
# only these tables; Cilium, Docker, NetBird and CrowdSec tables stay untouched.
|
||||||
@@ -47,15 +95,72 @@ table inet host {
|
|||||||
{{ addr_set('admin_v6', 'ipv6_addr', firewall.admin.v6) }}
|
{{ addr_set('admin_v6', 'ipv6_addr', firewall.admin.v6) }}
|
||||||
{{ addr_set('cluster_v4', 'ipv4_addr', cluster.v4) }}
|
{{ addr_set('cluster_v4', 'ipv4_addr', cluster.v4) }}
|
||||||
{{ addr_set('cluster_v6', 'ipv6_addr', cluster.v6) }}
|
{{ addr_set('cluster_v6', 'ipv6_addr', cluster.v6) }}
|
||||||
|
{% if lapi_rule %}
|
||||||
|
{{ addr_set('lapi_clients_v4', 'ipv4_addr', lapi.clients) }}
|
||||||
|
{% endif %}
|
||||||
|
{% if journal_rule %}
|
||||||
|
{{ addr_set('journal_clients_v4', 'ipv4_addr', journal.clients) }}
|
||||||
|
{% endif %}
|
||||||
{{ addr_set('scrapers_v4', 'ipv4_addr', scrapers.v4) }}
|
{{ addr_set('scrapers_v4', 'ipv4_addr', scrapers.v4) }}
|
||||||
{{ addr_set('scrapers_v6', 'ipv6_addr', scrapers.v6) }}
|
{{ addr_set('scrapers_v6', 'ipv6_addr', scrapers.v6) }}
|
||||||
set ssh_meter_v4 {
|
{{ addr_list_set('rl_exempt_v4', 'ipv4_addr', exempt_v4) }}
|
||||||
|
{{ addr_list_set('rl_exempt_v6', 'ipv6_addr', exempt_v6) }}
|
||||||
|
{% for svc in rl_services if svc.input or svc.forward %}
|
||||||
|
set rl_{{ svc.name }}_v4 {
|
||||||
type ipv4_addr; flags dynamic; timeout 10m; size 65535;
|
type ipv4_addr; flags dynamic; timeout 10m; size 65535;
|
||||||
}
|
}
|
||||||
set ssh_meter_v6 {
|
set rl_{{ svc.name }}_v6 {
|
||||||
type ipv6_addr; flags dynamic; timeout 10m; size 65535;
|
type ipv6_addr; flags dynamic; timeout 10m; size 65535;
|
||||||
}
|
}
|
||||||
|
set rl_{{ svc.name }}_v4r {
|
||||||
|
type ipv4_addr; flags dynamic; timeout 10m; size 16384;
|
||||||
|
}
|
||||||
|
set rl_{{ svc.name }}_v6r {
|
||||||
|
type ipv6_addr; flags dynamic; timeout 10m; size 16384;
|
||||||
|
}
|
||||||
|
set rl_hs_{{ svc.name }}_v4 {
|
||||||
|
type ipv4_addr; flags dynamic; timeout 10m; size 65535;
|
||||||
|
}
|
||||||
|
set rl_hs_{{ svc.name }}_v6 {
|
||||||
|
type ipv6_addr; flags dynamic; timeout 10m; size 65535;
|
||||||
|
}
|
||||||
|
{% endfor %}
|
||||||
|
{% if rl_input or rl_forward %}
|
||||||
|
# Flows the handshake meter rejected: the client sends its first data segment right behind the ACK, which reaches the
|
||||||
|
# host before the reset reaches the client and would complete the handshake there.
|
||||||
|
set rl_hs_rejected_v4 {
|
||||||
|
type ipv4_addr . inet_service . ipv4_addr . inet_service; flags dynamic,timeout; timeout 30s; size 65535;
|
||||||
|
}
|
||||||
|
set rl_hs_rejected_v6 {
|
||||||
|
type ipv6_addr . inet_service . ipv6_addr . inet_service; flags dynamic,timeout; timeout 30s; size 65535;
|
||||||
|
}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if cluster.v4 is defined and cluster.v4.pods is defined %}
|
||||||
|
# NetBird marks new flows in prerouting (priority mangle, -150) and masquerades marked ones in postrouting, which
|
||||||
|
# rewrites the source of cross-node pod traffic and breaks Cilium identity and network policy when pod traffic passes
|
||||||
|
# the host stack (veth with legacy host routing). This chain runs right after. Flows from the cluster ring (pods,
|
||||||
|
# node NetBird addresses) into the pod CIDR arriving on wt0 get mark 0x1bd20: not masqueraded, and accepted by the
|
||||||
|
# NetBird forward filter, which drops forwarded wt0 traffic that no route group allows. Other pod to pod flows
|
||||||
|
# lose their marks. The same mark lets the LAPI clients (@lapi_clients_v4) reach the pod port of the NodePort service
|
||||||
|
# with their own address: Cilium has translated the NodePort before this point, so NetBird would masquerade the flow
|
||||||
|
# to the cilium_host address and the network policy would see world.
|
||||||
|
# The journal uploaders (@journal_clients_v4) get the same mark on the Traefik pod port: the NetBird allowlist of
|
||||||
|
# the ingest route checks their own address.
|
||||||
|
chain pod_identity {
|
||||||
|
type filter hook prerouting priority -140; policy accept;
|
||||||
|
iifname "wt0" ct state new ip saddr @cluster_v4 ip daddr {{ cluster.v4.pods }} meta mark set 0x0001bd20
|
||||||
|
{% if lapi_rule %}
|
||||||
|
iifname "wt0" ct state new ip saddr @lapi_clients_v4 ip daddr {{ cluster.v4.pods }} tcp dport {{ lapi.port }} meta mark set 0x0001bd20
|
||||||
|
{% endif %}
|
||||||
|
{% if journal_rule %}
|
||||||
|
iifname "wt0" ct state new ip saddr @journal_clients_v4 ip daddr {{ cluster.v4.pods }} tcp dport {{ journal.port }} meta mark set 0x0001bd20
|
||||||
|
{% endif %}
|
||||||
|
ct state new ip saddr {{ cluster.v4.pods }} ip daddr {{ cluster.v4.pods }} meta mark 0x0001bd21 meta mark set 0
|
||||||
|
ct state new ip saddr {{ cluster.v4.pods }} ip daddr {{ cluster.v4.pods }} meta mark 0x0001bd22 meta mark set 0
|
||||||
|
}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
chain input {
|
chain input {
|
||||||
type filter hook input priority filter; policy drop;
|
type filter hook input priority filter; policy drop;
|
||||||
{% if blocklists %}
|
{% if blocklists %}
|
||||||
@@ -67,9 +172,19 @@ table inet host {
|
|||||||
ip6 saddr @spamhaus_v6 jump spamhaus_in
|
ip6 saddr @spamhaus_v6 jump spamhaus_in
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if firewall.firehol %}
|
{% if firewall.firehol %}
|
||||||
ip saddr @firehol_v4 jump firehol_in
|
ip saddr @firehol_v4 jump firehol1_in
|
||||||
|
ip saddr @firehol_level2_v4 jump firehol2_in
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if rl_input %}
|
||||||
|
# Before the established rule. Packets of rejected flows get a reset (not on RST, so that the half-open socket of the
|
||||||
|
# client side reset is cleaned up; a reset per packet is cheap, the client sends only a few before it sees the first).
|
||||||
|
# The packet that completes a handshake is a bare ACK and the second original-direction packet (needs
|
||||||
|
# net.netfilter.nf_conntrack_acct); an RST or FIN as second packet is no handshake, and a blind spoofer can send it.
|
||||||
|
meta l4proto tcp tcp flags & rst == 0 ip saddr . tcp sport . ip daddr . tcp dport @rl_hs_rejected_v4 counter reject with tcp reset
|
||||||
|
meta l4proto tcp tcp flags & rst == 0 ip6 saddr . tcp sport . ip6 daddr . tcp dport @rl_hs_rejected_v6 counter reject with tcp reset
|
||||||
|
meta l4proto tcp tcp flags & (fin | syn | rst | ack) == ack ct state established ct direction original ct original packets 2 jump ratelimit_hs_in
|
||||||
{% endif %}
|
{% endif %}
|
||||||
ct state established,related accept
|
ct state established,related accept
|
||||||
{% if firewall.scanners %}
|
{% if firewall.scanners %}
|
||||||
@@ -127,6 +242,84 @@ table inet host {
|
|||||||
limit rate {{ firewall.log.in_rate }} log prefix "fw-in-drop: "
|
limit rate {{ firewall.log.in_rate }} log prefix "fw-in-drop: "
|
||||||
drop
|
drop
|
||||||
}
|
}
|
||||||
|
{% if rl_services | selectattr('input') | list or rl_forward %}
|
||||||
|
|
||||||
|
# Per-service limits on new inbound TCP connections (firewall.ratelimit): per source address (IPv4 /32, IPv6 /64) and per
|
||||||
|
# range (IPv4 /24, IPv6 /48; the per-source rate times range_factor). Admin, cluster, VPN, guest and internal sources
|
||||||
|
# and the public addresses of all inventory hosts (rl_exempt_v4, rl_exempt_v6) are exempt: cluster nodes reach other hosts
|
||||||
|
# with their public address (ArgoCD git fetches, mail submission). The public set is checked only here, no other chain
|
||||||
|
# trusts it. The handshake meters carry the service limit (rate and burst of firewall.ratelimit): they count the packet that
|
||||||
|
# completes a handshake (the second original-direction packet of an established connection), which a spoofed source cannot
|
||||||
|
# send, so a real client above the limit is logged with fw-rl-hs: and reset. Only the address tier exists there; ranges are
|
||||||
|
# left to CrowdSec. The SYN meters are a looser flood cap at twice the rate and burst: they drop the excess with the log
|
||||||
|
# prefixes fw-rl-syn-addr: (per address) and fw-rl-syn-range: (per range), which a spoofed source can trigger, so they are
|
||||||
|
# evidence only. Their cap sits above the service limit so that a real client reaches the handshake meter first.
|
||||||
|
{% macro rl_exempt() %}
|
||||||
|
iifname "wt0" return
|
||||||
|
{% for iface in cluster_ifaces + internal_ifaces + guest_ifaces %}
|
||||||
|
iifname "{{ iface }}" return
|
||||||
|
{% endfor %}
|
||||||
|
ip saddr @admin_v4 return
|
||||||
|
ip6 saddr @admin_v6 return
|
||||||
|
ip saddr @cluster_v4 return
|
||||||
|
ip6 saddr @cluster_v6 return
|
||||||
|
ip saddr @rl_exempt_v4 return
|
||||||
|
ip6 saddr @rl_exempt_v6 return
|
||||||
|
{% endmacro %}
|
||||||
|
{% for hook, svcs in [('in', rl_input), ('fwd', rl_forward)] if svcs %}
|
||||||
|
chain ratelimit_{{ hook }} {
|
||||||
|
{{ rl_exempt() }}
|
||||||
|
{% for svc in svcs %}
|
||||||
|
meta l4proto tcp ct original proto-dst { {{ svc.ports }} } counter jump rl_{{ svc.name }}
|
||||||
|
{% endfor %}
|
||||||
|
}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
{% for hook, svcs in [('in', rl_input), ('fwd', rl_forward)] if svcs %}
|
||||||
|
chain ratelimit_hs_{{ hook }} {
|
||||||
|
{{ rl_exempt() }}
|
||||||
|
{% for svc in svcs %}
|
||||||
|
meta l4proto tcp ct original proto-dst { {{ svc.ports }} } counter jump rl_hs_{{ svc.name }}
|
||||||
|
{% endfor %}
|
||||||
|
}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
{% for svc in rl_services if svc.input or svc.forward %}
|
||||||
|
chain rl_{{ svc.name }} {
|
||||||
|
update @rl_{{ svc.name }}_v4 { ip saddr limit rate over {{ svc.syn_rate }}/{{ svc.per }} burst {{ svc.syn_burst }} packets } counter jump rl_drop_addr
|
||||||
|
update @rl_{{ svc.name }}_v6 { ip6 saddr & ffff:ffff:ffff:ffff:: limit rate over {{ svc.syn_rate }}/{{ svc.per }} burst {{ svc.syn_burst }} packets } counter jump rl_drop_addr
|
||||||
|
update @rl_{{ svc.name }}_v4r { ip saddr & 255.255.255.0 limit rate over {{ svc.syn_rate * svc.f4 }}/{{ svc.per }} burst {{ svc.syn_burst * svc.f4 }} packets } counter jump rl_drop_range
|
||||||
|
update @rl_{{ svc.name }}_v6r { ip6 saddr & ffff:ffff:ffff:: limit rate over {{ svc.syn_rate * svc.f6 }}/{{ svc.per }} burst {{ svc.syn_burst * svc.f6 }} packets } counter jump rl_drop_range
|
||||||
|
}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
{% for svc in rl_services if svc.input or svc.forward %}
|
||||||
|
chain rl_hs_{{ svc.name }} {
|
||||||
|
update @rl_hs_{{ svc.name }}_v4 { ip saddr limit rate over {{ svc.rate }}/{{ svc.per }} burst {{ svc.burst }} packets } counter jump rl_hs_reject
|
||||||
|
update @rl_hs_{{ svc.name }}_v6 { ip6 saddr & ffff:ffff:ffff:ffff:: limit rate over {{ svc.rate }}/{{ svc.per }} burst {{ svc.burst }} packets } counter jump rl_hs_reject
|
||||||
|
}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
# One log limit per prefix, so a flood of spoofed SYNs cannot use up the budget of the handshake evidence.
|
||||||
|
chain rl_drop_addr {
|
||||||
|
limit rate {{ firewall.log.ratelimit_rate }} log prefix "fw-rl-syn-addr: "
|
||||||
|
drop
|
||||||
|
}
|
||||||
|
|
||||||
|
chain rl_drop_range {
|
||||||
|
limit rate {{ firewall.log.ratelimit_rate }} log prefix "fw-rl-syn-range: "
|
||||||
|
drop
|
||||||
|
}
|
||||||
|
|
||||||
|
# The handshake is complete, so the connection has to be ended actively; the flow is remembered so that its later
|
||||||
|
# packets are reset without a log line (one fw-rl-hs: line per rejected connection).
|
||||||
|
chain rl_hs_reject {
|
||||||
|
meta nfproto ipv4 add @rl_hs_rejected_v4 { ip saddr . tcp sport . ip daddr . tcp dport }
|
||||||
|
meta nfproto ipv6 add @rl_hs_rejected_v6 { ip6 saddr . tcp sport . ip6 daddr . tcp dport }
|
||||||
|
limit rate {{ firewall.log.ratelimit_rate }} log prefix "fw-rl-hs: "
|
||||||
|
reject with tcp reset
|
||||||
|
}
|
||||||
|
{% endif %}
|
||||||
{% if firewall.spamhaus %}
|
{% if firewall.spamhaus %}
|
||||||
|
|
||||||
# Own limits, so a listed scanner cannot use up the budget of fw-in-drop.
|
# Own limits, so a listed scanner cannot use up the budget of fw-in-drop.
|
||||||
@@ -143,13 +336,23 @@ table inet host {
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% if firewall.firehol %}
|
{% if firewall.firehol %}
|
||||||
|
|
||||||
chain firehol_in {
|
chain firehol1_in {
|
||||||
limit rate {{ firewall.log.spamhaus_rate }} log prefix "fw-firehol-in: "
|
limit rate {{ firewall.log.spamhaus_rate }} log prefix "fw-firehol1-in: "
|
||||||
drop
|
drop
|
||||||
}
|
}
|
||||||
|
|
||||||
chain firehol_out {
|
chain firehol1_out {
|
||||||
limit rate {{ firewall.log.spamhaus_rate }} log prefix "fw-firehol-out: "
|
limit rate {{ firewall.log.spamhaus_rate }} log prefix "fw-firehol1-out: "
|
||||||
|
reject
|
||||||
|
}
|
||||||
|
|
||||||
|
chain firehol2_in {
|
||||||
|
limit rate {{ firewall.log.spamhaus_rate }} log prefix "fw-firehol2-in: "
|
||||||
|
drop
|
||||||
|
}
|
||||||
|
|
||||||
|
chain firehol2_out {
|
||||||
|
limit rate {{ firewall.log.spamhaus_rate }} log prefix "fw-firehol2-out: "
|
||||||
reject
|
reject
|
||||||
}
|
}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -176,7 +379,8 @@ table inet host {
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% if firewall.firehol %}
|
{% if firewall.firehol %}
|
||||||
|
|
||||||
ip daddr @firehol_v4 jump firehol_out
|
ip daddr @firehol_v4 jump firehol1_out
|
||||||
|
ip daddr @firehol_level2_v4 jump firehol2_out
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if firewall.block_smtp_out %}
|
{% if firewall.block_smtp_out %}
|
||||||
|
|
||||||
@@ -204,6 +408,9 @@ table inet host {
|
|||||||
}
|
}
|
||||||
|
|
||||||
chain public {
|
chain public {
|
||||||
|
{% if rl_input %}
|
||||||
|
ct state new jump ratelimit_in
|
||||||
|
{% endif %}
|
||||||
{% if list(firewall.public.tcp) %}
|
{% if list(firewall.public.tcp) %}
|
||||||
tcp dport { {{ list(firewall.public.tcp) }} } accept
|
tcp dport { {{ list(firewall.public.tcp) }} } accept
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -232,18 +439,32 @@ table inet host {
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
ip saddr @admin_v4 accept
|
ip saddr @admin_v4 accept
|
||||||
ip6 saddr @admin_v6 accept
|
ip6 saddr @admin_v6 accept
|
||||||
tcp dport 22 ct state new update @ssh_meter_v4 { ip saddr limit rate over {{ firewall.ssh_rate_limit }} } jump drop_log
|
|
||||||
# One IPv6 client usually holds a whole /64.
|
|
||||||
tcp dport 22 ct state new update @ssh_meter_v6 { ip6 saddr & ffff:ffff:ffff:ffff:: limit rate over {{ firewall.ssh_rate_limit }} } jump drop_log
|
|
||||||
{% if firewall.geo_countries %}
|
{% if firewall.geo_countries %}
|
||||||
ip saddr @geo_v4 accept
|
ip saddr @geo_v4 accept
|
||||||
ip6 saddr @geo_v6 accept
|
ip6 saddr @geo_v6 accept
|
||||||
{% endif %}
|
{% endif %}
|
||||||
}
|
}
|
||||||
{% if forward_guard or blocklists or firewall.scanners %}
|
{% set forward_policy = firewall.forward_policy | default('drop', true) %}
|
||||||
|
{% set forward_ifaces = firewall.forward_ifaces | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | unique | list %}
|
||||||
|
{% set forward_trusted = (([] if 'external' in group_names else ['wt0']) + cluster_ifaces + internal_ifaces + guest_ifaces + forward_ifaces) | unique | list %}
|
||||||
|
{% if forward_guard or blocklists or firewall.scanners or rl_forward or firewall.block_smtp_out or firewall.uplinks or no_reflect or forward_policy != 'accept' %}
|
||||||
|
|
||||||
chain forward {
|
chain forward {
|
||||||
type filter hook forward priority filter; policy accept;
|
type filter hook forward priority filter; policy {{ 'drop' if forward_policy == 'drop' else 'accept' }};
|
||||||
|
{% if no_reflect %}
|
||||||
|
|
||||||
|
# A packet that arrives on the interface of the default route and would leave through it again is a foreign
|
||||||
|
# destination the datacenter routed to this host: it is not forwarded, or the host acts as a reflector.
|
||||||
|
iifname { "{{ no_reflect | join('", "') }}" } oifname { "{{ no_reflect | join('", "') }}" } ct state new counter drop
|
||||||
|
{% endif %}
|
||||||
|
{% if rl_forward %}
|
||||||
|
|
||||||
|
# Docker-published ports and port forwards arrive here after DNAT; pod and guest egress is not DNATed.
|
||||||
|
ct status dnat ct state new jump ratelimit_fwd
|
||||||
|
meta l4proto tcp ct status dnat tcp flags & rst == 0 ip saddr . tcp sport . ip daddr . tcp dport @rl_hs_rejected_v4 counter reject with tcp reset
|
||||||
|
meta l4proto tcp ct status dnat tcp flags & rst == 0 ip6 saddr . tcp sport . ip6 daddr . tcp dport @rl_hs_rejected_v6 counter reject with tcp reset
|
||||||
|
meta l4proto tcp tcp flags & (fin | syn | rst | ack) == ack ct status dnat ct state established ct direction original ct original packets 2 jump ratelimit_hs_fwd
|
||||||
|
{% endif %}
|
||||||
{% if firewall.spamhaus %}
|
{% if firewall.spamhaus %}
|
||||||
|
|
||||||
ip saddr @spamhaus_v4 jump spamhaus_in
|
ip saddr @spamhaus_v4 jump spamhaus_in
|
||||||
@@ -253,8 +474,10 @@ table inet host {
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% if firewall.firehol %}
|
{% if firewall.firehol %}
|
||||||
|
|
||||||
ip saddr @firehol_v4 jump firehol_in
|
ip saddr @firehol_v4 jump firehol1_in
|
||||||
ip daddr @firehol_v4 jump firehol_out
|
ip daddr @firehol_v4 jump firehol1_out
|
||||||
|
ip saddr @firehol_level2_v4 jump firehol2_in
|
||||||
|
ip daddr @firehol_level2_v4 jump firehol2_out
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if firewall.scanners %}
|
{% if firewall.scanners %}
|
||||||
|
|
||||||
@@ -281,6 +504,48 @@ table inet host {
|
|||||||
{{ match }} jump drop_log
|
{{ match }} jump drop_log
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% for name, iface in firewall.uplinks.items() if iface is not none %}
|
||||||
|
|
||||||
|
{% if routed_v6 %}
|
||||||
|
# {{ name }}: from outside only what was DNATed here, admitted by a forward_guard zone above or, for IPv6, routed out of a guest bridge.
|
||||||
|
iifname "{{ iface }}" ct state new ct status & dnat == 0 meta nfproto ipv4 counter drop
|
||||||
|
iifname "{{ iface }}" ct state new ct status & dnat == 0 meta nfproto ipv6 oifname != { "{{ routed_v6 | join('", "') }}" } counter drop
|
||||||
|
{% else %}
|
||||||
|
# {{ name }}: from outside only what was DNATed here or admitted by a forward_guard zone above.
|
||||||
|
iifname "{{ iface }}" ct state new ct status & dnat == 0 counter drop
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% if firewall.block_smtp_out %}
|
||||||
|
{% set smtp_oif = ('oifname { "' ~ (uplink_ifaces | join('", "')) ~ '" } ') if uplink_ifaces else '' %}
|
||||||
|
|
||||||
|
# Pod, container and guest egress to tcp/25 is rejected like the host's own (chain output). Connections DNATed to
|
||||||
|
# a mail host (ct status dnat) and traffic inside the cluster ring (nodes, pods) pass. With uplinks configured
|
||||||
|
# only packets leaving through one are egress: a scan forwarded from the uplink to a guest is not.
|
||||||
|
ct status & dnat == 0 {{ smtp_oif }}ip daddr != @cluster_v4 tcp dport 25 limit rate {{ firewall.log.out_rate }} log prefix "fw-out-reject: "
|
||||||
|
ct status & dnat == 0 {{ smtp_oif }}ip daddr != @cluster_v4 tcp dport 25 reject with tcp reset
|
||||||
|
ct status & dnat == 0 {{ smtp_oif }}ip6 daddr != @cluster_v6 tcp dport 25 limit rate {{ firewall.log.out_rate }} log prefix "fw-out-reject: "
|
||||||
|
ct status & dnat == 0 {{ smtp_oif }}ip6 daddr != @cluster_v6 tcp dport 25 reject with tcp reset
|
||||||
|
{% endif %}
|
||||||
|
{% if forward_policy != 'accept' %}
|
||||||
|
|
||||||
|
# What is forwarded on purpose: replies, connections DNATed here, traffic that arrives on a trusted interface (mesh,
|
||||||
|
# cluster, internal and guest interfaces) and traffic to the pods (Cilium translates services before netfilter, so
|
||||||
|
# connections from outside arrive as client -> pod without ct status dnat). One rule per interface: a set that mixes
|
||||||
|
# wildcards and plain names did not match wt0. Everything else is logged (fw-fwd-drop:, the first place to look when a Cilium or network change breaks forwarding), counted and, with forward_policy drop, dropped. Reflected packets drop above, silently.
|
||||||
|
ct state established,related accept
|
||||||
|
ct status dnat accept
|
||||||
|
{% for iface in forward_trusted %}
|
||||||
|
iifname "{{ iface }}" accept
|
||||||
|
{% endfor %}
|
||||||
|
{% for iface in cluster_ifaces %}
|
||||||
|
oifname "{{ iface }}" accept
|
||||||
|
{% endfor %}
|
||||||
|
{% if routed_v6 %}
|
||||||
|
meta nfproto ipv6 oifname { "{{ routed_v6 | join('", "') }}" } accept
|
||||||
|
{% endif %}
|
||||||
|
limit rate {{ firewall.log.in_rate }} log prefix "fw-fwd-drop: "
|
||||||
|
counter
|
||||||
|
{% endif %}
|
||||||
}
|
}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ dump() { # file, container, command run inside the container
|
|||||||
dump {{ d.file | quote }} {{ d.container | quote }} {{ d.command | quote }}
|
dump {{ d.file | quote }} {{ d.container | quote }} {{ d.command | quote }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
# Global policy of the repository, inherited by every source; the repository is shared by all hosts of the bucket
|
||||||
|
kopia policy set --global --compression=zstd >/dev/null 2>&1 ||
|
||||||
|
{ echo "setting the global compression failed" >&2; failed=1; }
|
||||||
{% set ignores = kopia_backup.ignore | dict2items | rejectattr('value', 'none') | list %}
|
{% set ignores = kopia_backup.ignore | dict2items | rejectattr('value', 'none') | list %}
|
||||||
{% if ignores %}
|
{% if ignores %}
|
||||||
|
|
||||||
@@ -50,6 +54,24 @@ ignore() {
|
|||||||
ignore {{ i.key | quote }} {{ i.value | map('quote') | join(' ') }}
|
ignore {{ i.key | quote }} {{ i.value | map('quote') | join(' ') }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% set retentions = kopia_backup.retention | default({}) | dict2items | rejectattr('value', 'none') | list %}
|
||||||
|
{% if retentions %}
|
||||||
|
|
||||||
|
# Per-source retention overrides, applied as a whole. A keep flag of 0 means "inherit",
|
||||||
|
# so setting all four flags explicitly fully defines the retention for the path.
|
||||||
|
retention() {
|
||||||
|
local path=$1; shift
|
||||||
|
kopia policy set "$path" "$@" >/dev/null 2>&1 ||
|
||||||
|
{ echo "setting the retention of $path failed" >&2; failed=1; }
|
||||||
|
}
|
||||||
|
{% for r in retentions %}
|
||||||
|
retention {{ r.key | quote }} \
|
||||||
|
--keep-daily={{ r.value.keep_daily | default(0) }} \
|
||||||
|
--keep-weekly={{ r.value.keep_weekly | default(0) }} \
|
||||||
|
--keep-monthly={{ r.value.keep_monthly | default(0) }} \
|
||||||
|
--keep-annual={{ r.value.keep_annual | default(0) }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
for p in {{ kopia_backup.sources | map('quote') | join(' ') }}{{ ' "$etcd"' if kopia_backup.etcd_snapshot }}{{ ' "$dumps"' if kopia_backup.dumps }}; do
|
for p in {{ kopia_backup.sources | map('quote') | join(' ') }}{{ ' "$etcd"' if kopia_backup.etcd_snapshot }}{{ ' "$dumps"' if kopia_backup.dumps }}; do
|
||||||
[ -d "$p" ] && sources+=("$p")
|
[ -d "$p" ] && sources+=("$p")
|
||||||
|
|||||||
@@ -19,10 +19,16 @@ kubernetes:
|
|||||||
token: <shared token for nodes to join>
|
token: <shared token for nodes to join>
|
||||||
|
|
||||||
network:
|
network:
|
||||||
# Copies the current /etc/resolv.conf whilst only keeping "nameserver" lines
|
# Writes /etc/resolv-k3s.conf (k3s resolv-conf, CoreDNS upstreams) from
|
||||||
# can be used to remove filter
|
# resolv_conf_nameservers
|
||||||
clean_resolv_conf: false
|
clean_resolv_conf: false
|
||||||
|
|
||||||
|
# Fixed upstreams, not copied from the node: a copied snapshot goes stale
|
||||||
|
# when the node's DNS changes and can leave CoreDNS with a single upstream
|
||||||
|
resolv_conf_nameservers:
|
||||||
|
- 1.1.1.1
|
||||||
|
- 9.9.9.9
|
||||||
|
|
||||||
# One of [none, flannel, calico, cilium]
|
# One of [none, flannel, calico, cilium]
|
||||||
plugin: calico
|
plugin: calico
|
||||||
|
|
||||||
|
|||||||
@@ -45,17 +45,15 @@
|
|||||||
else (ansible_default_ipv6.address | default('')) }}
|
else (ansible_default_ipv6.address | default('')) }}
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
- name: Read resolv.conf
|
- name: Write /etc/resolv-k3s.conf with the fixed nameservers
|
||||||
shell: "grep '^nameserver' /etc/resolv.conf"
|
template:
|
||||||
register: nameserver_line
|
src: resolv-k3s.conf.jinja2
|
||||||
changed_when: false
|
|
||||||
check_mode: false
|
|
||||||
|
|
||||||
- name: Write /etc/resolv-k3s.conf with only nameservers
|
|
||||||
copy:
|
|
||||||
content: "{{ nameserver_line.stdout }}"
|
|
||||||
dest: /etc/resolv-k3s.conf
|
dest: /etc/resolv-k3s.conf
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0644"
|
||||||
when: kubernetes.network.clean_resolv_conf is true
|
when: kubernetes.network.clean_resolv_conf is true
|
||||||
|
tags: resolv_conf
|
||||||
|
|
||||||
- name: Run handlers to reload configurations
|
- name: Run handlers to reload configurations
|
||||||
meta: flush_handlers
|
meta: flush_handlers
|
||||||
|
|||||||
@@ -23,12 +23,14 @@ spec:
|
|||||||
hostNetwork: true
|
hostNetwork: true
|
||||||
containers:
|
containers:
|
||||||
- name: routingtabletowg
|
- name: routingtabletowg
|
||||||
image: "ruakij/routingtabletowg:0.2.0"
|
image: "ghcr.io/ruakij/routingtabletowg:0.3.0@sha256:a2c505e0f716dbbfdda1a535e2631e5a73b64236cd68d459eb407beab2e1032e"
|
||||||
env:
|
env:
|
||||||
- name: INTERFACE
|
- name: INTERFACE
|
||||||
value: {{ kubernetes.ipPool.nodeIp_interface }}
|
value: {{ kubernetes.ipPool.nodeIp_interface }}
|
||||||
- name: FILTER_PROTOCOL
|
- name: FILTER_PROTOCOL
|
||||||
value: bird
|
value: bird
|
||||||
|
- name: FILTER_TABLE
|
||||||
|
value: main
|
||||||
- name: PERIODIC_SYNC
|
- name: PERIODIC_SYNC
|
||||||
value: '300'
|
value: '300'
|
||||||
securityContext:
|
securityContext:
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# Managed by Ansible (role kubernetes). Fixed upstreams, not copied from the node.
|
||||||
|
{% for nameserver in kubernetes.network.resolv_conf_nameservers %}
|
||||||
|
nameserver {{ nameserver }}
|
||||||
|
{% endfor %}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
# Every host sends its mail through the mailcow submission port with its own mailbox
|
# Every host sends its mail through the mailcow submission port with its own mailbox
|
||||||
# (doc/host-mail-relay.md in the kubernetes repo). The password is set in host_vars.
|
# (doc/security-perimeter.md in the kubernetes repo). The password is set in host_vars.
|
||||||
mail_relay:
|
mail_relay:
|
||||||
host: tranio.ruekov.eu
|
host: tranio.ruekov.eu
|
||||||
port: 587
|
port: 587
|
||||||
|
|||||||
@@ -9,3 +9,5 @@ netbird_client:
|
|||||||
iface_blacklist_extra: []
|
iface_blacklist_extra: []
|
||||||
# Overrides the --log-level of the netbird service when set
|
# Overrides the --log-level of the netbird service when set
|
||||||
log_level:
|
log_level:
|
||||||
|
# MTU of wt0, written to /var/lib/netbird/default.json (netbird restarts on change); leave empty to keep the config as is
|
||||||
|
mtu:
|
||||||
|
|||||||
@@ -36,6 +36,44 @@
|
|||||||
cfg: "{{ netbird_config_stopped.content | b64decode | from_json }}"
|
cfg: "{{ netbird_config_stopped.content | b64decode | from_json }}"
|
||||||
when: netbird_stopped is changed
|
when: netbird_stopped is changed
|
||||||
|
|
||||||
|
- name: Read netbird config for the MTU
|
||||||
|
slurp:
|
||||||
|
src: /var/lib/netbird/default.json
|
||||||
|
register: netbird_config_mtu_file
|
||||||
|
when: netbird_client.mtu | default('') | string | length > 0
|
||||||
|
tags: netbird_client_config
|
||||||
|
|
||||||
|
- name: Set the wt0 MTU in the netbird config
|
||||||
|
when: netbird_config_mtu_file.content is defined
|
||||||
|
vars:
|
||||||
|
netbird_config_mtu: "{{ netbird_config_mtu_file.content | b64decode | from_json }}"
|
||||||
|
netbird_mtu_differs: "{{ (netbird_config_mtu.MTU | default(0)) != (netbird_client.mtu | int) }}"
|
||||||
|
tags: netbird_client_config
|
||||||
|
block:
|
||||||
|
# netbird writes its in-memory config back on exit, so edit only while it is stopped
|
||||||
|
- name: Stop netbird to edit its MTU
|
||||||
|
systemd:
|
||||||
|
name: netbird
|
||||||
|
state: stopped
|
||||||
|
when: netbird_mtu_differs
|
||||||
|
notify: restart_netbird
|
||||||
|
|
||||||
|
- name: Re-read netbird config after stop
|
||||||
|
slurp:
|
||||||
|
src: /var/lib/netbird/default.json
|
||||||
|
register: netbird_config_mtu_stopped
|
||||||
|
when: netbird_mtu_differs
|
||||||
|
|
||||||
|
- name: Write MTU
|
||||||
|
copy:
|
||||||
|
dest: /var/lib/netbird/default.json
|
||||||
|
content: "{{ cfg | combine({'MTU': netbird_client.mtu | int}) | to_nice_json(indent=4, sort_keys=False) }}\n"
|
||||||
|
mode: "0600"
|
||||||
|
vars:
|
||||||
|
cfg: "{{ netbird_config_mtu_stopped.content | b64decode | from_json }}"
|
||||||
|
when: netbird_mtu_differs
|
||||||
|
notify: restart_netbird
|
||||||
|
|
||||||
- name: Set netbird log level
|
- name: Set netbird log level
|
||||||
copy:
|
copy:
|
||||||
dest: /etc/systemd/system/netbird.service.d/20-log-level.conf
|
dest: /etc/systemd/system/netbird.service.d/20-log-level.conf
|
||||||
|
|||||||
@@ -5,19 +5,33 @@
|
|||||||
- curl
|
- curl
|
||||||
- gnupg
|
- gnupg
|
||||||
|
|
||||||
# Same keyring path the hand-installed hosts use, so the repository line is identical.
|
# Same keyring path the hand-installed hosts use, so the repository file is identical.
|
||||||
- name: Install the netbird repository keyring
|
- name: Install the netbird repository keyring
|
||||||
ansible.builtin.shell:
|
ansible.builtin.shell:
|
||||||
cmd: set -o pipefail && curl -fsSL https://pkgs.netbird.io/debian/public.key | gpg --dearmor -o /usr/share/keyrings/netbird-archive-keyring.gpg
|
cmd: set -o pipefail && curl -fsSL https://pkgs.netbird.io/debian/public.key | gpg --dearmor -o /usr/share/keyrings/netbird-archive-keyring.gpg
|
||||||
executable: /bin/bash
|
executable: /bin/bash
|
||||||
creates: /usr/share/keyrings/netbird-archive-keyring.gpg
|
creates: /usr/share/keyrings/netbird-archive-keyring.gpg
|
||||||
|
|
||||||
|
- name: Remove one-line netbird-repository
|
||||||
|
file:
|
||||||
|
path: /etc/apt/sources.list.d/netbird.list
|
||||||
|
state: absent
|
||||||
|
register: netbird_list
|
||||||
|
|
||||||
- name: Add netbird-repository
|
- name: Add netbird-repository
|
||||||
apt_repository:
|
deb822_repository:
|
||||||
repo: "deb [signed-by=/usr/share/keyrings/netbird-archive-keyring.gpg] https://pkgs.netbird.io/debian stable main"
|
name: netbird
|
||||||
state: present
|
types: deb
|
||||||
filename: netbird
|
uris: https://pkgs.netbird.io/debian
|
||||||
|
suites: stable
|
||||||
|
components: main
|
||||||
|
signed_by: /usr/share/keyrings/netbird-archive-keyring.gpg
|
||||||
|
register: netbird_repo
|
||||||
|
|
||||||
|
- name: Update apt cache after netbird-repository change
|
||||||
|
apt:
|
||||||
update_cache: yes
|
update_cache: yes
|
||||||
|
when: netbird_list.changed or netbird_repo.changed
|
||||||
|
|
||||||
# present, not latest: an upgrade restarts the daemon and drops the tunnels of the node.
|
# present, not latest: an upgrade restarts the daemon and drops the tunnels of the node.
|
||||||
- name: Install wireguard & netbird
|
- name: Install wireguard & netbird
|
||||||
|
|||||||
@@ -23,6 +23,36 @@
|
|||||||
dest: /etc/apt/apt.conf.d/52unattended-upgrades-local
|
dest: /etc/apt/apt.conf.d/52unattended-upgrades-local
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
|
|
||||||
|
# needrestart (Ubuntu default) restarts every service that uses an upgraded library, containerd and netbird included:
|
||||||
|
# after a libc upgrade the dead FUSE mounts hung systemd-resolved on antius and the node went NotReady (2026-11-14).
|
||||||
|
# List only; the services pick up the library at the next reboot, which HostRebootRequired tracks.
|
||||||
|
- name: Check for needrestart
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: /etc/needrestart/conf.d
|
||||||
|
register: unattended_upgrades_needrestart
|
||||||
|
|
||||||
|
- name: Let needrestart list the services instead of restarting them
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: needrestart-list-only.conf.j2
|
||||||
|
dest: /etc/needrestart/conf.d/90-list-only.conf
|
||||||
|
mode: "0644"
|
||||||
|
when: unattended_upgrades_needrestart.stat.exists
|
||||||
|
|
||||||
|
# Debian installs apt-listchanges with email_address=root, which mails the NEWS of every
|
||||||
|
# unattended upgrade through the mail relay.
|
||||||
|
- name: Check for the apt-listchanges config
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: /etc/apt/listchanges.conf
|
||||||
|
register: unattended_upgrades_listchanges
|
||||||
|
|
||||||
|
- name: Disable the apt-listchanges mails
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
path: /etc/apt/listchanges.conf
|
||||||
|
regexp: '^email_address='
|
||||||
|
line: email_address=none
|
||||||
|
insertafter: '^\[apt\]'
|
||||||
|
when: unattended_upgrades_listchanges.stat.exists
|
||||||
|
|
||||||
- name: Enable the apt timers
|
- name: Enable the apt timers
|
||||||
ansible.builtin.systemd:
|
ansible.builtin.systemd:
|
||||||
name: "{{ item }}"
|
name: "{{ item }}"
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
# {{ ansible_managed }}
|
||||||
|
$nrconf{restart} = 'l';
|
||||||
@@ -5,7 +5,10 @@
|
|||||||
|
|
||||||
- name: Download binary
|
- name: Download binary
|
||||||
get_url:
|
get_url:
|
||||||
url: https://github.com/Ruakij/wg-ipv6-converter/releases/{{ versionUri }}/wg-ipv6-converter_{{ arch }}
|
url: https://github.com/Ruakij/wg-ipv6-converter/releases/{{ versionUri }}/wg-ipv6-converter-linux-{{ arch }}
|
||||||
dest: /usr/local/bin/wg-ipv6-converter
|
dest: /usr/local/bin/wg-ipv6-converter
|
||||||
mode: "744"
|
mode: "744"
|
||||||
|
# Replaces a differing binary (get_url keeps an existing dest without a
|
||||||
|
# checksum) and verifies the download.
|
||||||
|
checksum: "sha256:https://github.com/Ruakij/wg-ipv6-converter/releases/{{ versionUri }}/SHA256SUMS"
|
||||||
register: deployDownload
|
register: deployDownload
|
||||||
|
|||||||
@@ -3,5 +3,10 @@
|
|||||||
# interface without its IPv6 addresses. Start it again whenever
|
# interface without its IPv6 addresses. Start it again whenever
|
||||||
# {{ wireguard_ipv6_converter.service.bindTo }} starts. --no-block because the converter orders
|
# {{ wireguard_ipv6_converter.service.bindTo }} starts. --no-block because the converter orders
|
||||||
# itself After={{ wireguard_ipv6_converter.service.bindTo }}.
|
# itself After={{ wireguard_ipv6_converter.service.bindTo }}.
|
||||||
|
# Upholds= additionally restarts the converter whenever it stops while
|
||||||
|
# {{ wireguard_ipv6_converter.service.bindTo }} is active, e.g. after it exhausted its start limit.
|
||||||
|
[Unit]
|
||||||
|
Upholds=wg-ipv6-converter_{{ wireguard_ipv6_converter.setup.interface }}.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStartPost=/bin/systemctl --no-block start wg-ipv6-converter_{{ wireguard_ipv6_converter.setup.interface }}.service
|
ExecStartPost=/bin/systemctl --no-block start wg-ipv6-converter_{{ wireguard_ipv6_converter.setup.interface }}.service
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ RestartSec=30
|
|||||||
|
|
||||||
Environment="INTERFACE={{ wireguard_ipv6_converter.setup.interface }}"
|
Environment="INTERFACE={{ wireguard_ipv6_converter.setup.interface }}"
|
||||||
{% if wireguard_ipv6_converter.setup.ipv6_format is defined %}
|
{% if wireguard_ipv6_converter.setup.ipv6_format is defined %}
|
||||||
Environment="IPV6_FORMAT={{ wireguard_ipv6_converter.setup.ipv6_format }}"
|
{# systemd expands specifiers in Environment=, so every % must be doubled. #}
|
||||||
|
Environment="IPV6_FORMAT={{ wireguard_ipv6_converter.setup.ipv6_format | replace('%', '%%') }}"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if wireguard_ipv6_converter.setup.filter_prefix is defined %}
|
{% if wireguard_ipv6_converter.setup.filter_prefix is defined %}
|
||||||
Environment="FILTER_PREFIX={{ wireguard_ipv6_converter.setup.filter_prefix }}"
|
Environment="FILTER_PREFIX={{ wireguard_ipv6_converter.setup.filter_prefix }}"
|
||||||
|
|||||||
Reference in New Issue
Block a user