Skip to content

Review capacity registration that checks live Devices - #150

Closed
scotwells wants to merge 16 commits into
review/capacity-registration-basefrom
review/capacity-registration
Closed

scotwells wants to merge 16 commits into
review/capacity-registration-basefrom
review/capacity-registration

Conversation

@scotwells

Copy link
Copy Markdown
Contributor

Capacity registration changes went onto the staging branch of #90 without review. This PR shows those 13 commits alone so they can be reviewed. Fixes go to that branch, and this PR closes instead of merging.

Registration now checks live Devices instead of keeping its own ledger, and signed activation is gone. Each Device backs at most one capacity, which stays Disabled. Devices gain a lifecycle, and environments can opt in to blocking Device deletion.

Known gaps: two Devices registered at the same moment with the same serial both succeed, caller identity is unchecked (#149), and allocation stays out of scope.

Details are in the first comment.

🤖 Generated with Claude Code

scotwells and others added 13 commits November 22, 2026 16:22
Remove the registration ledger and everything that served it: the
Secret-backed CAS store, sealed segments, signed activation and
expansion, the control ConfigMap and key, /activationz and /status,
cmd/fleet-registration-control, the ledger retention policies and
the ledger Secret RBAC.

The webhook now keeps no state. A capacity create must be named
device-<Device UID>, so the API server refuses a second capacity for
the same Device. It is checked against the live Device, the caller's
SARs, aliases on every live Device in the provider scope, and every
existing capacity. The webhook fences capacity writes only; Device,
namespace and Project writes no longer pass through it. The
registration pod mounts no service account token.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add config/components/device-deletion-protection, a
ValidatingAdmissionPolicy and binding that deny every Device DELETE
with no exemptions. config/milo-production is config/milo plus the
component. config/milo, config/milo-synthetic and every other root
leave it out, so test and staging control planes can still delete
Devices.

The overlay isolation validator now fails when a production-style
root lacks the component or any other root renders it. CI builds the
new root.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The registration form no longer asks for a capacity name. It shows
device-<Device UID>, which is what admission now requires, and marks
every Device that shares a normalized serial, system UUID or provider
host reference with another Device as Conflicting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewrite the stage-1 contract around the decision to drop the ledger
and signed activation: live-Device checks, Device-derived capacity
names, the documented duplicate race, and optional Device deletion
protection, including deletecollection, namespace and project
cascades, remediation and retirement. Remove the storage rollout
runbook, which only described the ledger.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add spec.lifecycle to Device with Active (the CRD default),
Decommissioning and Retired. CRD transition rules on spec allow
Active and Decommissioning to move between each other and
Decommissioning to move to Retired. Active to Retired is rejected
and nothing leaves Retired, including by removing the field, which
defaults back to Active. Creation in any lifecycle is allowed.

The CRD is hand-maintained YAML; this repository has no CRD
generator, so the schema and its offline tests change together.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Registration admits new capacity only for an Active Device. A
capacity update that would leave Disabled while its Device is
Decommissioning or Retired is denied for that reason, after
checking that the caller can read the Device; every other update
keeps the stage-1 denial. Retired Devices still take part in the
duplicate-identity scan while they exist.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Production-specific configuration belongs to the deploying
repository, so remove the config/milo-production root. The
device-deletion-protection component stays as a reusable component
that no root here includes.

The policy now admits a Device DELETE only when namespaceObject
has a deletion timestamp (null-guarded, so a missing namespace
denies) or the deleted Device is Retired. Everything else is
denied with a message to move the Device to Decommissioning, then
Retired. It keeps failurePolicy Fail, Deny only, and no subject
checks or exemptions.

The overlay isolation validator renders the component on its own
and requires that exact policy and binding, fails if any root here
renders the policy under any name, and fails if the inventory
component exists without the deletion component. Fixtures cover a
root including the component and the policy renamed, audit-only,
warn-only, fail-open, scoped, exempted or given a weaker rule.

envtest applies the component and checks Active and
Decommissioning deletes are denied, Retired deletes pass,
deletecollection over mixed Devices denies the non-retired ones,
and Devices of a deleting namespace can be deleted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The registration picker refuses Devices that are Decommissioning or
Retired with an explicit reason, and still marks an Active Device
that shares identity with a Retired one as conflicting. The
inventory detail panel shows the lifecycle, defaulting to Active.
The UI does not edit lifecycle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Document the lifecycle values and transitions, the registration
rules, and the deletion policy's two exceptions. Deploying
repositories opt into the component; this repository no longer
has a production Milo root. Namespace deletion is the privileged
escape hatch and now completes with its Devices. The earlier
stays-Terminating remediation is removed.

Record that pinned Milo project purge issues collection deletes in
every namespace before marking any, and never deletes default, so
a project that holds Devices that are not Retired does not finish
purging while the component is installed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Milo project purge drains every namespace, default included, with
DeleteCollection before it deletes any namespace, so the
deleting-namespace exception never applies and a denied Device aborts
the purge. Add a third exception: the request's username is listed
exactly in the cleanupUsernames key of a ConfigMap parameter.

The policy gains paramKind core/v1 ConfigMap. The shipped binding has
no paramRef, so params is null and the exception is off; deploying
repositories add the ConfigMap and a paramRef with
parameterNotFoundAction Deny. Entries are trimmed, empty entries and
an empty username never match, and groups, prefixes and wildcards are
not consulted. failurePolicy Fail and validationActions Deny stay.

The overlay validator requires the exact rendered policy, including
paramKind, and rejects wildcard, prefix, group-based,
null-params-allows-all, empty-username and always-true variants, a
different or missing paramKind, and any paramRef in the component.

Envtest on Kubernetes 1.37.0 covers the null-params binding, listed,
unlisted, prefix and superset users, deletecollection, a Milo-style
purge of default and another namespace, and fail-closed denial (422
Invalid) when the referenced ConfigMap is missing. An offline test
runs the expression through the admission CEL compiler for an empty
username.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Document the third Device deletion exception, how a deploying
repository enables it with a ConfigMap and a paramRef that sets
parameterNotFoundAction Deny, and that a missing ConfigMap then denies
every Device delete. Note that impersonating a listed identity grants
the exemption. Project deletion now completes when the cleanup
identity is configured and stays blocked otherwise, unless every
Device is Retired.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mark the cleanup identity exemption as a stopgap. Once Milo marks each
namespace it purges, default included, before deleting its contents, the
deletion policy can rely on the namespace signal alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The capacity registration webhook matched every MachineCapacity create,
update and delete, and every status write, in every namespace, and denied
all but gated creates. That blocked synthetic capacity a GitOps controller
re-applies, a synthetic provider's status writes, and hand-made capacity.

The webhook now governs only inventory-backed capacity: capacity carrying
a fleet.datumapis.com/registration-* annotation on the new or old object,
or a create under the derived device- name. A match condition routes only
those requests, so adding, changing or removing the marker is still
denied. Status writes are no longer routed; the status subresource cannot
change metadata or spec, so they cannot strip the marker or enable
capacity. The handler allows unmarked requests without reading Devices.

failurePolicy Fail, sideEffects None and the timeout are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scotwells
scotwells requested a review from a team as a code owner November 23, 2026 02:35
@scotwells

Copy link
Copy Markdown
Contributor Author

Detail for review. The 13 commits run from ea64db6 to b3dc951 on feat/manual-inventory-records.

Registration webhook (internal/registration, config/components/registration-admission)

  • A capacity create is denied unless the Device exists in the caller's scope, the caller can read the Device and create capacity (SubjectAccessReview), the Device's spec.lifecycle is Active, and no other live Device shares a normalized serial, system UUID or provider host ref.
  • The name must be device-<Device UID>, so the API server refuses a second capacity for the same Device.
  • Registered capacity stays Disabled and can't be updated or deleted.
  • A matchConditions entry routes only device- creates and objects carrying fleet.datumapis.com/registration-* annotations (old or new object). Adding, removing or changing that marker is denied. machinecapacities/status was removed from the rules. Unmarked capacity is allowed in the handler too.
  • The ledger (ledger.go, segments.go, control.go, fence.go), signed activation and cmd/fleet-registration-control were removed.

Device lifecycle (internal/api/inventory, CRD)

  • spec.lifecycle is Active, Decommissioning or Retired, with an Active default. CEL transition rules make Retired terminal, and it must be reached through Decommissioning.

Deletion protection (config/components/device-deletion-protection, opt-in)

  • A ValidatingAdmissionPolicy allows a Device DELETE when namespaceObject has a deletionTimestamp, when oldObject.spec.lifecycle == 'Retired', or when the username is listed in a paramKind: ConfigMap (cleanupUsernames). The binding ships without a paramRef, so the subject exemption is off.
  • The subject exemption is a stopgap. Milo's project purge deletes namespaced resources before it marks namespaces, and it never deletes default.
  • hack/overlay-isolation-validator.go fails if any root in this repo renders the policy, or if the component's policy is weakened.

UI (ui/provider)

  • The portal derives the capacity name, refuses Devices that aren't Active, and marks shared hardware identity as Conflicting.

Open points

  • The concurrent-create race on duplicate identity is documented rather than closed.
  • Caller identity is not checked: #149.
  • The cleanup-identity ConfigMap path fails closed with 422 when the ConfigMap is missing under parameterNotFoundAction: Deny.

@scotwells
scotwells requested a review from ecv November 23, 2026 02:35

@ecv ecv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes. Dropping the ledger is a real narrowing: no state writes, no Secret access, and it fails closed. But the tenancy guard has no test.

  • The provider-project check (!slices.Contains(handler.Projects, name)) is the only gate on which project a request is judged in. Resolve, the webhook matchConditions and the SubjectAccessReview take no project scope, and the SAR uses the request's own UserInfo. Disabling the check leaves every unit and envtest suite green at b3dc951. Add a test that a project outside --provider-projects is denied before any Device read or SAR.
  • The project.Identity.RouteName != name checks are untested too: every Resolve stub returns a RouteName equal to the name asked for. Make one return a mismatch and assert denial.
  • Caller identity is still unchecked (#149). Any client certificate from the CA can post an AdmissionReview and read the verdict, which names Devices and their lifecycle. That makes the scope check the only thing limiting the oracle.

Follow-ups:

  • The concurrent same-serial race is documented but not closed. Capacity stays Disabled, so allocation must not land before it is.
  • A Device deleted after the check leaves orphan capacity unless the opt-in deletion policy is installed, and staging doesn't install it.
  • Clusters that ran the ledger keep their fleet-system-private Secrets and ConfigMap after prune. Say whether to remove them by hand.

scotwells and others added 3 commits November 22, 2026 21:03
The provider-project check was the only gate on which project a
request is judged in, yet disabling it left every suite green: each
Resolve stub returned a fixed route, so the route check denied first.
Likewise no stub returned a route other than the one asked for.

Add unit and envtest cases with a Resolve that resolves any name, and
project clients and SubjectAccessReviews that fail the test if they
are reached. A project outside the scope is denied on create and on an
enabling update before any of them run, and a mismatched route is
denied on both paths before its client is used. Disabling the scope
check or either route check now fails these tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
State that the provider-project scope check is the only limit on what
a client certificate holder can learn until the webhook checks its
caller (#149).

State that allocation must not be enabled for inventory-backed
capacity until the same-serial race is closed.

Describe orphaned capacity: it stays Disabled and immutable, blocks a
same-name replacement, and blocks every registration in the provider
scope. Document re-recording the deleted machine as Retired under its
old name, and pin that remediation in a unit test.

List all three as stage-2 blockers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Prune removes only what the ledger manifests applied. List the objects
the ledger revisions created at runtime: the root Secret and sealed
segment Secrets in fleet-system-private and the control ConfigMap in
fleet-system. Say to remove them by hand, in which order, and not to
delete the shared private namespace. Environments that never deployed
the registration service have nothing to clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scotwells

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Each finding is addressed below. The commits are on this PR's head as 8b4e57d, 98e285f and b01ce48, and on feat/manual-inventory-records as b659387, 683ffad and 6398b46.

1. The provider-project check had no test. Fixed in 8b4e57d.
You were right about why it slipped through. The old wrong project case had a Resolve stub that always returned provider, so the route check denied the request first. The new tests use a Resolve that resolves any name it is given, as the real one does. The project client and the SubjectAccessReview stub fail the test if they are called at all.

  • TestOutOfScopeProjectIsDeniedBeforeAnyRead (unit) covers a create and an update that would leave Disabled.
  • TestWebhookJudgesOnlyTheConfiguredProject (envtest, behind the packaged webhook) covers the same two cases. The caller is cluster-admin in a project outside the scope, so only the scope check can deny it.
  • Mutation check: with the guard disabled, both new tests fail on both paths. Nothing else fails.

2. The RouteName != name checks had no test. Fixed in 8b4e57d.
Resolve now returns a different route, and the test asserts denial before that project's client is used for a Device read or a SubjectAccessReview. The check exists in two places, evaluate (create) and evaluateUpdate (enabling update), and both are covered in TestResolvedRouteMismatchIsDenied (unit) and in the envtest above.

  • Mutation check: disabling the check in evaluate fails only the two create cases. Disabling it in evaluateUpdate fails only the two update cases.
  • Not changed: scan resolves every provider project and does not check the returned route. That is not a scope bypass, but it is a place where a bad Resolve would go unnoticed. I left it alone because it was outside this review. Say if you want it added.

3. Caller identity (#149). Documented in 98e285f, with no code change.
The new "Provider-project scope" section says that, until #149 is fixed, the scope check is the only limit on what a certificate holder can learn. The SubjectAccessReviews do not limit such a caller, because it writes the user and extras in the review itself.

Follow-ups, all in docs/development/inventory-capacity-registration.md:

  • Same-serial race (98e285f): the doc now says allocation must not be enabled for inventory-backed capacity until the race is closed, and lists this as a stage 2 blocker.
  • Orphaned capacity (98e285f): the doc describes the resulting state. The capacity stays Disabled and immutable and blocks a same-name replacement. It also blocks every registration in the provider scope, because the scan finds capacity with unresolved identity. It also covers the remediation: re-record the deleted machine as Retired under its old name, then register the real replacement under a new name. TestOrphanedCapacityBlocksUnrelatedRegistration pins both the blocking and the remediation. Removing the capacity itself has no in-band path and is listed as a stage 2 blocker.
  • Leftover ledger objects (b01ce48): the doc lists what the old ledger created: the root Secret fleet-capacity-registration-v1 and the fleet-registration-segment-* Secrets in fleet-system-private, and the fleet-registration-control ConfigMap. That ConfigMap is in fleet-system, not fleet-system-private. Prune does not remove any of them. The doc says to remove them by hand, gives the order and the commands, and warns not to delete fleet-system-private, which the manager still uses. Environments that never deployed the registration service have nothing to clean.

Checks run on both branches: go build ./..., go vet ./..., go test -race -count=1 ./... with Kubernetes 1.37.0 envtest assets, hack/validate-doc-links.sh and git diff --check.

@scotwells
scotwells requested a review from ecv November 23, 2026 03:08

@ecv ecv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve. The tenancy guards are now covered. At b01ce48, disabling the provider-project check fails TestOutOfScopeProjectIsDeniedBeforeAnyRead and TestWebhookJudgesOnlyTheConfiguredProject. Disabling either RouteName check fails TestResolvedRouteMismatchIsDenied and the same envtest. The delta is tests and docs only.

Follow-ups:

  • #149 is still open: any client certificate from the CA can read verdicts for the configured projects.
  • Last review's follow-ups still stand: the same-serial race, orphan capacity when a Device is deleted after the check, and leftover ledger Secrets after prune.

@scotwells

Copy link
Copy Markdown
Contributor Author

Closing as planned. This was a review-only view of commits already on feat/manual-inventory-records (#90), where the review fixes also landed. Open follow-ups: #149, the same-serial race, orphaned capacity after a Device is deleted, and leftover ledger objects (now documented).

@scotwells scotwells closed this Nov 23, 2026
@scotwells
scotwells deleted the review/capacity-registration branch November 23, 2026 03:44
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.

2 participants