Skip to content
6 changes: 4 additions & 2 deletions docs/development/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ and inert: the `DeviceCustody` and Device operation kinds, the creator webhook,
the kind registry and admission rule table, and the coordinator that admits,
fences, holds, recovers and rebuilds custody. Tests against a real API server
verify it. No deployment root, manager or staging overlay includes it, and the
Secret-backed lifecycle is unchanged. Site execution, the cutover and the
end-to-end failure scenarios are proposed.
Secret-backed lifecycle is unchanged. Increment B, the site framework with
per-Device fencing, journal, credentials and pinned TLS and the Redfish
install and wipe workers, is implemented and inert until the cutover. The
cutover and the end-to-end failure scenarios are proposed.

## API group naming

Expand Down
147 changes: 134 additions & 13 deletions docs/development/device-custody.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/development/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ and incomplete cleaning cannot cause duplicate effects or premature reuse.
The [device custody and operations work](device-custody.md) replaces
per-allocation fencing with one custody record per Device, ahead of real
hardware qualification. Increment A, the inert control-plane foundation, is
implemented. Increments B (site execution), C (cutover) and D (end-to-end
failure scenarios) are proposed. An allocation's private facts will live on
implemented, and so is Increment B, the inert site execution framework.
Increments C (cutover) and D (end-to-end failure scenarios) are proposed. An allocation's private facts will live on
its MachineAllocation, which C implements after B.

Acceptance: the #174 acceptance tests pass, in envtest and in fresh local
Expand Down
6 changes: 6 additions & 0 deletions docs/operations/redfish-lab.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ later.

## Redfish executor contract

