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
32 changes: 32 additions & 0 deletions .github/workflows/publish-device-hardware-publisher.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Publish Fleet Device hardware publisher

on:
push:
release:
types: [published]
workflow_dispatch:

jobs:
validate-device-hardware-publisher:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: true
- run: go test -count=1 -race ./internal/devicehardwarepublisher ./internal/devicehardwaremetrics ./internal/hardwaremetrics ./cmd/fleet-device-hardware-publisher
- run: go vet ./internal/devicehardwarepublisher ./internal/devicehardwaremetrics ./cmd/fleet-device-hardware-publisher
publish-device-hardware-publisher-image:
needs: validate-device-hardware-publisher
permissions:
id-token: write
contents: read
packages: write
uses: datum-cloud/actions/.github/workflows/publish-docker.yaml@v1.27.1
with:
image-name: fleet-device-hardware-publisher
dockerfile-path: build/device-hardware-publisher.Dockerfile
platforms: linux/amd64,linux/arm64
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,20 @@ The [Bare Metal CLI enhancement](docs/enhancements/metal-cli/README.md) proposes
`datumctl metal` discovery, machine management, and safe recovery workflows.

The [BMC hardware telemetry enhancement](docs/enhancements/hardware-telemetry/README.md)
proposes operator and tenant hardware metrics collected from server BMCs.
proposes operator and tenant hardware metrics collected from server BMCs. The
[inventory-owner Device projection](docs/enhancements/hardware-telemetry/device-owner-integration.md)
provides a tested library for routing qualified readings to the current owning
Project regardless of allocation or custody. An [independent publisher](docs/enhancements/hardware-telemetry/device-owner-publisher.md)
adds authenticated inventory reads and qualified source ingestion with synthetic
tests; it is not deployed. Metal consumer metrics retain separate activation/release gates.

Control-plane [resource metadata](docs/enhancements/hardware-telemetry/resource-metadata.md)
is a separate feed: Fleet defines
`ResourceMetricsPolicy` objects for resource-metrics to evaluate against inventory
objects. Those policies do not generate sensor samples or become an authority
dependency of the sensor publisher. Shared telemetry retains ingestion, storage,
federation, and customer query/export authorization for both feeds. See the
[telemetry ownership boundary](docs/enhancements/hardware-telemetry/README.md#telemetry-ownership-boundary).

Contributors should also read the [repository guidance](AGENTS.md) and
[implementation roadmap](docs/development/roadmap.md).
13 changes: 13 additions & 0 deletions build/device-hardware-publisher.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM --platform=$BUILDPLATFORM golang:1.27.4-alpine@sha256:70bd7ddea8b6cbe5d6943cde279d6b67feb10cc924fb9100d1d8757c1575b280 AS build
ARG TARGETOS TARGETARCH
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY cmd/ ./cmd/
COPY internal/ ./internal/
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -trimpath -ldflags='-s -w' -o /out/fleet-device-hardware-publisher ./cmd/fleet-device-hardware-publisher

FROM gcr.io/distroless/static-debian12:nonroot@sha256:afa5c872c891853ca7fcf1f12c3edb23f7eeef36189728842dd51042ff57f7ab
COPY --from=build /out/fleet-device-hardware-publisher /fleet-device-hardware-publisher
EXPOSE 9090
ENTRYPOINT ["/fleet-device-hardware-publisher"]
39 changes: 39 additions & 0 deletions cmd/fleet-device-hardware-publisher/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"flag"
"fmt"
"net"
"net/http"
"os"
"strconv"
"time"

"go.datum.net/fleet/internal/devicehardwarepublisher"
)

