Files
Kamino/roles/ufw/defaults/main.yml
T
Defame1297 c617bee02a
Build / build (pull_request) Successful in 33s
Molecule / select (pull_request) Successful in 2s
Lint / lint (pull_request) Successful in 4m5s
Molecule / scenarios (pull_request) Successful in 12m51s
Molecule / Result (pull_request) Successful in 0s
fix(ufw): mask nftables.service so an upgrade cannot flush the rules
When nftables.service is enabled, the nftables package's postinst
restarts it on upgrade. The stock /etc/nftables.conf begins with
`flush ruleset` and the unit's ExecStop flushes too, so every rule ufw
and Docker loaded was deleted until they reloaded.

The role now masks the unit without stopping it, gated on ufw_enabled
and the new opt-out input ufw_mask_nftables. systemd refuses every job
but a stop on a masked unit, so the postinst's try-restart fails
before anything runs (the postinst ignores the failure) and the unit
does not start at boot. Masking works when the unit is absent too.

Assisted-by: Claude Code:claude-opus-5-5
2026-12-05 22:33:26 +00:00

58 lines
2.6 KiB
YAML

---
ufw_enabled: true
ufw_manage_rules: true
ufw_defaults:
incoming: deny
outgoing: allow
routed: deny
ufw_logging: "on"
# Mask nftables.service (not stopped), so a restart by a package upgrade cannot flush the rules
# ufw loaded. false: leave the unit alone, for hosts that load their own ruleset through it.
ufw_mask_nftables: true
# Lock-out guard: with a deny/reject incoming default the play refuses to run
# unless an allow/limit rule for this TCP port is in the rule list, since the
# default is applied before the rules and a missing rule cuts the SSH session.
ufw_require_ssh_allow: true
ufw_ssh_port: "{{ ansible_port | default(22, true) }}"
ufw_rules: []
ufw_before_rules: []
# Keys/values written into /etc/ufw/sysctl.conf so ufw's stock file does not
# reset values set by the system_baseline role of this Collection. Set per group of hosts.
ufw_sysctl_overrides: []
# service_rules entry point. The owner tag is written into each rule's
# comment as `<prefix>[<owner>:<key>]: <text>`; stale detection reads it back
# from `ufw show added`. The regex captures (owner, key) and must match the tag
# built from the prefix: change both together, and note that changing either
# orphans every rule already tagged.
ufw_tag_prefix: ansible-ufw
ufw_tag_regex: "comment 'ansible-ufw\\[([a-z0-9_]+):([0-9a-f]{10})\\]:"
# Characters allowed in a tagged comment: printable ASCII without the single
# quote (it breaks the ufw module) and the backslash.
ufw_tag_comment_regex: '^[] -&(-[^-~]*\Z'
# Finds the port tokens of a rule line (comment removed): a number or a range or list such as
# 20:30 or 22,80, followed by /tcp, /udp, a space or the end, and not part of an address,
# interface name or CIDR. A line is deleted as stale or orphaned only with exactly one plain
# numeric token that is not ufw_ssh_port; every other line may carry SSH and is kept.
ufw_port_token_regex: '(?<![0-9A-Za-z_.:/-])[0-9]+(?::[0-9]+)?(?:,[0-9]+(?::[0-9]+)?)*(?=/(?:tcp|udp)|[ ]|$)'
# Owner names no service may use: `base` is reserved for the base play.
ufw_reserved_owners: [base]
ufw_service_state: present
# false: stale rules of the owner are only reported. true: they are deleted
# after every desired rule was applied.
ufw_purge_stale: false
# orphan_rules entry point. ufw_managed_owners has NO default on purpose: the
# entry point does nothing while it is undefined or empty (fail closed). false: orphaned
# rules (tagged, owner neither managed nor reserved) are only reported. true: they are deleted.
# The default stays false; a caller that wants the purge sets true in the task vars of its
# orphan_rules call.
ufw_purge_orphans: false