Merge branch 'feature-75'
All checks were successful
Documentation / publish (push) Successful in 1m29s
All checks were successful
Documentation / publish (push) Successful in 1m29s
This commit is contained in:
commit
a729cf8891
16 changed files with 266 additions and 13 deletions
|
|
@ -122,6 +122,29 @@ bridge
|
||||||
Le subnet est rattaché directement à un bridge existant de l'host. Pas de tunnel, pas de route
|
Le subnet est rattaché directement à un bridge existant de l'host. Pas de tunnel, pas de route
|
||||||
VPC : le trafic sort par le bridge, et la VM est joignable depuis l'host.
|
VPC : le trafic sort par le bridge, et la VM est joignable depuis l'host.
|
||||||
|
|
||||||
|
Le même subnet peut être posé sur plusieurs hôtes raccordés au même segment. Chaque hôte porte
|
||||||
|
alors la **même** ``interface_ip`` dans son netns, avec sa propre MAC. Pour qu'une VM ne voie que
|
||||||
|
l'``interface_ip`` de son hôte (gateway, metadata, DHCP), l'agent pose quatre règles ebtables sur
|
||||||
|
le veth du subnet dans le netns (``v-<subnet>-i``), en sortie vers le bridge de l'host :
|
||||||
|
|
||||||
|
* les requêtes ARP des VM **vers** ``interface_ip`` ne quittent pas l'hôte (``FORWARD``) ;
|
||||||
|
* l'ARP émis **depuis** ``interface_ip`` par le netns, requêtes et réponses, ne sort pas
|
||||||
|
(``OUTPUT``) : une VM d'un autre hôte n'associe jamais ``interface_ip`` à cet hôte ;
|
||||||
|
* le DHCP émis depuis ``interface_ip`` ne sort ni en transit (``FORWARD``) ni depuis le serveur
|
||||||
|
local lui-même (``OUTPUT``).
|
||||||
|
|
||||||
|
Le trafic entre VM du subnet, sur un même hôte ou sur des hôtes différents, n'est pas concerné.
|
||||||
|
Par conception, une VM ne joint pas le netns d'un autre hôte. Les règles sont retirées à la
|
||||||
|
suppression du subnet ; une règle déjà absente ne fait pas échouer la suppression. Le watchdog
|
||||||
|
signale les règles manquantes.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
Un subnet ``bridge`` créé par une version antérieure de l'agent n'a que la règle DHCP
|
||||||
|
``FORWARD`` : il reste exposé jusqu'à sa recréation, et le watchdog le signale. L'agent ne
|
||||||
|
répare pas les règles au démarrage. Les règles ne couvrent que IPv4 : le voisinage IPv6 du
|
||||||
|
netns relève de #61.
|
||||||
|
|
||||||
Routes annoncées aux VM
|
Routes annoncées aux VM
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -336,9 +336,9 @@ Générée par ``test/e2e/run.sh --matrice`` à partir des en-têtes ; à régé
|
||||||
- hv1
|
- hv1
|
||||||
- #57, #41
|
- #57, #41
|
||||||
* - ``33-bridge``
|
* - ``33-bridge``
|
||||||
- subnet en mode bridge rattaché au bridge br-lan de l'hôte — un hôte, puis le même subnet sur deux hôtes (une seule réponse ARP pour interface_ip, métadonnées servies par l'hôte de la VM)
|
- subnet en mode bridge rattaché au bridge br-lan de l'hôte — un hôte, puis le même subnet sur deux hôtes (interface_ip confinée à son hôte : une seule réponse ARP, métadonnées servies par l'hôte de la VM, ni ARP ni DHCP de la gateway sur le segment, règles surveillées par le watchdog)
|
||||||
- hv1 hv2
|
- hv1 hv2
|
||||||
- #70
|
- #70, #75
|
||||||
* - ``34-isolation-locale``
|
* - ``34-isolation-locale``
|
||||||
- isolation entre deux VPC sur un même hôte — ni ICMP ni TCP d'un VPC à l'autre
|
- isolation entre deux VPC sur un même hôte — ni ICMP ni TCP d'un VPC à l'autre
|
||||||
- hv1
|
- hv1
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
package ebtables
|
package ebtables
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func addRule(args ...string) error {
|
func addRule(args ...string) error {
|
||||||
|
|
@ -89,3 +91,63 @@ func DeleteConfineMAC(iface, mac string) error {
|
||||||
}
|
}
|
||||||
return first
|
return first
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func gatewayRules(iface, ip string) [][]string {
|
||||||
|
dhcp := []string{"-p", "IPv4", "--ip-protocol", "udp", "--ip-source-port", "67:68", "--ip-destination-port", "67:68", "--ip-source", ip, "-j", "DROP"}
|
||||||
|
return [][]string{
|
||||||
|
{"-t", "filter", "FORWARD", "--out-interface", iface, "-p", "arp", "--arp-op", "Request", "--arp-ip-dst", ip, "-j", "DROP"},
|
||||||
|
{"-t", "filter", "OUTPUT", "--out-interface", iface, "-p", "arp", "--arp-ip-src", ip, "-j", "DROP"},
|
||||||
|
append([]string{"-t", "filter", "FORWARD", "--out-interface", iface}, dhcp...),
|
||||||
|
append([]string{"-t", "filter", "OUTPUT", "--out-interface", iface}, dhcp...),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ruleExists(rule []string) (bool, error) {
|
||||||
|
err := exec.Command("ebtables", withAction("--check", rule)...).Run()
|
||||||
|
var exit *exec.ExitError
|
||||||
|
switch {
|
||||||
|
case err == nil:
|
||||||
|
return true, nil
|
||||||
|
case errors.As(err, &exit) && exit.ExitCode() == 1:
|
||||||
|
return false, nil
|
||||||
|
default:
|
||||||
|
return false, fmt.Errorf("ebtables --check %s: %w", strings.Join(rule, " "), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ConfineGateway(iface, ip string) error {
|
||||||
|
for _, rule := range gatewayRules(iface, ip) {
|
||||||
|
if err := exec.Command("ebtables", withAction("-A", rule)...).Run(); err != nil {
|
||||||
|
return fmt.Errorf("ebtables confine gateway %s on %s (%s): %w", ip, iface, strings.Join(rule, " "), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeleteConfineGateway(iface, ip string) error {
|
||||||
|
var first error
|
||||||
|
for _, rule := range gatewayRules(iface, ip) {
|
||||||
|
exists, err := ruleExists(rule)
|
||||||
|
if err == nil && exists {
|
||||||
|
err = exec.Command("ebtables", withAction("-D", rule)...).Run()
|
||||||
|
}
|
||||||
|
if err != nil && first == nil {
|
||||||
|
first = fmt.Errorf("ebtables unconfine gateway %s on %s (%s): %w", ip, iface, strings.Join(rule, " "), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return first
|
||||||
|
}
|
||||||
|
|
||||||
|
func MissingGatewayRules(iface, ip string) ([]string, error) {
|
||||||
|
var missing []string
|
||||||
|
for _, rule := range gatewayRules(iface, ip) {
|
||||||
|
exists, err := ruleExists(rule)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !exists {
|
||||||
|
missing = append(missing, strings.Join(rule, " "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return missing, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,3 +41,30 @@ func TestWithActionDoesNotAlterTheRule(t *testing.T) {
|
||||||
t.Errorf("la règle a été modifiée : %q devenu %q", before, strings.Join(rule, " "))
|
t.Errorf("la règle a été modifiée : %q devenu %q", before, strings.Join(rule, " "))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGatewayRules(t *testing.T) {
|
||||||
|
want := []string{
|
||||||
|
"-t filter -A FORWARD --out-interface v-t33a-i -p arp --arp-op Request --arp-ip-dst 10.33.0.1 -j DROP",
|
||||||
|
"-t filter -A OUTPUT --out-interface v-t33a-i -p arp --arp-ip-src 10.33.0.1 -j DROP",
|
||||||
|
"-t filter -A FORWARD --out-interface v-t33a-i -p IPv4 --ip-protocol udp --ip-source-port 67:68 --ip-destination-port 67:68 --ip-source 10.33.0.1 -j DROP",
|
||||||
|
"-t filter -A OUTPUT --out-interface v-t33a-i -p IPv4 --ip-protocol udp --ip-source-port 67:68 --ip-destination-port 67:68 --ip-source 10.33.0.1 -j DROP",
|
||||||
|
}
|
||||||
|
rules := gatewayRules("v-t33a-i", "10.33.0.1")
|
||||||
|
if len(rules) != len(want) {
|
||||||
|
t.Fatalf("%d règles, %d attendues", len(rules), len(want))
|
||||||
|
}
|
||||||
|
for i, rule := range rules {
|
||||||
|
if got := strings.Join(withAction("-A", rule), " "); got != want[i] {
|
||||||
|
t.Errorf("règle %d : %q, %q attendu", i, got, want[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGatewayRulesDoNotShareSlices(t *testing.T) {
|
||||||
|
rules := gatewayRules("v-x-i", "10.0.0.1")
|
||||||
|
before := strings.Join(rules[2], " ")
|
||||||
|
rules[3][len(rules[3])-1] = "ACCEPT"
|
||||||
|
if strings.Join(rules[2], " ") != before {
|
||||||
|
t.Errorf("les deux règles DHCP partagent leur tableau : %q", strings.Join(rules[2], " "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ func createSubnet(db *badger.DB, subnetName string, d subnetData, backend dhcpba
|
||||||
if err := netif.RouteAdd(d.bridge, d.cidr); err != nil {
|
if err := netif.RouteAdd(d.bridge, d.cidr); err != nil {
|
||||||
return fmt.Errorf("add route: %w", err)
|
return fmt.Errorf("add route: %w", err)
|
||||||
}
|
}
|
||||||
return ebtables.DropDHCP(vethI, d.interfaceIP.String())
|
return ebtables.ConfineGateway(vethI, d.interfaceIP.String())
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return fmt.Errorf("configure netns: %w", err)
|
return fmt.Errorf("configure netns: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,8 +105,8 @@ func deleteSubnetBridge(d subnetData) error {
|
||||||
vethI := "v-" + d.subnetID + "-i"
|
vethI := "v-" + d.subnetID + "-i"
|
||||||
|
|
||||||
if err := netns.Call(d.vpc, func() error {
|
if err := netns.Call(d.vpc, func() error {
|
||||||
if err := ebtables.DeleteDHCP(vethI, d.interfaceIP.String()); err != nil {
|
if err := ebtables.DeleteConfineGateway(vethI, d.interfaceIP.String()); err != nil {
|
||||||
return fmt.Errorf("delete ebtables dhcp rule: %w", err)
|
return fmt.Errorf("delete ebtables gateway rules: %w", err)
|
||||||
}
|
}
|
||||||
return netif.DeleteLink(d.bridge)
|
return netif.DeleteLink(d.bridge)
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
|
|
||||||
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)
|
checkSubnetNetns(name, vpc, nsVeth, bridge, n)
|
||||||
if mode == modeVxlan {
|
switch mode {
|
||||||
|
case modeVxlan:
|
||||||
checkAnycastGateway(db, name, vpc, bridge, n)
|
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)
|
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
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,14 @@ L3VNI, avec une configuration BGP pilotée par l'agent ; documentation du projet
|
||||||
`/run/two/dhcp/<netns>_<bridge>.sock` après la suppression du subnet. L'agent supprime aussi
|
`/run/two/dhcp/<netns>_<bridge>.sock` après la suppression du subnet. L'agent supprime aussi
|
||||||
cette socket avec le fichier d'état, ce qui couvre une mort brutale du processus (#77)
|
cette socket avec le fichier d'état, ce qui couvre une mort brutale du processus (#77)
|
||||||
|
|
||||||
|
- **Mode `bridge` sur plusieurs hôtes : `interface_ip` confinée à son hôte (#75).** Chaque hôte
|
||||||
|
portant la même `interface_ip`, une VM obtenait parfois l'ARP, les métadonnées ou le DHCP d'un
|
||||||
|
autre hôte : en lab, une VM ne recevait ses propres métadonnées que 3 à 4 fois sur 5. L'agent
|
||||||
|
bloque désormais vers le segment les requêtes ARP vers `interface_ip`, l'ARP émis depuis elle
|
||||||
|
et le DHCP émis depuis elle, y compris par le serveur local (chaîne `OUTPUT`, que la règle
|
||||||
|
précédente ne couvrait pas). Le watchdog signale une règle manquante ; la suppression d'un
|
||||||
|
subnet ne retire que les règles présentes
|
||||||
|
|
||||||
## Changements internes
|
## Changements internes
|
||||||
|
|
||||||
- Nouveaux paquets `internal/frr` (seul point d'appel à `vtysh` : génération des commandes,
|
- Nouveaux paquets `internal/frr` (seul point d'appel à `vtysh` : génération des commandes,
|
||||||
|
|
@ -189,7 +197,8 @@ quatre exceptions près, qui touchent les appelants de l'API :
|
||||||
qui les montait par `/dev/sdY` doit passer à `/dev/xvdX`
|
qui les montait par `/dev/sdY` doit passer à `/dev/xvdX`
|
||||||
|
|
||||||
Les subnets `vxlan` existants gardent leur adressage et le modèle précédent (gateway sur le
|
Les subnets `vxlan` existants gardent leur adressage et le modèle précédent (gateway sur le
|
||||||
bridge) jusqu'à leur recréation.
|
bridge) jusqu'à leur recréation. Les subnets `bridge` existants restent sans le confinement de
|
||||||
|
`interface_ip` (#75) jusqu'à leur recréation ; le watchdog les signale.
|
||||||
|
|
||||||
Pour router entre hyperviseurs : ajouter la section `bgp`, réduire `frr.conf` à `hostname` et
|
Pour router entre hyperviseurs : ajouter la section `bgp`, réduire `frr.conf` à `hostname` et
|
||||||
`log` (l'agent pose le reste), puis créer les VPC avec `l3vni`. Pour passer au serveur intégré, suivre la procédure de bascule dans la
|
`log` (l'agent pose le reste), puis créer les VPC avec `l3vni`. Pour passer au serveur intégré, suivre la procédure de bascule dans la
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,8 @@ def match(kind, a, f):
|
||||||
t = f[12:14]
|
t = f[12:14]
|
||||||
if kind == 'arp-req':
|
if kind == 'arp-req':
|
||||||
return t == b'\x08\x06' and f[20:22] == b'\x00\x01' and f[38:42] == ipb(a[0])
|
return t == b'\x08\x06' and f[20:22] == b'\x00\x01' and f[38:42] == ipb(a[0])
|
||||||
|
if kind == 'arp-from':
|
||||||
|
return t == b'\x08\x06' and f[28:32] == ipb(a[0])
|
||||||
if kind == 'udp-from':
|
if kind == 'udp-from':
|
||||||
return t == b'\x08\x00' and f[23] == 17 and f[26:30] == ipb(a[0]) and struct.unpack('!H', f[34:36])[0] == int(a[1])
|
return t == b'\x08\x00' and f[23] == 17 and f[26:30] == ipb(a[0]) and struct.unpack('!H', f[34:36])[0] == int(a[1])
|
||||||
if kind == 'marker':
|
if kind == 'marker':
|
||||||
|
|
|
||||||
|
|
@ -142,6 +142,10 @@ vm_meta () {
|
||||||
vm_ssh "${1}" "${2}" "curl -fsS http://169.254.169.254/${3}"
|
vm_ssh "${1}" "${2}" "curl -fsS http://169.254.169.254/${3}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vm_cloud_init_done () {
|
||||||
|
vm_ssh "${1}" "${2}" "timeout ${3:-300} cloud-init status --wait"
|
||||||
|
}
|
||||||
|
|
||||||
vm_boot_id () {
|
vm_boot_id () {
|
||||||
vm_ssh "${1}" "${2}" 'cat /proc/sys/kernel/random/boot_id'
|
vm_ssh "${1}" "${2}" 'cat /proc/sys/kernel/random/boot_id'
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -400,6 +400,14 @@ test_vm_lease_reads_one_field_of_the_interface_lease () {
|
||||||
teardown
|
teardown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test_vm_cloud_init_done_waits_with_a_bound () {
|
||||||
|
setup "vm_cloud_init_done : attend la fin de cloud-init, avec un délai borné, et en rend le code"
|
||||||
|
[[ $(node 'vm_ssh () { echo "$1 $2 $3"; }; vm_cloud_init_done vp 1.2.3.4') == "vp 1.2.3.4 timeout 300 cloud-init status --wait" ]] || fail "commande par défaut"
|
||||||
|
[[ $(node 'vm_ssh () { echo "$3"; }; vm_cloud_init_done vp 1.2.3.4 60') == "timeout 60 cloud-init status --wait" ]] || fail "délai fourni"
|
||||||
|
[[ $(node 'vm_ssh () { return 2; }; vm_cloud_init_done vp 1.2.3.4 || echo NON') == NON ]] || fail "cloud-init en erreur accepté"
|
||||||
|
teardown
|
||||||
|
}
|
||||||
|
|
||||||
test_vm_has_ip_matches_the_exact_address () {
|
test_vm_has_ip_matches_the_exact_address () {
|
||||||
setup "vm_has_ip : adresse exacte, sur n'importe quelle interface"
|
setup "vm_has_ip : adresse exacte, sur n'importe quelle interface"
|
||||||
local stub='vm_ssh () { echo "3: ens4 inet 10.25.2.10/24 brd 10.25.2.255 scope global ens4"; }; '
|
local stub='vm_ssh () { echo "3: ens4 inet 10.25.2.10/24 brd 10.25.2.255 scope global ens4"; }; '
|
||||||
|
|
@ -641,6 +649,26 @@ test_runner_counts_known_apart_unless_connus () {
|
||||||
teardown
|
teardown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test_frames_match_selects_arp_by_sender () {
|
||||||
|
setup "frames : arp-from retient l'ARP émis depuis une adresse, requête ou réponse, et rien d'autre"
|
||||||
|
local src arp garp dhcp
|
||||||
|
src=$(node 'frames_py')
|
||||||
|
arp=$(node 'FRAMES_DRY=1 FRAMES_MAC=02:00:00:00:00:0a frames arp ens3 10.33.0.1 10.33.0.21 1')
|
||||||
|
garp=$(node 'FRAMES_DRY=1 FRAMES_MAC=02:00:00:00:00:0a frames garp ens3 10.33.0.1 1')
|
||||||
|
dhcp=$(node 'FRAMES_DRY=1 FRAMES_MAC=02:00:00:00:00:0a frames dhcp ens3 10.33.0.1 68 1')
|
||||||
|
python3 - "${src}" "${arp}" "${garp}" "${dhcp}" <<'PY' || fail "arp-from : ${arp} / ${garp} / ${dhcp}"
|
||||||
|
import sys
|
||||||
|
exec(sys.argv[1].split('cmd, a = ')[0])
|
||||||
|
arp, garp, dhcp = (bytes.fromhex(x) for x in sys.argv[2:])
|
||||||
|
assert match('arp-from', ['10.33.0.1'], arp), 'requête depuis 10.33.0.1'
|
||||||
|
assert match('arp-from', ['10.33.0.1'], garp), 'réponse depuis 10.33.0.1'
|
||||||
|
assert not match('arp-from', ['10.33.0.21'], arp), 'la cible n\'est pas l\'émetteur'
|
||||||
|
assert not match('arp-from', ['10.33.0.1'], dhcp), 'DHCP depuis 10.33.0.1'
|
||||||
|
assert match('udp-from', ['10.33.0.1', '67'], dhcp), 'udp-from témoin'
|
||||||
|
PY
|
||||||
|
teardown
|
||||||
|
}
|
||||||
|
|
||||||
for T in $(declare -F | awk '{print $3}' | grep '^test_'); do
|
for T in $(declare -F | awk '{print $3}' | grep '^test_'); do
|
||||||
"${T}"
|
"${T}"
|
||||||
done
|
done
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ check "VM t23-s : sshkey seule (témoin)" vm_launch t23-s --nic sn-t23=10.23.1.1
|
||||||
check "VM t23-n : ni sshkey ni password" vm_launch t23-n --nic sn-t23=10.23.1.12
|
check "VM t23-n : ni sshkey ni password" vm_launch t23-n --nic sn-t23=10.23.1.12
|
||||||
|
|
||||||
check "t23-k joignable en SSH (sshkey servie)" vm_wait vp-t23 10.23.1.10
|
check "t23-k joignable en SSH (sshkey servie)" vm_wait vp-t23 10.23.1.10
|
||||||
|
check "t23-k : cloud-init terminé" vm_cloud_init_done vp-t23 10.23.1.10
|
||||||
check "t23-k : meta-data, instance-id = nom de la VM" vm_grep vp-t23 10.23.1.10 'curl -fsS http://169.254.169.254/meta-data' '^instance-id: t23-k$'
|
check "t23-k : meta-data, instance-id = nom de la VM" vm_grep vp-t23 10.23.1.10 'curl -fsS http://169.254.169.254/meta-data' '^instance-id: t23-k$'
|
||||||
check "t23-k : user-data servi tel quel" test "$(vm_meta vp-t23 10.23.1.10 user-data)" = "$(printf '%s' "${UD}")"
|
check "t23-k : user-data servi tel quel" test "$(vm_meta vp-t23 10.23.1.10 user-data)" = "$(printf '%s' "${UD}")"
|
||||||
check "t23-k : runcmd du user_data exécuté" vm_grep vp-t23 10.23.1.10 'cat /var/tmp/t23-runcmd' '^t23$'
|
check "t23-k : runcmd du user_data exécuté" vm_grep vp-t23 10.23.1.10 'cat /var/tmp/t23-runcmd' '^t23$'
|
||||||
|
|
@ -22,6 +23,7 @@ check "t23-k : vendor-data porte la clé SSH" vm_grep vp-t23 10.23.1.10 'curl -f
|
||||||
check "t23-k : hash du password posé sur le compte syonad" vm_ssh vp-t23 10.23.1.10 "sudo grep -qF 'syonad:${HASH}:' /etc/shadow"
|
check "t23-k : hash du password posé sur le compte syonad" vm_ssh vp-t23 10.23.1.10 "sudo grep -qF 'syonad:${HASH}:' /etc/shadow"
|
||||||
|
|
||||||
check "t23-s joignable en SSH" vm_wait vp-t23 10.23.1.11
|
check "t23-s joignable en SSH" vm_wait vp-t23 10.23.1.11
|
||||||
|
check "t23-s : cloud-init terminé" vm_cloud_init_done vp-t23 10.23.1.11
|
||||||
check "t23-s : user_data absent, user-data servi vide (template)" test -z "$(vm_meta vp-t23 10.23.1.11 user-data)"
|
check "t23-s : user_data absent, user-data servi vide (template)" test -z "$(vm_meta vp-t23 10.23.1.11 user-data)"
|
||||||
check "t23-s : aucun runcmd exécuté" vm_fails vp-t23 10.23.1.11 'test -e /var/tmp/t23-runcmd'
|
check "t23-s : aucun runcmd exécuté" vm_fails vp-t23 10.23.1.11 'test -e /var/tmp/t23-runcmd'
|
||||||
check "t23-s : password absent, compte syonad verrouillé" vm_ssh vp-t23 10.23.1.11 "sudo grep -q '^syonad:!' /etc/shadow"
|
check "t23-s : password absent, compte syonad verrouillé" vm_ssh vp-t23 10.23.1.11 "sudo grep -q '^syonad:!' /etc/shadow"
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ check "VPC vp-t27" vpc_create vp-t27 10.27.0.0/16
|
||||||
check "subnet sn-t27" subnet_create sn-t27 vp-t27 2701 10.27.1.0/24
|
check "subnet sn-t27" subnet_create sn-t27 vp-t27 2701 10.27.1.0/24
|
||||||
check "VM t27-r, user_data qui écrit une ligne par exécution" vm_launch t27-r --nic sn-t27=10.27.1.10 --sshkey "${KEY}" --user-data "${UD64}"
|
check "VM t27-r, user_data qui écrit une ligne par exécution" vm_launch t27-r --nic sn-t27=10.27.1.10 --sshkey "${KEY}" --user-data "${UD64}"
|
||||||
check "t27-r joignable" vm_wait vp-t27 10.27.1.10
|
check "t27-r joignable" vm_wait vp-t27 10.27.1.10
|
||||||
|
check "t27-r : cloud-init terminé au premier démarrage" vm_cloud_init_done vp-t27 10.27.1.10
|
||||||
check "t27-r : runcmd exécuté une fois au premier démarrage" test "$(vm_ssh vp-t27 10.27.1.10 'wc -l < /var/tmp/t27-runcmd')" -eq 1
|
check "t27-r : runcmd exécuté une fois au premier démarrage" test "$(vm_ssh vp-t27 10.27.1.10 'wc -l < /var/tmp/t27-runcmd')" -eq 1
|
||||||
BOOT=$(vm_boot_id vp-t27 10.27.1.10)
|
BOOT=$(vm_boot_id vp-t27 10.27.1.10)
|
||||||
QEMU=$(pgrep -f "${VOLUMES}/t27-r.qcow2" | sort | tr '\n' ' ')
|
QEMU=$(pgrep -f "${VOLUMES}/t27-r.qcow2" | sort | tr '\n' ' ')
|
||||||
|
|
@ -16,6 +17,7 @@ info "boot_id ${BOOT:-illisible} ; processus QEMU ${QEMU:-introuvable}"
|
||||||
check "prérequis : boot_id et processus QEMU relevés" test -n "${BOOT}" -a -n "${QEMU}"
|
check "prérequis : boot_id et processus QEMU relevés" test -n "${BOOT}" -a -n "${QEMU}"
|
||||||
check "t27-r : redémarrage demandé depuis l'invité" vm_ssh vp-t27 10.27.1.10 'sudo systemd-run --on-active=2 systemctl reboot'
|
check "t27-r : redémarrage demandé depuis l'invité" vm_ssh vp-t27 10.27.1.10 'sudo systemd-run --on-active=2 systemctl reboot'
|
||||||
check "t27-r : redémarrée (boot_id changé) et de nouveau joignable" wait_reboot vp-t27 10.27.1.10 "${BOOT}"
|
check "t27-r : redémarrée (boot_id changé) et de nouveau joignable" wait_reboot vp-t27 10.27.1.10 "${BOOT}"
|
||||||
|
check "t27-r : cloud-init terminé après le redémarrage" vm_cloud_init_done vp-t27 10.27.1.10
|
||||||
check "t27-r : toujours running pour l'API" test "$(api_state vms/t27-r)" = running
|
check "t27-r : toujours running pour l'API" test "$(api_state vms/t27-r)" = running
|
||||||
check "t27-r : même processus QEMU (redémarrage invité, pas de recréation)" test "$(pgrep -f "${VOLUMES}/t27-r.qcow2" | sort | tr '\n' ' ')" = "${QEMU}"
|
check "t27-r : même processus QEMU (redémarrage invité, pas de recréation)" test "$(pgrep -f "${VOLUMES}/t27-r.qcow2" | sort | tr '\n' ' ')" = "${QEMU}"
|
||||||
check "t27-r : même adresse 10.27.1.10" has_addr vp-t27 10.27.1.10
|
check "t27-r : même adresse 10.27.1.10" has_addr vp-t27 10.27.1.10
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# fonctionnalité: subnet en mode bridge rattaché au bridge br-lan de l'hôte — un hôte, puis le même subnet sur deux hôtes (une seule réponse ARP pour interface_ip, métadonnées servies par l'hôte de la VM)
|
# fonctionnalité: subnet en mode bridge rattaché au bridge br-lan de l'hôte — un hôte, puis le même subnet sur deux hôtes (interface_ip confinée à son hôte : une seule réponse ARP, métadonnées servies par l'hôte de la VM, ni ARP ni DHCP de la gateway sur le segment, règles surveillées par le watchdog)
|
||||||
# hôtes: hv1 hv2
|
# hôtes: hv1 hv2
|
||||||
# tickets: #70
|
# tickets: #70, #75
|
||||||
|
|
||||||
on hv1 <<'NODE'
|
on hv1 <<'NODE'
|
||||||
KEY=$(vm_key)
|
KEY=$(vm_key)
|
||||||
|
|
@ -47,11 +47,37 @@ own_meta () {
|
||||||
done
|
done
|
||||||
[ "${ok}" -eq 5 ] || { echo "${2} : ${ok}/5 réponses avec ses propres métadonnées"; return 1; }
|
[ "${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
|
||||||
RESPONDERS=$(vm_frames vp-t33 10.33.0.21 arp-who ens3 10.33.0.21 10.33.0.1 2)
|
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})"
|
info "MAC qui répondent pour 10.33.0.1 vues de t33-a1 : $(echo ${RESPONDERS})"
|
||||||
known "#75" "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'
|
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'
|
||||||
known "#75" "deux hôtes : une seule MAC répond pour interface_ip 10.33.0.1" test "$(grep -c . <<<"${RESPONDERS}")" -eq 1
|
check "deux hôtes : une seule MAC répond pour interface_ip 10.33.0.1, celle de br-t33a de hv1" test "${RESPONDERS}" = "$(ip -n vp-t33 link show br-t33a | awk '/ether/ {print $2}')"
|
||||||
known_flaky "#75" "deux hôtes : t33-a1 reçoit toujours ses propres métadonnées (5 essais, cache ARP vidé)" own_meta 10.33.0.21 t33-a1
|
check "deux hôtes : t33-a1 reçoit toujours ses propres métadonnées (5 essais, cache ARP vidé)" own_meta 10.33.0.21 t33-a1
|
||||||
|
S=$(mktemp -d)
|
||||||
|
AGEING=$(ip netns exec vp-t33 cat /sys/class/net/br-t33a/bridge/ageing_time)
|
||||||
|
check "br-t33a sans apprentissage le temps de la capture (toute trame du netns inonde v-t33a-i)" ip netns exec vp-t33 ip link set br-t33a type bridge ageing_time 0
|
||||||
|
sniff_start "${S}/arp" v-t33a-e 20 arp-from 10.33.0.1
|
||||||
|
sniff_start "${S}/dhcp" v-t33a-e 20 udp-from 10.33.0.1 67
|
||||||
|
sniff_start "${S}/vm-arp" v-t33a-e 20 arp-from 10.33.0.21
|
||||||
|
vm_sniff_start "${S}/arp.temoin" vp-t33 10.33.0.21 ens3 16 arp-from 10.33.0.1
|
||||||
|
vm_sniff_start "${S}/dhcp.temoin" vp-t33 10.33.0.21 ens3 16 udp-from 10.33.0.1 67
|
||||||
|
ip -n vp-t33 neigh flush dev br-t33a
|
||||||
|
ip netns exec vp-t33 ping -c 2 -W 1 10.33.0.21 >/dev/null 2>&1
|
||||||
|
vm_ssh vp-t33 10.33.0.21 'sudo networkctl renew ens3' >/dev/null 2>&1
|
||||||
|
vm_frames vp-t33 10.33.0.21 arp ens3 10.33.0.21 10.33.0.99 3 >/dev/null 2>&1
|
||||||
|
wait
|
||||||
|
check "br-t33a : apprentissage rétabli (ageing_time ${AGEING})" ip netns exec vp-t33 ip link set br-t33a type bridge ageing_time "${AGEING}"
|
||||||
|
info "trames capturées : ARP depuis 10.33.0.1 vers le segment $(cat "${S}/arp"), DHCP $(cat "${S}/dhcp"), ARP de t33-a1 $(cat "${S}/vm-arp") ; reçues par t33-a1 : ARP $(cat "${S}/arp.temoin"), DHCP $(cat "${S}/dhcp.temoin")"
|
||||||
|
check "témoin : t33-a1 reçoit l'ARP émis depuis 10.33.0.1" test "$(cat "${S}/arp.temoin")" -gt 0
|
||||||
|
check "témoin : t33-a1 reçoit le DHCP émis depuis 10.33.0.1" test "$(cat "${S}/dhcp.temoin")" -gt 0
|
||||||
|
check "témoin : l'ARP émis par t33-a1 atteint le segment par v-t33a-e (capture opérante)" test "$(cat "${S}/vm-arp")" -gt 0
|
||||||
|
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}
|
||||||
NODE
|
NODE
|
||||||
|
|
||||||
on hv2 <<'NODE'
|
on hv2 <<'NODE'
|
||||||
|
|
@ -63,6 +89,6 @@ own_meta () {
|
||||||
done
|
done
|
||||||
[ "${ok}" -eq 5 ] || { echo "${2} : ${ok}/5 réponses avec ses propres métadonnées"; return 1; }
|
[ "${ok}" -eq 5 ] || { echo "${2} : ${ok}/5 réponses avec ses propres métadonnées"; return 1; }
|
||||||
}
|
}
|
||||||
known_flaky "#75" "deux hôtes : t33-b1 (hv2) reçoit toujours ses propres métadonnées (5 essais, cache ARP vidé)" own_meta 10.33.0.23 t33-b1
|
check "deux hôtes : t33-b1 (hv2) reçoit toujours ses propres métadonnées (5 essais, cache ARP vidé)" own_meta 10.33.0.23 t33-b1
|
||||||
check "deux hôtes : t33-b1 (hv2) joint t33-a2 (hv1)" vm_ssh vp-t33 10.33.0.23 'ping -n -c 3 -W 2 10.33.0.22'
|
check "deux hôtes : t33-b1 (hv2) joint t33-a2 (hv1)" vm_ssh vp-t33 10.33.0.23 'ping -n -c 3 -W 2 10.33.0.22'
|
||||||
NODE
|
NODE
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue