2 Commits
5 changed files with 43 additions and 0 deletions
+5
View File
@@ -31,6 +31,11 @@ firewall:
dnat: {} dnat: {}
# IPv4 source NAT: name -> nft match, e.g. 'oifname "vmbr0"'. # IPv4 source NAT: name -> nft match, e.g. 'oifname "vmbr0"'.
masquerade: {} masquerade: {}
# Forwarded traffic to guarded guests: name -> {ifaces, v4, v6}, where v4 and
# v6 are {daddr, tcp: ports, icmp: icmp or icmpv6 types}. Replies and traffic
# in on ifaces pass, the listed ports and types pass, the rest to daddr drops;
# traffic to other addresses is not filtered.
forward_guard: {}
ssh_rate_limit: "10/minute burst 5 packets" ssh_rate_limit: "10/minute burst 5 packets"
# 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
# ports to the admin set; a load peaks at about 60 MB of kernel memory, too much for a 1 GB host. # ports to the admin set; a load peaks at about 60 MB of kernel memory, too much for a 1 GB host.
+27
View File
@@ -18,6 +18,7 @@ set {{ name }} {
{% 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 forward_guard = firewall.forward_guard | default({}, true) | dict2items | rejectattr('value', 'none') | 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.
@@ -119,6 +120,32 @@ table inet host {
ip6 saddr @geo_v6 accept ip6 saddr @geo_v6 accept
{% endif %} {% endif %}
} }
{% if forward_guard %}
chain forward {
type filter hook forward priority filter; policy accept;
{% for guard in forward_guard %}
# {{ guard.key }}
{% set ifaces = guard.value.ifaces | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | unique | list %}
{% for fam, l3, icmp in [('v4', 'ip', 'icmp'), ('v6', 'ip6', 'icmpv6')] if list((guard.value[fam] | default({}, true)).daddr) %}
{% set zone = guard.value[fam] %}
{% set match = l3 ~ ' daddr { ' ~ list(zone.daddr) ~ ' }' %}
{{ match }} ct state established,related accept
{% if ifaces %}
{{ match }} iifname { "{{ ifaces | join('", "') }}" } accept
{% endif %}
{% if list(zone.tcp) %}
{{ match }} tcp dport { {{ list(zone.tcp) }} } accept
{% endif %}
{% if list(zone.icmp) %}
{{ match }} {{ icmp }} type { {{ list(zone.icmp) }} } accept
{% endif %}
{{ match }} drop
{% endfor %}
{% endfor %}
}
{% endif %}
} }
{% if dnat or masquerade %} {% if dnat or masquerade %}
+2
View File
@@ -15,6 +15,8 @@ kopia_backup:
sources: [] sources: []
# source path -> ignore rules, replacing the policy rules on every run (null drops one). # source path -> ignore rules, replacing the policy rules on every run (null drops one).
ignore: {} ignore: {}
# Command run first, e.g. a host script writing dumps into a source; a failure fails the run, the snapshot still runs.
pre_command: ""
# Database dumps written to /var/backups/dumps before the snapshot, which then includes that directory. # Database dumps written to /var/backups/dumps before the snapshot, which then includes that directory.
# Each item: file, container, command (run with sh -c inside the container, output is the dump). # Each item: file, container, command (run with sh -c inside the container, output is the dump).
dumps: [] dumps: []
+5
View File
@@ -15,6 +15,11 @@
state: directory state: directory
mode: "0755" mode: "0755"
- name: Install gpg for the apt key
ansible.builtin.apt:
name: gpg
state: present
- name: Add the Kopia apt key - name: Add the Kopia apt key
ansible.builtin.shell: curl -fsSL https://kopia.io/signing-key | gpg --dearmor -o /etc/apt/keyrings/kopia-keyring.gpg ansible.builtin.shell: curl -fsSL https://kopia.io/signing-key | gpg --dearmor -o /etc/apt/keyrings/kopia-keyring.gpg
args: args:
+4
View File
@@ -5,6 +5,10 @@ set -uo pipefail
export KOPIA_CHECK_FOR_UPDATES=false export KOPIA_CHECK_FOR_UPDATES=false
failed=0 failed=0
sources=() sources=()
{% if kopia_backup.pre_command %}
{{ kopia_backup.pre_command }} || { echo "pre_command failed" >&2; failed=1; }
{% endif %}
{% if kopia_backup.etcd_snapshot %} {% if kopia_backup.etcd_snapshot %}
# Only the latest etcd snapshot; the live etcd dir is not consistent on disk and older snapshots only add churn # Only the latest etcd snapshot; the live etcd dir is not consistent on disk and older snapshots only add churn