From 01c6a3da21d4815f7c74f1320c6d82ea8d936db5 Mon Sep 17 00:00:00 2001 From: Scot Wells Date: Mon, 30 Nov 2026 15:40:54 -0600 Subject: [PATCH 1/3] feat: own reusable isolated DHCP consumer configuration --- .github/workflows/dhcp-isolated.yml | 30 ++++ .../site/dhcp/isolated-example/kea-dhcp4.conf | 28 ++++ .../dhcp/isolated-example/kustomization.yaml | 13 ++ .../site/dhcp/isolated-example/namespace.yaml | 4 + config/site/dhcp/isolated/README.md | 23 +++ config/site/dhcp/isolated/dhcp.yaml | 140 ++++++++++++++++++ config/site/dhcp/isolated/kustomization.yaml | 4 + hack/dhcp/control.go | 46 ++++++ hack/dhcp/test-transport.sh | 51 +++++++ hack/dhcp/validate-isolated.sh | 49 ++++++ 10 files changed, 388 insertions(+) create mode 100644 .github/workflows/dhcp-isolated.yml create mode 100644 config/site/dhcp/isolated-example/kea-dhcp4.conf create mode 100644 config/site/dhcp/isolated-example/kustomization.yaml create mode 100644 config/site/dhcp/isolated-example/namespace.yaml create mode 100644 config/site/dhcp/isolated/README.md create mode 100644 config/site/dhcp/isolated/dhcp.yaml create mode 100644 config/site/dhcp/isolated/kustomization.yaml create mode 100644 hack/dhcp/control.go create mode 100644 hack/dhcp/test-transport.sh create mode 100644 hack/dhcp/validate-isolated.sh diff --git a/.github/workflows/dhcp-isolated.yml b/.github/workflows/dhcp-isolated.yml new file mode 100644 index 00000000..c6a3a72c --- /dev/null +++ b/.github/workflows/dhcp-isolated.yml @@ -0,0 +1,30 @@ +name: Isolated DHCP consumer +on: + pull_request: + paths: + - config/site/dhcp/isolated/** + - config/site/dhcp/isolated-example/** + - hack/dhcp/** + - .github/workflows/dhcp-isolated.yml + push: + branches: [main, feat/manual-inventory-records] + paths: + - config/site/dhcp/isolated/** + - config/site/dhcp/isolated-example/** + - hack/dhcp/** + - .github/workflows/dhcp-isolated.yml +permissions: + contents: read +jobs: + consumer: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-go@v6 + with: {go-version-file: go.mod, cache: false} + - uses: imranismail/setup-kustomize@v2 + with: {kustomize-version: 5.8.1} + - run: go install github.com/mikefarah/yq/v4@v4.54.3 + - run: shellcheck hack/dhcp/*.sh + - run: bash hack/dhcp/test-transport.sh diff --git a/config/site/dhcp/isolated-example/kea-dhcp4.conf b/config/site/dhcp/isolated-example/kea-dhcp4.conf new file mode 100644 index 00000000..fca96e21 --- /dev/null +++ b/config/site/dhcp/isolated-example/kea-dhcp4.conf @@ -0,0 +1,28 @@ +{ + "Dhcp4": { + "interfaces-config": { + "interfaces": ["eth0"], + "dhcp-socket-type": "udp", + "service-sockets-require-all": true + }, + "control-sockets": [{ + "socket-type": "unix", + "socket-name": "/run/kea/control/kea4-ctrl-socket" + }], + "lease-database": {"type": "memfile", "persist": false}, + "host-reservation-identifiers": ["hw-address"], + "authoritative": false, + "valid-lifetime": 60, + "subnet4": [{ + "id": 1, + "subnet": "192.168.77.0/24", + "relay": {"ip-addresses": ["192.168.77.1"]}, + "option-data": [{"name": "routers", "data": "192.168.77.1"}] + }], + "loggers": [{ + "name": "kea-dhcp4", + "output-options": [{"output": "stdout"}], + "severity": "INFO" + }] + } +} diff --git a/config/site/dhcp/isolated-example/kustomization.yaml b/config/site/dhcp/isolated-example/kustomization.yaml new file mode 100644 index 00000000..2b5ff48e --- /dev/null +++ b/config/site/dhcp/isolated-example/kustomization.yaml @@ -0,0 +1,13 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +namespace: fleet-dhcp-proof +resources: + - ../isolated + - namespace.yaml +configMapGenerator: + - name: fleet-dhcp-proof-base + files: + - kea-dhcp4.conf + - name: fleet-dhcp-proof-settings + literals: + - feed-url=https://feed.example.invalid:8081 diff --git a/config/site/dhcp/isolated-example/namespace.yaml b/config/site/dhcp/isolated-example/namespace.yaml new file mode 100644 index 00000000..65ad4ddb --- /dev/null +++ b/config/site/dhcp/isolated-example/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: fleet-dhcp-proof diff --git a/config/site/dhcp/isolated/README.md b/config/site/dhcp/isolated/README.md new file mode 100644 index 00000000..b9b87ecb --- /dev/null +++ b/config/site/dhcp/isolated/README.md @@ -0,0 +1,23 @@ +# Isolated synchronized DHCP consumer + +This reusable Kea 3.0.3 profile prepares one disposable synchronized DHCP instance. It is not the existing two-instance public DHCP component, a site producer, or proof of an end-to-end lease. The headless Service creates no public address. The stable instance name is `fleet-dhcp-proof-0`; the real worker enrollment must declare that exact name in `dhcpInstances`. + +## Environment contract + +Consume this Kustomize base from a pinned Fleet revision. The environment owns the namespace, connectivity policies, and these inputs: + +- Override `ghcr.io/datum-cloud/fleet:replace-me` with the reviewed synchronizer image digest using Kustomize images. The placeholder deliberately cannot deploy as provided. +- Generate `fleet-dhcp-proof-settings` with `feed-url`: the real HTTPS origin, whose certificate matches its hostname. Kustomize rewrites the generated ConfigMap reference. +- Generate `fleet-dhcp-proof-base` with `kea-dhcp4.conf`: approved subnet IDs, relay addresses, interface and router options. Use UDP sockets, the UNIX socket path `/run/kea/control/kea4-ctrl-socket`, and non-authoritative operation. Do not supply device reservations or Kea pools that bypass IPAM. Network operations owns this topology, not the generic consumer. +- Provision Secrets `fleet-dhcp-proof-sync` (key `token`) and `fleet-dhcp-proof-feed-ca` (key `ca.crt`) outside Git. The token must match the real feed; the CA must verify it. +- Restrict ingress to the approved relay, and egress to that relay, DNS and the real feed. Provide the relay return route and matching producer ingress. The base intentionally does not invent environment-specific NetworkPolicy selectors. + +The pinned Kea image requires amd64. Both processes use UID 100/GID 101 with no capabilities and read-only roots. A shared UNIX socket connects the synchronizer and Kea. Leases and runtime state are ephemeral. A socket readiness check is not evidence that synchronization or DHCP has succeeded. + +## Validation and activation + +`../isolated-example` is a render fixture with a reserved invalid feed origin and synthetic topology, not a deployable site. Run `bash hack/dhcp/validate-isolated.sh` and `bash hack/dhcp/test-transport.sh` from Fleet. The transport test creates and removes only its own Docker resources, exposes no host ports, and verifies status/apply/readback, not a DHCP lease. + +The real feed must share the admitted worker journal and boot evidence and enforce synced enrollment and network-boot delivery. See [boot networking](../../../../docs/operations/boot-network.md). Publishing a consumer does not package or supply that producer. + +Before activation, prove real operation/IPAM allocation, authenticated feed application for the exact instance, a matching disposable client lease, and withdrawal. The existing `hack/multiplane/run.sh --redfish --synced-dhcp` lab exercises the real IPAM contract, but its native Kea is not this consumer. Validate the composed deployment separately. Never substitute the hand-addressed Kea lab for dynamic allocation proof. Do not activate a real site's relay or boot existing devices as part of this preparation. diff --git a/config/site/dhcp/isolated/dhcp.yaml b/config/site/dhcp/isolated/dhcp.yaml new file mode 100644 index 00000000..c45f9f0b --- /dev/null +++ b/config/site/dhcp/isolated/dhcp.yaml @@ -0,0 +1,140 @@ +apiVersion: v1 +kind: Service +metadata: + name: fleet-dhcp-proof +spec: + clusterIP: None + selector: + app.kubernetes.io/name: fleet-dhcp-proof + ports: + - name: dhcp + port: 67 + protocol: UDP +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: fleet-dhcp-proof +spec: + serviceName: fleet-dhcp-proof + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: fleet-dhcp-proof + template: + metadata: + labels: + app.kubernetes.io/name: fleet-dhcp-proof + spec: + automountServiceAccountToken: false + enableServiceLinks: false + nodeSelector: + kubernetes.io/arch: amd64 + securityContext: + runAsNonRoot: true + runAsUser: 100 + runAsGroup: 101 + fsGroup: 101 + seccompProfile: + type: RuntimeDefault + sysctls: + - name: net.ipv4.ip_unprivileged_port_start + value: "67" + initContainers: + - name: control-directory + image: docker.cloudsmith.io/isc/docker/kea-dhcp4:3.0.3@sha256:ab73f52bca146a8df749490d464ca3b3f21cd00e114e6ed01cbb85b1bfc5ca32 + command: [/bin/sh, -ec, 'mkdir -p /run/kea/control && chmod 0750 /run/kea/control'] + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: [ALL] + volumeMounts: + - name: run + mountPath: /run/kea + containers: + - name: kea + image: docker.cloudsmith.io/isc/docker/kea-dhcp4:3.0.3@sha256:ab73f52bca146a8df749490d464ca3b3f21cd00e114e6ed01cbb85b1bfc5ca32 + command: [/lib/ld-musl-x86_64.so.1, /usr/sbin/kea-dhcp4] + args: [-c, /etc/kea/kea-dhcp4.conf] + env: + - name: KEA_CONTROL_SOCKET_DIR + value: /run/kea/control + ports: + - name: dhcp + containerPort: 67 + protocol: UDP + readinessProbe: + exec: + command: [/bin/sh, -ec, 'test -S /run/kea/control/kea4-ctrl-socket'] + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: [ALL] + resources: + requests: {cpu: 10m, memory: 32Mi} + limits: {memory: 128Mi} + volumeMounts: + - name: base + mountPath: /etc/kea + readOnly: true + - name: run + mountPath: /run/kea + - name: leases + mountPath: /var/lib/kea + - name: sync + image: ghcr.io/datum-cloud/fleet:replace-me + command: [/fleet-dhcp-sync] + args: + - -feed=$(FLEET_DHCP_FEED_URL) + - -token-file=/etc/fleet-dhcp/token + - -ca-file=/etc/fleet-dhcp-ca/ca.crt + - -kea-socket=/run/kea/control/kea4-ctrl-socket + - -base-config=/etc/kea/kea-dhcp4.conf + env: + - name: FLEET_DHCP_FEED_URL + valueFrom: + configMapKeyRef: + name: fleet-dhcp-proof-settings + key: feed-url + - name: POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: [ALL] + resources: + requests: {cpu: 10m, memory: 16Mi} + limits: {memory: 64Mi} + volumeMounts: + - name: base + mountPath: /etc/kea + readOnly: true + - name: run + mountPath: /run/kea + - name: token + mountPath: /etc/fleet-dhcp + readOnly: true + - name: ca + mountPath: /etc/fleet-dhcp-ca + readOnly: true + volumes: + - name: base + configMap: + name: fleet-dhcp-proof-base + - name: run + emptyDir: {medium: Memory, sizeLimit: 1Mi} + - name: leases + emptyDir: {medium: Memory, sizeLimit: 16Mi} + - name: token + secret: + secretName: fleet-dhcp-proof-sync + defaultMode: 0440 + - name: ca + secret: + secretName: fleet-dhcp-proof-feed-ca + defaultMode: 0440 diff --git a/config/site/dhcp/isolated/kustomization.yaml b/config/site/dhcp/isolated/kustomization.yaml new file mode 100644 index 00000000..1edda1dc --- /dev/null +++ b/config/site/dhcp/isolated/kustomization.yaml @@ -0,0 +1,4 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - dhcp.yaml diff --git a/hack/dhcp/control.go b/hack/dhcp/control.go new file mode 100644 index 00000000..405e4a2f --- /dev/null +++ b/hack/dhcp/control.go @@ -0,0 +1,46 @@ +package main + +import ( + "encoding/json" + "fmt" + "net" + "os" + "time" +) + +func main() { + if err := run(); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } +} + +func run() error { + connection, err := net.DialTimeout("unix", "/run/kea/control/kea4-ctrl-socket", 5*time.Second) + if err != nil { + return err + } + defer connection.Close() + if err := connection.SetDeadline(time.Now().Add(10 * time.Second)); err != nil { + return err + } + var request map[string]any + if err := json.NewDecoder(os.Stdin).Decode(&request); err != nil { + return err + } + if err := json.NewEncoder(connection).Encode(request); err != nil { + return err + } + var response struct { + Result int `json:"result"` + Text string `json:"text"` + Arguments json.RawMessage `json:"arguments"` + } + if err := json.NewDecoder(connection).Decode(&response); err != nil { + return err + } + if response.Result != 0 { + return fmt.Errorf("Kea rejected command: %s", response.Text) + } + return json.NewEncoder(os.Stdout).Encode(response) +} diff --git a/hack/dhcp/test-transport.sh b/hack/dhcp/test-transport.sh new file mode 100644 index 00000000..b00d53e8 --- /dev/null +++ b/hack/dhcp/test-transport.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +set -euo pipefail +root=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd) +overlay="$root/config/site/dhcp/isolated-example" +work=$(mktemp -d) +container="fleet-dhcp-transport-$(openssl rand -hex 6)" +cleanup() { + docker rm -f "$container" "$container-files" >/dev/null 2>&1 || true + docker volume rm "$container" >/dev/null 2>&1 || true + rm -rf "$work" +} +trap cleanup EXIT +bash "$root/hack/dhcp/validate-isolated.sh" +image=$(yq -r 'select(.kind == "StatefulSet") | .spec.template.spec.containers[] | select(.name == "kea") | .image' "$root/config/site/dhcp/isolated/dhcp.yaml") +GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o "$work/control" "$root/hack/dhcp/control.go" +cp "$overlay/kea-dhcp4.conf" "$work/kea-dhcp4.conf" +chmod 0755 "$work/control" +chmod 0644 "$work/kea-dhcp4.conf" +docker volume create "$container" >/dev/null +docker create --name "$container-files" --platform linux/amd64 -v "$container:/proof" --entrypoint /bin/true "$image" >/dev/null +docker cp "$work/." "$container-files:/proof" >/dev/null +docker rm "$container-files" >/dev/null +docker create --name "$container" --platform linux/amd64 --user 100:101 \ + --cap-drop ALL --security-opt no-new-privileges --read-only \ + --sysctl net.ipv4.ip_unprivileged_port_start=67 \ + --tmpfs /run/kea:uid=0,gid=101,mode=2770 \ + --tmpfs /var/lib/kea:uid=100,gid=101,mode=0750 \ + -v "$container:/proof:ro" \ + -e KEA_CONTROL_SOCKET_DIR=/run/kea/control --entrypoint /bin/sh "$image" \ + -ec 'mkdir -p /run/kea/control && chmod 0750 /run/kea/control && exec /lib/ld-musl-x86_64.so.1 /usr/sbin/kea-dhcp4 -c /proof/kea-dhcp4.conf' >/dev/null +docker start "$container" >/dev/null +ready=0 +for _attempt in $(seq 1 30); do + if printf '%s\n' '{"command":"status-get"}' | docker exec -i "$container" /proof/control > "$work/status.json" 2>/dev/null; then + ready=1 + break + fi + sleep 1 +done +if [[ "$ready" != 1 ]]; then + docker logs "$container" >&2 + echo 'Kea UNIX control socket did not become ready' >&2 + exit 1 +fi +jq -e '.arguments.pid > 0' "$work/status.json" >/dev/null +jq -n --slurpfile base "$work/kea-dhcp4.conf" '{command:"config-set",arguments:$base[0]}' \ + | docker exec -i "$container" /proof/control > "$work/applied.json" +printf '%s\n' '{"command":"config-get"}' | docker exec -i "$container" /proof/control > "$work/config.json" +jq -e '.arguments.Dhcp4.subnet4 | length == 1' "$work/config.json" >/dev/null +echo 'PASS pinned Kea UNIX status-get, config-set, config-get as UID 100:GID 101, read-only root and zero capabilities' +echo 'NOT TESTED: Fleet operation, IPAM allocation, authenticated feed, DHCP lease, withdrawal, GKE or DFW3' diff --git a/hack/dhcp/validate-isolated.sh b/hack/dhcp/validate-isolated.sh new file mode 100644 index 00000000..86cc1edd --- /dev/null +++ b/hack/dhcp/validate-isolated.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +set -euo pipefail +root=${ROOT:-$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)} +overlay="$root/config/site/dhcp/isolated-example" +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT +kustomize build "$overlay" > "$work/render.yaml" +yq -o=json '.' "$work/render.yaml" | jq -s '.' > "$work/render.json" +jq -e ' + length > 0 and + ([.[] | select(.kind == "Namespace") | .metadata.name] == ["fleet-dhcp-proof"]) and + all(.[]; .kind == "Namespace" or .metadata.namespace == "fleet-dhcp-proof") and + all(.[]; .kind != "Secret") and + ([.[] | select(.kind == "StatefulSet")] | length == 1) and + all(.[] | select(.kind == "Service"); .spec.clusterIP == "None" and (.spec.type // "ClusterIP") == "ClusterIP") and + all(.[] | select(.kind == "StatefulSet"); + .spec.replicas == 1 and + .spec.template.spec.automountServiceAccountToken == false and + (.spec.template.spec.hostNetwork // false) == false and + .spec.template.spec.securityContext.runAsNonRoot == true and + .spec.template.spec.securityContext.runAsUser == 100 and + .spec.template.spec.securityContext.runAsGroup == 101 and + .spec.template.spec.securityContext.fsGroup == 101 and + ([.spec.template.spec.containers[].name] == ["kea", "sync"]) and + all(.spec.template.spec.containers[], .spec.template.spec.initContainers[]; + .securityContext.allowPrivilegeEscalation == false and + .securityContext.readOnlyRootFilesystem == true and + .securityContext.capabilities.drop == ["ALL"] and + (.securityContext.capabilities.add // [] | length == 0))) +' "$work/render.json" > /dev/null +jq -e ' + . as $resources | + .[] | select(.kind == "StatefulSet") | + .spec.template.spec.containers[] | select(.name == "sync") | + select((.args | index("-feed=$(FLEET_DHCP_FEED_URL)")) != null) | + select((.args | index("-ca-file=/etc/fleet-dhcp-ca/ca.crt")) != null) | + select((.args | index("-token-file=/etc/fleet-dhcp/token")) != null) | + ([.env[] | select(.name == "FLEET_DHCP_FEED_URL") | .valueFrom.configMapKeyRef] | .[0]) as $ref | + any($resources[]; .kind == "ConfigMap" and .metadata.name == $ref.name and .data[$ref.key] == "https://feed.example.invalid:8081") +' "$work/render.json" > /dev/null +jq -er '.[] | select(.kind == "ConfigMap") | .data["kea-dhcp4.conf"] // empty' "$work/render.json" > "$work/kea.json" +jq -e ' + .Dhcp4.authoritative == false and + .Dhcp4["interfaces-config"]["dhcp-socket-type"] == "udp" and + .Dhcp4["control-sockets"] == [{"socket-type":"unix","socket-name":"/run/kea/control/kea4-ctrl-socket"}] and + (.Dhcp4.subnet4 | length == 1) and + ([.. | objects | select(has("reservations") or has("pools"))] | length == 0) +' "$work/kea.json" > /dev/null +echo 'PASS isolated consumer render' From 853831f48b3667e8c05f5989963b7aa398188613 Mon Sep 17 00:00:00 2001 From: Scot Wells Date: Mon, 30 Nov 2026 15:45:27 -0600 Subject: [PATCH 2/3] test: register isolated DHCP roots as explicit opt-ins --- hack/validate-network-boot-inactive.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hack/validate-network-boot-inactive.sh b/hack/validate-network-boot-inactive.sh index 9e3df217..dfd91e21 100755 --- a/hack/validate-network-boot-inactive.sh +++ b/hack/validate-network-boot-inactive.sh @@ -17,6 +17,8 @@ opt_in=( config/site/dhcp/component config/site/dhcp/example config/site/dhcp/feed + config/site/dhcp/isolated + config/site/dhcp/isolated-example config/site/redfish/synced/graph config/site/redfish/synced/services ) From fc1e98684a243cb7e8dfdc824bffecad2be6a467 Mon Sep 17 00:00:00 2001 From: Scot Wells Date: Mon, 30 Nov 2026 20:38:13 -0600 Subject: [PATCH 3/3] fix: keep DHCP transport disclaimer environment-neutral --- hack/dhcp/test-transport.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/dhcp/test-transport.sh b/hack/dhcp/test-transport.sh index b00d53e8..b00d2735 100644 --- a/hack/dhcp/test-transport.sh +++ b/hack/dhcp/test-transport.sh @@ -48,4 +48,4 @@ jq -n --slurpfile base "$work/kea-dhcp4.conf" '{command:"config-set",arguments:$ printf '%s\n' '{"command":"config-get"}' | docker exec -i "$container" /proof/control > "$work/config.json" jq -e '.arguments.Dhcp4.subnet4 | length == 1' "$work/config.json" >/dev/null echo 'PASS pinned Kea UNIX status-get, config-set, config-get as UID 100:GID 101, read-only root and zero capabilities' -echo 'NOT TESTED: Fleet operation, IPAM allocation, authenticated feed, DHCP lease, withdrawal, GKE or DFW3' +echo 'NOT TESTED: Fleet operation, IPAM allocation, authenticated feed, DHCP lease, withdrawal, or any real cluster or site'