Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 30 additions & 0 deletions .github/workflows/dhcp-isolated.yml
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions config/site/dhcp/isolated-example/kea-dhcp4.conf
Original file line number Diff line number Diff line change
@@ -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"
}]
}
}
13 changes: 13 additions & 0 deletions config/site/dhcp/isolated-example/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions config/site/dhcp/isolated-example/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: fleet-dhcp-proof
23 changes: 23 additions & 0 deletions config/site/dhcp/isolated/README.md
Original file line number Diff line number Diff line change
@@ -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.
140 changes: 140 additions & 0 deletions config/site/dhcp/isolated/dhcp.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions config/site/dhcp/isolated/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- dhcp.yaml
46 changes: 46 additions & 0 deletions hack/dhcp/control.go
Original file line number Diff line number Diff line change
@@ -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)
}
51 changes: 51 additions & 0 deletions hack/dhcp/test-transport.sh
Original file line number Diff line number Diff line change
@@ -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, or any real cluster or site'
49 changes: 49 additions & 0 deletions hack/dhcp/validate-isolated.sh
Original file line number Diff line number Diff line change
@@ -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'
Loading
Loading