Region as certificate authority, BMC power drivers, IPv6
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:
1 parent
736a7e38a3
commit
c8465c235a
29 files changed
+3156
-241
No files matched your search
@@ -5,8 +5,9 @@ set -eu
|
||||
cd "$(dirname "$0")"
|
||||
getent passwd pve-vbmc >/dev/null || useradd --system --no-create-home --shell /usr/sbin/nologin --user-group pve-vbmc
|
||||
install -m 0755 pve_vbmc.py /usr/local/bin/pve_vbmc.py
|
||||
install -m 0755 pve_redfish.py /usr/local/bin/pve_redfish.py
|
||||
install -m 0755 pve-vbmc-addrs.sh /usr/local/bin/pve-vbmc-addrs.sh
|
||||
install -m 0644 pve-vbmc@.service pve-vbmc-addrs.service /etc/systemd/system/
|
||||
install -m 0644 pve-vbmc@.service pve-redfish@.service pve-vbmc-addrs.service /etc/systemd/system/
|
||||
chgrp pve-vbmc /etc/pve-vbmc/config.json && chmod 0640 /etc/pve-vbmc/config.json
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now pve-vbmc-addrs.service
|
||||
@@ -16,4 +17,9 @@ systemctl enable --now pve-vbmc-addrs.service
|
||||
for v in $(python3 -c 'import json;print(" ".join(str(b["vmid"]) for b in json.load(open("/etc/pve-vbmc/config.json"))["bmcs"]))'); do
|
||||
systemctl enable --now "pve-vbmc@$v.service"
|
||||
done
|
||||
systemctl --no-pager --type=service | grep pve-vbmc
|
||||
# BMC entries with "redfish": "idrac" | "ilo" | "generic" also get a Redfish service on port 443
|
||||
for v in $(python3 -c 'import json;print(" ".join(str(b["vmid"]) for b in json.load(open("/etc/pve-vbmc/config.json"))["bmcs"] if b.get("redfish")))'); do
|
||||
systemctl enable --now "pve-redfish@$v.service"
|
||||
systemctl restart "pve-redfish@$v.service"
|
||||
done
|
||||
systemctl --no-pager --type=service | grep -E "pve-vbmc|pve-redfish"
|
||||
@@ -0,0 +1,21 @@
|
||||
[Unit]
|
||||
Description=pve-redfish Redfish service for Proxmox VM %i (lab BMC driver tests)
|
||||
After=network-online.target pve-vbmc-addrs.service
|
||||
Wants=network-online.target
|
||||
Requires=pve-vbmc-addrs.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/local/bin/pve_redfish.py --config /etc/pve-vbmc/config.json --vmid %i
|
||||
Restart=always
|
||||
RestartSec=3
|
||||
AmbientCapabilities=CAP_NET_BIND_SERVICE
|
||||
User=pve-vbmc
|
||||
Group=pve-vbmc
|
||||
NoNewPrivileges=yes
|
||||
ProtectSystem=strict
|
||||
ProtectHome=yes
|
||||
PrivateTmp=yes
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,239 @@
|
||||
#!/usr/bin/env python3
|
||||
"""pve-redfish: a small Redfish service for one Proxmox VM, for testing BMC drivers.
|
||||
|
||||
It answers on the same address as the VM's pve-vbmc (port 443 instead of UDP
|
||||
623) and shapes itself like a vendor so rollcall's Redfish probe and the
|
||||
idrac / ilo / generic drivers see what real hardware shows:
|
||||
|
||||
idrac Vendor "Dell", system /redfish/v1/Systems/System.Embedded.1, PowerCycle
|
||||
ilo Vendor "HPE", system /redfish/v1/Systems/1, no PowerCycle, PushPowerButton
|
||||
generic no vendor, system /redfish/v1/Systems/1, AllowableValues via @Redfish.ActionInfo
|
||||
|
||||
Config: the pve-vbmc config.json; a bmcs entry may carry "redfish": "idrac"|"ilo"|"generic".
|
||||
Basic auth with the same user/password as the IPMI side. Self-signed TLS.
|
||||
"""
|
||||
import argparse
|
||||
import base64
|
||||
import ipaddress
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import socket
|
||||
import ssl
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
|
||||
import requests
|
||||
import urllib3
|
||||
|
||||
log = logging.getLogger("pve-redfish")
|
||||
|
||||
PROFILES = {
|
||||
"idrac": {"vendor": "Dell", "manufacturer": "Dell Inc.", "model": "PowerEdge R760 (pve)", "id": "System.Embedded.1",
|
||||
"resets": ["On", "ForceOff", "ForceRestart", "GracefulRestart", "GracefulShutdown", "PushPowerButton", "Nmi", "PowerCycle"],
|
||||
"actioninfo": False, "etag": True},
|
||||
"ilo": {"vendor": "HPE", "manufacturer": "HPE", "model": "ProLiant DL380 Gen11 (pve)", "id": "1",
|
||||
"resets": ["On", "ForceOff", "ForceRestart", "Nmi", "PushPowerButton"], "actioninfo": False, "etag": False},
|
||||
"generic": {"vendor": "", "manufacturer": "QEMU", "model": "Standard PC (pve)", "id": "1",
|
||||
"resets": ["On", "ForceOff", "GracefulShutdown", "ForceRestart"], "actioninfo": True, "etag": False},
|
||||
}
|
||||
|
||||
|
||||
class Pve:
|
||||
def __init__(self, cfg, vmid):
|
||||
self.api, self.node, self.vmid = cfg["api"].rstrip("/"), cfg["node"], int(vmid)
|
||||
self.http = requests.Session()
|
||||
self.http.headers["Authorization"] = "PVEAPIToken=" + cfg["token"]
|
||||
self.http.verify = cfg.get("verify_tls", False)
|
||||
if not self.http.verify:
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
|
||||
def _url(self, path):
|
||||
return f"{self.api}/api2/json/nodes/{self.node}/qemu/{self.vmid}/{path}"
|
||||
|
||||
def get(self, path):
|
||||
r = self.http.get(self._url(path), timeout=10)
|
||||
r.raise_for_status()
|
||||
return r.json()["data"]
|
||||
|
||||
def post(self, path, **data):
|
||||
r = self.http.post(self._url(path), data=data, timeout=30)
|
||||
r.raise_for_status()
|
||||
return r.json()["data"]
|
||||
|
||||
def put(self, path, **data):
|
||||
r = self.http.put(self._url(path), data=data, timeout=30)
|
||||
r.raise_for_status()
|
||||
|
||||
def running(self):
|
||||
return self.get("status/current")["status"] == "running"
|
||||
|
||||
def boot(self, target):
|
||||
cfg = self.get("config")
|
||||
disks = [k for k in ("scsi0", "virtio0", "sata0", "ide0") if k in cfg]
|
||||
cds = sorted(k for k, v in cfg.items() if "media=cdrom" in str(v))
|
||||
nets = sorted(k for k in cfg if k.startswith("net") and k[3:].isdigit())
|
||||
order = {"Pxe": nets + disks + cds, "Cd": cds + disks + nets}.get(target, disks + cds + nets)
|
||||
self.put("config", boot="order=" + ";".join(order))
|
||||
return order
|
||||
|
||||
|
||||
def make_handler(pve, prof, user, password):
|
||||
sysid = prof["id"]
|
||||
syspath = f"/redfish/v1/Systems/{sysid}"
|
||||
state = {"override": "None", "enabled": "Disabled", "etag": 1}
|
||||
want = "Basic " + base64.b64encode(f"{user}:{password}".encode()).decode()
|
||||
|
||||
class H(BaseHTTPRequestHandler):
|
||||
server_version = "pve-redfish"
|
||||
|
||||
def log_message(self, fmt, *args):
|
||||
log.info("%s %s", self.address_string(), fmt % args)
|
||||
|
||||
def send(self, code, body=None, headers=None):
|
||||
data = json.dumps(body).encode() if body is not None else b""
|
||||
self.send_response(code)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.send_header("OData-Version", "4.0")
|
||||
for k, v in (headers or {}).items():
|
||||
self.send_header(k, v)
|
||||
self.send_header("Content-Length", str(len(data)))
|
||||
self.end_headers()
|
||||
self.wfile.write(data)
|
||||
|
||||
def error(self, code, msg):
|
||||
self.send(code, {"error": {"code": "Base.1.0.GeneralError", "message": msg,
|
||||
"@Message.ExtendedInfo": [{"Message": msg}]}})
|
||||
|
||||
def authed(self):
|
||||
if self.path.rstrip("/") == "/redfish/v1" or self.path.rstrip("/") == "/redfish":
|
||||
return True
|
||||
if self.headers.get("Authorization") != want:
|
||||
self.error(401, "authentication required")
|
||||
return False
|
||||
return True
|
||||
|
||||
def body(self):
|
||||
n = int(self.headers.get("Content-Length") or 0)
|
||||
return json.loads(self.rfile.read(n) or b"{}")
|
||||
|
||||
def system(self):
|
||||
reset = {"target": syspath + "/Actions/ComputerSystem.Reset"}
|
||||
if prof["actioninfo"]:
|
||||
reset["@Redfish.ActionInfo"] = syspath + "/ResetActionInfo"
|
||||
else:
|
||||
reset["ResetType@Redfish.AllowableValues"] = prof["resets"]
|
||||
return {"@odata.id": syspath, "Id": sysid, "Name": "System", "Manufacturer": prof["manufacturer"], "Model": prof["model"],
|
||||
"PowerState": "On" if pve.running() else "Off",
|
||||
"Boot": {"BootSourceOverrideTarget": state["override"], "BootSourceOverrideEnabled": state["enabled"],
|
||||
"BootSourceOverrideTarget@Redfish.AllowableValues": ["None", "Pxe", "Hdd", "Cd", "BiosSetup"]},
|
||||
"Actions": {"#ComputerSystem.Reset": reset}}
|
||||
|
||||
def do_GET(self):
|
||||
if not self.authed():
|
||||
return
|
||||
p = self.path.split("?")[0].rstrip("/")
|
||||
if p in ("/redfish/v1", "/redfish"):
|
||||
root = {"@odata.id": "/redfish/v1/", "RedfishVersion": "1.15.0", "Systems": {"@odata.id": "/redfish/v1/Systems"}}
|
||||
if prof["vendor"]:
|
||||
root["Vendor"] = prof["vendor"]
|
||||
root["Oem"] = {prof["vendor"]: {}}
|
||||
return self.send(200, root)
|
||||
if p == "/redfish/v1/Systems":
|
||||
return self.send(200, {"Members": [{"@odata.id": syspath}], "Members@odata.count": 1})
|
||||
if p == syspath:
|
||||
hdr = {"ETag": f'W/"{state["etag"]}"'} if prof["etag"] else None
|
||||
return self.send(200, self.system(), hdr)
|
||||
if p == syspath + "/ResetActionInfo":
|
||||
return self.send(200, {"Parameters": [{"Name": "ResetType", "Required": True, "AllowableValues": prof["resets"]}]})
|
||||
self.error(404, "not found")
|
||||
|
||||
def do_PATCH(self):
|
||||
if not self.authed():
|
||||
return
|
||||
if self.path.rstrip("/") != syspath:
|
||||
return self.error(404, "not found")
|
||||
if prof["etag"] and self.headers.get("If-Match") not in (f'W/"{state["etag"]}"', "*"):
|
||||
return self.error(412, "If-Match does not match the current ETag")
|
||||
boot = self.body().get("Boot", {})
|
||||
if "BootSourceOverrideEnabled" in boot:
|
||||
state["enabled"] = boot["BootSourceOverrideEnabled"]
|
||||
if "BootSourceOverrideTarget" in boot:
|
||||
state["override"] = boot["BootSourceOverrideTarget"]
|
||||
if state["enabled"] != "Disabled":
|
||||
order = pve.boot(state["override"])
|
||||
log.info("boot override %s -> order %s", state["override"], order)
|
||||
state["etag"] += 1
|
||||
self.send(204)
|
||||
|
||||
def do_POST(self):
|
||||
if not self.authed():
|
||||
return
|
||||
if self.path.rstrip("/") != syspath + "/Actions/ComputerSystem.Reset":
|
||||
return self.error(404, "not found")
|
||||
t = self.body().get("ResetType", "")
|
||||
if t not in prof["resets"]:
|
||||
return self.error(400, f"ResetType {t} is not supported")
|
||||
on = pve.running()
|
||||
log.info("reset %s (was %s)", t, "on" if on else "off")
|
||||
if t == "On" or (t == "PushPowerButton" and not on):
|
||||
if not on:
|
||||
pve.post("status/start")
|
||||
elif t == "ForceOff":
|
||||
if on:
|
||||
pve.post("status/stop")
|
||||
elif t in ("GracefulShutdown",) or (t == "PushPowerButton" and on):
|
||||
pve.post("status/shutdown", forceStop=1, timeout=60)
|
||||
elif t in ("ForceRestart", "GracefulRestart", "PowerCycle"):
|
||||
pve.post("status/reset" if on else "status/start")
|
||||
self.send(204)
|
||||
|
||||
return H
|
||||
|
||||
|
||||
def self_signed(addr):
|
||||
d = tempfile.mkdtemp()
|
||||
crt, key = os.path.join(d, "c.pem"), os.path.join(d, "k.pem")
|
||||
subprocess.run(["openssl", "req", "-x509", "-newkey", "ec", "-pkeyopt", "ec_paramgen_curve:prime256v1", "-nodes", "-days", "3650",
|
||||
"-subj", "/CN=pve-redfish", "-addext", f"subjectAltName=IP:{addr}", "-keyout", key, "-out", crt],
|
||||
check=True, capture_output=True)
|
||||
return crt, key
|
||||
|
||||
|
||||
class Server6(ThreadingHTTPServer):
|
||||
address_family = socket.AF_INET6
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--config", default="/etc/pve-vbmc/config.json")
|
||||
ap.add_argument("--vmid", type=int, required=True)
|
||||
args = ap.parse_args()
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)s %(levelname)s %(message)s")
|
||||
cfg = json.load(open(args.config))
|
||||
entry = next((b for b in cfg["bmcs"] if int(b["vmid"]) == args.vmid), None)
|
||||
if entry is None:
|
||||
log.error("vmid %s not in config", args.vmid)
|
||||
sys.exit(2)
|
||||
prof = PROFILES[entry.get("redfish", "generic")]
|
||||
addr = entry["address"]
|
||||
user = entry.get("user", cfg.get("user", "admin"))
|
||||
password = entry.get("password", cfg.get("password", "password"))
|
||||
handler = make_handler(Pve(cfg, args.vmid), prof, user, password)
|
||||
ip = ipaddress.ip_address(addr)
|
||||
cls = Server6 if ip.version == 6 else ThreadingHTTPServer
|
||||
srv = cls((addr, int(entry.get("redfish_port", 443))), handler)
|
||||
crt, key = self_signed(addr)
|
||||
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
||||
ctx.load_cert_chain(crt, key)
|
||||
srv.socket = ctx.wrap_socket(srv.socket, server_side=True)
|
||||
log.info("Redfish (%s profile) for VM %s on https://%s:%s", entry.get("redfish", "generic"), args.vmid, addr, entry.get("redfish_port", 443))
|
||||
srv.serve_forever()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user