The [site framework for Device custody](../development/device-custody.md#site-execution-increment-b)
ports the install and wipe phases below to per-Device fencing, a per-Device
journal and per-Device credentials with the approved TLS pin. It is
implemented and inert. This lab still runs the executor described here until
the cutover.

`internal/redfish` implements `executor.Client` behind the unchanged
`LocalAssetMapping`, coordination and lifecycle code. It has no process
execution, libvirt client or lab dependency. A Go test parses its imports to
Expand Down
1 change: 1 addition & 0 deletions docs/operations/site-execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ container and is unchanged.
| Redfish execution Jobs with no libvirt path, against the DMTF Redfish Interface Emulator and lab VMs | Implemented as a separate mode; see [Redfish-mode acceptance](redfish-lab.md) for its run record |
| Synchronized DHCP boot reservations with served and withdrawn evidence | Implemented and unit tested; not exercised at a site ([Boot network](boot-network.md)) |
| Physical Redfish/BMC execution Jobs | Not qualified (lab emulator only; see the [hardware readiness checklist](redfish-lab.md#limitations-and-physical-hardware-readiness)) |
| Per-Device fence store and journal, older-worker stop with a confirmation, worker deadlines, fenced typed results, per-Device credentials with the approved TLS pin, and the operation handoff payload ([device custody](../development/device-custody.md#site-execution-increment-b)) | Implemented and inert: unit tested, and nothing at the site runs it until the cutover. The site-wide journal above still drives this acceptance. |

## Independent review of the recorded run

Expand Down
13 changes: 13 additions & 0 deletions internal/bmcdiscovery/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,16 @@ func selectCredential(secrets []corev1.Secret) (cred Credential, found bool, err
}
return cred, true, nil
}

// CredentialFor returns the credential for one Device, named
// "<namespace>/<name>" in project, from the credential Secrets of its site.
// The site worker uses it, with the same contract as discovery.
func CredentialFor(secrets []corev1.Secret, project, device string) (Credential, bool, error) {
var matched []corev1.Secret
for index := range secrets {
if deviceKey(&secrets[index], project) == device {
matched = append(matched, secrets[index])
}
}
return selectCredential(matched)
}
4 changes: 2 additions & 2 deletions internal/custody/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

// Sites reports what each site serving a Device has stored. Delivery and
// results are added in Increment B; until then tests supply a fake.
// Sites reports what each site serving a Device has stored. The site
// framework's Report implements it for one site; tests supply a fake.
type Sites interface {
// Serving returns the sites explicitly configured to serve the Device.
// The coordinator never infers a site from placement.
Expand Down
16 changes: 16 additions & 0 deletions internal/custody/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,22 @@ func TestExtensionSeams(t *testing.T) {
e.requirePhase(refused, ops.PhaseFailed, ReasonNotRetryable)
})

t.Run("a worker result with a reason its kind never declared is recorded as UndeclaredReason", func(t *testing.T) {
e := e.sub(t)
device := fresh()
operation := e.staffOp(device, "ok")
e.settle(device.Name)
active := e.custody(device.Name).Spec.ActiveOperation
if err := e.coord.AcceptResult(e.ctx, SiteResult{Site: testSite, Device: device.Name, Operation: active.OperationReference, Fence: active.Fence, Phase: ops.PhaseFailed, Reason: "InventedAtTheSite"}); err != nil {
t.Fatal(err)
}
e.settle(device.Name)
status := e.requirePhase(operation, ops.PhaseFailed, ReasonUndeclared)
if !strings.Contains(status.Message, "InventedAtTheSite") {
t.Fatalf("message = %s", status.Message)
}
})

t.Run("a worker refusal with nothing sent ends Failed and returns a Service holder to None", func(t *testing.T) {
e := e.sub(t)
device := fresh()
Expand Down
11 changes: 10 additions & 1 deletion internal/custody/kinds.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@ const (
ReasonRetryAuthorized = "RetryAlreadyAuthorized"
ReasonDisposalRequired = "DisposalRequired"
ReasonInvalidResolve = "InvalidResolve"
// Reasons the Redfish install and wipe workers raise.
ReasonTargetUnsupported = "TargetUnsupported"
ReasonTargetDisks = "TargetDisksUnknown"
ReasonInputsUnreadable = "InputsUnreadable"
)

// redfishWorkerReasons are the reasons the site's install and wipe workers
// raise before sending anything.
var redfishWorkerReasons = []Reason{{Name: ReasonTargetUnsupported, RaisedBy: RaisedByWorker}, {Name: ReasonTargetDisks, RaisedBy: RaisedByWorker}, {Name: ReasonInputsUnreadable, RaisedBy: RaisedByWorker}}

const evidenceLimit = 4096

var gv = ops.GroupVersion
Expand Down Expand Up @@ -106,7 +114,7 @@ func DeviceInstallationKind() Kind {
return refuse(ReasonBootInterfaceUnknown, "the Device records no interface %q with a MAC address", installation.Spec.BootInterface)
},
Settles: []SettleRule{{Held: "DeviceInstallation"}},
Reasons: []Reason{{Name: ReasonBootstrapUnsupported, RaisedBy: RaisedByBoth}, {Name: ReasonBootInterfaceUnknown, RaisedBy: RaisedByCoordinator}},
Reasons: append([]Reason{{Name: ReasonBootstrapUnsupported, RaisedBy: RaisedByBoth}, {Name: ReasonBootInterfaceUnknown, RaisedBy: RaisedByCoordinator}}, redfishWorkerReasons...),
Evidence: StrictEvidence(evidenceLimit, func(_ ops.Operation, evidence *ops.InstallationEvidence) error {
return validateSteps(evidence.Steps)
}),
Expand Down Expand Up @@ -135,6 +143,7 @@ func DeviceWipeKind() Kind {
// settled by a later wipe only after a DeviceRecovery with Retry.
Settles: []SettleRule{{Held: "DeviceInstallation"}, {Held: "DeviceWipe", RequiresRetry: true}},
Retryable: true,
Reasons: redfishWorkerReasons,
Evidence: StrictEvidence(evidenceLimit, func(_ ops.Operation, evidence *ops.WipeEvidence) error {
if len(evidence.WipedDisks) > 16 {
return errors.New("evidence records at most 16 disks")
Expand Down
17 changes: 16 additions & 1 deletion internal/custody/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,23 @@ const (
ReasonSnapshotInvalid = "SnapshotInvalid"
)

// Reasons the site framework raises for any kind.
const (
ReasonUnsupportedKind = "UnsupportedKind"
ReasonInputMismatch = "InputMismatch"
ReasonCredentialMissing = "CredentialMissing"
ReasonPinNotApproved = "PinNotApproved"
ReasonPublicKeyMismatch = "PublicKeyMismatch"
ReasonNotEnrolled = "NotEnrolled"
ReasonBMCUnavailable = "BMCUnavailable"
ReasonWorkerRunning = "OlderWorkerRunning"
ReasonStale = "Stale"
ReasonStepUnknown = "StepOutcomeUnknown"
)

// sharedReasons are the reasons every kind may raise.
var sharedReasons = []string{ReasonCustodyUnverified, ReasonCreatorNotPermitted, ReasonHolderMismatch, ReasonOperationInProgress, ReasonDeviceIdentityMismatch,
var sharedReasons = []string{ReasonUnsupportedKind, ReasonInputMismatch, ReasonCredentialMissing, ReasonPinNotApproved, ReasonPublicKeyMismatch,
ReasonNotEnrolled, ReasonBMCUnavailable, ReasonWorkerRunning, ReasonStale, ReasonStepUnknown, ReasonCustodyUnverified, ReasonCreatorNotPermitted, ReasonHolderMismatch, ReasonOperationInProgress, ReasonDeviceIdentityMismatch,
ReasonSharedPublicKey, ReasonRecoveryHold, ReasonNameMismatch, ReasonExpired, ReasonSuperseded, ReasonWithdrawn, ReasonDeadlineExceeded,
ReasonSiteNotConfirmed, ReasonSiteUnknown, ReasonInvalidEvidence, ReasonUndeclared, ReasonSnapshotInvalid}

Expand Down
7 changes: 7 additions & 0 deletions internal/custody/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ func (c *Coordinator) AcceptResult(ctx context.Context, result SiteResult) error
default:
return fmt.Errorf("a site cannot report phase %q", result.Phase)
}
// A worker reports only reasons that are shared or that its kind
// declares.
reason, message := result.Reason, result.Message
if reason != "" && !c.Registry.Declared(kind.GVK.Kind, reason, RaisedByWorker) {
reason, message = ReasonUndeclared, fmt.Sprintf("the site reported %s, which %s does not declare", reason, kind.GVK.Kind)
}
result.Reason, result.Message = reason, message
var evidence []byte
if result.Phase == ops.PhaseSucceeded && kind.EvidenceRequired && len(result.Evidence) == 0 {
c.holdUnknown(custody, *active, ReasonInvalidEvidence, "the kind requires evidence, and the site sent none", nil)
Expand Down
56 changes: 37 additions & 19 deletions internal/redfish/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,13 @@ type System struct {
ResetTarget string `json:"resetTarget"`
ResetTypes []string `json:"resetTypes"`
BootTargets []string `json:"bootTargets"`
// noOnce records that the System does not offer a one-time override.
noOnce bool
}

// OffersOnce reports whether the System offers a one-time boot override.
func (s System) OffersOnce() bool { return !s.noOnce }

// Power is one observation of a System's power and boot override state.
type Power struct {
State string `json:"state"`
Expand All @@ -251,13 +256,38 @@ type resetAction struct {
}
}

// Discover walks the service root to the enrolled System. Every member of the
// Systems collection, across all pages, must be read: exactly one must carry
// the enrolled UUID, and it must have the enrolled Id; a member with the
// enrolled Id but another UUID is a renumbered or swapped target. The reset
// target and ActionInfo must belong to that System, and On, ForceOff, Pxe and
// Hdd must be advertised. Discovery issues GETs only.
// Discover is Identify followed by the install and cleanup capability
// checks: On, ForceOff, Pxe and Hdd must be advertised, and a one-time boot
// override offered.
func (c *Client) Discover(ctx context.Context, t Target) (System, error) {
sys, err := c.Identify(ctx, t)
if err != nil {
return System{}, err
}
for _, need := range []string{"On", "ForceOff"} {
if !contains(sys.ResetTypes, need) {
return System{}, fmt.Errorf("%w: ResetType %s", ErrUnsupported, need)
}
}
for _, need := range []string{"Pxe", "Hdd"} {
if !contains(sys.BootTargets, need) {
return System{}, fmt.Errorf("%w: boot override target %s", ErrUnsupported, need)
}
}
if sys.noOnce {
return System{}, fmt.Errorf("%w: one-time boot override", ErrUnsupported)
}
return sys, nil
}

// Identify walks the service root to the enrolled System and reads what it
// offers. Every member of the Systems collection, across all pages, must be
// read: exactly one must carry the enrolled UUID, and it must have the
// enrolled Id; a member with the enrolled Id but another UUID is a renumbered
// or swapped target. The reset target and ActionInfo must belong to that
// System. It requires no capability, so each caller checks what it uses. It
// issues GETs only.
func (c *Client) Identify(ctx context.Context, t Target) (System, error) {
api, err := c.connect(ctx)
if err != nil {
return System{}, err
Expand Down Expand Up @@ -349,19 +379,7 @@ func (c *Client) Discover(ctx context.Context, t Target) (System, error) {
for _, b := range s.Boot.AllowableBootSourceOverrideTargetValues {
sys.BootTargets = append(sys.BootTargets, string(b))
}
for _, need := range []string{"On", "ForceOff"} {
if !contains(sys.ResetTypes, need) {
return System{}, fmt.Errorf("%w: ResetType %s", ErrUnsupported, need)
}
}
for _, need := range []string{"Pxe", "Hdd"} {
if !contains(sys.BootTargets, need) {
return System{}, fmt.Errorf("%w: boot override target %s", ErrUnsupported, need)
}
}
if raw.Boot.Enabled != nil && !contains(*raw.Boot.Enabled, "Once") {
return System{}, fmt.Errorf("%w: one-time boot override", ErrUnsupported)
}
sys.noOnce = raw.Boot.Enabled != nil && !contains(*raw.Boot.Enabled, "Once")
return sys, nil
}

Expand Down
107 changes: 107 additions & 0 deletions internal/site/access.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package site

import (
"context"
"errors"
"strings"
"time"

"go.datum.net/fleet/internal/bmcdiscovery"
"go.datum.net/fleet/internal/custody"
"go.datum.net/fleet/internal/redfish"
)

// Access is the framework's check that it is safe to reach a Device's
// server, and the connection a kind then uses. It reads the credential, the
// enrollment and the server's identity, and changes nothing. Adding an access
// type, such as the local VM's, does not change the Kind contract.
type Access interface {
Prepare(ctx context.Context, assignment Assignment) (any, *custody.Refusal)
}

// Credentials looks up a Device's BMC credential at the site.
type Credentials interface {
Lookup(ctx context.Context, device string) (bmcdiscovery.Credential, bool, error)
}

// Targets is the site's enrollment: the Redfish System and boot NIC of each
// Device it serves. It is a site-local fact, checked against the snapshot.
type Targets interface {
Target(device string) (redfish.Target, bool)
}

// RedfishConnection is what RedfishAccess prepares: the enrolled target, the
// System whose identity it verified, and a client pinned to the approved
// key. The framework checks identity only; each kind checks the capabilities
// it uses, such as boot targets or reset types, on System.
type RedfishConnection struct {
Target redfish.Target
System redfish.System
BMC *redfish.Client
}

// Observe reads the verified System's power and boot override.
func (c *RedfishConnection) Observe(ctx context.Context) (redfish.Power, error) {
return c.BMC.Observe(ctx, c.System)
}

// Reset posts one ComputerSystem.Reset to the verified System.
func (c *RedfishConnection) Reset(ctx context.Context, kind string) error {
return c.BMC.Reset(ctx, c.System, kind)
}

// SetBootOnce arms one boot override on the verified System.
func (c *RedfishConnection) SetBootOnce(ctx context.Context, target string) error {
return c.BMC.SetBootOnce(ctx, c.System, target)
}

// RedfishAccess reaches a server through its BMC. It checks the site's
// enrollment against the admitted snapshot, reads the per-Device credential,
// requires the operator-approved pin to equal the key discovery recorded at
// admission, and reads the BMC only over a connection pinned to that key.
type RedfishAccess struct {
Credentials Credentials
Targets Targets
// Dial opens a client pinned to the approved key. Tests replace it.
Dial func(endpoint, username, password, pin string) (*redfish.Client, error)
}

func (a RedfishAccess) Prepare(ctx context.Context, assignment Assignment) (any, *custody.Refusal) {
target, ok := a.Targets.Target(assignment.Device)
if !ok {
return nil, &custody.Refusal{Reason: ReasonNotEnrolled, Message: "this site does not serve the Device"}
}
snapshot := assignment.Snapshot
if !strings.EqualFold(target.SystemUUID, snapshot.SystemUUID) || target.Endpoint != snapshot.BMCEndpoint || (snapshot.BootMACAddress != "" && !strings.EqualFold(target.MAC, snapshot.BootMACAddress)) {
return nil, &custody.Refusal{Reason: custody.ReasonDeviceIdentityMismatch, Message: "the site's enrollment does not match the admitted snapshot"}
}
credential, found, err := a.Credentials.Lookup(ctx, assignment.Device)
switch {
case err != nil || !found:
return nil, &custody.Refusal{Reason: ReasonCredentialMissing, Message: "no usable BMC credential is on record for the Device"}
case credential.Pin == "":
return nil, &custody.Refusal{Reason: ReasonPinNotApproved, Message: "no operator has approved the BMC's key"}
case credential.Pin != snapshot.BMCPublicKeySHA256:
return nil, &custody.Refusal{Reason: ReasonPublicKeyMismatch, Message: "the approved key differs from the key discovery recorded at admission"}
}
dial := a.Dial
if dial == nil {
dial = func(endpoint, username, password, pin string) (*redfish.Client, error) {
return redfish.NewPinnedClient(endpoint, username, password, pin, 30*time.Second)
}
}
client, err := dial(target.Endpoint, credential.Username, credential.Password, credential.Pin)
if err != nil {
return nil, &custody.Refusal{Reason: ReasonBMCUnavailable, Message: "a pinned BMC client could not be built"}
}
system, err := client.Identify(ctx, target)
switch {
case errors.Is(err, redfish.ErrPinMismatch):
return nil, &custody.Refusal{Reason: ReasonPublicKeyMismatch, Message: "the BMC presented a key other than the approved one"}
case errors.Is(err, redfish.ErrIdentity):
return nil, &custody.Refusal{Reason: custody.ReasonDeviceIdentityMismatch, Message: "the BMC reports another system"}
case err != nil:
return nil, &custody.Refusal{Reason: ReasonBMCUnavailable, Message: "the BMC could not be read"}
}
return &RedfishConnection{Target: target, System: system, BMC: client}, nil
}
Loading
Loading