#!/usr/sbin/nft -f # ========== ПЕРЕМЕННЫЕ ========== define VIP_ADDRESSES = { {% for vip in vip_addresses %} {{ vip }}{% if not loop.last %},{% endif %} {% endfor %} } define WHITE_LIST_PORTS = { {% for port in white_list_tcp_ports %} {{ port }}{% if not loop.last %},{% endif %} {% endfor %} } define WHITE_LIST_PORTS_UDP = { {% for port in white_list_udp_ports %} {{ port }}{% if not loop.last %},{% endif %} {% endfor %} } flush ruleset table inet my-firewall { # ========== ЦЕПОЧКА ДЛЯ ВХОДЯЩИХ ПАКЕТОВ (INPUT) ========== chain input { type filter hook input priority -10; policy drop; # Разрешаем уже установленные соединения ct state established,related accept # Разрешаем loopback iifname "lo" accept # Разрешаем ping icmp type echo-request accept # --- VIP-адреса (полный доступ на INPUT) --- ip saddr $VIP_ADDRESSES accept # --- Белый список портов для всех остальных на INPUT --- tcp dport $WHITE_LIST_PORTS accept udp dport $WHITE_LIST_PORTS_UDP accept # Логируем и дропаем всё остальное log prefix "{{ nftables_log_prefix_input }}" counter drop } # ========== ЦЕПОЧКА ДЛЯ МАРШРУТИЗАЦИИ (FORWARD) ========== chain forward { type filter hook forward priority -10; policy drop; # Разрешаем уже установленные соединения ct state established,related accept # --- VIP-адреса (полный доступ ко всем контейнерам) --- ip saddr $VIP_ADDRESSES accept # --- Белый список портов для всех остальных --- tcp dport $WHITE_LIST_PORTS accept udp dport $WHITE_LIST_PORTS_UDP accept # ВСЁ остальное блокируем log prefix "{{ nftables_log_prefix_forward }}" counter drop } # ========== ЦЕПОЧКА ДЛЯ ИСХОДЯЩИХ ПАКЕТОВ (OUTPUT) ========== chain output { type filter hook output priority -10; policy accept; } }