Skip to content

feat(inventory): observe NetBox devices as observed-only evidence - #88

Closed
scotwells wants to merge 3 commits into
pxe/boot-networkfrom
feat/netbox-inventory-import
Closed

scotwells wants to merge 3 commits into
pxe/boot-networkfrom
feat/netbox-inventory-import

Conversation

@scotwells

@scotwells scotwells commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem and outcome

Fleet has no way to read real hardware records. MachineCapacity.spec.deviceRef names a Device, but the Device kind is still only proposed. Hardware facts reach Fleet only from synthetic writers. To validate inventory integration against real equipment, Fleet must read an existing inventory system without provisioning anything, publishing capacity, or taking ownership.

This PR adds InventoryObservation (fleet.datumapis.com/v1alpha1) and the fleet-inventory-observer command. An operator names one NetBox device by its stable ID. The observer copies an allowlisted set of that device's recorded facts into the observation's status with the read time, the source revision, a content digest, and the ObservedOnly-v1 trust profile. Nothing in Fleet reads observations. They publish no supply, reserve nothing, and authorize no hardware effect.

Why an observation and not MachineCapacity or Device

  • Writing MachineCapacity from an import would merge the physical-asset and supply identities. It would also put recorded, unverified facts into status.hardware, which the allocator matches against profiles.
  • The inventory proposal says discovery creates observed-only evidence, not a Device or free supply. Registering a Device is a separate, authorized transition. This PR implements only the evidence step and keeps it a separate identity.

Changes

  • internal/api/inventory/v1alpha1: types, scheme registration, deepcopy.
  • config/inventory-observer: an opt-in root containing the CRD, a ServiceAccount, a namespace-scoped Role (get/list observations and update on their status only), and a 15-minute Forbid CronJob. No production root references it, and the CRD has no Milo discovery annotation. publish.yml pins its image to the manager build. The manager image now includes /fleet-inventory-observer.
  • internal/netbox: a read-only client. It sends GET only and requires HTTPS (loopback excepted for tests). It does not follow redirects, never follows server next URLs, caps body and interface counts, and picks Bearer for nbt_ v2 tokens and Token otherwise. It decodes an allowlist of fields; custom fields, comments, and config contexts are never decoded.
  • internal/inventoryobserver: refresh semantics.
    • A failed read keeps the last facts and sets Observed=False with SourceUnavailable, SourceUnauthorized, or SourceObjectMissing.
    • An expectedName mismatch, or a serial that differs from the one previously observed, is IdentityMismatch. The facts are not updated: replaced hardware is a new identity.
    • Status updates carry the listed resourceVersion, so concurrent changes conflict instead of being overwritten.
    • After the first 401/403 in a run, the observer stops contacting the source. Sources often ban addresses that repeat failed authentication, and a ban would also hit every client sharing the egress address.
  • spec.source is immutable (CEL), and the status trust profile is restricted to ObservedOnly-v1.
  • Docs: docs/operations/inventory-observation.md, plus status rows in the architecture, development, operations, and config guides. Deferred decisions are listed there: where operator inventory finally lives, Device registration, hardware facts from a qualified collector, and bulk selection.
  • CI: renders the new root and installs envtest assets, the same step main already has.

Verification

  • go vet ./... and go test -race ./... pass. The envtest test was also run with KUBEBUILDER_ASSETS set. It runs the observer as its packaged service account against a real API server and checks that:

    • create, delete, and spec edits are Forbidden;
    • other namespaces and Secrets are Forbidden;
    • retargeting spec.source is Invalid;
    • a stale status write is a Conflict; and
    • raising the trust profile is Invalid.
  • All kustomize build roots in ci.yml render, including config/inventory-observer. The synthetic-staging render, overlay-isolation, standalone, Milo acceptance validate, and multiplane harness checks pass. hack/validate-doc-links.sh passes when run with a real ripgrep.

  • hack/test-standalone-build-context.sh was not run locally because there was no Docker daemon. It fails the same way on the base branch locally; CI runs it.

  • One manual run outside CI, with an uncommitted harness: the real observer and client against a live NetBox 4.6.8 (read-only) and a disposable local API server. It recorded one device with Observed=True, its interfaces, and cable peers. No custom field was copied. That source data is not part of this repository.

Not verified: behavior in a deployed cluster. Test fixtures are synthetic.

Stack and deployment note

This PR is based on pxe/boot-network (#86). That stack predates main's multi-project manager and pricing changes, so an environment that already runs main should not deploy this branch's bundle directly. A separate integration branch, staging/netbox-inventory, merges current main with this branch. It is for deployment only and is not for review or merge.

🤖 Generated with Claude Code

scotwells and others added 2 commits November 19, 2026 14:33
Add InventoryObservation (fleet.datumapis.com/v1alpha1) and the
fleet-inventory-observer command. An operator names one NetBox device by
its stable ID; the observer copies an allowlist of recorded facts into the
observation's status with the read time, source revision, a content digest,
and the ObservedOnly-v1 trust profile.

Observations are evidence, not Devices or capacity. No controller reads
them, and they publish no supply and authorize no hardware effect. The
observer sends only GET requests to NetBox and writes only the status
subresource of existing observations in one namespace. Failed reads keep
the last facts and report Observed=False. A name or serial mismatch is an
IdentityMismatch, not an update.

config/inventory-observer packages the CRD, status-only RBAC, and a
CronJob as an opt-in root. No production root references it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Exercise the packaged Role, CRD validation, and status subresource
against a real API server: status-only writes, immutable source, stale
write conflict, and no trust-profile escalation. CI installs the
envtest assets that main already uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sources commonly ban clients that repeat failed authentication, and a
ban would also block every other client sharing the observer's egress
address. After the first 401 or 403 in a run, mark the remaining
observations SourceUnauthorized without another request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scotwells scotwells closed this Nov 19, 2026
@scotwells
scotwells deleted the feat/netbox-inventory-import branch November 19, 2026 21:05
@scotwells

Copy link
Copy Markdown
Contributor Author

Closed and replaced. The direction changed: Fleet will not integrate with an external inventory system directly. The reworked change records inventory manually as operator-written, observed-only records, with no client, controller, or CronJob. Renaming the head branch to match closed this PR, so the replacement continues in a new draft PR on feat/manual-inventory-records, against the same base.

@scotwells

Copy link
Copy Markdown
Contributor Author

Replacement: #90.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant