CA (llmgw-style) - region creates its CA (ECDSA P-256) and serves API/UI/images over HTTPS on tls_listen with a certificate for every name/address it has (reissued on change or a month before expiry); admin_http policy (allow|loopback|deny) for the admin API over plain HTTP; /ca.pem - rack controllers enroll with one-time join codes (CA fingerprint + secret + expiry + address): rollcall controller join-code, rollcall rack join; mutual TLS from then on, identity from the certificate (CN rack:NAME, serial on record), removal revokes, renewal a month before expiry; the shared rack_secret stays as a legacy fallback - clients: CA from the server config, ROLLCALL_CA, or trusted on first connect in the console after showing the fingerprint (kept in client.json); deployed machines trust it via cloud-init ca_certs (allowed on RHEL-family images), overlays get .CA; rollcall ca show|issue Power drivers - ipmi (cipher/privilege/interface), redfish (system discovery, ResetType from AllowableValues or ActionInfo, boot override with If-Match), idrac, ilo, supermicro, xcc, openbmc, proxmox (API token), manual; executed on the rack controller; Redfish auto-detection after commissioning; operator settings survive recommissioning; rollcall bmc, BMC editing in web UI and console - lab: pve_redfish.py Redfish emulator per Proxmox VM (iDRAC, iLO, generic profiles) IPv6 - IPv6 subnets and IPAM (netip), dual-stack default layout (all subnets of the boot VLAN), per-family default routes, accept-ra off where addresses are planned, dnsmasq RA/DHCPv6 with router lifetime 0 unless the rack is the gateway, AAAA host records from IPAM, IPv6 listen addresses and URLs, rack interfaces and region certificate with IPv6, agent reports IPv6 Tests for CA/join/pinning/CSR signing, Redfish (iDRAC, iLO fallbacks, probe), Proxmox, manual, IPv6 candidates, dual-stack plans and dnsmasq IPv6. Verified in the lab: rack2 enrolled and running on mutual TLS only, revocation and single-use codes; iLO auto-detected through rack2, iDRAC and Proxmox drivers, wrong password not saved; Debian 13 (bond+VLAN), Rocky 9 and AlmaLinux 9 dual-stack with Redfish-driven deployments; CA trusted on Debian and AlmaLinux; admin CLI over HTTPS on IPv4 and IPv6. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
227 lines
10 KiB
Go
227 lines
10 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func labSubnet() Subnet {
|
|
return Subnet{CIDR: "10.0.0.0/24", Gateway: "10.0.0.1", DNS: []string{"10.0.0.1"}, Domain: "lab.local", Fabric: "f0", MTU: 1500,
|
|
DHCP: true, PrimaryRack: "r1", Purpose: "provisioning",
|
|
Ranges: []IPRange{{Kind: "reserved", Start: "10.0.0.2", End: "10.0.0.20"}, {Kind: "dynamic", Start: "10.0.0.100", End: "10.0.0.200"}}}
|
|
}
|
|
|
|
func TestFreeCandidates(t *testing.T) {
|
|
sn := labSubnet()
|
|
got := freeCandidates(sn, map[string]bool{"10.0.0.21": true}, []string{"10.0.0.22/24"}, 3)
|
|
if strings.Join(got, " ") != "10.0.0.23 10.0.0.24 10.0.0.25" {
|
|
t.Errorf("candidates: %v", got)
|
|
}
|
|
for _, ip := range freeCandidates(sn, nil, nil, 0) {
|
|
if ip == "10.0.0.1" || ip == "10.0.0.0" || ip == "10.0.0.255" || (ipLess("10.0.0.99", ip) && ipLess(ip, "10.0.0.201")) {
|
|
t.Fatalf("handed out %s", ip)
|
|
}
|
|
}
|
|
sn.Ranges = append(sn.Ranges, IPRange{Kind: "static", Start: "10.0.0.50", End: "10.0.0.52"})
|
|
if got := freeCandidates(sn, nil, nil, 0); strings.Join(got, " ") != "10.0.0.50 10.0.0.51 10.0.0.52" {
|
|
t.Errorf("static range: %v", got)
|
|
}
|
|
}
|
|
|
|
func allocFrom(next ...string) func(Subnet, string) (string, error) {
|
|
return func(Subnet, string) (string, error) {
|
|
ip := next[0]
|
|
next = next[1:]
|
|
return ip, nil
|
|
}
|
|
}
|
|
|
|
func TestDefaultPlanAndNetworkConfig(t *testing.T) {
|
|
nics := []invNIC{{Name: "eno1", MAC: "aa:bb:cc:00:00:01", Speed: 1000, Link: true, IPv4: []string{"10.0.0.150/24"}}}
|
|
p := resolvePlan(nil, nics, &nics[0], []Subnet{labSubnet()}, nil, allocFrom("10.0.0.21"))
|
|
if len(p.Warnings) > 0 || len(p.Ifaces) != 1 {
|
|
t.Fatalf("plan: %+v", p)
|
|
}
|
|
if mgmt, _ := p.primaryIPs(); mgmt != "10.0.0.21" {
|
|
t.Errorf("mgmt %q", mgmt)
|
|
}
|
|
b, _ := json.Marshal(networkConfig(p))
|
|
s := string(b)
|
|
for _, want := range []string{`"macaddress":"aa:bb:cc:00:00:01"`, `"set-name":"eno1"`, `"addresses":["10.0.0.21/24"]`,
|
|
`"routes":[{"to":"0.0.0.0/0","via":"10.0.0.1"}]`, `"search":["lab.local"]`, `"dhcp4":false`, `"accept-ra":false`} {
|
|
if !strings.Contains(s, want) {
|
|
t.Errorf("network-config lacks %s:\n%s", want, s)
|
|
}
|
|
}
|
|
// a pinned address wins over allocation
|
|
p = resolvePlan(nil, nics, &nics[0], []Subnet{labSubnet()}, []IPAddr{{IP: "10.0.0.60", Subnet: "10.0.0.0/24", Iface: "eno1", Kind: "static"}}, allocFrom("10.0.0.21"))
|
|
if p.Ifaces[0].Links[0].IP != "10.0.0.60" || p.Ifaces[0].Links[0].Mode != "static" {
|
|
t.Errorf("static pin ignored: %+v", p.Ifaces[0].Links[0])
|
|
}
|
|
// no subnet model for the boot network: DHCP, as before
|
|
p = resolvePlan(nil, nics, &nics[0], nil, nil, nil)
|
|
if p.Ifaces[0].Links[0].Mode != "dhcp" {
|
|
t.Errorf("without subnets the default is dhcp, got %+v", p.Ifaces[0].Links)
|
|
}
|
|
}
|
|
|
|
func TestBondVLANLayout(t *testing.T) {
|
|
nics := []invNIC{
|
|
{Name: "eno1", MAC: "aa:00:00:00:00:01", Speed: 1000, Link: true, IPv4: []string{"10.0.0.150/24"}},
|
|
{Name: "ens1f0", MAC: "aa:00:00:00:00:02", Speed: 100000, Link: true},
|
|
{Name: "ens1f1", MAC: "aa:00:00:00:00:03", Speed: 100000, Link: true},
|
|
{Name: "ibp1s0", MAC: "80:00:00:00", IB: true, Link: true},
|
|
}
|
|
storage := Subnet{CIDR: "10.20.0.0/24", Fabric: "f0", VID: 200, MTU: 9000}
|
|
ib := Subnet{CIDR: "10.30.0.0/24", Fabric: "ib0"}
|
|
l := &NetLayout{Name: "gpu", Interfaces: []LayoutIface{
|
|
{Type: "physical", Select: "boot", Links: []LayoutLink{{Subnet: "boot", Mode: "auto", Gateway: true}}},
|
|
{Type: "bond", Name: "bond0", Members: []string{"fastest:2"}, Links: []LayoutLink{{Mode: "link_up"}}},
|
|
{Type: "vlan", Parent: "bond0", VID: 200, Links: []LayoutLink{{Subnet: "10.20.0.0/24", Mode: "auto"}}},
|
|
{Type: "physical", Select: "ib:0", Links: []LayoutLink{{Subnet: "10.30.0.0/24", Mode: "auto"}}},
|
|
}}
|
|
p := resolvePlan(l, nics, &nics[0], []Subnet{labSubnet(), storage, ib}, nil, allocFrom("10.0.0.21", "10.20.0.5", "10.30.0.5"))
|
|
if len(p.Warnings) > 0 {
|
|
t.Fatalf("warnings: %v", p.Warnings)
|
|
}
|
|
if got := p.Ifaces[1].Members; strings.Join(got, ",") != "ens1f0,ens1f1" {
|
|
t.Errorf("bond members %v (the boot NIC must not be taken)", got)
|
|
}
|
|
if p.Ifaces[2].Name != "bond0.200" || p.Ifaces[2].MTU != 9000 {
|
|
t.Errorf("vlan iface %+v", p.Ifaces[2])
|
|
}
|
|
if mgmt, ibip := p.primaryIPs(); mgmt != "10.0.0.21" || ibip != "10.30.0.5" {
|
|
t.Errorf("primary %s ib %s", mgmt, ibip)
|
|
}
|
|
b, _ := json.Marshal(networkConfig(p))
|
|
s := string(b)
|
|
for _, want := range []string{`"bonds":{"bond0":`, `"interfaces":["ens1f0","ens1f1"]`, `"mode":"802.3ad"`, `"vlans":{"bond0.200":`,
|
|
`"link":"bond0"`, `"id":200`, `"10.20.0.5/24"`, `"mtu":9000`, `"ibp1s0":{`, `"addresses":["10.30.0.5/24"]`} {
|
|
if !strings.Contains(s, want) {
|
|
t.Errorf("network-config lacks %s:\n%s", want, s)
|
|
}
|
|
}
|
|
if strings.Count(s, "0.0.0.0/0") != 1 {
|
|
t.Errorf("want exactly one default route:\n%s", s)
|
|
}
|
|
rules := linkRules(p)
|
|
for _, want := range []string{`ATTR{address}=="aa:00:00:00:00:01", NAME="eno1"`, `ATTR{address}=="aa:00:00:00:00:02", NAME="ens1f0"`, `ATTR{address}=="aa:00:00:00:00:03", NAME="ens1f1"`} {
|
|
if !strings.Contains(rules, want) {
|
|
t.Errorf("udev rules lack %s:\n%s", want, rules)
|
|
}
|
|
}
|
|
if strings.Contains(rules, "ibp1s0") {
|
|
t.Errorf("InfiniBand ports keep their names:\n%s", rules)
|
|
}
|
|
}
|
|
|
|
// NICs of one speed (VMs, a box of identical 25G ports): the bond must not count the boot NIC.
|
|
func TestBondSkipsUsedNICs(t *testing.T) {
|
|
nics := []invNIC{
|
|
{Name: "ens18", MAC: "bc:00:00:00:00:01", Link: true, IPv4: []string{"10.0.0.150/24"}},
|
|
{Name: "ens19", MAC: "bc:00:00:00:00:02", Link: true},
|
|
{Name: "ens20", MAC: "bc:00:00:00:00:03", Link: true},
|
|
}
|
|
l := &NetLayout{Interfaces: []LayoutIface{
|
|
{Type: "physical", Select: "boot", Links: []LayoutLink{{Subnet: "boot", Mode: "auto", Gateway: true}}},
|
|
{Type: "bond", Name: "bond0", Members: []string{"fastest:2"}, BondMode: "active-backup", Links: []LayoutLink{{Mode: "link_up"}}},
|
|
}}
|
|
p := resolvePlan(l, nics, &nics[0], []Subnet{labSubnet()}, nil, allocFrom("10.0.0.21"))
|
|
if got := strings.Join(p.Ifaces[1].Members, ","); got != "ens19,ens20" {
|
|
t.Errorf("bond members %q, want ens19,ens20", got)
|
|
}
|
|
if lk := p.Ifaces[1].Links[0]; lk.Subnet != "" || lk.Mode != "link_up" {
|
|
t.Errorf("a link_up link without a subnet stays without one: %+v", lk)
|
|
}
|
|
}
|
|
|
|
func TestDnsmasqConfig(t *testing.T) {
|
|
rc := RackController{Name: "r1", TFTPRoot: "/srv/tftp", Interfaces: []RackIface{{Name: "eth0", Addrs: []string{"192.168.1.5/24"}}, {Name: "eth1", Addrs: []string{"10.0.0.1/24"}}}}
|
|
conf, ok := dnsmasqConfig(rc, []Subnet{labSubnet()}, "/var/lib/rollcall/dnsmasq")
|
|
if !ok {
|
|
t.Fatal("r1 serves 10.0.0.0/24")
|
|
}
|
|
for _, want := range []string{"interface=eth1\n", "dhcp-range=set:s0,10.0.0.100,10.0.0.200,255.255.255.0,12h", "dhcp-option=tag:s0,option:router,10.0.0.1",
|
|
"dhcp-option=tag:s0,option:dns-server,10.0.0.1", "domain=lab.local,10.0.0.0/24", "dhcp-authoritative", "tftp-root=/srv/tftp"} {
|
|
if !strings.Contains(conf, want) {
|
|
t.Errorf("dnsmasq conf lacks %q:\n%s", want, conf)
|
|
}
|
|
}
|
|
if strings.Contains(conf, "interface=eth0") {
|
|
t.Errorf("must not serve the management interface:\n%s", conf)
|
|
}
|
|
// two racks: each takes half of the pool, nobody is authoritative
|
|
sn := labSubnet()
|
|
sn.SecondaryRack = "r2"
|
|
c1, _ := dnsmasqConfig(rc, []Subnet{sn}, "/d")
|
|
c2, _ := dnsmasqConfig(RackController{Name: "r2", Interfaces: []RackIface{{Name: "eth1", Addrs: []string{"10.0.0.2/24"}}}}, []Subnet{sn}, "/d")
|
|
if !strings.Contains(c1, "10.0.0.100,10.0.0.150,") || !strings.Contains(c2, "10.0.0.151,10.0.0.200,") || strings.Contains(c1, "dhcp-authoritative") {
|
|
t.Errorf("split pool:\n%s\n%s", c1, c2)
|
|
}
|
|
if _, ok := dnsmasqConfig(RackController{Name: "other"}, []Subnet{labSubnet()}, "/d"); ok {
|
|
t.Errorf("a rack that serves nothing must not get a config")
|
|
}
|
|
}
|
|
|
|
func v6Subnet() Subnet {
|
|
return Subnet{CIDR: "fd00:213:77::/64", Gateway: "fd00:213:77::1", DNS: []string{"fd00:213:77::1"}, Domain: "lab.local", Fabric: "f0", VLANID: 1,
|
|
DHCP: true, PrimaryRack: "r1", Purpose: "provisioning",
|
|
Ranges: []IPRange{{Kind: "static", Start: "fd00:213:77::50", End: "fd00:213:77::99"}, {Kind: "dynamic", Start: "fd00:213:77::100", End: "fd00:213:77::1ff"}}}
|
|
}
|
|
|
|
func TestIPv6Candidates(t *testing.T) {
|
|
got := freeCandidates(v6Subnet(), map[string]bool{"fd00:213:77::50": true}, []string{"fd00:213:77::51/64"}, 2)
|
|
if strings.Join(got, " ") != "fd00:213:77::52 fd00:213:77::53" {
|
|
t.Errorf("v6 candidates %v", got)
|
|
}
|
|
open := Subnet{CIDR: "fd00:1::/64", Gateway: "fd00:1::1", Ranges: []IPRange{{Kind: "reserved", Start: "fd00:1::2", End: "fd00:1::ff"}}}
|
|
if got := freeCandidates(open, nil, nil, 1); len(got) != 1 || got[0] != "fd00:1::100" {
|
|
t.Errorf("v6 without static range %v", got)
|
|
}
|
|
if familyOf("fd00:1::/64") != 6 || familyOf("10.0.0.0/24") != 4 {
|
|
t.Error("familyOf")
|
|
}
|
|
}
|
|
|
|
func TestDualStackDefaultPlan(t *testing.T) {
|
|
v4 := labSubnet()
|
|
v4.VLANID = 1
|
|
nics := []invNIC{{Name: "eno1", MAC: "aa:bb:cc:00:00:01", Link: true, IPv4: []string{"10.0.0.150/24"}}}
|
|
p := resolvePlan(nil, nics, &nics[0], []Subnet{v4, v6Subnet()}, nil, allocFrom("10.0.0.21", "fd00:213:77::50"))
|
|
if len(p.Ifaces) != 1 || len(p.Ifaces[0].Links) != 2 {
|
|
t.Fatalf("plan %+v", p)
|
|
}
|
|
b, _ := json.Marshal(networkConfig(p))
|
|
s := string(b)
|
|
for _, want := range []string{`"10.0.0.21/24"`, `"fd00:213:77::50/64"`, `{"to":"0.0.0.0/0","via":"10.0.0.1"}`, `{"to":"::/0","via":"fd00:213:77::1"}`,
|
|
`"addresses":["10.0.0.1","fd00:213:77::1"]`} {
|
|
if !strings.Contains(s, want) {
|
|
t.Errorf("network-config lacks %s:\n%s", want, s)
|
|
}
|
|
}
|
|
if mgmt, _ := p.primaryIPs(); mgmt != "10.0.0.21" {
|
|
t.Errorf("mgmt prefers IPv4, got %s", mgmt)
|
|
}
|
|
}
|
|
|
|
func TestDnsmasqIPv6(t *testing.T) {
|
|
rc := RackController{Name: "r1", Interfaces: []RackIface{{Name: "eth1", Addrs: []string{"10.0.0.1/24", "fd00:213:77::2/64"}}}}
|
|
conf, _ := dnsmasqConfig(rc, []Subnet{labSubnet(), v6Subnet()}, "/d")
|
|
for _, want := range []string{"enable-ra", "ra-param=eth1,10,0", "dhcp-range=set:s1,fd00:213:77::100,fd00:213:77::1ff,64,12h",
|
|
"dhcp-option=tag:s1,option6:dns-server,[fd00:213:77::1]", "dhcp-option=tag:s1,option6:domain-search,lab.local", "dhcp-option=tag:s0,option:dns-server,10.0.0.1\n"} {
|
|
if !strings.Contains(conf, want) {
|
|
t.Errorf("dnsmasq conf lacks %q:\n%s", want, conf)
|
|
}
|
|
}
|
|
if strings.Contains(conf, "tag:s1,option:router") {
|
|
t.Errorf("no IPv4 router option on an IPv6 subnet:\n%s", conf)
|
|
}
|
|
// the rack is the IPv6 gateway: it advertises itself as router (no lifetime 0)
|
|
rc.Interfaces[0].Addrs[1] = "fd00:213:77::1/64"
|
|
conf, _ = dnsmasqConfig(rc, []Subnet{labSubnet(), v6Subnet()}, "/d")
|
|
if strings.Contains(conf, "ra-param=eth1,10,0") {
|
|
t.Errorf("router lifetime 0 although the rack is the gateway:\n%s", conf)
|
|
}
|
|
}
|