Skip to content
Draft
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
10 changes: 6 additions & 4 deletions cmd/fleet-registration/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,25 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

"go.datum.net/fleet/internal/custody/creatorwebhook"
"go.datum.net/fleet/internal/powerwebhook"
)

func main() {
var configFile, providers, cert, key, clientCA string
var configFile, providers, powerWriter, cert, key, clientCA string
flag.StringVar(&configFile, "config", "", "Fleet manager discovery configuration")
flag.StringVar(&providers, "provider-projects", "", "complete comma-separated provider scope searched for duplicate hardware identity")
flag.StringVar(&powerWriter, "machine-power-writer", "", "username of the manager's Milo identity, the only writer of Machine status.power; empty refuses every power change")
flag.StringVar(&cert, "tls-cert", "/etc/fleet/registration/tls.crt", "serving certificate")
flag.StringVar(&key, "tls-key", "/etc/fleet/registration/tls.key", "serving key")
flag.StringVar(&clientCA, "client-ca", "/etc/fleet/registration/client-ca.crt", "CA dedicated to trusted API-server webhook clients")
flag.Parse()
if err := run(ctrl.SetupSignalHandler(), configFile, providers, cert, key, clientCA); err != nil {
if err := run(ctrl.SetupSignalHandler(), configFile, providers, powerWriter, cert, key, clientCA); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}

func run(ctx context.Context, configFile, providers, cert, key, clientCA string) error {
func run(ctx context.Context, configFile, providers, powerWriter, cert, key, clientCA string) error {
config, err := projectdiscovery.LoadConfig(configFile)
if err != nil {
return err
Expand Down Expand Up @@ -76,7 +78,7 @@ func run(ctx context.Context, configFile, providers, cert, key, clientCA string)
if err != nil {
return err
}
server := &http.Server{Addr: ":9443", Handler: http.MaxBytesHandler(handler.Transport(&creatorwebhook.Handler{Projects: projects, Resources: creatorwebhook.Resources}), 2<<20), ReadHeaderTimeout: 5 * time.Second, ReadTimeout: 15 * time.Second, WriteTimeout: 20 * time.Second, TLSConfig: tlsConfig}
server := &http.Server{Addr: ":9443", Handler: http.MaxBytesHandler(handler.Transport(&creatorwebhook.Handler{Projects: projects, Resources: creatorwebhook.Resources}, &powerwebhook.Handler{Writer: powerWriter}), 2<<20), ReadHeaderTimeout: 5 * time.Second, ReadTimeout: 15 * time.Second, WriteTimeout: 20 * time.Second, TLSConfig: tlsConfig}
go func() {
<-ctx.Done()
shutdown, cancel := context.WithTimeout(context.Background(), 5*time.Second)
Expand Down
20 changes: 14 additions & 6 deletions config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,21 @@ The one `fleet-manager` Deployment serves every Milo project that consumes the
`metal` service; see [project discovery](#project-discovery).

The separate `fleet-registration` Deployment serves inert inventory-backed
capacity admission only. It keeps no state: each capacity create is checked
against live Devices and capacities in the provider projects. Its TLS trust,
read/SAR credentials and webhook serving CA are environment-owned; it has no
host RBAC and mounts no service account token. Read the
capacity admission, the operation creator webhook, and the Machine power
webhook. `config/components/machine-power-admission` admits a change to a
Machine's `status.power` only from the identity named by `fleet-registration`'s
`--machine-power-writer` flag, the manager's Milo identity; unset, every power
change is refused. `config/milo` includes it, and `config/standalone` enforces
the same rule with a ValidatingAdmissionPolicy. See
[Machine power](../docs/development/device-custody.md#machine-power).
The service keeps no state: each capacity create is checked against live
Devices and capacities in the provider projects. Its TLS trust, read/SAR
credentials and webhook serving CA are environment-owned; it has no host RBAC
and mounts no service account token. Read the
[registration rollout contract](../docs/development/inventory-capacity-registration.md#production-packaging-and-rollout)
before applying either root: an unavailable service blocks capacity writes
globally, and nothing else. Pod TCP readiness is transport-only; it must not
before applying either root: an unavailable service blocks capacity writes,
operation creates and Machine power changes globally, and nothing else. Pod
TCP readiness is transport-only; it must not
enable UI registration. This does not enable production allocation or
provisioning.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- webhook.yaml
33 changes: 33 additions & 0 deletions config/components/machine-power-admission/webhook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: fleet-machine-power
webhooks:
# The manager's power projector is the only writer of a Machine's
# status.power. RBAC cannot hold that field to one writer: Milo authorizes a
# status write with the Machine's update and patch permissions, which the
# consumer roles hold. Milo's root API server calls this webhook, because
# Milo does not evaluate admission policies stored in a project. Only status
# writes that change status.power are routed, so an unavailable service
# blocks power changes and nothing else. It is fail-closed. The
# fleet-registration server serves it; its --machine-power-writer flag names
# the projector's identity, and without it every power change is refused.
- name: power.machines.metal.datumapis.com
admissionReviewVersions: [v1]
failurePolicy: Fail
matchPolicy: Equivalent
sideEffects: None
timeoutSeconds: 10
clientConfig:
url: https://fleet-registration.fleet-system.svc:9443/validate-machine-power
rules:
- apiGroups: [metal.datumapis.com]
apiVersions: [v1alpha1]
operations: [UPDATE]
resources: [machines/status]
scope: Namespaced
matchConditions:
- name: power-changes
expression: >-
(has(object.status) && has(object.status.power)) != (has(oldObject.status) && has(oldObject.status.power))
|| (has(object.status) && has(object.status.power) && object.status.power != oldObject.status.power)
1 change: 1 addition & 0 deletions config/milo/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ resources:
- ../components/inventory
- ../components/registration-admission
- ../components/device-operations
- ../components/machine-power-admission
1 change: 1 addition & 0 deletions config/standalone/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ resources:
- rbac.yaml
- fixtures.yaml
- site.yaml
- machine-power.yaml
- smoke-cronjobs.yaml
images:
- name: ghcr.io/datum-cloud/fleet-simulator
Expand Down
29 changes: 29 additions & 0 deletions config/standalone/machine-power.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# The power rule. Milo projects ignore admission policies, so Milo uses the
# Machine power webhook; a plain cluster enforces the same rule with this
# policy: only the power projector's identity changes a Machine's
# status.power. Here that is the smoke runner, which runs the manager's
# projector for its fixture Machines.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata: {name: fleet-machine-power}
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups: [metal.datumapis.com]
apiVersions: ["*"]
operations: [UPDATE]
resources: [machines/status]
validations:
- expression: >-
request.userInfo.username == 'system:serviceaccount:fleet-system:fleet-standalone-smoke'
|| ((has(object.status) && has(object.status.power)) == (has(oldObject.status) && has(oldObject.status.power))
&& (!(has(object.status) && has(object.status.power)) || object.status.power == oldObject.status.power))
message: Only the power projector writes status.power.
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata: {name: fleet-machine-power}
spec:
policyName: fleet-machine-power
validationActions: [Deny]
36 changes: 36 additions & 0 deletions docs/development/device-custody.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,32 @@ manager, custody, allocation and Device events in the provider project wake
the consumer's Machines, so a new hold shows as `Unknown` without a Machine
event.

Admission keeps power to that one writer. RBAC alone cannot: Milo authorizes a
status write with the Machine's `update` and `patch` permissions, which the
consumer and claimant roles hold, and the manager's other status writers share
the projector's identity.

| Mode | Guard | Writer |
| --- | --- | --- |
| Production Milo root (`config/milo`) | The Machine power webhook, served by `fleet-registration` at `/validate-machine-power`. Only status writes that change `status.power` are routed, fail-closed. | The username in `fleet-registration`'s `--machine-power-writer` flag: the manager's Milo identity. Unset, every power change is refused. Set it before a power projector runs against this root. |
| Standalone (`config/standalone`) | A ValidatingAdmissionPolicy on `machines/status` | The smoke runner's service account, which runs the projector for its fixtures |
| Synthetic Milo root and multi-plane local Milo | None. Neither runs `fleet-registration`, and Milo ignores policies stored in a project. RBAC grants Machine status only to the manager, but the consumer roles' `update` permission still reaches it. | See [Points for a person](#points-for-a-person) |

Who can write Machine status, and who can change power:

| Identity | Machine status | Power |
| --- | --- | --- |
| The manager: the power projector, the staging handler and the requested-hardware projector | All fields | The only writer, once the flag names it |
| The standalone smoke runner | Its fixture Machine | The only writer in standalone |
| Milo consumer and claimant roles | All fields, through `update` and `patch` | Refused |
| The Metal provider and allocator, the release controller, the custody coordinator, discovery, the inventory and operation roles, Karmada, kro and federation | None | None |

Within the manager, the staging handler, the requested-hardware projector and
the runners carry power forward unchanged; admission cannot tell them apart
from the projector. A render check over every root in `config` fails if any
other Kubernetes role gains Machine status writes, or any other Milo role gains
a Machine status, update or patch permission.

### Deleted, with no compatibility

- The Secret-backed coordinator and its records, the private-record RBAC, the
Expand Down Expand Up @@ -779,6 +805,16 @@ These need a decision before the increment that depends on them.
`Healthy` and `Available` themselves.
- **O10: the sealed store for bootstrap payloads.** Bootstrap stays refused in
every increment until a store is chosen.
- **Machine status writes by consumers in Milo.** Milo's authorizer, with
subresource authorization off, checks a status write against `update` and
`patch`, which the consumer and claimant roles hold. The power webhook refuses
their power changes, but they can still write every other Machine status
field. Closing it needs subresource authorization enabled in Milo, the
Machine ProtectedResource to declare its status subresource, and the
controller role alone to hold `machines/status.update` and `.patch`.
- **The power guard in synthetic staging and the multi-plane local Milo.**
Neither runs `fleet-registration`, so neither has the power webhook, as
neither has the creator webhook.
- **A second person for `DeviceRecovery`.** Not required yet. A person
accepted this for now, and it stays open for a later decision.
- **Synthetic staging needs its records imported again, new credentials and
Expand Down
14 changes: 12 additions & 2 deletions docs/development/inventory-capacity-registration.md
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,11 @@ synthetic ones.
service blocks writes to inventory-backed capacity and nothing else:
unmarked capacity, capacity status, Device, namespace and Project writes do
not pass through the registration webhook.
- `config/milo` also includes the fail-closed
[Machine power webhook](device-custody.md#machine-power) on the same
service. It matches only Machine status writes that change `status.power`,
so an unreachable service also blocks power changes, and no other Machine
write.
- No root in this repository includes Device deletion protection. A
deploying repository adds `config/components/device-deletion-protection` to
the root it applies to Milo when it must keep in-service Devices.
Expand Down Expand Up @@ -586,8 +591,13 @@ Environment-owned inputs, none of which this repository supplies:
2. Supply `fleet-registration-tls` with `tls.crt`, `tls.key` and a dedicated
`client-ca.crt`. Configure Milo's admission webhook client with an
API-server client certificate signed by that CA, patch the webhook URL for
reachability, and set `clientConfig.caBundle` to the serving CA.
3. Keep `--provider-projects` equal to the complete provider scope.
reachability, and set `clientConfig.caBundle` to the serving CA. Do the
same for the Machine power webhook, or every power change fails closed.
3. Keep `--provider-projects` equal to the complete provider scope. Before a
power projector runs against the root, set `--machine-power-writer` to the
username Milo reports for the manager's identity in a routed project
request. Confirm it with one of the manager's own status writes: a
mismatch refuses every power change.
4. Decide whether the Milo root you apply includes
`config/components/device-deletion-protection`. With it, the only Device
deletes admitted are of Retired Devices, of Devices in a deleting namespace,
Expand Down
Loading
Loading