Region as certificate authority, BMC power drivers, IPv6
CI / agent (push) Successful in 2s
CI / site (push) Successful in 3s
CI / go (push) Successful in 34s

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>
This commit is contained in:
Ilker ManapandClaude Opus 5.5 committed 2026-10-28 07:44:13 +01:00
1 parent 736a7e38a3
commit c8465c235a
29 files changed
+3156 -241

No files matched your search

+213 -66
View File
@@ -13,6 +13,7 @@ import (
"errors"
"fmt"
"net"
"net/netip"
"regexp"
"sort"
"strconv"
@@ -63,7 +64,8 @@ type Subnet struct {
Comment string `json:"comment"`
Ranges []IPRange `json:"ranges"`
Used int `json:"used"`
Size int `json:"size"`
Size int `json:"size"` // host addresses; 0 when too many to count (IPv6)
Family int `json:"family"` // 4 or 6
}
type IPAddr struct {
@@ -192,9 +194,17 @@ func (s *Store) Subnets(ctx context.Context) ([]Subnet, error) {
if sn.DNS == nil {
sn.DNS = []string{}
}
sn.Family = familyOf(sn.CIDR)
if _, n, err := net.ParseCIDR(sn.CIDR); err == nil {
ones, bits := n.Mask.Size()
sn.Size = max(0, 1<<(bits-ones)-2)
switch {
case bits-ones > 30:
sn.Size = 0
case sn.Family == 6:
sn.Size = 1<<(bits-ones) - 1
default:
sn.Size = max(0, 1<<(bits-ones)-2)
}
}
sn.Ranges = []IPRange{}
out = append(out, sn)
@@ -374,15 +384,31 @@ func u2ip(u uint32) string {
return b.String()
}
// parseAddr reads an IPv4 or IPv6 address (brackets and a /prefix are ignored).
func parseAddr(s string) (netip.Addr, bool) {
a, err := netip.ParseAddr(strings.Trim(stripPrefix(strings.TrimSpace(s)), "[]"))
if err != nil {
return netip.Addr{}, false
}
return a.Unmap(), true
}
func ipLess(a, b string) bool {
x, ok1 := ip4(a)
y, ok2 := ip4(b)
x, ok1 := parseAddr(a)
y, ok2 := parseAddr(b)
if ok1 && ok2 {
return x < y
return x.Less(y)
}
return a < b
}
func familyOf(cidr string) int {
if p, err := netip.ParsePrefix(cidr); err == nil && p.Addr().Is6() && !p.Addr().Is4In6() {
return 6
}
return 4
}
func stripPrefix(s string) string { ip, _, _ := strings.Cut(s, "/"); return ip }
func (sn Subnet) contains(ip string) bool {
@@ -426,24 +452,22 @@ func subnetByRef(subnets []Subnet, ref string) *Subnet {
// freeCandidates lists the addresses IPAM may hand out in a subnet, in order:
// inside static ranges when the subnet has any, never in dynamic or reserved
// ranges, never the network, broadcast, gateway, a rack controller or a used one.
// ranges, never the network (or IPv4 broadcast), the gateway, a rack
// controller or a used one. IPv6 subnets are walked from the start of the
// static ranges (or the subnet) for a bounded number of steps.
func freeCandidates(sn Subnet, used map[string]bool, avoid []string, limit int) []string {
_, n, err := net.ParseCIDR(sn.CIDR)
if err != nil || n.IP.To4() == nil {
pfx, err := netip.ParsePrefix(sn.CIDR)
if err != nil {
return nil
}
ones, bits := n.Mask.Size()
if bits-ones > 16 { // a /15 or larger: refuse to walk it
ones = bits - 16
}
base := binary.BigEndian.Uint32(n.IP.To4())
last := base | (1<<(bits-ones) - 1)
type span struct{ lo, hi uint32 }
pfx = pfx.Masked()
base := pfx.Addr()
type span struct{ lo, hi netip.Addr }
var static, blocked []span
for _, r := range sn.Ranges {
lo, ok1 := ip4(r.Start)
hi, ok2 := ip4(r.End)
if !ok1 || !ok2 {
lo, ok1 := parseAddr(r.Start)
hi, ok2 := parseAddr(r.End)
if !ok1 || !ok2 || hi.Less(lo) {
continue
}
if r.Kind == "static" {
@@ -452,35 +476,58 @@ func freeCandidates(sn Subnet, used map[string]bool, avoid []string, limit int)
blocked = append(blocked, span{lo, hi})
}
}
skip := map[uint32]bool{base: true, last: true}
if g, ok := ip4(sn.Gateway); ok {
skip := map[netip.Addr]bool{base: true}
if base.Is4() {
last := base.As4()
bits := pfx.Bits()
v := binary.BigEndian.Uint32(last[:]) | (1<<(32-bits) - 1)
var b [4]byte
binary.BigEndian.PutUint32(b[:], v)
skip[netip.AddrFrom4(b)] = true
}
if g, ok := parseAddr(sn.Gateway); ok {
skip[g] = true
}
for _, a := range avoid {
if u, ok := ip4(stripPrefix(a)); ok {
if u, ok := parseAddr(a); ok {
skip[u] = true
}
}
in := func(x uint32, ss []span) bool {
in := func(x netip.Addr, ss []span) bool {
for _, s := range ss {
if x >= s.lo && x <= s.hi {
if !x.Less(s.lo) && !s.hi.Less(x) {
return true
}
}
return false
}
var out []string
for x := base + 1; x < last; x++ {
if skip[x] || in(x, blocked) || (len(static) > 0 && !in(x, static)) {
continue
try := func(x netip.Addr) bool {
if skip[x] || in(x, blocked) || used[x.String()] {
return false
}
ip := u2ip(x)
if used[ip] {
continue
out = append(out, x.String())
return limit > 0 && len(out) >= limit
}
const maxSteps = 1 << 16
if len(static) > 0 {
sort.Slice(static, func(i, j int) bool { return static[i].lo.Less(static[j].lo) })
for _, s := range static {
steps := 0
for x := s.lo; pfx.Contains(x) && !s.hi.Less(x) && steps < maxSteps; x = x.Next() {
steps++
if try(x) {
return out
}
}
}
out = append(out, ip)
if limit > 0 && len(out) >= limit {
break
return out
}
steps := 0
for x := base.Next(); x.IsValid() && pfx.Contains(x) && steps < maxSteps; x = x.Next() {
steps++
if try(x) {
return out
}
}
return out
@@ -636,6 +683,7 @@ func selectNICs(nics []invNIC, boot *invNIC, sel string) []invNIC {
// ---------------------------------------------------------------- plan
type PlanLink struct {
Family int `json:"family"`
Subnet string `json:"subnet"`
Mode string `json:"mode"`
IP string `json:"ip"`
@@ -667,12 +715,20 @@ type NetPlan struct {
member map[string]invNIC
}
func defaultLayout(bootSubnet *Subnet) *NetLayout {
link := LayoutLink{Subnet: "boot", Mode: "auto", Gateway: true}
// defaultLayout: the boot NIC on its subnet, plus every other subnet of the same
// VLAN (an IPv6 prefix next to the IPv4 one makes the machine dual-stack).
func defaultLayout(bootSubnet *Subnet, subnets []Subnet) *NetLayout {
links := []LayoutLink{{Subnet: "boot", Mode: "auto", Gateway: true}}
if bootSubnet == nil {
link = LayoutLink{Subnet: "boot", Mode: "dhcp"}
links = []LayoutLink{{Subnet: "boot", Mode: "dhcp"}}
} else if bootSubnet.VLANID != 0 {
for _, s := range subnets {
if s.VLANID == bootSubnet.VLANID && s.CIDR != bootSubnet.CIDR {
links = append(links, LayoutLink{Subnet: s.CIDR, Mode: "auto"})
}
}
}
return &NetLayout{Name: "(default)", Interfaces: []LayoutIface{{Type: "physical", Select: "boot", Links: []LayoutLink{link}}}}
return &NetLayout{Name: "(default)", Interfaces: []LayoutIface{{Type: "physical", Select: "boot", Links: links}}}
}
// resolvePlan turns a layout into concrete interfaces for one machine. alloc is
@@ -689,7 +745,7 @@ func resolvePlan(l *NetLayout, nics []invNIC, boot *invNIC, subnets []Subnet, ha
}
}
if l == nil {
l = defaultLayout(bootSubnet)
l = defaultLayout(bootSubnet, subnets)
}
p := &NetPlan{Layout: l.Name, Warnings: []string{}, member: map[string]invNIC{}}
used := map[string]bool{}
@@ -796,13 +852,13 @@ func resolvePlan(l *NetLayout, nics []invNIC, boot *invNIC, subnets []Subnet, ha
}
if sn == nil {
if mode == "dhcp" || mode == "link_up" {
pi.Links = append(pi.Links, PlanLink{Mode: mode})
pi.Links = append(pi.Links, PlanLink{Mode: mode, Family: 4})
continue
}
p.Warnings = append(p.Warnings, fmt.Sprintf("%s: subnet %q is not defined", pi.Name, lk.Subnet))
continue
}
pl := PlanLink{Subnet: sn.CIDR, Mode: mode, Prefix: sn.bits(), Gateway: sn.Gateway, Default: lk.Gateway, DNS: sn.DNS, Domain: sn.Domain}
pl := PlanLink{Family: familyOf(sn.CIDR), Subnet: sn.CIDR, Mode: mode, Prefix: sn.bits(), Gateway: sn.Gateway, Default: lk.Gateway, DNS: sn.DNS, Domain: sn.Domain}
if pi.MTU == 0 && sn.MTU > 0 && sn.MTU != 1500 {
pi.MTU = sn.MTU
}
@@ -830,14 +886,18 @@ func resolvePlan(l *NetLayout, nics []invNIC, boot *invNIC, subnets []Subnet, ha
}
p.Ifaces = append(p.Ifaces, pi)
}
// one default route: the flagged link, else the first addressed link with a gateway on the boot NIC, else anywhere
hasDefault := false
for _, pi := range p.Ifaces {
for _, pl := range pi.Links {
hasDefault = hasDefault || pl.Default
// one default route per family: the flagged link, else the first addressed
// link with a gateway on the boot NIC, else anywhere
for _, fam := range []int{4, 6} {
hasDefault := false
for _, pi := range p.Ifaces {
for _, pl := range pi.Links {
hasDefault = hasDefault || (pl.Default && pl.Family == fam)
}
}
if hasDefault {
continue
}
}
if !hasDefault {
pickDefault := func(onBoot bool) bool {
for i := range p.Ifaces {
carriesBoot := false
@@ -849,7 +909,7 @@ func resolvePlan(l *NetLayout, nics []invNIC, boot *invNIC, subnets []Subnet, ha
}
for j := range p.Ifaces[i].Links {
pl := &p.Ifaces[i].Links[j]
if pl.Gateway != "" && (pl.Mode == "auto" || pl.Mode == "static") {
if pl.Family == fam && pl.Gateway != "" && (pl.Mode == "auto" || pl.Mode == "static") {
pl.Default = true
return true
}
@@ -864,13 +924,19 @@ func resolvePlan(l *NetLayout, nics []invNIC, boot *invNIC, subnets []Subnet, ha
return p
}
// primaryIPs returns the address carrying the default route and the first IB address.
// primaryIPs returns the address carrying the default route (IPv4 first) and the first IB address.
func (p *NetPlan) primaryIPs() (mgmt, ib string) {
for _, fam := range []int{4, 6} {
for _, pi := range p.Ifaces {
for _, pl := range pi.Links {
if pl.Default && pl.IP != "" && mgmt == "" && pl.Family == fam {
mgmt = pl.IP
}
}
}
}
for _, pi := range p.Ifaces {
for _, pl := range pi.Links {
if pl.Default && pl.IP != "" && mgmt == "" {
mgmt = pl.IP
}
if pi.IB && pl.IP != "" && ib == "" {
ib = pl.IP
}
@@ -897,18 +963,27 @@ func networkConfig(p *NetPlan) map[string]any {
e["mtu"] = pi.MTU
}
var addrs, dns, search []string
dhcp := false
var routes []map[string]any
dhcp4, dhcp6 := false, false
for _, pl := range pi.Links {
switch pl.Mode {
case "dhcp":
dhcp = true
if pl.Family == 6 {
dhcp6 = true
} else {
dhcp4 = true
}
case "auto", "static":
if pl.IP == "" {
continue
}
addrs = append(addrs, fmt.Sprintf("%s/%d", pl.IP, pl.Prefix))
if pl.Default && pl.Gateway != "" {
e["routes"] = []map[string]any{{"to": "0.0.0.0/0", "via": pl.Gateway}}
to := "0.0.0.0/0"
if pl.Family == 6 {
to = "::/0"
}
routes = append(routes, map[string]any{"to": to, "via": pl.Gateway})
}
for _, d := range pl.DNS {
if !hasTag(dns, d) {
@@ -920,10 +995,20 @@ func networkConfig(p *NetPlan) map[string]any {
}
}
}
e["dhcp4"] = dhcp
e["dhcp4"] = dhcp4
if dhcp6 {
e["dhcp6"] = true
} else {
// addresses come from the plan (or none at all): router advertisements must not add
// SLAAC/DHCPv6 addresses or a second default route
e["accept-ra"] = false
}
if len(addrs) > 0 {
e["addresses"] = addrs
}
if len(routes) > 0 {
e["routes"] = routes
}
if len(dns) > 0 || len(search) > 0 {
ns := map[string]any{}
if len(dns) > 0 {
@@ -961,6 +1046,7 @@ func networkConfig(p *NetPlan) map[string]any {
for _, n := range pi.nics {
e := physical(n, nil)
e["dhcp4"] = false
e["accept-ra"] = false
if pi.MTU > 0 {
e["mtu"] = pi.MTU
}
@@ -1162,47 +1248,108 @@ func dnsmasqConfig(rc RackController, subnets []Subnet, dnsDir string) (string,
if !shared {
b.WriteString("dhcp-authoritative\n")
}
// IPv6: router advertisements carry the prefix; the rack only offers
// itself as the default router when it is the subnet's gateway
v6ifaces := map[string]bool{}
routerOn := map[string]bool{}
for _, sn := range served {
if familyOf(sn.CIDR) != 6 {
continue
}
for _, ri := range rc.Interfaces {
for _, ad := range ri.Addrs {
if sn.contains(ad) {
v6ifaces[ri.Name] = true
if stripPrefix(ad) == sn.Gateway {
routerOn[ri.Name] = true
}
}
}
}
}
if len(v6ifaces) > 0 {
b.WriteString("enable-ra\n")
for _, i := range sortedKeys(v6ifaces) {
if !routerOn[i] {
fmt.Fprintf(&b, "ra-param=%s,10,0\n", i)
}
}
}
for _, d := range domains {
fmt.Fprintf(&b, "local=/%s/\n", d)
}
for i, sn := range served {
tag := fmt.Sprintf("s%d", i)
v6 := familyOf(sn.CIDR) == 6
fmt.Fprintf(&b, "\n# %s · %s vlan %d · %s\n", sn.CIDR, orDash(sn.Fabric), sn.VID, sn.Purpose)
if sn.Domain != "" {
fmt.Fprintf(&b, "domain=%s,%s\n", sn.Domain, sn.CIDR)
}
mask := sn.netmask()
if v6 {
mask = strconv.Itoa(sn.bits())
}
dyn := 0
for _, r := range sn.Ranges {
if r.Kind != "dynamic" {
continue
}
lo, ok1 := ip4(r.Start)
hi, ok2 := ip4(r.End)
if !ok1 || !ok2 || hi < lo {
lo, ok1 := parseAddr(r.Start)
hi, ok2 := parseAddr(r.End)
if !ok1 || !ok2 || hi.Less(lo) {
continue
}
// two racks on one VLAN: each serves its own half of the pool
if sn.SecondaryRack != "" {
mid := lo + (hi-lo)/2
if sn.SecondaryRack != "" && lo.Is4() {
l4, h4 := lo.As4(), hi.As4()
a, z := binary.BigEndian.Uint32(l4[:]), binary.BigEndian.Uint32(h4[:])
mid := a + (z-a)/2
if rc.Name == sn.PrimaryRack {
hi = mid
z = mid
} else {
lo = mid + 1
a = mid + 1
}
var bl, bh [4]byte
binary.BigEndian.PutUint32(bl[:], a)
binary.BigEndian.PutUint32(bh[:], z)
lo, hi = netip.AddrFrom4(bl), netip.AddrFrom4(bh)
}
fmt.Fprintf(&b, "dhcp-range=set:%s,%s,%s,%s,12h\n", tag, u2ip(lo), u2ip(hi), sn.netmask())
fmt.Fprintf(&b, "dhcp-range=set:%s,%s,%s,%s,12h\n", tag, lo, hi, mask)
dyn++
}
if dyn == 0 {
// static leases only (known machines), no pool for strangers
_, n, _ := net.ParseCIDR(sn.CIDR)
fmt.Fprintf(&b, "dhcp-range=set:%s,%s,static,%s,12h\n", tag, n.IP.String(), sn.netmask())
fmt.Fprintf(&b, "dhcp-range=set:%s,%s,static,%s,12h\n", tag, n.IP.String(), mask)
}
if v6 {
if len(sn.DNS) > 0 {
var ds []string
for _, d := range sn.DNS {
if a, ok := parseAddr(d); ok && a.Is6() {
ds = append(ds, "["+a.String()+"]")
}
}
if len(ds) > 0 {
fmt.Fprintf(&b, "dhcp-option=tag:%s,option6:dns-server,%s\n", tag, strings.Join(ds, ","))
}
}
if sn.Domain != "" {
fmt.Fprintf(&b, "dhcp-option=tag:%s,option6:domain-search,%s\n", tag, sn.Domain)
}
continue
}
if sn.Gateway != "" {
fmt.Fprintf(&b, "dhcp-option=tag:%s,option:router,%s\n", tag, sn.Gateway)
}
if len(sn.DNS) > 0 {
fmt.Fprintf(&b, "dhcp-option=tag:%s,option:dns-server,%s\n", tag, strings.Join(sn.DNS, ","))
var ds []string
for _, d := range sn.DNS {
if a, ok := parseAddr(d); ok && a.Is4() {
ds = append(ds, a.String())
}
}
if len(ds) > 0 {
fmt.Fprintf(&b, "dhcp-option=tag:%s,option:dns-server,%s\n", tag, strings.Join(ds, ","))
}
if sn.MTU > 0 && sn.MTU != 1500 {
fmt.Fprintf(&b, "dhcp-option=tag:%s,option:mtu,%d\n", tag, sn.MTU)