f-76: vm: filtrage nftables par tap, champ dhcp_server, watchdog #76

Chaque NIC a sa chaîne pre-tap<id>, posée avant le tap et retirée après :
MAC, ARP et IPv4 source limités à ceux de la NIC (0.0.0.0 pour le client
DHCP et la sonde ARP), réponses DHCP refusées sauf si dhcp_server, seuls
IPv4, ARP et IPv6 émis. Le watchdog vérifie la chaîne de chaque NIC.

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-10-25 22:59:45 +01:00
commit 74bfda7004
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
16 changed files with 295 additions and 15 deletions

View file

@ -10,9 +10,11 @@ import (
configuration "git.g3e.fr/syonad/two/internal/config/agent"
"git.g3e.fr/syonad/two/internal/netns"
"git.g3e.fr/syonad/two/internal/nft"
"git.g3e.fr/syonad/two/internal/qemu"
"git.g3e.fr/syonad/two/internal/qmp"
"git.g3e.fr/syonad/two/internal/state"
"git.g3e.fr/syonad/two/internal/vm"
"git.g3e.fr/syonad/two/internal/watchdog/notify"
"git.g3e.fr/syonad/two/pkg/db/kv"
@ -71,7 +73,7 @@ func checkVM(db *badger.DB, cfg *configuration.Config, name string, u unitChecke
n.Notify(kindVM, name, fmt.Sprintf("vpc of subnet %s unreadable in database: %v", subnetName, err))
continue
}
checkVMTap(entries[prefix+"tap_id"], name, vpc, idx, n)
checkVMTap(entries, prefix, name, vpc, idx, n)
}
checkVMQemu(cfg, name, n)
@ -99,7 +101,12 @@ func nicIndexes(entries map[string]string, prefix string) []int {
return indexes
}
func checkVMTap(raw, name, vpc string, idx int, n notify.Notifier) {
func tapPortFromEntries(entries map[string]string, prefix string, tapID int) nft.Port {
return vm.TapPort(tapID, entries[prefix+"mac"], entries[prefix+"ip"], entries[prefix+"dhcp_server"] == "true")
}
func checkVMTap(entries map[string]string, prefix, name, vpc string, idx int, n notify.Notifier) {
raw := entries[prefix+"tap_id"]
if raw == "" {
n.Notify(kindVM, name, fmt.Sprintf("interface %d has no tap_id in database", idx))
return
@ -119,6 +126,14 @@ func checkVMTap(raw, name, vpc string, idx int, n notify.Notifier) {
if p := linkProblem(tapName(tapID)); p != "" {
n.Notify(kindVM, name, p+" (in netns "+vpc+")")
}
missing, err := nft.MissingRules(tapPortFromEntries(entries, prefix, tapID))
if err != nil {
n.Notify(kindVM, name, fmt.Sprintf("interface %d: nftables rules unreadable in netns %s: %v", idx, vpc, err))
return nil
}
for _, rule := range missing {
n.Notify(kindVM, name, fmt.Sprintf("interface %d: nftables rule missing in netns %s: %s", idx, vpc, rule))
}
return nil
}); err != nil {
n.Notify(kindVM, name, fmt.Sprintf("cannot enter netns %s: %v", vpc, err))