Copied from the environment repository's local role. The files are identical except: galaxy namespace mortis; comments, argument_specs descriptions and the README scrubbed of environment references (issue numbers, CI runs, playbooks, inventory paths and groups, scripts and caller roles by name), with the technical explanation kept and reworded generically; the stray-variable guard's fail message drops its issue reference; the molecule scenario calls the role by its FQCN (mortis.kamino.ufw), follows the Kamino scenario conventions (kamino-molecule header, scenario.test_sequence) and no longer sets ANSIBLE_COLLECTIONS_PATH or ANSIBLE_ROLES_PATH. No variable, default, argument_specs type or task logic changed; the test coverage is the same. The README follows the other Kamino roles: purpose, the main, service_rules and orphan_rules entry points, variables, and example plays with the FQCN and tasks_from. The meta licence stays GPL-3.0-or-later AND GPL-3.0-only (templates/before.rules.j2 is derived from ufw's own file, already annotated in REUSE.toml and NOTICE). galaxy.yml's dependency comment names ufw as a community.general user. Not verified locally: the molecule scenario (it runs on the kamino-molecule runner in CI) and ansible-test sanity. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
85 lines
3.4 KiB
Django/Jinja
85 lines
3.4 KiB
Django/Jinja
{#
|
||
SPDX-License-Identifier: GPL-3.0-only
|
||
Derived from ufw conf/before.rules (https://git.launchpad.net/ufw),
|
||
Copyright 2008-2023 Canonical Ltd., GPL-3.0-only. Modified by Defame1297.
|
||
#}
|
||
# Managed by Ansible – UFW before.rules
|
||
|
||
*filter
|
||
|
||
:ufw-before-input - [0:0]
|
||
:ufw-before-output - [0:0]
|
||
:ufw-before-forward - [0:0]
|
||
:ufw-not-local - [0:0]
|
||
|
||
# Allow all traffic on loopback - this file fully replaces the stock
|
||
# /etc/ufw/before.rules (which always includes this), so without it any
|
||
# fresh (non-conntrack-established) loopback connection - e.g. DNS queries
|
||
# to systemd-resolved's 127.0.0.53 stub - is silently dropped by the
|
||
# default-deny INPUT policy.
|
||
-A ufw-before-input -i lo -j ACCEPT
|
||
-A ufw-before-output -o lo -j ACCEPT
|
||
|
||
# Allow established and related connections
|
||
-A ufw-before-input -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
|
||
-A ufw-before-output -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
|
||
-A ufw-before-forward -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
|
||
|
||
# drop INVALID packets (logs these in loglevel medium and higher)
|
||
-A ufw-before-input -m conntrack --ctstate INVALID -j ufw-logging-deny
|
||
-A ufw-before-input -m conntrack --ctstate INVALID -j DROP
|
||
|
||
# The rules in this file mirror stock ufw's before.rules (checked against
|
||
# ufw 0.36.2); the only deviations are this file's header comments, the
|
||
# omitted stock "End required lines" markers and the aggregated rules loop
|
||
# at the end. Since this template fully replaces that file rather than
|
||
# layering on top of it, dropping the stock rules would silently break
|
||
# ping/PMTU-discovery and treat broadcast/multicast traffic as spoofed
|
||
# non-local input on every host, custom aggregated rules or not.
|
||
|
||
# ok icmp codes for INPUT
|
||
-A ufw-before-input -p icmp --icmp-type destination-unreachable -j ACCEPT
|
||
-A ufw-before-input -p icmp --icmp-type time-exceeded -j ACCEPT
|
||
-A ufw-before-input -p icmp --icmp-type parameter-problem -j ACCEPT
|
||
-A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT
|
||
|
||
# ok icmp codes for FORWARD
|
||
-A ufw-before-forward -p icmp --icmp-type destination-unreachable -j ACCEPT
|
||
-A ufw-before-forward -p icmp --icmp-type time-exceeded -j ACCEPT
|
||
-A ufw-before-forward -p icmp --icmp-type parameter-problem -j ACCEPT
|
||
-A ufw-before-forward -p icmp --icmp-type echo-request -j ACCEPT
|
||
|
||
# allow dhcp client to work
|
||
-A ufw-before-input -p udp --sport 67 --dport 68 -j ACCEPT
|
||
|
||
#
|
||
# ufw-not-local
|
||
#
|
||
-A ufw-before-input -j ufw-not-local
|
||
|
||
# if LOCAL, RETURN
|
||
-A ufw-not-local -m addrtype --dst-type LOCAL -j RETURN
|
||
|
||
# if MULTICAST, RETURN
|
||
-A ufw-not-local -m addrtype --dst-type MULTICAST -j RETURN
|
||
|
||
# if BROADCAST, RETURN
|
||
-A ufw-not-local -m addrtype --dst-type BROADCAST -j RETURN
|
||
|
||
# all other non-local packets are dropped
|
||
-A ufw-not-local -m limit --limit 3/min --limit-burst 10 -j ufw-logging-deny
|
||
-A ufw-not-local -j DROP
|
||
|
||
# allow MULTICAST mDNS for service discovery
|
||
-A ufw-before-input -p udp -d 224.0.0.251 --dport 5353 -j ACCEPT
|
||
|
||
# allow MULTICAST UPnP for service discovery
|
||
-A ufw-before-input -p udp -d 239.255.255.250 --dport 1900 -j ACCEPT
|
||
|
||
{% for rule in ufw_aggregated_before_rules %}
|
||
# {{ rule.comment | default('before-rule') }}
|
||
-A ufw-before-input{% if rule.interface is defined %} -i {{ rule.interface }}{% endif %}{% if rule.proto is defined %} -p {{ rule.proto }}{% endif %}{% if rule.port is defined %} --dport {{ rule.port }}{% endif %}{% if rule.from is defined %} -s {{ rule.from }}{% endif %} -j ACCEPT
|
||
{% endfor %}
|
||
|
||
COMMIT
|