f-75: watchdog: règles de confinement manquantes sur les subnets bridge #75
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
f966f394eb
commit
85abdaa1ef
3 changed files with 69 additions and 1 deletions
36
internal/watchdog/check_bridge.go
Normal file
36
internal/watchdog/check_bridge.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package watchdog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.g3e.fr/syonad/two/internal/ebtables"
|
||||
"git.g3e.fr/syonad/two/internal/netns"
|
||||
"git.g3e.fr/syonad/two/internal/watchdog/notify"
|
||||
"git.g3e.fr/syonad/two/pkg/db/kv"
|
||||
|
||||
"github.com/dgraph-io/badger/v4"
|
||||
)
|
||||
|
||||
func checkBridgeGateway(db *badger.DB, name, vpc, nsVeth string, n notify.Notifier) {
|
||||
gatewayIP, err := kv.GetFromDB(db, prefixSubnet+name+"/interface_ip")
|
||||
if err != nil {
|
||||
n.Notify(kindSubnet, name, fmt.Sprintf("interface_ip unreadable in database: %v", err))
|
||||
return
|
||||
}
|
||||
if !netns.Exist(vpc) {
|
||||
return
|
||||
}
|
||||
if err := netns.Call(vpc, func() error {
|
||||
missing, err := ebtables.MissingGatewayRules(nsVeth, gatewayIP)
|
||||
if err != nil {
|
||||
n.Notify(kindSubnet, name, fmt.Sprintf("gateway ebtables rules unreadable in netns %s: %v", vpc, err))
|
||||
return nil
|
||||
}
|
||||
for _, rule := range missing {
|
||||
n.Notify(kindSubnet, name, fmt.Sprintf("ebtables rule missing in netns %s: %s", vpc, rule))
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
n.Notify(kindSubnet, name, fmt.Sprintf("cannot enter netns %s: %v", vpc, err))
|
||||
}
|
||||
}
|
||||
|
|
@ -89,8 +89,11 @@ func checkSubnet(db *badger.DB, name string, backend dhcpbackend.Backend, u unit
|
|||
}
|
||||
|
||||
checkSubnetNetns(name, vpc, nsVeth, bridge, n)
|
||||
if mode == modeVxlan {
|
||||
switch mode {
|
||||
case modeVxlan:
|
||||
checkAnycastGateway(db, name, vpc, bridge, n)
|
||||
case modeBridge:
|
||||
checkBridgeGateway(db, name, vpc, nsVeth, n)
|
||||
}
|
||||
|
||||
checkDHCP(db, name, dhcpbackend.Subnet{Name: name, VPC: vpc, Bridge: bridge}, backend, u, n)
|
||||
|
|
|
|||
|
|
@ -280,3 +280,32 @@ func problems(ns []notification) []string {
|
|||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func TestCheckSubnets_BridgeSansInterfaceIP(t *testing.T) {
|
||||
db := newTestDB(t)
|
||||
seedSubnet(t, db, "br-000042", "vp-admin", modeBridge)
|
||||
r := &recorder{}
|
||||
|
||||
if err := CheckSubnets(db, dnsmasqConfig(), newFakeUnits(), r); err != nil {
|
||||
t.Fatalf("erreur inattendue: %v", err)
|
||||
}
|
||||
|
||||
if !r.hasProblemContaining("interface_ip unreadable") {
|
||||
t.Errorf("un subnet bridge sans interface_ip devrait être signalé, obtenu %v", r.calls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckSubnets_VxlanSansInterfaceIPNeVerifiePasLesReglesBridge(t *testing.T) {
|
||||
db := newTestDB(t)
|
||||
seedSubnet(t, db, "br-000042", "vp-admin", modeVxlan)
|
||||
seedKV(t, db, prefixSubnet+"br-000042/vxlan_id", "42")
|
||||
r := &recorder{}
|
||||
|
||||
if err := CheckSubnets(db, dnsmasqConfig(), newFakeUnits(), r); err != nil {
|
||||
t.Fatalf("erreur inattendue: %v", err)
|
||||
}
|
||||
|
||||
if r.hasProblemContaining("interface_ip unreadable") {
|
||||
t.Errorf("un subnet vxlan ne passe pas par la vérification bridge, obtenu %v", r.calls)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue