Files
werewulf/docs/24-bare-metal.md
ilkerandClaude Opus 5.5 d07f443d0b
ci / derle (push) Successful in 49s
baremetal: run on SONiC, and the four bugs it found
The sonic driver, tested only against a fake until now, built a cluster
on SONiC 202505 (VS), cleaned two machines at once in its cleaning VLAN,
and released them. Fixed on the way:

- port changes raced: parallel processes both created a cluster's VLAN;
  the driver now locks on the switch around every change
- a cleaning killed between its two switch changes left a dirty machine
  in no VLAN, which looks free; a cleaning now records its start first,
  a machine is free only if its last cleaning finished and passed, and
  one cleaning per machine runs at a time under a lock
- the portal's startup sweep marked a selftest's destroy failed, which
  killed it; builds and destroys hold a lock the sweep respects
- setup wrote the trunk's configuration without applying it

Also selftest -boot-timeout, sonic.sh prepare, and the portal showing an
interrupted cleaning, with Retry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 17:33:34 +01:00

24 KiB

24. Bare metal — clusters on physical machines

Section 20 builds a tenant cluster out of virtual machines on a hypervisor. This section is the backend where the compute nodes are not guests but servers: a rack of machines with BMCs, cabled to a fabric switch, given to one cluster at a time, and wiped before the next.

Status: built, and run end to end on a simulated rack. Placement, discovery, power, network boot, per-cluster VLANs, cleaning, the portal's view of the machines, and the switch drivers have been run on the simulation described in 24.10, which is built from the same software a real rack runs (Redfish, IPMI, a VLAN-filtering bridge, SONiC 202505, real NVMe and ATA command sets as QEMU emulates them). None of it has yet run on physical hardware; 24.11 is the list of what that will be the first test of.


24.1 What a bare-metal site is

                       control plane (hpcod)
                  placement · portal · Terraform runner
                     │ SSH (pinned)        │ Redfish / IPMI
   ┌─────────────────┴───────┐         ┌───┴──────────────────────────┐
   │ head host (KVM)         │         │ BMCs (out-of-band network)   │
   │  heads: one VM/cluster  │         └───┬───────────┬──────────┬───┘
   │  bridge, VLAN-aware     │             │           │          │
   │  hpcod-switch, -clean   │          ┌──┴──┐     ┌──┴──┐    ┌──┴──┐
   └──────────┬──────────────┘          │ m01 │     │ m02 │ …  │ mNN │
              │ trunk (all cluster VLANs, cleaning VLAN)        machines
        ┌─────┴──────────────────────────┴───────────┴──────────┴──┐
        │ fabric switch: one access port per machine, in its       │
        │ cluster's VLAN or in none                                │
        └──────────────────────────────────────────────────────────┘
  • The head of each cluster is still a VM, on one libvirt/KVM host beside the rack: built by the libvirt module (§20), from the same head image. Its fabric NIC is a port on that host's VLAN-aware bridge.
  • Compute nodes are machines. A node gets a whole machine, whatever it asked for; nothing else is placed on that machine until the cluster is released. Machines boot diskless from their head (Warewulf, PXE), as guests do.
  • Isolation is the switch's. Every cluster has a VLAN, BM_VLAN_BASE + cluster_id. Its head's port and its machines' ports are access ports in it; a port in no cluster is in no VLAN at all, so a machine nobody holds can reach nothing.
  • Power is the BMC's, through Redfish or IPMI: on with a one-time network boot, off.

The code: internal/provider/baremetal (discovery, ports, power, cleaning), internal/redfish, terraform/envs/baremetal, internal/setup/baremetal_backend.go, and the scripts the head host runs, deploy/switch/ and deploy/clean/.

24.2 A cluster's life

  1. Placement. The head goes to the head host (HeadOnly), each compute node to a free machine big enough for it (Machine). A machine is free when the switch has its port in no VLAN, it is powered off, and no live cluster holds it in the database.
  2. Recording. The cluster is recorded with its machines (cluster_machine, one live holder per machine, enforced by a unique index). Two requests planned in the same second cannot both get one.
  3. Build (tofu apply, started=false): the head VM, its port into the cluster's VLAN on the head host, each machine's port into it on the fabric switch. The machines stay off.
  4. Start (started=true, once the head's portal answers): each machine is set to network boot once and powered on. It PXE boots from its head, which knows it by MAC, and joins Slurm.
  5. Release (tofu destroy): machines powered off; each is then cleaned (24.6) — not freed — and the head VM and its port go. The database releases the machines only when Terraform has finished, which it has not until every cleaning passed.

Every switch and BMC change is read back before the step returns, because Terraform takes exit 0 as done and never looks again.

24.3 Isolation, in detail

Port Where VLAN
a head's fabric NIC head host bridge, by MAC its cluster's, untagged
a machine's NIC fabric switch, by port its cluster's, untagged; none when free
head host ↔ switch both ends trunk: every cluster VLAN, and the cleaning VLAN, tagged
a machine being cleaned fabric switch the cleaning VLAN, BM_VLAN_BASE + 255
  • The head host's bridge filters VLANs and puts new ports in none (DefaultPVID=none). Setup refuses a bridge that does otherwise: with a default VLAN, every unassigned port shares one segment.
  • A guest's port on the head host is a tap made anew at each start. A libvirt hook, which setup installs with hpcod-switch, puts it back in its VLAN on every start; without it a rebooted head would be cut off.
  • A machine's port is never moved from one cluster's VLAN to another's. The only move allowed is into the cleaning VLAN, on release.
  • Nothing is routed out of the cleaning VLAN on the head host.

Tested on the simulation with two clusters up at once: a machine's traffic reached its own head and not the other (tcpdump on both heads' ports while it network booted), and a machine powered on behind hpcod's back, in no VLAN, reached neither. hpcod baremetal power refused to boot it, and discovery reported it as not free.

24.4 Configuration

site.env (setup)

SITE_KIND=baremetal, everything a libvirt site has for the head host (LIBVIRT_*, MGMT_*), and:

Key Default
BM_FABRIC_BRIDGE bmfab the head host's VLAN-aware bridge onto the fabric
BM_UPLINK empty its port to the switch, carrying every VLAN tagged
BM_VLAN_BASE 1000 cluster N is on base+N; base+255 is the cleaning VLAN
BM_CLEAN_ADDR 172.31.255.1/24 the head host's address in the cleaning VLAN
BM_CLEAN_MODE purge full also overwrites disks that were purged
BM_MACHINES /etc/hpcod/machines.yaml the machines file
BM_ENROLL empty Redfish services to write the machines file from, once
BMC_USER, BMC_INSECURE, BMC_CA admin, false, empty the site's BMC login and trust

The BMC password is not in site.env, which is world-readable: it is given to setup as BMC_PASSWORD in its environment and kept in /etc/hpcod/env. IPMI passwords are at most 20 bytes, that protocol's limit; a longer one is refused before any IPMI call.

machines.yaml

switches:                 # optional; without it, the site has one switch
  - {name: tor1, driver: sonic, host: 192.0.2.40, uplink: Ethernet48}
  - {name: tor2, driver: exec, command: /usr/local/bin/netauto}
machines:
  - name: node01
    bmc: https://192.0.2.50/redfish/v1/Systems/1   # or ipmi://host[:port]
    mac: "b8:59:9f:00:00:01"      # the NIC cabled to the fabric
    switch: tor1
    switch_port: Ethernet0
    bmc_user: root                # optional: this machine's own login
    bmc_password: file:/etc/hpcod/bmc/node01      # env:NAME or file:/path only
  - name: old01
    bmc: ipmi://192.0.2.60
    mac: "00:25:90:00:00:01"
    cores: 16                     # required for IPMI, which reports no size
    memory_gb: 64
    switch: tor2
    switch_port: "Gi1/0/12"

The file is checked as a whole and every problem reported at once: names, MACs (no multicast, no duplicates), BMC URLs, one machine per switch port, the uplink never a machine's port, and passwords only as references — a password written into the file is an error, not a password.

The MAC is configured, not discovered: a server has several NICs, and which one is on the fabric is a fact about the cabling. Discovery and setup check that the BMC reports it, where the BMC reports NICs at all.

From NetBox

Where the data centre keeps its servers in NetBox, the file is written from there instead of by hand: hpcod netbox reads the site's devices, their NICs and MACs, which switch port each NIC is cabled to, and their BMC addresses. A wrong MAC or port in a hand-written file puts a machine into another cluster's VLAN; one written from the cabling record does not drift from it.

export NETBOX_TOKEN=...        # read-only is enough; never written to
hpcod netbox -url https://netbox.example -site dc1 -role hpc-compute     # shows it
hpcod netbox -url https://netbox.example -site dc1 -role hpc-compute -write
systemctl restart hpcod-portal # the service reads the file when it starts
Machine field From NetBox
name the device's name, lower-cased
mac the fabric interface's primary MAC (NetBox 4.2+), or its mac_address before that
switch, switch_port the device and interface at the other end of that interface's cable
bmc the custom field hpcod_bmc (a full URL) where set; else the device's out-of-band IP as https://IP/redfish/v1/Systems/1 (-redfish-system changes the path, -bmc ipmi makes it ipmi://IP)
cores, memory_gb custom fields hpcod_cores, hpcod_memory_gb, where set
bmc_user, bmc_password custom fields hpcod_bmc_user, hpcod_bmc_password (a reference, as in the file)

Which devices: active ones at the site with the role (-role) and/or tag (-tag) given — one of them is required, or every device at the site, switches included, would be a machine.

Which NIC: NetBox does not know which network is the cluster fabric, and the import does not guess. The fabric switches are the ones the file's switches: section names — by their NetBox name, lower-cased — or, for a file without one, the single switch named with -switch. A machine's fabric NIC is its one interface cabled to a fabric switch. None, or more than one, is an error.

What NetBox does not know, the file keeps: the switches: section (drivers, hosts, commands), and a machine's size or login where NetBox has no custom field set for it. A machine in the file that NetBox no longer lists is kept and reported; -prune drops it — first make sure no cluster holds it.

Every device that cannot be made a machine is listed, and then nothing is written: a machine quietly left at what the file said before is the drift this is for. The file is written only if it checks as ReadMachines checks it; the old one is kept as machines.yaml.prev, owner and mode are kept, and the result is read back and compared before the command succeeds.

Tested against a real NetBox 4.7.5 (netbox-docker) holding the simulated rack, with a read-only v2 token: the file it wrote was the hand-written one, field for field, with a second NIC on a management switch and a non-machine device on the fabric switch both left out; a drifted file (wrong MAC and port, a machine missing, a stale one) was put right with -write -prune; a BMC from the out-of-band IP; and a machine given a second fabric NIC was refused, with nothing written. NetBox before 4.2 (MAC on the interface) is covered by unit tests only.

24.5 Switch drivers

Driver How Status
linux-bridge hpcod-switch on a host, over SSH; ports by MAC tested end to end
exec a program of the site's: CMD assign|clear|list SWITCH [PORT [VLAN]] tested end to end
http the same over REST, bearer token unit-tested
sonic SONiC over SSH: config to change, CONFIG_DB to read tested end to end on SONiC VS 202505

The sonic driver takes a lock on the switch (a file in its login's home) around every change. A cluster's ports are made in parallel, each by its own process, and a VLAN's first and last members are read-then-write: the first run on a real SONiC had two machines both find the new VLAN missing and both add it, and the second failed. SONiC expects the ports it is given to be plain L2 ports - a routed port (one with an IP address) cannot be a VLAN member, and is the network team's to change, not hpcod's.

exec and http are for the common case where the network team does not let applications log in to switches but does have automation — an Ansible job, a NetBox script — that hpcod can call. The contract:

assign SWITCH PORT VLAN   PORT an access port in VLAN, saved
clear  SWITCH PORT        PORT in no VLAN
list   SWITCH             "PORT VLAN" for every access port in a VLAN

GET    {url}/switches/{switch}/ports         {"ports": {"Ethernet0": 1001}}
PUT    {url}/switches/{switch}/ports/{port}  {"vlan": 1001}
DELETE {url}/switches/{switch}/ports/{port}

A change must be made, not queued, before the call returns: hpcod reads list back after every change and stops if it disagrees (a program that claims success without changing anything is caught). Arguments are passed as an argument list, never through a shell. deploy/baremetal-sim/netauto-example is a working example.

Uplinks — between switches, and to the head host — are the network team's, configured once as trunks carrying BM_VLAN_BASE to BM_VLAN_BASE + 255. hpcod changes access ports only. Setup pins the host keys of SSH-driven switches on first contact and refuses a changed one after.

24.6 Cleaning

A released machine is wiped before anyone else gets it. The nodes boot diskless, but a real server has local disks, and a tenant with root on a node can write to them.

How. The machine is powered off, its port moved into the cleaning VLAN, and it network boots, once, a wipe image that hpcod-clean on the head host builds from that host's own kernel and busybox and serves from dnsmasq and busybox httpd — in that VLAN only. A machine gets the image only while it is armed: iPXE asks for a script named after its MAC, which exists only between arm and disarm, and every cleaning has a random one-time token.

What the image does to each non-removable disk (NIST SP 800-88):

Device Purge, in order of preference
NVMe sanitize (crypto, then block erase) — whole controller, every namespace; else format with secure erase
ATA host protected area removed; sanitize (crypto, block); else enhanced secure erase if not frozen
SCSI / SAS sanitize (crypto, block)
anything else, or any of the above that refuses clear: overwritten whole with zeros, read back whole

A purge reaches what an overwrite cannot: spare flash, remapped sectors, hidden namespaces. A disk that can only be cleared is reported as such; the site decided (this is a policy choice) that a cleared machine may be given out again.

How it is checked. Before the wipe, markers carrying the token are written at 64 random places across each disk; after it, none may be readable. That works for every method — after a crypto erase a disk reads as noise, not zeros. An overwrite is also read back as zeros end to end. Discard (TRIM) is not a method: a drive may keep, and return, what it was asked to discard.

The decision is the control plane's. The image reports each disk's method, level and check, with the token, and powers off. hpcod frees the port only on a complete report of that cleaning with every disk verified and a level for each. Anything else — no report by the deadline, a disk that failed, another cleaning's token, a cut-off report — leaves the machine powered off and in the cleaning VLAN, which discovery reads as held. The cluster's release fails until someone looks.

Records. Every cleaning, passed or failed, is in /var/lib/hpcod/cleaning/<site>/<machine>.jsonl: when, at whose request, each disk's method, level, sample count and result. A cleaning writes a line when it starts, before it touches the machine, and another when it ends; the end is written before the port is freed, and a cleaning whose record cannot be written fails.

A machine is free only if it is known to be clean. On the switch, a free machine is a port in no VLAN — and so is a machine whose cleaning was killed between taking its port out of the cluster's VLAN and putting it in the cleaning one (two switch changes). So a port in no VLAN counts as free only when the machine's last cleaning finished and passed; a start with no end, or a failure, holds it. That happened on the simulation: a cleaning's Terraform was interrupted, and until this rule the machine showed as free with the tenant's data on its disks.

One cleaning of a machine runs at a time: each holds a lock, <machine>.lock beside its record, for as long as it runs. That is also how a running cleaning is told from one whose process died.

Retrying. hpcod baremetal clean -site S -machine M, or the portal's Retry button (24.7). A retry takes a machine whose last cleaning failed or never finished, with its port in the cleaning VLAN or in none — never one in a cluster's VLAN, and never one being cleaned.

Tested on the simulation, with tenant data written into each disk and checked from the host by qemu-io exit codes: an NVMe disk purged by format with secure erase, a SATA and a virtio disk cleared by overwrite, all three wiped and the machine freed in 58 s; with the cleaning service stopped, the machine left off and held; a retry freed it. Not yet tested: NVMe sanitize, ATA sanitize and secure erase, SCSI sanitize — QEMU does not implement them — and any real drive's firmware.

What cleaning does not cover is in 24.9.

24.7 The portal

The sites page lists a bare-metal site's machines: state (free; in use, and by which VLAN; cleaning; cleaning failed, and why; unreachable, and why), size, and the last cleaning with each disk's method and level. An administrator sees a Retry cleaning button on a machine whose last cleaning failed, and nowhere else. The portal refuses a retry for a machine whose last cleaning passed (a release may be cleaning it now) or one already being retried; the provider refuses, against the switch, one that is not waiting in the cleaning VLAN. Retries are attributed to whoever pressed.

Placing and releasing machines are a cluster's business; the portal has no other control over them.

24.8 Operating it

Command
hpcod verify the head host, switch driver, cleaning service, machines file, every machine through its BMC, and how many are free
hpcod discover -json every machine with allocated_to and problem
hpcod baremetal port -site S -machine M -vlan N | -clear a port by hand
hpcod baremetal power -site S -machine M -on -vlan N | -off power by hand; refuses to boot a machine whose port is not in that VLAN
hpcod baremetal clean -site S -machine M wipe and free one machine
hpcod-switch list (head host) ports the linux-bridge driver has assigned
systemctl status hpcod-clean (head host) the cleaning service

Reading a machine's state.

Shown as Meaning What to do
free port in no VLAN, powered off —
in use, VLAN N (cluster k) a live cluster has it —
in use, powered on, in no cluster's VLAN someone switched it on outside hpcod find out who; hpcod will not offer it
cleaning a release or a retry is wiping it wait
cleaning failed its last cleaning did not pass; held read the record's error, fix, Retry
cleaning interrupted its last cleaning started and never finished — the process was killed; held, its disks not known to be clean Retry
unreachable: BMC … its BMC refused or did not answer check the BMC, its login, the OOB network
unreachable: the BMC lists NICs …, not … mac in the machines file is not this machine's NIC fix the machines file
unreachable: switch … the switch could not be read; nothing on it is offered check the switch or the delegated program

24.9 Security limits

  • Cleaning covers disks only. Firmware, BIOS settings, EFI variables, the BMC's own accounts and storage (vFlash, SD modules) are not checked, and a tenant with root on a node can reach the BMC from inside it (IPMI over KCS, the Redfish host interface). Turn those interfaces off on the machines, or do not give tenants root.
  • A purge is as good as the drive's firmware. Buy drives that support sanitize (or self-encrypting ones) where purge is required everywhere; a disk that cannot be purged is only cleared.
  • An overwrite takes hours on a large disk, and the cluster's release waits for it.
  • The trunk to the head host carries every cluster's VLAN; the head host is trusted, as the hypervisor is on the other backends.

24.10 The simulation

deploy/baremetal-sim/setup.sh, run as root on a libvirt host, makes a rack out of that host:

  • machines bm01…: guests with the network first in the boot order and a local disk each, their MACs fixed as a real NIC's are;
  • BMCs: sushy-emulator, one Redfish service fronting all of them, and virtualbmc giving some (IPMI_MACHINES) an IPMI BMC as well;
  • the switch: a VLAN-filtering bridge with no default VLAN.

deploy/baremetal-sim/sonic.sh re-cables the same rack behind a SONiC VM (one two-ended bridge per machine as its cable, a trunk to the head host), and sonic.sh prepare ADDRESS then makes it the switch a network team would hand over: the VS image boots as a router, every port with an address, so those go, and hpcod's key is given its admin login. (The addresses were first removed by hand, with the same commands; prepare has since run only on the switch already prepared.) Its data plane is software (saivs) and slow - about 0.45 MB/s per machine - so a node's network boot through it takes over 15 minutes, and selftest needs -boot-timeout 30m. deploy/baremetal-sim/netauto-example is an exec driver for the simulation.

What has been run on it, on one nested-KVM host:

Run Result
hpcod selftest -compute 2 (Redfish machines) built, Slurm idle on both, srun -N 2, released
hpcod selftest -compute 3 (two Redfish, one IPMI) the same with three; the IPMI machine never touched Redfish
two clusters at once each machine's traffic reached only its own head; an unassigned machine reached neither
selftest through the exec driver, one machine with its own BMC login passed; a wrong password failed that machine alone
cleaning: NVMe, SATA, virtio disks with tenant data NVMe purged, the others cleared, data gone, freed in 58 s
cleaning with the service stopped; then a retry held and powered off; the retry freed it
portal: failed cleaning, Retry pressed shown with one button; cleaned and freed in a minute; second press 409
hpcod selftest -compute 2 -boot-timeout 30m behind SONiC 202505 built through the switch and the trunk, srun -N 2, released, both machines cleaned in parallel; 17 min, most of it the image at the VS's software speed
two machines' ports changed at once on SONiC first run: the second failed adding the VLAN the first had just added; with the switch-side lock, both assigned and both cleared
a cleaning killed with kill -9 while moving the port, port then in no VLAN held as "never finished", shown as cleaning interrupted with Retry; Retry purged NVMe, cleared SATA and virtio, freed it
the portal restarted during a selftest's destroy left it alone (its lock held); the destroy finished, both machines cleaned

24.11 On real hardware

The first real rack will be the first test of:

  • BMCs: vendor Redfish (iDRAC, iLO, XCC, Supermicro) — the boot override in UEFI mode, ETag (If-Match) on PATCH where a BMC demands it, real certificates through BMC_CA.
  • Network boot: UEFI PXE (or HTTP boot) on the fabric NIC only, with PXE off on the others; Secure Boot off, or the boot chain signed.
  • Drives: NVMe sanitize, ATA sanitize and secure erase (and drives left frozen by firmware), SAS sanitize — each on the models the site has.
  • Switches: the site's own automation through exec or http, or SONiC natively; uplinks set as trunks by the network team beforehand.

Before the first cluster: give hpcod a VLAN range and the cleaning VLAN, trunk them to the head host, put the BMCs where the control plane can reach them, turn off in-band BMC access on the machines, and run hpcod verify until every machine is free.

Still to be built: native drivers for the switches sites actually have, and heads that are machines too.