f-76: nft: règles de pont en nftables, ebtables retiré #76
internal/nft pose les règles d'un port en une transaction, dans une table bridge two par netns de VPC. Subnets, gateway anycast et watchdog l'utilisent, même filtrage qu'avec ebtables. bootstrap_kvm.sh et le lab installent nftables ; helpers e2e, doc et notes 0.3.0 suivent. Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
da6295baf1
commit
d98e42e0a8
27 changed files with 823 additions and 341 deletions
|
|
@ -1,4 +1,4 @@
|
|||
# fonctionnalité: hypothèses d'environnement de la suite — firmware UEFI, unités modèles de l'agent, journalctl, format de ebtables -L, br-lan, priorités VRRP lues dans FRR
|
||||
# fonctionnalité: hypothèses d'environnement de la suite — firmware UEFI, unités modèles de l'agent, journalctl, format de nft list table, br-lan, priorités VRRP lues dans FRR
|
||||
# hôtes: hv1 hv2 hv3
|
||||
# tickets: #70
|
||||
|
||||
|
|
@ -17,20 +17,32 @@ check "${HOST} : journalctl accepte --since @<epoch>" journalctl --since "@$(dat
|
|||
for unit in dhcp@.service dnsmasq@.service metadata@.service; do
|
||||
check "${HOST} : unité modèle ${unit} installée" systemctl cat "${unit}"
|
||||
done
|
||||
NS=t02-ebt
|
||||
NS=t02-nft
|
||||
MAC=02:01:00:00:0c:27
|
||||
ip netns add "${NS}"
|
||||
check "${HOST} : ebtables -L, aucune règle avant (témoin)" test "$(ebt_confined "${NS}" v-t02-i "${MAC}")" -eq 0
|
||||
ip netns exec "${NS}" ebtables -t nat -A PREROUTING --in-interface v-t02-i -s "${MAC}" -j DROP
|
||||
ip netns exec "${NS}" ebtables -t filter -A FORWARD --out-interface v-t02-i -s "${MAC}" -j DROP
|
||||
ip netns exec "${NS}" ebtables -t filter -A OUTPUT --out-interface v-t02-i -s "${MAC}" -j DROP
|
||||
ip netns exec "${NS}" ebtables -A FORWARD --out-interface v-t02-i -p arp --arp-op Request --arp-ip-dst 10.2.1.254 -j DROP
|
||||
ip netns exec "${NS}" ebtables -A FORWARD --out-interface v-t02-i -p IPv4 --ip-protocol udp --ip-source-port 67:68 --ip-destination-port 67:68 --ip-source 10.2.1.254 -j DROP
|
||||
check "${HOST} : ebtables -L, confinement de MAC lu par ebt_confined (3 règles)" test "$(ebt_confined "${NS}" v-t02-i "${MAC}")" -eq 3
|
||||
check "${HOST} : ebtables -L, blocage ARP vers la gateway lu par ebt_arp_drop" ebt_arp_drop "${NS}" v-t02-i 10.2.1.254
|
||||
check "${HOST} : ebtables -L, blocage DHCP lu par ebt_dhcp_drop" ebt_dhcp_drop "${NS}" v-t02-i 10.2.1.254
|
||||
other_ip_ignored () { ! ebt_arp_drop "${NS}" v-t02-i 10.2.1.25; }
|
||||
check "${HOST} : ebt_arp_drop ne confond pas une autre adresse (témoin)" other_ip_ignored
|
||||
check "${HOST} : nft installé" command -v nft
|
||||
check "${HOST} : nft list table, aucune règle avant (témoin)" test "$(nft_confined "${NS}" v-t02-i "${MAC}")" -eq 0
|
||||
ip netns exec "${NS}" nft -f - <<NFT
|
||||
add table bridge two
|
||||
add chain bridge two pre-v-t02-i
|
||||
add rule bridge two pre-v-t02-i ether saddr ${MAC} drop
|
||||
add chain bridge two fwd-v-t02-i
|
||||
add rule bridge two fwd-v-t02-i ether saddr ${MAC} drop
|
||||
add rule bridge two fwd-v-t02-i arp operation request arp daddr ip 10.2.1.254 drop
|
||||
add rule bridge two fwd-v-t02-i ip saddr 10.2.1.254 udp sport 67-68 udp dport 67-68 drop
|
||||
add chain bridge two out-v-t02-i
|
||||
add rule bridge two out-v-t02-i ether saddr ${MAC} drop
|
||||
add chain bridge two fwd-v-t02x-i
|
||||
add rule bridge two fwd-v-t02x-i arp operation request arp daddr ip 10.2.9.254 drop
|
||||
NFT
|
||||
check "${HOST} : nft list table, confinement de MAC lu par nft_confined (3 règles)" test "$(nft_confined "${NS}" v-t02-i "${MAC}")" -eq 3
|
||||
check "${HOST} : nft list table, blocage ARP vers la gateway lu par nft_arp_drop" nft_arp_drop "${NS}" v-t02-i 10.2.1.254
|
||||
check "${HOST} : nft list table, blocage DHCP lu par nft_dhcp_drop" nft_dhcp_drop "${NS}" v-t02-i 10.2.1.254
|
||||
other_ip_ignored () { ! nft_arp_drop "${NS}" v-t02-i 10.2.1.25; }
|
||||
check "${HOST} : nft_arp_drop ne confond pas une autre adresse (témoin)" other_ip_ignored
|
||||
other_port_ignored () { ! nft_arp_drop "${NS}" v-t02-i 10.2.9.254; }
|
||||
check "${HOST} : nft_rules ne lit pas la chaîne d'un autre port (témoin)" other_port_ignored
|
||||
check "${HOST} : nft_handle trouve le numéro d'une règle" test -n "$(nft_handle "${NS}" out-v-t02-i "ether saddr ${MAC} drop")"
|
||||
ip netns del "${NS}"
|
||||
case "${HOST}" in
|
||||
hv1) LAN=10.33.0.11 ;;
|
||||
|
|
|
|||
|
|
@ -18,10 +18,10 @@ check "sn-t31a : route du subnet émise depuis la gateway" sh -c "ip -n vp-t31 -
|
|||
for dev in br-t31a gw-t31a; do
|
||||
check "sn-t31a : ${dev}, arp_ignore=1 et arp_announce=2" sh -c "[ \"\$(ip netns exec vp-t31 sysctl -n net.ipv4.conf.${dev}.arp_ignore) \$(ip netns exec vp-t31 sysctl -n net.ipv4.conf.${dev}.arp_announce)\" = '1 2' ]"
|
||||
done
|
||||
check "sn-t31a : confinement de la MAC anycast sur v-t31a-i (nat PREROUTING, FORWARD, OUTPUT)" test "$(ebt_confined vp-t31 v-t31a-i "${MAC}")" -eq 3
|
||||
check "sn-t31a : confinement de la MAC anycast sur v-t31a-i (prerouting, forward, output)" test "$(nft_confined vp-t31 v-t31a-i "${MAC}")" -eq 3
|
||||
for ip in 10.31.1.254 10.31.1.253; do
|
||||
check "sn-t31a : requêtes ARP vers ${ip} bloquées en sortie de v-t31a-i" ebt_arp_drop vp-t31 v-t31a-i "${ip}"
|
||||
check "sn-t31a : DHCP émis depuis ${ip} bloqué en sortie de v-t31a-i" ebt_dhcp_drop vp-t31 v-t31a-i "${ip}"
|
||||
check "sn-t31a : requêtes ARP vers ${ip} bloquées en sortie de v-t31a-i" nft_arp_drop vp-t31 v-t31a-i "${ip}"
|
||||
check "sn-t31a : DHCP émis depuis ${ip} bloqué en sortie de v-t31a-i" nft_dhcp_drop vp-t31 v-t31a-i "${ip}"
|
||||
done
|
||||
check "VM t31-a" vm_create t31-a sn-t31a 10.31.1.10 "${KEY}"
|
||||
check "VM t31-b" vm_create t31-b sn-t31b 10.31.2.10 "${KEY}"
|
||||
|
|
@ -39,8 +39,8 @@ check "suppression de t31-a" vm_delete t31-a
|
|||
check "suppression de sn-t31a" api_delete subnets/sn-t31a
|
||||
check "sn-t31a supprimé" wait_state subnets/sn-t31a deleted
|
||||
check "sn-t31a : plus de macvlan gw-t31a dans le netns" sh -c "! ip -n vp-t31 link show gw-t31a >/dev/null 2>&1"
|
||||
check "sn-t31a : plus aucune règle ebtables pour v-t31a-i" test -z "$(ebt_rules vp-t31 v-t31a-i)"
|
||||
check "sn-t31b : règles de son propre subnet toujours présentes (témoin)" test -n "$(ebt_rules vp-t31 v-t31b-i)"
|
||||
check "sn-t31a : plus aucune règle nftables pour v-t31a-i" test -z "$(nft_rules vp-t31 v-t31a-i)"
|
||||
check "sn-t31b : règles de son propre subnet toujours présentes (témoin)" test -n "$(nft_rules vp-t31 v-t31b-i)"
|
||||
check "sn-t31a recréé" subnet_create sn-t31a vp-t31 3101 10.31.1.0/24
|
||||
check "VM t31-a2 sur le subnet recréé" vm_create t31-a2 sn-t31a 10.31.1.11 "${KEY}"
|
||||
check "t31-a2 joignable" vm_wait vp-t31 10.31.1.11
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ own_meta () {
|
|||
done
|
||||
[ "${ok}" -eq 5 ] || { echo "${2} : ${ok}/5 réponses avec ses propres métadonnées"; return 1; }
|
||||
}
|
||||
check "hv1 : quatre règles de confinement de 10.33.0.1 sur v-t33a-i" test "$(ebt_rules vp-t33 v-t33a-i | grep -c '10.33.0.1 ')" -eq 4
|
||||
check "hv1 : quatre règles de confinement de 10.33.0.1 sur v-t33a-i" test "$(nft_rules vp-t33 v-t33a-i | grep -c '10.33.0.1 ')" -eq 4
|
||||
RESPONDERS=$(vm_frames vp-t33 10.33.0.21 arp-who ens3 10.33.0.21 10.33.0.1 2)
|
||||
info "MAC qui répondent pour 10.33.0.1 vues de t33-a1 : $(echo ${RESPONDERS})"
|
||||
check "deux hôtes : t33-a1 (hv1) joint t33-b1 (hv2) sur le segment lan" vm_ssh vp-t33 10.33.0.21 'ping -n -c 3 -W 2 10.33.0.23'
|
||||
|
|
@ -74,10 +74,11 @@ check "témoin : l'ARP émis par t33-a1 atteint le segment par v-t33a-e (capture
|
|||
check "aucune trame ARP depuis 10.33.0.1 vers le segment (v-t33a-e)" test "$(cat "${S}/arp")" -eq 0
|
||||
check "aucune trame DHCP depuis 10.33.0.1 vers le segment (v-t33a-e)" test "$(cat "${S}/dhcp")" -eq 0
|
||||
rm -r "${S}"
|
||||
RULE='OUTPUT --out-interface v-t33a-i -p arp --arp-ip-src 10.33.0.1 -j DROP'
|
||||
check "règle ARP OUTPUT retirée à la main" ip netns exec vp-t33 ebtables -D ${RULE}
|
||||
check "watchdog : règle manquante signalée pour sn-t33a" wait_watchdog "ebtables rule missing in netns vp-t33"
|
||||
check "règle ARP OUTPUT reposée" ip netns exec vp-t33 ebtables -A ${RULE}
|
||||
RULE='arp saddr ip 10.33.0.1 drop'
|
||||
HANDLE=$(nft_handle vp-t33 out-v-t33a-i "${RULE}")
|
||||
check "règle ARP output retirée à la main (handle ${HANDLE:-absent})" ip netns exec vp-t33 nft delete rule bridge two out-v-t33a-i handle "${HANDLE}"
|
||||
check "watchdog : règle manquante signalée pour sn-t33a" wait_watchdog "nftables rule missing in netns vp-t33: out-v-t33a-i: ${RULE}"
|
||||
check "règle ARP output reposée" ip netns exec vp-t33 nft add rule bridge two out-v-t33a-i ${RULE}
|
||||
NODE
|
||||
|
||||
on hv2 <<'NODE'
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ sleep 20
|
|||
check "après redémarrage : même processus QEMU pour t61-a (ni arrêtée ni recréée)" test "$(pgrep -f "${VOLUMES}/t61-a.qcow2" | sort | tr '\n' ' ')" = "${QEMU}"
|
||||
check "après redémarrage : même processus QEMU pour t61-d" test "$(pgrep -f "${VOLUMES}/t61-d.qcow2" | sort | tr '\n' ' ')" = "${QEMU_D}"
|
||||
check "après redémarrage : mêmes fichiers sous /run/two, /etc/dnsmasq.d et les volumes (sinon, fichiers en cause)" section_unchanged "${STATE_DIR}/t61.restart" fichiers
|
||||
check "après redémarrage : hôte inchangé (netns, liens, taps, adresses, routes, ebtables, iptables, FRR, frr.conf, fichiers, unités)" same_as "${STATE_DIR}/t61.restart" host_state
|
||||
check "après redémarrage : hôte inchangé (netns, liens, taps, adresses, routes, nftables de pont, iptables, FRR, frr.conf, fichiers, unités)" same_as "${STATE_DIR}/t61.restart" host_state
|
||||
check "après redémarrage : l'API rend les mêmes ressources dans le même état" same_as "${STATE_DIR}/t61.api" api_snapshot
|
||||
for rr in 10.255.255.1 10.255.255.2; do
|
||||
check "après redémarrage : session EVPN vers ${rr} établie, jamais coupée" sh -c "vtysh -c 'show bgp neighbors ${rr}' | grep -q 'BGP state = Established' && [ \"\$(vtysh -c 'show bgp neighbors ${rr}' | grep -o 'dropped [0-9]*')\" = \"\$(cat '${STATE_DIR}/t61.${rr}')\" ]"
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ check "${HOST} : aucune unité two-vm-*" none systemctl list-units --all --plain
|
|||
check "${HOST} : aucune instance DHCP (dhcp@, dnsmasq@) ni de métadonnées (metadata@) active" none sh -c "systemctl list-units --plain --no-legend 'dhcp@*' 'dnsmasq@*' 'metadata@*' | grep -w active"
|
||||
check "${HOST} : aucun socket de contrôle DHCP" none sh -c "ls /run/two/dhcp/*.sock 2>/dev/null"
|
||||
check "${HOST} : aucun processus QEMU" none pgrep -a qemu-system
|
||||
check "${HOST} : aucune règle ebtables qui vise une interface de subnet" none sh -c "{ ebtables -t filter -L; ebtables -t nat -L; } | grep -E -- '-(i|o) v-'"
|
||||
check "${HOST} : aucune règle nftables de pont qui vise une interface de subnet" none sh -c "nft list ruleset bridge | grep -E 'v-[a-z0-9]'"
|
||||
check "${HOST} : aucune règle iptables qui vise une interface de subnet ou de VPC" none sh -c "iptables-save | grep -E -- '(v-|vp-|tap)[a-z0-9]'"
|
||||
check "${HOST} : aucun volume de VM de test" none sh -c "ls '${VOLUMES}'/t[0-9][0-9]-* 2>/dev/null"
|
||||
check "${HOST} : FRR garde la base BGP (témoin)" sh -c "vtysh -c 'show running-config' | grep -q 'peer-group fabric'"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue