BMC hints: the password stays on the region
GET /api/v1/bmc-hint answered with the BMC password to anyone with the agent token (public on the PXE command line) and a MAC (visible on the wire). It now returns the address and user only. When a machine reports in, the region matches its MACs against bmc_hints itself, seals the configured password into the record, and checks the BMC with a status call from the rack controller (verified_oob). The agent skips its own check when no password comes; old agents keep working. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a495c33b66
commit
e474fbcf16
4 files changed
+102
-18
No files matched your search
+58
-17
@@ -554,8 +554,28 @@ func (a *App) handleCommission(w http.ResponseWriter, r *http.Request) {
|
||||
// Pull the BMC password out of the payload before anything is persisted.
|
||||
var secret []byte
|
||||
detail := "bmc=none"
|
||||
if bmc, _ := inv["bmc"].(obj); bmc == nil || str(bmc["source"]) == "hint" || str(bmc["address"]) == "" {
|
||||
// a configured out-of-band BMC: the region's credentials, whatever the agent sent
|
||||
if h := a.hintFor(macs); h != nil {
|
||||
port := h.Port
|
||||
if port == 0 {
|
||||
port = 623
|
||||
}
|
||||
nb := obj{"source": "hint", "address": h.Address, "port": port, "user": h.User, "configured": true, "password": "<from bmc_hints>"}
|
||||
if bmc != nil {
|
||||
nb["agent"] = obj{"source": bmc["source"], "errors": bmc["errors"]}
|
||||
}
|
||||
inv["bmc"] = nb
|
||||
if h.Password != "" {
|
||||
if secret, err = a.sealer.Seal(h.Password, m.ID); err != nil {
|
||||
fail(w, 500, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if bmc, ok := inv["bmc"].(obj); ok {
|
||||
if pw := str(bmc["password"]); pw != "" {
|
||||
if pw := str(bmc["password"]); pw != "" && str(bmc["source"]) != "hint" {
|
||||
secret, err = a.sealer.Seal(pw, m.ID)
|
||||
if err != nil {
|
||||
fail(w, 500, err)
|
||||
@@ -603,9 +623,15 @@ func (a *App) handleCommission(w http.ResponseWriter, r *http.Request) {
|
||||
if isNew || oldErr != nil || old.State == "recommission" || old.RackController == "" {
|
||||
_ = a.store.SetRackController(r.Context(), m.ID, a.fromRack(r)) // a ready machine is not moved by whoever reports it
|
||||
}
|
||||
if full, err := a.store.Get(r.Context(), m.ID); err == nil {
|
||||
go a.probeBMC(full)
|
||||
}
|
||||
go func(id string) { // check a hinted BMC from where it is reachable, then look for Redfish
|
||||
ctx := context.Background()
|
||||
if full, err := a.store.Get(ctx, id); err == nil {
|
||||
a.verifyHintedBMC(full)
|
||||
}
|
||||
if full, err := a.store.Get(ctx, id); err == nil {
|
||||
a.probeBMC(full)
|
||||
}
|
||||
}(m.ID)
|
||||
if full, err := a.store.Get(r.Context(), m.ID); err == nil {
|
||||
m = full // carries profile / node token when this is a re-commission of a stateless node
|
||||
}
|
||||
@@ -623,22 +649,37 @@ func recommissionable(state string) bool {
|
||||
return state == "new" || state == "ready" || state == "recommission" || strings.HasSuffix(state, "-failed")
|
||||
}
|
||||
|
||||
func (a *App) handleHint(w http.ResponseWriter, r *http.Request) {
|
||||
// hintFor is the configured out-of-band BMC for one of these MACs.
|
||||
func (a *App) hintFor(macs []string) *BMCHint {
|
||||
want := map[string]bool{}
|
||||
for _, m := range strings.Split(r.URL.Query().Get("macs"), ",") {
|
||||
want[normMAC(m)] = true
|
||||
}
|
||||
for _, h := range a.cfg.BMCHints {
|
||||
if want[normMAC(h.MAC)] {
|
||||
port := h.Port
|
||||
if port == 0 {
|
||||
port = 623
|
||||
}
|
||||
writeJSON(w, 200, obj{"address": h.Address, "port": port, "user": h.User, "password": h.Password})
|
||||
return
|
||||
for _, m := range macs {
|
||||
if n := normMAC(m); n != "" {
|
||||
want[n] = true
|
||||
}
|
||||
}
|
||||
writeJSON(w, 200, obj{})
|
||||
for i, h := range a.cfg.BMCHints {
|
||||
if want[normMAC(h.MAC)] {
|
||||
return &a.cfg.BMCHints[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// handleHint tells a commissioning agent that a BMC is configured for it: the
|
||||
// address, never the password (the agent token is public, MACs are visible on
|
||||
// the wire). The region attaches the credentials itself when the machine
|
||||
// reports in (handleCommission) and checks them from the rack controller.
|
||||
func (a *App) handleHint(w http.ResponseWriter, r *http.Request) {
|
||||
h := a.hintFor(strings.Split(r.URL.Query().Get("macs"), ","))
|
||||
if h == nil {
|
||||
writeJSON(w, 200, obj{})
|
||||
return
|
||||
}
|
||||
port := h.Port
|
||||
if port == 0 {
|
||||
port = 623
|
||||
}
|
||||
writeJSON(w, 200, obj{"address": h.Address, "port": port, "user": h.User, "credentials": "on the region"})
|
||||
}
|
||||
|
||||
func (a *App) handleList(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in new issue
Block a user