func run(args []string) error {
flags := flag.NewFlagSet("fleet-device-hardware-publisher", flag.ContinueOnError)
config := flags.String("config", "", "required protected publisher JSON configuration")
listen := flags.String("listen-address", ":9090", "internal metrics listen address")
if e := flags.Parse(args); e != nil {
return e
}
_, port, e := net.SplitHostPort(*listen)
portNumber, portErr := strconv.Atoi(port)
if e != nil || portErr != nil || portNumber < 1 || portNumber > 65535 || *config == "" || flags.NArg() != 0 {
return fmt.Errorf("--config and a valid --listen-address are required")
}
p, e := devicehardwarepublisher.New(*config)
if e != nil {
return e
}
server := &http.Server{Addr: *listen, Handler: p, ReadHeaderTimeout: 5 * time.Second, ReadTimeout: 5 * time.Second, WriteTimeout: 35 * time.Second, IdleTimeout: 30 * time.Second, MaxHeaderBytes: 8192}
return server.ListenAndServe()
}
func main() {
if e := run(os.Args[1:]); e != nil {
fmt.Fprintln(os.Stderr, "publisher stopped:", e)
os.Exit(1)
}
}
11 changes: 11 additions & 0 deletions cmd/fleet-device-hardware-publisher/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import "testing"

func TestInvalidFlags(t *testing.T) {
for _, args := range [][]string{nil, {"--unknown"}, {"--config", "missing", "--listen-address", "invalid"}, {"--config", "missing", "extra"}} {
if run(args) == nil {
t.Fatalf("accepted %v", args)
}
}
}
26 changes: 26 additions & 0 deletions config/components/resource-metrics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Optional Device resource metadata

This standalone Kustomization installs only Fleet's `ResourceMetricsPolicy` on
the resource-metrics management control plane. It is not included by Fleet's
default deployment. It neither installs nor upgrades resource-metrics.

Render and validate locally from the Fleet repository root:

```sh
kubectl kustomize config/components/resource-metrics
kubectl kustomize config/components/resource-metrics/project-reader
go test ./config/components/resource-metrics
```

The separately rendered `project-reader` role belongs on each authorized project
control plane, not automatically on the policy management cluster. It opts into
resource-metrics' reader aggregation, but creates no binding and is not evidence
of Milo authorization. It permits full Device reads (including private fields),
even though the policy exports only four allowlisted labels. Approve that reader
trust boundary explicitly. No Secret read, Fleet mutation, or sensor permission
is granted. Do not substitute the broad inventory viewer role or a privileged
control certificate to make a failed authorization check pass.

Deployment, exact principal/binding selection, project discovery, Fleet API
availability, ingestion, and tenant query isolation require separate
qualification. See [the metadata contract and rollout gates](../../../docs/enhancements/hardware-telemetry/resource-metadata.md).
27 changes: 27 additions & 0 deletions config/components/resource-metrics/device-policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: resourcemetrics.miloapis.com/v1alpha1
kind: ResourceMetricsPolicy
metadata:
name: fleet-device-metadata
spec:
metricNamePrefix: fleet
generators:
- name: device-metadata
resource:
group: fleet.datumapis.com
version: v1alpha1
resource: devices
families:
- name: device_info
help: Observed Device identity and declared asset lifecycle; not readiness or allocation eligibility.
type: gauge
metrics:
- value: "1.0"
labels:
- name: device
value: object.metadata.name
- name: namespace
value: object.metadata.namespace
- name: device_uid
value: object.metadata.uid
- name: lifecycle
value: "!has(object.spec.lifecycle) || object.spec.lifecycle == '' ? 'Active' : (object.spec.lifecycle in ['Active', 'Decommissioning', 'Retired'] ? object.spec.lifecycle : 'Unknown')"
4 changes: 4 additions & 0 deletions config/components/resource-metrics/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:
- device-policy.yaml
178 changes: 178 additions & 0 deletions config/components/resource-metrics/policy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
package resourcemetrics_test

import (
"bytes"
"encoding/json"
"os"
"reflect"
"testing"

"github.com/google/cel-go/cel"
"github.com/google/cel-go/ext"
inventory "go.datum.net/fleet/internal/api/inventory/v1alpha1"
"go.yaml.in/yaml/v3"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)

type policyDocument struct {
APIVersion string `yaml:"apiVersion"`
Kind string `yaml:"kind"`
Metadata struct{ Name string } `yaml:"metadata"`
Spec struct {
MetricNamePrefix string `yaml:"metricNamePrefix"`
Generators []struct {
Name string
Resource struct{ Group, Version, Resource string }
Families []struct {
Name, Help, Type string
Metrics []struct {
Value string
Labels []struct{ Name, Value string }
}
}
}
}
}

func TestDeviceMetadataPolicy(t *testing.T) {
contents, err := os.ReadFile("device-policy.yaml")
if err != nil {
t.Fatal(err)
}
var document policyDocument
decoder := yaml.NewDecoder(bytes.NewReader(contents))
decoder.KnownFields(true)
if err := decoder.Decode(&document); err != nil {
t.Fatal(err)
}
if document.APIVersion != "resourcemetrics.miloapis.com/v1alpha1" || document.Kind != "ResourceMetricsPolicy" || document.Metadata.Name != "fleet-device-metadata" || document.Spec.MetricNamePrefix != "fleet" || len(document.Spec.Generators) != 1 {
t.Fatalf("unexpected policy contract: %+v", document)
}
generator := document.Spec.Generators[0]
if generator.Resource.Group != inventory.GroupVersion.Group || generator.Resource.Version != inventory.GroupVersion.Version || generator.Resource.Resource != "devices" || len(generator.Families) != 1 {
t.Fatalf("unexpected generator: %+v", generator)
}
family := generator.Families[0]
if family.Name != "device_info" || family.Type != "gauge" || family.Help == "" || len(family.Metrics) != 1 {
t.Fatalf("unexpected family: %+v", family)
}
metric := family.Metrics[0]
if len(metric.Labels) != 4 {
t.Fatalf("unexpected label count: %d", len(metric.Labels))
}
environment, err := cel.NewEnv(cel.Variable("object", cel.DynType), ext.Strings(), ext.Encoders(), ext.Math(), ext.Lists())
if err != nil {
t.Fatal(err)
}
compile := func(expression string) cel.Program {
t.Helper()
parsed, issues := environment.Compile(expression)
if issues.Err() != nil {
t.Fatal(issues.Err())
}
program, err := environment.Program(parsed)
if err != nil {
t.Fatal(err)
}
return program
}
valueProgram := compile(metric.Value)
programs := map[string]cel.Program{}
for _, label := range metric.Labels {
if _, exists := programs[label.Name]; exists {
t.Fatalf("duplicate label %s", label.Name)
}
programs[label.Name] = compile(label.Value)
}
for _, fixture := range []struct {
name, lifecycle, expected, uid string
explicitEmpty bool
}{
{name: "omitted-default", expected: "Active", uid: "device-uid-one"},
{name: "empty-default", expected: "Active", uid: "device-uid-one", explicitEmpty: true},
{name: "active", lifecycle: "Active", expected: "Active", uid: "device-uid-one"},
{name: "decommissioning", lifecycle: "Decommissioning", expected: "Decommissioning", uid: "device-uid-one"},
{name: "retired", lifecycle: "Retired", expected: "Retired", uid: "device-uid-one"},
{name: "unrecognized", lifecycle: "FutureState", expected: "Unknown", uid: "device-uid-one"},
{name: "recreated", lifecycle: "Active", expected: "Active", uid: "device-uid-two"},
} {
t.Run(fixture.name, func(t *testing.T) {
device := inventory.Device{
ObjectMeta: metav1.ObjectMeta{Name: "synthetic-device", Namespace: "inventory", UID: types.UID(fixture.uid), Labels: map[string]string{"private": "never-export"}, Annotations: map[string]string{"credential": "synthetic-secret"}},
Spec: inventory.DeviceSpec{Lifecycle: inventory.DeviceLifecycle(fixture.lifecycle), AssetTag: "private-asset", DisplayName: "private-display"},
}
encoded, err := json.Marshal(device)
if err != nil {
t.Fatal(err)
}
var object map[string]any
if err := json.Unmarshal(encoded, &object); err != nil {
t.Fatal(err)
}
if fixture.explicitEmpty {
object["spec"].(map[string]any)["lifecycle"] = ""
}
delete(object, "status")
activation := map[string]any{"object": object}
value, _, err := valueProgram.Eval(activation)
if err != nil || value.Value() != float64(1) {
t.Fatalf("value = %v, error = %v", value, err)
}
labels := map[string]any{}
for name, program := range programs {
value, _, err := program.Eval(activation)
if err != nil {
t.Fatalf("label %s: %v", name, err)
}
labels[name] = value.Value()
}
want := map[string]any{"device": "synthetic-device", "namespace": "inventory", "device_uid": fixture.uid, "lifecycle": fixture.expected}
if !reflect.DeepEqual(labels, want) {
t.Fatalf("labels = %v, want %v", labels, want)
}
for _, field := range []string{"name", "namespace", "uid"} {
metadata := object["metadata"].(map[string]any)
original := metadata[field]
delete(metadata, field)
label := map[string]string{"name": "device", "namespace": "namespace", "uid": "device_uid"}[field]
if _, _, err := programs[label].Eval(activation); err == nil {
t.Fatalf("missing %s must fail, not invent identity", field)
}
metadata[field] = original
}
})
}
}

func TestProjectReaderIsDeviceReadOnly(t *testing.T) {
contents, err := os.ReadFile("project-reader/role.yaml")
if err != nil {
t.Fatal(err)
}
var role struct {
APIVersion string `yaml:"apiVersion"`
Kind string
Metadata struct {
Name string
Labels map[string]string
}
Rules []struct {
APIGroups []string `yaml:"apiGroups"`
Resources []string
Verbs []string
}
}
decoder := yaml.NewDecoder(bytes.NewReader(contents))
decoder.KnownFields(true)
if err := decoder.Decode(&role); err != nil {
t.Fatal(err)
}
if role.APIVersion != "rbac.authorization.k8s.io/v1" || role.Kind != "ClusterRole" || role.Metadata.Name != "fleet-resource-metrics-device-reader" || !reflect.DeepEqual(role.Metadata.Labels, map[string]string{"resourcemetrics.miloapis.com/aggregate-to-reader": "true"}) || len(role.Rules) != 1 {
t.Fatalf("unexpected reader contract: %+v", role)
}
rule := role.Rules[0]
if !reflect.DeepEqual(rule.APIGroups, []string{inventory.GroupVersion.Group}) || !reflect.DeepEqual(rule.Resources, []string{"devices"}) || !reflect.DeepEqual(rule.Verbs, []string{"get", "list", "watch"}) {
t.Fatalf("reader must grant only Device get/list/watch: %+v", rule)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- role.yaml
10 changes: 10 additions & 0 deletions config/components/resource-metrics/project-reader/role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: fleet-resource-metrics-device-reader
labels:
resourcemetrics.miloapis.com/aggregate-to-reader: "true"
rules:
- apiGroups: [fleet.datumapis.com]
resources: [devices]
verbs: [get, list, watch]
12 changes: 12 additions & 0 deletions docs/architecture/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ their owning services. Fleet consumes these contracts and their evidence.

## Lifecycle and authority contracts

Hardware telemetry follows a separate
[ownership boundary](../enhancements/hardware-telemetry/README.md#telemetry-ownership-boundary):
Fleet qualifies and attributes sensor samples using direct inventory reads;
resource-metrics generates control-plane metadata from
[Fleet-owned policies](../enhancements/hardware-telemetry/resource-metadata.md);
shared telemetry handles ingestion, storage, federation, and customer query/export
authorization. These are complementary feeds, not a synchronous metrics join.
Sensor readings never belong in Kubernetes status, and metadata observations do
not establish provisioning or allocation authority. Customer rollout and read
authorization require independent qualification; this boundary is not a claim
of deployed behavior.

1. **Preserve distinct identities.** DeviceClaim describes an approved physical
installation; Device identifies an actual asset; MachineCapacity represents
provider supply; a customer Machine receives one immutable MachineAllocation;
Expand Down
Loading
Loading