nftables.conf.j2 37 lignes · 1648 octets
#!/usr/sbin/nft -f
# {{ ansible_managed }}
# Seule la table open_iam est remplacée : les règles d'autres outils (Docker…) sont conservées.
table inet open_iam
delete table inet open_iam

table inet open_iam {
  chain entree {
    type filter hook input priority filter; policy drop;
    iif "lo" accept
    ct state established,related accept
    ct state invalid drop
    meta l4proto { icmp, ipv6-icmp } accept
    tcp dport {{ oiam_port_ssh }} accept comment "SSH"
{% if oiam_ports_ouverts | length > 0 %}
    tcp dport { {{ oiam_ports_ouverts | join(', ') }} } accept comment "Services Open IAM"
{% endif %}
{% if oiam_plages_tcp_ouvertes | length > 0 %}
    tcp dport { {{ oiam_plages_tcp_ouvertes | join(', ') }} } accept comment "Plages Open IAM"
{% endif %}
{% if oiam_ports_udp_ouverts | length > 0 %}
    udp dport { {{ oiam_ports_udp_ouverts | join(', ') }} } accept comment "Services Open IAM (UDP)"
{% endif %}
{% if oiam_topologie | default('local') == 'multi' %}
{# Supervision répartie : collecte des métriques par les hôtes de supervision, journaux vers Loki. #}
{% set ips = oiam_ip_par_adresse | default({}) %}
{% for hote in oiam_hotes | default([]) if 'supervision' in hote.roles and hote.adresse in ips %}
    ip saddr {{ ips[hote.adresse] }} tcp dport { 9100, 9330, 12345 } accept comment "Collecte depuis {{ hote.nom }}"
{% endfor %}
{% if oiam_hote_roles is defined and 'supervision' in oiam_hote_roles %}
{% for hote in oiam_hotes | default([]) if hote.adresse in ips %}
    ip saddr {{ ips[hote.adresse] }} tcp dport 3100 accept comment "Journaux depuis {{ hote.nom }}"
{% endfor %}
{% endif %}
{% endif %}
  }
}