Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ jobs:
- name: Install ripgrep for the link check
run: sudo apt-get update -qq && sudo apt-get install -y -qq --no-install-recommends ripgrep
- run: ./hack/test-run-standalone-smoke.sh
- run: ./hack/validate-site-dhcp-render.sh
- run: ./hack/validate-network-boot-inactive.sh
- run: ./hack/validate-doc-links.sh
- run: ./hack/multiplane/test-harness.sh
- run: shellcheck -S warning hack/multiplane/*.sh hack/local-vm/start-libvirt hack/local-vm/site-runtime
Expand Down
5 changes: 5 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ tasks:
cmds:
- ./hack/run-standalone-smoke.sh

boot-network:kea-lab:
desc: Prove the site DHCP path with real Kea, the synchronizer and the feed on one container bridge.
cmds:
- ./hack/boot-network/kea-lab.sh

multiplane:acceptance:
desc: Fresh local Milo/Karmada/kro/PXE acceptance, every service installed by per-cluster Flux from the checkout, in the task-owned Colima profile (exit 0 pass, 1 fail, 2 preflight, 3 blocked, 4 timeout).
env:
Expand Down
27 changes: 21 additions & 6 deletions cmd/fleet-dhcp-sync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package main

import (
"context"
"crypto/tls"
"crypto/x509"
"errors"
"flag"
"fmt"
Expand All @@ -21,23 +23,25 @@ import (
)

func main() {
var feed, tokenPath, instance, socket, base string
var interval time.Duration
var feed, tokenPath, caPath, instance, socket, base string
var interval, refresh time.Duration
flag.StringVar(&feed, "feed", "", "site DHCP feed origin, https://host[:port]")
flag.StringVar(&tokenPath, "token-file", "", "file holding the synchronizer bearer token")
flag.StringVar(&caPath, "ca-file", "", "PEM CA bundle the feed's certificate must chain to; default the system roots")
flag.StringVar(&instance, "instance", os.Getenv("POD_NAME"), "stable name of this Kea instance")
flag.StringVar(&socket, "kea-socket", "/run/kea/kea4-ctrl-socket", "Kea DHCPv4 unix control socket")
flag.StringVar(&socket, "kea-socket", "/var/run/kea/kea4-ctrl-socket", "Kea DHCPv4 unix control socket; Kea 2.6 allows only /var/run/kea")
flag.StringVar(&base, "base-config", "/etc/kea/kea-dhcp4.conf", "Kea configuration without Fleet reservations")
flag.DurationVar(&interval, "interval", 5*time.Second, "feed poll interval")
flag.DurationVar(&refresh, "refresh", dhcpsync.DefaultRefresh, "least time between two reports of an unchanged applied feed")
flag.Parse()
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
if err := run(logger, feed, tokenPath, instance, socket, base, interval); err != nil && !errors.Is(err, context.Canceled) {
if err := run(logger, feed, tokenPath, caPath, instance, socket, base, interval, refresh); err != nil && !errors.Is(err, context.Canceled) {
logger.Error("dhcp sync stopped", "error", err)
os.Exit(1)
}
}

func run(logger *slog.Logger, feed, tokenPath, instance, socket, base string, interval time.Duration) error {
func run(logger *slog.Logger, feed, tokenPath, caPath, instance, socket, base string, interval, refresh time.Duration) error {
u, err := url.Parse(feed)
if err != nil || u.Scheme != "https" || u.Host == "" || (u.Path != "" && u.Path != "/") || u.RawQuery != "" || u.User != nil {
return errors.New("feed must be an https origin")
Expand All @@ -48,8 +52,19 @@ func run(logger *slog.Logger, feed, tokenPath, instance, socket, base string, in
}
transport := http.DefaultTransport.(*http.Transport).Clone()
transport.Proxy = nil
if caPath != "" {
pem, err := os.ReadFile(caPath)
if err != nil {
return fmt.Errorf("CA bundle: %w", err)
}
roots := x509.NewCertPool()
if !roots.AppendCertsFromPEM(pem) {
return errors.New("CA bundle holds no certificate")
}
transport.TLSClientConfig = &tls.Config{RootCAs: roots, MinVersion: tls.VersionTLS12}
}
s := &dhcpsync.Syncer{
Feed: u.Scheme + "://" + u.Host, Token: strings.TrimSpace(string(token)), Instance: instance, Socket: socket, Base: base,
Feed: u.Scheme + "://" + u.Host, Token: strings.TrimSpace(string(token)), Instance: instance, Socket: socket, Base: base, Refresh: refresh,
HTTP: &http.Client{Timeout: 15 * time.Second, Transport: transport, CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }},
}
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
Expand Down
19 changes: 13 additions & 6 deletions cmd/fleet-multiplane/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"go.datum.net/fleet/internal/multiplane"
"go.datum.net/fleet/internal/redfish"
"go.datum.net/fleet/internal/site"
"go.datum.net/fleet/internal/site/redfishwork"
)

func main() {
Expand All @@ -33,7 +32,7 @@ func main() {

func run() error {
if len(os.Args) < 2 {
return fmt.Errorf("usage: fleet-multiplane coordinator|site-worker|site-observer|image|boot-service|boot-withhold|boot-denials|dhcp-feed|dhcp-retire|redfish-probe|<management phase> [flags]")
return fmt.Errorf("usage: fleet-multiplane coordinator|site-worker|site-observer|image|boot-service|boot-withhold|boot-denials|dhcp-feed|redfish-probe|<management phase> [flags]")
}
fs := flag.NewFlagSet(os.Args[1], flag.ContinueOnError)
once := fs.Bool("once", false, "one attempt, for fault injection")
Expand All @@ -53,7 +52,8 @@ func run() error {
syncToken := fs.String("sync-token-file", "", "file holding the DHCP synchronizer bearer token (dhcp-feed)")
installationDeadline := fs.Duration("installation-deadline", 0, "replace the installation deadline for operations this coordinator admits (coordinator)")
skewMargin := fs.Duration("skew-margin", 0, "replace the margin after a deadline before the coordinator declares it exceeded (coordinator)")
instance := fs.String("instance", "", "DHCP instance an operator retires (dhcp-retire)")
tlsCert := fs.String("tls-cert", "", "TLS certificate the DHCP feed serves (dhcp-feed)")
tlsKey := fs.String("tls-key", "", "TLS key of the DHCP feed (dhcp-feed)")
if err := fs.Parse(os.Args[2:]); err != nil {
return err
}
Expand Down Expand Up @@ -81,11 +81,9 @@ func run() error {
fmt.Println(image)
return nil
case "boot-service", "boot-denials", "dhcp-feed":
return boot(os.Args[1], *origin, *extraMAC, *syncToken)
return boot(os.Args[1], *origin, *extraMAC, *syncToken, *tlsCert, *tlsKey)
case "boot-withhold":
return armWithhold(fs.Arg(0))
case "dhcp-retire":
return redfishwork.RetireInstance(os.Getenv("FLEET_BOOT_EVIDENCE"), *instance)
case "site-worker", "site-observer":
default:
return fmt.Errorf("unknown command")
Expand Down Expand Up @@ -161,6 +159,15 @@ func phase(name, configPath string, once bool) error {
}[name]
last := ""
for {
// With synchronized lab DHCP, bind the boot address claims this phase
// is waiting on, in IPAM's place.
if r.IPAM != nil {
if bound, bindErr := r.IPAM.Bind(ctx); bindErr != nil {
fmt.Printf("%s: lab IPAM stand-in: %v\n", name, bindErr)
} else if bound > 0 {
fmt.Printf("%s: lab IPAM stand-in bound %d boot address claim(s)\n", name, bound)
}
}
err = action(ctx)
// Report each new reason a phase is waiting, so a phase that times
// out shows what it waited for.
Expand Down
46 changes: 36 additions & 10 deletions cmd/fleet-multiplane/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func redfishConfig() (redfishwork.Config, redfish.Enrollment, error) {
if err != nil {
return redfishwork.Config{}, redfish.Enrollment{}, err
}
return redfishwork.Config{ConsoleRoot: console, BootRoot: boot, Synced: enrollment.DHCP == redfish.DHCPSynced}, enrollment, nil
return redfishwork.Config{ConsoleRoot: console, BootRoot: boot, Synced: enrollment.DHCP == redfish.DHCPSynced, DHCPInstances: enrollment.DHCPInstances}, enrollment, nil
}

// siteRunner is the site runner for this cell's mode. A Redfish worker reads
Expand Down Expand Up @@ -228,7 +228,7 @@ func redfishKinds(work redfishwork.Config, burnIn string) map[string]site.Kind {

// boot serves network boots, the DHCP reservation feed, or probes that
// every closed admission is denied.
func boot(command, origin, extraMAC, syncToken string) error {
func boot(command, origin, extraMAC, syncToken, tlsCert, tlsKey string) error {
store, err := openStore()
if err != nil {
return err
Expand Down Expand Up @@ -256,19 +256,31 @@ func boot(command, origin, extraMAC, syncToken string) error {
fmt.Println(summary)
return nil
}
if redfishMode() && command == "dhcp-feed" {
// Reservations come from the admitted operations in the store, and
// reports go beside the boot evidence. The feed serves no boot
// artifacts, so it needs no boot origin or installer image. It reads
// the workers' enrollment for one thing: the expected DHCP instances,
// the only ones it serves and takes reports from.
root, err := bootRoot()
if err != nil {
return err
}
enrollment, err := feedEnrollment([]byte(os.Getenv("FLEET_REDFISH_ENROLLMENT")))
if err != nil {
return err
}
token, err := os.ReadFile(syncToken)
if err != nil {
return fmt.Errorf("DHCP synchronizer token: %w", err)
}
return redfishwork.BootServer{Store: store, BootRoot: root, DHCPInstances: enrollment.DHCPInstances}.ServeDHCP(strings.TrimSpace(string(token)), tlsCert, tlsKey)
}
if redfishMode() {
server, err := redfishBootServer(store)
if err != nil {
return err
}
if command == "dhcp-feed" {
// Reservations come from the admitted operations in the store.
token, err := os.ReadFile(syncToken)
if err != nil {
return fmt.Errorf("DHCP synchronizer token: %w", err)
}
return server.ServeDHCP(strings.TrimSpace(string(token)))
}
return serveBoot(server.Handler(), vmwork.DefaultBootWindow*2)
}
if command == "dhcp-feed" {
Expand All @@ -281,3 +293,17 @@ func boot(command, origin, extraMAC, syncToken string) error {
// Emulated firmware takes minutes to fetch the installer.
return serveBoot(vm.BootHandler(store), vmwork.DefaultBootWindow)
}

// feedEnrollment is the enrollment the DHCP reservation feed serves. Only a
// site whose enrollment has synced DHCP has a feed; the default, static,
// leaves DHCP to the site and starts no feed.
func feedEnrollment(raw []byte) (redfish.Enrollment, error) {
enrollment, err := redfish.ParseEnrollment(raw)
if err != nil {
return redfish.Enrollment{}, err
}
if enrollment.DHCP != redfish.DHCPSynced {
return redfish.Enrollment{}, errors.New("the DHCP reservation feed serves only a site whose enrollment has synced DHCP")
}
return enrollment, nil
}
23 changes: 23 additions & 0 deletions cmd/fleet-multiplane/site_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,26 @@ func TestARedfishSiteRunsPowerOperations(t *testing.T) {
}
}
}

// syntheticEnrollment is a one-target site enrollment with the given DHCP
// fields.
func syntheticEnrollment(dhcp string) []byte {
return []byte(`{` + dhcp + `"targets":[{"device":"fleet-provider/server-example-001","endpoint":"https://192.0.2.10:8443","systemID":"System-1",` +
`"systemUUID":"00000000-0000-4000-8000-000000000001","diskBytes":2147483648,"console":"server-example-001.log"}]}`)
}

// TestTheDHCPFeedStartsOnlyForSyncedDHCP refuses to start the reservation
// feed for an enrollment that leaves DHCP to the site, or names no DHCP
// mode.
func TestTheDHCPFeedStartsOnlyForSyncedDHCP(t *testing.T) {
if _, err := feedEnrollment(syntheticEnrollment(`"dhcp":"static",`)); err == nil || !strings.Contains(err.Error(), "synced DHCP") {
t.Errorf("static DHCP: the feed started: %v", err)
}
if _, err := feedEnrollment(syntheticEnrollment(``)); err == nil {
t.Error("no DHCP mode: the feed started")
}
enrollment, err := feedEnrollment(syntheticEnrollment(`"dhcp":"synced","dhcpInstances":["fleet-site-dhcp-0"],`))
if err != nil || len(enrollment.DHCPInstances) != 1 {
t.Fatalf("synced DHCP: %+v, %v", enrollment, err)
}
}
131 changes: 131 additions & 0 deletions config/site/dhcp/component/dhcp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
apiVersion: v1
kind: ServiceAccount
metadata: {name: fleet-site-dhcp, namespace: fleet-site}
automountServiceAccountToken: false
---
# One site's Kea DHCPv4 instances, in a central cluster rather than at the
# site. Each Pod's name is its stable instance name in the applied reports,
# so a StatefulSet, never a Deployment: a replaced Pod keeps its name and its
# last report. The instances share one load-balancer address on UDP 67
# (below), which the site's relays reach over the WAN link. Kea answers only relayed
# requests, on a UDP socket, so it needs no host networking; the base
# configuration's relay filter limits it to the site's relays. The site's
# enrollment lists these Pods' names as its expected DHCP instances. To
# retire one, make sure it no longer answers, scale down (the highest
# ordinal goes first), shrink the enrollment's dhcpInstances to match, and
# restart the site's workers and feed.
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: fleet-site-dhcp
namespace: fleet-site
spec:
serviceName: fleet-site-dhcp
replicas: 2
podManagementPolicy: Parallel
selector:
matchLabels: {app.kubernetes.io/name: fleet-site-dhcp}
template:
metadata:
labels: {app.kubernetes.io/name: fleet-site-dhcp}
spec:
serviceAccountName: fleet-site-dhcp
automountServiceAccountToken: false
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector: {matchLabels: {app.kubernetes.io/name: fleet-site-dhcp}}
topologyKey: kubernetes.io/hostname
containers:
- name: kea
# ISC's image, pinned by digest. It is built for linux/amd64 only.
image: docker.cloudsmith.io/isc/docker/kea-dhcp4:2.6.3@sha256:c40abb1522b15edb9a6d1119ad22b3765bf818a51d6776f498e874ad13416065
# Kea 2.6 refuses a control socket directory that is not 0750,
# and an emptyDir is created 0777.
command: [sh, -c, 'chmod 0750 /var/run/kea && exec kea-dhcp4 -c /etc/kea-base/kea-dhcp4.conf']
ports:
- {name: dhcp, containerPort: 67, protocol: UDP}
securityContext:
runAsUser: 0
allowPrivilegeEscalation: false
capabilities: {drop: [ALL], add: [NET_BIND_SERVICE]}
resources:
requests: {cpu: 50m, memory: 64Mi}
limits: {memory: 256Mi}
volumeMounts:
- {name: base, mountPath: /etc/kea-base, readOnly: true}
- {name: control, mountPath: /var/run/kea}
- name: sync
image: "${FLEET_DHCP_SYNC_IMAGE}"
imagePullPolicy: IfNotPresent
command:
- /fleet-dhcp-sync
# The site's feed, over TLS only, wherever the site's boot Pod
# runs.
- -feed=${FLEET_DHCP_FEED_URL}
- -token-file=/etc/fleet-dhcp/token
- -ca-file=/etc/fleet-dhcp-tls/ca.crt
- -kea-socket=/var/run/kea/kea4-ctrl-socket
- -base-config=/etc/kea-base/kea-dhcp4.conf
env:
- name: POD_NAME
valueFrom: {fieldRef: {fieldPath: metadata.name}}
securityContext:
runAsUser: 0
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities: {drop: [ALL]}
resources:
requests: {cpu: 10m, memory: 16Mi}
limits: {memory: 64Mi}
volumeMounts:
- {name: base, mountPath: /etc/kea-base, readOnly: true}
- {name: control, mountPath: /var/run/kea}
- {name: token, mountPath: /etc/fleet-dhcp, readOnly: true}
- {name: feed-ca, mountPath: /etc/fleet-dhcp-tls, readOnly: true}
volumes:
- name: base
configMap: {name: fleet-site-dhcp-base}
- name: control
emptyDir: {}
- name: token
secret: {secretName: fleet-site-dhcp-sync, defaultMode: 0400}
- name: feed-ca
secret: {secretName: fleet-site-dhcp-feed-tls, defaultMode: 0400, items: [{key: ca.crt, path: ca.crt}]}
---
# One instance may restart at a time. Retiring an instance is an operator
# step; see the comment on the StatefulSet.
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: fleet-site-dhcp
namespace: fleet-site
spec:
maxUnavailable: 1
selector:
matchLabels: {app.kubernetes.io/name: fleet-site-dhcp}
---
# One load-balancer address on UDP 67 for all of the site's instances, which
# the site's relays forward to. Any instance may answer a request. Each
# instance applies the same feed through its own synchronizer and reports it
# under its own stable name, so the withdrawal gate covers every expected one;
# an instance that has not applied a reservation yet stays silent, because
# Kea is not authoritative, and the firmware retries. Client-IP affinity
# sends all of one relay's traffic to one instance, so the replicas give
# availability, not load sharing per relay; a relay's retries keep reaching
# the same instance until its synchronizer applies the reservation, within
# one poll. Kea replies to the relay
# address in each request; the site's relays must accept replies from the
# cluster's egress address.
apiVersion: v1
kind: Service
metadata:
name: fleet-site-dhcp
namespace: fleet-site
spec:
type: LoadBalancer
externalTrafficPolicy: Local
sessionAffinity: ClientIP
selector: {app.kubernetes.io/name: fleet-site-dhcp}
ports:
- {name: dhcp, port: 67, targetPort: 67, protocol: UDP}
14 changes: 14 additions & 0 deletions config/site/dhcp/component/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# One synchronized site's DHCP service, deployed to a central cluster: Kea
# DHCPv4 instances, each with its synchronizer, behind one load-balancer
# address on UDP 67. The site's feed is the separate ../feed component,
# beside the site's boot service. Network operations owns the base
# configuration (ConfigMap fleet-site-dhcp-base) and the relays that point at
# the instances' addresses. The environment supplies the Secrets
# fleet-site-dhcp-sync (key token, at least 32 characters) and
# fleet-site-dhcp-feed-tls (ca.crt), never in Git, and the
# FLEET_DHCP_FEED_URL and FLEET_DHCP_SYNC_IMAGE substitutions. See
# docs/operations/boot-network.md.
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
resources:
- dhcp.yaml
Loading
Loading