Compare commits
42
Commits
923cd85020
..
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 |
@@ -13,10 +13,27 @@ trap 'rm -f "$tmp"' EXIT
|
||||
# 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. A version in
|
||||
# several suites lists them all, comma separated. A package counts as security when any origin contains "security",
|
||||
# everything else as regular.
|
||||
pending=$(apt-get -s upgrade | awk -v host="$host" -v archs="$archs" '
|
||||
# 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)
|
||||
@@ -24,8 +41,7 @@ pending=$(apt-get -s upgrade | awk -v host="$host" -v archs="$archs" '
|
||||
n = split(line, f, " ")
|
||||
pkg_arch = f[n]
|
||||
gsub(/\[|\]/, "", pkg_arch)
|
||||
sub(/^[^ ]+ /, "", line)
|
||||
kind = (tolower(line) ~ /security/) ? "security" : "regular"
|
||||
kind = ($2 in sec) ? "security" : "regular"
|
||||
count[kind, pkg_arch]++
|
||||
}
|
||||
END {
|
||||
@@ -38,7 +54,7 @@ pending=$(apt-get -s upgrade | awk -v host="$host" -v archs="$archs" '
|
||||
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)
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ ipv6_accept_ra_interfaces: []
|
||||
disk_maintenance:
|
||||
# systemd OnCalendar for fstrim.timer; unset keeps the distribution schedule.
|
||||
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.
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
when: disk_maintenance.zfs_cron_time | default(none) is not none
|
||||
lineinfile:
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
- import_tasks: ./timesync.yml
|
||||
|
||||
- import_tasks: ./cloud_init.yml
|
||||
|
||||
- import_tasks: ./aliases.yml
|
||||
|
||||
- import_tasks: ./networking.yml
|
||||
|
||||
@@ -23,19 +23,16 @@
|
||||
|
||||
- name: Generate random IPv6 stable-secret
|
||||
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
|
||||
copy:
|
||||
dest: "/etc/sysctl.d/ipv6-slaac-address-generation.conf"
|
||||
content: |
|
||||
{% if ansible_facts.default_ipv6.interface is defined %}
|
||||
net.ipv6.conf.{{ ansible_facts.default_ipv6.interface }}.addr_gen_mode = 2
|
||||
net.ipv6.conf.{{ ansible_facts.default_ipv6.interface }}.stable_secret = {{ ipv6_stable_secret }}
|
||||
{% 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 %}
|
||||
{% set iface = ansible_facts.default_ipv6.interface | default(ansible_facts.default_ipv4.interface) %}
|
||||
net.ipv6.conf.{{ iface }}.stable_secret = {{ ipv6_stable_secret }}
|
||||
net.ipv6.conf.{{ iface }}.addr_gen_mode = 2
|
||||
notify: reload_sysctl
|
||||
when:
|
||||
- ansible_facts.default_ipv6 is defined
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
- name: Check if SSH daemon is active
|
||||
systemd:
|
||||
name: sshd
|
||||
name: ssh
|
||||
state: started
|
||||
register: sshd_status
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
- name: Restart SSH daemon
|
||||
service:
|
||||
name: sshd
|
||||
name: ssh
|
||||
state: restarted
|
||||
when: sshd_config.changed
|
||||
when: sshd_status.status.ActiveState == 'active'
|
||||
|
||||
@@ -19,6 +19,14 @@
|
||||
dest: /etc/apt/keyrings/crowdsec.asc
|
||||
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
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/apt/sources.list.d/crowdsec.list
|
||||
@@ -28,6 +36,7 @@
|
||||
https://packagecloud.io/crowdsec/crowdsec/{{ ansible_distribution | lower }}/
|
||||
{{ crowdsec.apt_suite_map[ansible_distribution_release] | default(ansible_distribution_release) }} main
|
||||
register: crowdsec_repo
|
||||
when: not crowdsec_sources.stat.exists
|
||||
|
||||
# The postinst asks these; without them it registers a local machine for a
|
||||
# local LAPI and enrols in the central CAPI.
|
||||
|
||||
@@ -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")
|
||||
NFT = "/usr/sbin/nft"
|
||||
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):
|
||||
@@ -35,11 +37,16 @@ def fetch_ranges(lapi_url, api_key):
|
||||
return []
|
||||
if not isinstance(decisions, list):
|
||||
raise ValueError("unexpected LAPI answer: %s" % type(decisions).__name__)
|
||||
return [
|
||||
ipaddress.ip_network(d["value"], strict=False)
|
||||
for d in decisions
|
||||
if d["type"] == "ban" and d["scope"].lower() == "range"
|
||||
]
|
||||
networks = []
|
||||
for d in decisions:
|
||||
if d["type"] != "ban" or 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):
|
||||
|
||||
@@ -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:
|
||||
name: "docker"
|
||||
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
|
||||
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
|
||||
ansible.builtin.copy:
|
||||
src: docker-compose
|
||||
dest: "/usr/local/bin/docker-compose"
|
||||
mode: preserve
|
||||
mode: "0755"
|
||||
|
||||
- name: Check for docker binary
|
||||
ansible.builtin.stat:
|
||||
|
||||
@@ -8,6 +8,15 @@
|
||||
install_recommends: false
|
||||
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
|
||||
|
||||
@@ -34,6 +34,16 @@ firewall:
|
||||
ifaces: {}
|
||||
v4: {}
|
||||
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
|
||||
# the maps above. Forwarded traffic passes the forward hook, not input.
|
||||
dnat: {}
|
||||
@@ -83,16 +93,18 @@ firewall:
|
||||
# Lets the kernel log the nft log statements of container network
|
||||
# namespaces (LXC guests) into the host kernel log.
|
||||
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 DROP, DROPv6 and ASN-DROP: traffic from the listed networks drops
|
||||
# (input, forward), traffic to them is rejected (output, forward). The sets
|
||||
# are refreshed daily by nft-host-spamhaus.
|
||||
spamhaus: true
|
||||
# FireHOL level1 (IPv4): treated like the Spamhaus lists, with the prefixes
|
||||
# fw-firehol-in: and fw-firehol-out: and the same log limit. Entries in
|
||||
# private or reserved space and ones holding an address of the host are left
|
||||
# out. Refreshed daily by nft-host-firehol.
|
||||
# FireHOL lists (IPv4 only, FireHOL has no IPv6 lists), from github.com/firehol/blocklist-ipsets:
|
||||
# level1 and level2 (level2 includes GreenSnow): treated like the Spamhaus lists, with the prefixes fw-firehol1-in: ,
|
||||
# fw-firehol1-out: (level1) and fw-firehol2-in: , fw-firehol2-out: (level2) and the same log limit.
|
||||
# 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
|
||||
# Internet-wide scanners (Censys, Shodan, ONYPHE, Shadowserver, ...), IPv4
|
||||
# and IPv6: the cidr files of github.com/OpenFilters/internet-scanners
|
||||
@@ -104,6 +116,28 @@ firewall:
|
||||
# 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.
|
||||
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.
|
||||
block_smtp_out: true
|
||||
# EU-27 plus CH, NO, GB, IS, LI (ipdeny country codes). Empty leaves the geo
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#!/usr/bin/python3
|
||||
# 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
|
||||
the previous set stays in place.
|
||||
Every set is built from one or more lists of the FireHOL blocklist-ipsets
|
||||
(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 json
|
||||
@@ -16,11 +19,16 @@ import time
|
||||
import urllib.request
|
||||
|
||||
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)"
|
||||
|
||||
# Lower bound that catches an empty or truncated answer.
|
||||
MIN_ENTRIES = 1000
|
||||
# set name -> (lists merged into it, lower bound for their entries together that
|
||||
# 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.
|
||||
MIN_PREFIXLEN = 8
|
||||
# Private, CGNAT (NetBird), loopback, link-local and multicast/reserved space:
|
||||
@@ -36,17 +44,18 @@ def fail(message):
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def fetch():
|
||||
def fetch(name):
|
||||
url = BASE_URL + name
|
||||
error = None
|
||||
for attempt in range(3):
|
||||
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:
|
||||
return response.read().decode("utf-8")
|
||||
except OSError as e:
|
||||
error = e
|
||||
time.sleep(5 * (attempt + 1))
|
||||
fail(f"download of {URL} failed: {error}")
|
||||
fail(f"download of {url} failed: {error}")
|
||||
|
||||
|
||||
def own_addresses():
|
||||
@@ -57,20 +66,20 @@ def own_addresses():
|
||||
for a in link.get("addr_info", []) if a.get("family") == "inet"]
|
||||
|
||||
|
||||
def main():
|
||||
def build_set(lists, minimum, own):
|
||||
networks = []
|
||||
for line in fetch().splitlines():
|
||||
for name in lists:
|
||||
for line in fetch(name).splitlines():
|
||||
line = line.strip()
|
||||
if not line or line.startswith("#"):
|
||||
continue
|
||||
try:
|
||||
networks.append(ipaddress.IPv4Network(line))
|
||||
except ValueError:
|
||||
fail(f"unparsable line: {line!r}")
|
||||
if len(networks) < MIN_ENTRIES:
|
||||
fail(f"only {len(networks)} entries")
|
||||
fail(f"unparsable line in {name}: {line!r}")
|
||||
if len(networks) < minimum:
|
||||
fail(f"only {len(networks)} entries in {', '.join(lists)}")
|
||||
|
||||
own = own_addresses()
|
||||
kept, excluded, own_skipped = [], 0, 0
|
||||
for network in networks:
|
||||
if any(network.overlaps(e) for e in EXCLUDED):
|
||||
@@ -82,21 +91,28 @@ def main():
|
||||
fail(f"suspiciously wide prefix {network}")
|
||||
kept.append(network)
|
||||
merged = list(ipaddress.collapse_addresses(kept))
|
||||
print(f"firehol_v4: {len(networks)} entries, {excluded} in private or reserved space and "
|
||||
f"{own_skipped} holding an own address skipped -> {len(merged)} merged")
|
||||
return networks, excluded, own_skipped, 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"
|
||||
"table inet host {\n"
|
||||
"\tset firehol_v4 { type ipv4_addr; flags interval; auto-merge; elements = {\n"
|
||||
f"\t\t{elements}\n\t}} }}\n}}\n")
|
||||
"table inet host {\n" + "".join(definitions) + "}\n")
|
||||
|
||||
# Checked under another table name: a dry run against the live table
|
||||
# name changes the live sets for its duration and unlisted addresses match.
|
||||
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)
|
||||
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:
|
||||
previous = None
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[Unit]
|
||||
Description=Refresh the FireHOL set of the host firewall
|
||||
Description=Refresh the FireHOL sets of the host firewall
|
||||
Wants=network-online.target
|
||||
After=network-online.target
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[Unit]
|
||||
Description=Daily refresh of the host firewall FireHOL set
|
||||
Description=Daily refresh of the host firewall FireHOL sets
|
||||
|
||||
[Timer]
|
||||
OnCalendar=daily
|
||||
|
||||
@@ -10,6 +10,11 @@
|
||||
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
|
||||
|
||||
- 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
|
||||
ansible.builtin.blockinfile:
|
||||
path: /etc/nftables.conf
|
||||
@@ -174,7 +179,7 @@
|
||||
path: /etc/nftables.d/host-spamhaus.nft
|
||||
state: absent
|
||||
|
||||
- name: FireHOL set
|
||||
- name: FireHOL sets
|
||||
when: firewall.firehol
|
||||
block:
|
||||
- name: Install the FireHOL set updater
|
||||
@@ -183,25 +188,40 @@
|
||||
dest: /usr/local/sbin/nft-host-firehol
|
||||
mode: "0755"
|
||||
|
||||
# The rule set includes this file, so a missing one would fail the load at boot.
|
||||
- name: Build the FireHOL set on first run
|
||||
ansible.builtin.command: /usr/local/sbin/nft-host-firehol
|
||||
args:
|
||||
creates: /etc/nftables.d/host-firehol.nft
|
||||
# The rule set includes this file and uses both sets, so a missing file or set would fail the load at boot.
|
||||
- name: Look for the FireHOL sets
|
||||
ansible.builtin.command: grep -cE 'set (firehol_v4|firehol_level2_v4) ' /etc/nftables.d/host-firehol.nft
|
||||
register: firewall_firehol_sets
|
||||
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:
|
||||
path: /etc/nftables.d/host-firehol.nft
|
||||
register: firewall_firehol
|
||||
|
||||
- name: Require non-empty FireHOL set
|
||||
- name: Require non-empty FireHOL sets
|
||||
ansible.builtin.assert:
|
||||
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
|
||||
# Check mode neither installs the updater nor builds the sets.
|
||||
when: not ansible_check_mode
|
||||
|
||||
- name: Enable the FireHOL set timer
|
||||
- name: Enable the FireHOL sets timer
|
||||
ansible.builtin.systemd:
|
||||
name: nft-host-firehol.timer
|
||||
enabled: true
|
||||
@@ -210,10 +230,10 @@
|
||||
# Check mode does not install the unit.
|
||||
ignore_errors: "{{ ansible_check_mode }}"
|
||||
|
||||
- name: Stop the FireHOL set refresh
|
||||
- name: Stop the FireHOL sets refresh
|
||||
when: not firewall.firehol
|
||||
block:
|
||||
- name: Disable the FireHOL set timer
|
||||
- name: Disable the FireHOL sets timer
|
||||
ansible.builtin.systemd:
|
||||
name: nft-host-firehol.timer
|
||||
enabled: false
|
||||
@@ -222,7 +242,7 @@
|
||||
# Check mode does not install the unit.
|
||||
ignore_errors: "{{ ansible_check_mode }}"
|
||||
|
||||
- name: Remove the FireHOL set file
|
||||
- name: Remove the FireHOL sets file
|
||||
ansible.builtin.file:
|
||||
path: /etc/nftables.d/host-firehol.nft
|
||||
state: absent
|
||||
@@ -361,3 +381,45 @@
|
||||
dest: /etc/nftables.d/host.nft.good
|
||||
remote_src: true
|
||||
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
|
||||
|
||||
@@ -30,8 +30,15 @@ set {{ name }} {
|
||||
{% set guest_match = 'iifname { "' ~ (guest_ifaces | join('", "')) ~ '" }' %}
|
||||
{% 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 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 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 %}
|
||||
{% macro port_values(map) -%}
|
||||
{{ map | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | map('string') | unique | join(' ') }}
|
||||
@@ -88,6 +95,12 @@ table inet host {
|
||||
{{ addr_set('admin_v6', 'ipv6_addr', firewall.admin.v6) }}
|
||||
{{ addr_set('cluster_v4', 'ipv4_addr', cluster.v4) }}
|
||||
{{ 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_v6', 'ipv6_addr', scrapers.v6) }}
|
||||
{{ addr_list_set('rl_exempt_v4', 'ipv4_addr', exempt_v4) }}
|
||||
@@ -123,6 +136,31 @@ table inet host {
|
||||
}
|
||||
{% 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 {
|
||||
type filter hook input priority filter; policy drop;
|
||||
{% if blocklists %}
|
||||
@@ -134,7 +172,8 @@ table inet host {
|
||||
ip6 saddr @spamhaus_v6 jump spamhaus_in
|
||||
{% endif %}
|
||||
{% 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 %}
|
||||
@@ -297,13 +336,23 @@ table inet host {
|
||||
{% endif %}
|
||||
{% if firewall.firehol %}
|
||||
|
||||
chain firehol_in {
|
||||
limit rate {{ firewall.log.spamhaus_rate }} log prefix "fw-firehol-in: "
|
||||
chain firehol1_in {
|
||||
limit rate {{ firewall.log.spamhaus_rate }} log prefix "fw-firehol1-in: "
|
||||
drop
|
||||
}
|
||||
|
||||
chain firehol_out {
|
||||
limit rate {{ firewall.log.spamhaus_rate }} log prefix "fw-firehol-out: "
|
||||
chain firehol1_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
|
||||
}
|
||||
{% endif %}
|
||||
@@ -330,7 +379,8 @@ table inet host {
|
||||
{% endif %}
|
||||
{% 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 %}
|
||||
{% if firewall.block_smtp_out %}
|
||||
|
||||
@@ -394,10 +444,19 @@ table inet host {
|
||||
ip6 saddr @geo_v6 accept
|
||||
{% endif %}
|
||||
}
|
||||
{% if forward_guard or blocklists or firewall.scanners or rl_forward %}
|
||||
{% 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 {
|
||||
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.
|
||||
@@ -415,8 +474,10 @@ table inet host {
|
||||
{% endif %}
|
||||
{% if firewall.firehol %}
|
||||
|
||||
ip saddr @firehol_v4 jump firehol_in
|
||||
ip daddr @firehol_v4 jump firehol_out
|
||||
ip saddr @firehol_v4 jump firehol1_in
|
||||
ip daddr @firehol_v4 jump firehol1_out
|
||||
ip saddr @firehol_level2_v4 jump firehol2_in
|
||||
ip daddr @firehol_level2_v4 jump firehol2_out
|
||||
{% endif %}
|
||||
{% if firewall.scanners %}
|
||||
|
||||
@@ -443,6 +504,48 @@ table inet host {
|
||||
{{ match }} jump drop_log
|
||||
{% 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 %}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,10 @@ dump() { # file, container, command run inside the container
|
||||
dump {{ d.file | quote }} {{ d.container | quote }} {{ d.command | quote }}
|
||||
{% endfor %}
|
||||
{% 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 %}
|
||||
{% if ignores %}
|
||||
|
||||
@@ -50,6 +54,24 @@ ignore() {
|
||||
ignore {{ i.key | quote }} {{ i.value | map('quote') | join(' ') }}
|
||||
{% endfor %}
|
||||
{% 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
|
||||
[ -d "$p" ] && sources+=("$p")
|
||||
|
||||
@@ -19,10 +19,16 @@ kubernetes:
|
||||
token: <shared token for nodes to join>
|
||||
|
||||
network:
|
||||
# Copies the current /etc/resolv.conf whilst only keeping "nameserver" lines
|
||||
# can be used to remove filter
|
||||
# Writes /etc/resolv-k3s.conf (k3s resolv-conf, CoreDNS upstreams) from
|
||||
# resolv_conf_nameservers
|
||||
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]
|
||||
plugin: calico
|
||||
|
||||
|
||||
@@ -45,17 +45,15 @@
|
||||
else (ansible_default_ipv6.address | default('')) }}
|
||||
|
||||
- block:
|
||||
- name: Read resolv.conf
|
||||
shell: "grep '^nameserver' /etc/resolv.conf"
|
||||
register: nameserver_line
|
||||
changed_when: false
|
||||
check_mode: false
|
||||
|
||||
- name: Write /etc/resolv-k3s.conf with only nameservers
|
||||
copy:
|
||||
content: "{{ nameserver_line.stdout }}"
|
||||
- name: Write /etc/resolv-k3s.conf with the fixed nameservers
|
||||
template:
|
||||
src: resolv-k3s.conf.jinja2
|
||||
dest: /etc/resolv-k3s.conf
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
when: kubernetes.network.clean_resolv_conf is true
|
||||
tags: resolv_conf
|
||||
|
||||
- name: Run handlers to reload configurations
|
||||
meta: flush_handlers
|
||||
|
||||
@@ -23,12 +23,14 @@ spec:
|
||||
hostNetwork: true
|
||||
containers:
|
||||
- name: routingtabletowg
|
||||
image: "ruakij/routingtabletowg:0.2.0"
|
||||
image: "ghcr.io/ruakij/routingtabletowg:0.3.0@sha256:a2c505e0f716dbbfdda1a535e2631e5a73b64236cd68d459eb407beab2e1032e"
|
||||
env:
|
||||
- name: INTERFACE
|
||||
value: {{ kubernetes.ipPool.nodeIp_interface }}
|
||||
- name: FILTER_PROTOCOL
|
||||
value: bird
|
||||
- name: FILTER_TABLE
|
||||
value: main
|
||||
- name: PERIODIC_SYNC
|
||||
value: '300'
|
||||
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 %}
|
||||
@@ -9,3 +9,5 @@ netbird_client:
|
||||
iface_blacklist_extra: []
|
||||
# Overrides the --log-level of the netbird service when set
|
||||
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 }}"
|
||||
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
|
||||
copy:
|
||||
dest: /etc/systemd/system/netbird.service.d/20-log-level.conf
|
||||
|
||||
@@ -5,19 +5,33 @@
|
||||
- curl
|
||||
- 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
|
||||
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
|
||||
executable: /bin/bash
|
||||
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
|
||||
apt_repository:
|
||||
repo: "deb [signed-by=/usr/share/keyrings/netbird-archive-keyring.gpg] https://pkgs.netbird.io/debian stable main"
|
||||
state: present
|
||||
filename: netbird
|
||||
deb822_repository:
|
||||
name: netbird
|
||||
types: deb
|
||||
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
|
||||
when: netbird_list.changed or netbird_repo.changed
|
||||
|
||||
# present, not latest: an upgrade restarts the daemon and drops the tunnels of the node.
|
||||
- name: Install wireguard & netbird
|
||||
|
||||
@@ -23,6 +23,21 @@
|
||||
dest: /etc/apt/apt.conf.d/52unattended-upgrades-local
|
||||
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
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
# {{ ansible_managed }}
|
||||
$nrconf{restart} = 'l';
|
||||
@@ -5,7 +5,10 @@
|
||||
|
||||
- name: Download binary
|
||||
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
|
||||
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
|
||||
|
||||
@@ -3,5 +3,10 @@
|
||||
# interface without its IPv6 addresses. Start it again whenever
|
||||
# {{ wireguard_ipv6_converter.service.bindTo }} starts. --no-block because the converter orders
|
||||
# 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]
|
||||
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 }}"
|
||||
{% 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 %}
|
||||
{% if wireguard_ipv6_converter.setup.filter_prefix is defined %}
|
||||
Environment="FILTER_PREFIX={{ wireguard_ipv6_converter.setup.filter_prefix }}"
|
||||
|
||||
Reference in New Issue
Block a user