Skip to content
Closed
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
56 changes: 0 additions & 56 deletions cmd/fleet-registration-control/main.go

This file was deleted.

51 changes: 0 additions & 51 deletions cmd/fleet-registration-control/main_test.go

This file was deleted.

85 changes: 23 additions & 62 deletions cmd/fleet-registration/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,55 +20,40 @@ import (
resourcemanager "go.miloapis.com/milo/pkg/apis/resourcemanager/v1alpha1"
"k8s.io/apimachinery/pkg/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func main() {
var configFile, providers, privateNamespace, cert, key, clientCA, controlKey, controlRequest string
var configFile, providers, cert, key, clientCA string
flag.StringVar(&configFile, "config", "", "Fleet manager discovery configuration")
flag.StringVar(&providers, "provider-projects", "", "complete comma-separated provider identity scope, fixed in the private ledger")
flag.StringVar(&privateNamespace, "private-namespace", "fleet-system-private", "private registration ledger namespace")
flag.StringVar(&providers, "provider-projects", "", "complete comma-separated provider scope searched for duplicate hardware identity")
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.StringVar(&controlKey, "control-key", "/etc/fleet/registration-control/public.pem", "operator Ed25519 public key; never a private key")
flag.StringVar(&controlRequest, "control-request", "/etc/fleet/registration-control/request.json", "optional signed activation or expansion request")
flag.Parse()
if err := run(ctrl.SetupSignalHandler(), configFile, providers, privateNamespace, cert, key, clientCA, controlKey, controlRequest); err != nil {
if err := run(ctrl.SetupSignalHandler(), configFile, providers, cert, key, clientCA); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}

func run(ctx context.Context, configFile, providers, namespace, cert, key, clientCA, controlKey, controlRequest string) error {
func run(ctx context.Context, configFile, providers, cert, key, clientCA string) error {
config, err := projectdiscovery.LoadConfig(configFile)
if err != nil {
return err
}
projects := strings.Split(providers, ",")
sort.Strings(projects)
for index, name := range projects {
if name == "" || strings.TrimSpace(name) != name || (index > 0 && projects[index-1] == name) {
return errors.New("a nonempty, unique provider scope is required")
}
projects, err := providerScope(providers)
if err != nil {
return err
}
scheme := runtime.NewScheme()
for _, add := range []func(*runtime.Scheme) error{clientgoscheme.AddToScheme, inventory.AddToScheme, metal.AddToScheme, resourcemanager.AddToScheme} {
if err := add(scheme); err != nil {
return err
}
}
host, err := rest.InClusterConfig()
if err != nil {
return err
}
private, err := client.New(host, client.Options{Scheme: scheme})
if err != nil {
return err
}
rootConfig, err := clientcmd.BuildConfigFromFlags("", config.Discovery.DiscoveryKubeconfigPath)
if err != nil {
return err
Expand All @@ -84,52 +69,17 @@ func run(ctx context.Context, configFile, providers, namespace, cert, key, clien
return err
}
}
keyBytes, err := os.ReadFile(controlKey)
if err != nil {
return err
}
publicKey, err := registration.ParseControlKey(keyBytes)
if err != nil {
return err
}
handler := registration.NewHandler(registration.Store{Client: private, Namespace: namespace, Authority: config.AuthorityID, Projects: projects, ControlKey: publicKey}, root, template, scheme)
handler := registration.NewHandler(config.AuthorityID, projects, root, template, scheme)
tlsConfig, err := webhookTLS(clientCA)
if err != nil {
return err
}
server := &http.Server{Addr: ":9443", Handler: http.MaxBytesHandler(handler.Transport(), 2<<20), ReadHeaderTimeout: 5 * time.Second, ReadTimeout: 15 * time.Second, WriteTimeout: 20 * time.Second, TLSConfig: tlsConfig}
go func() {
ticker := time.NewTicker(30 * time.Second)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
shutdown, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
_ = server.Shutdown(shutdown)
return
case <-ticker.C:
operation, cancel := context.WithTimeout(ctx, 20*time.Second)
if err := handler.Store.ResumeExpansion(operation); err != nil {
fmt.Fprintln(os.Stderr, "registration expansion remains fenced:", err)
}
if encoded, err := os.ReadFile(controlRequest); err == nil {
control, err := registration.ParseControl(encoded)
if err == nil {
err = handler.ApplyControl(operation, control)
}
if err != nil {
fmt.Fprintln(os.Stderr, "registration control not applied:", err)
}
} else if !os.IsNotExist(err) {
fmt.Fprintln(os.Stderr, "registration control unavailable:", err)
}
if err := handler.Recover(operation); err != nil {
fmt.Fprintln(os.Stderr, "registration recovery remains unknown:", err)
}
cancel()
}
}
<-ctx.Done()
shutdown, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
_ = server.Shutdown(shutdown)
}()
err = server.ListenAndServeTLS(cert, key)
if errors.Is(err, http.ErrServerClosed) {
Expand All @@ -138,6 +88,17 @@ func run(ctx context.Context, configFile, providers, namespace, cert, key, clien
return err
}

func providerScope(providers string) ([]string, error) {
projects := strings.Split(providers, ",")
sort.Strings(projects)
for index, name := range projects {
if name == "" || strings.TrimSpace(name) != name || (index > 0 && projects[index-1] == name) {
return nil, errors.New("a nonempty, unique provider scope is required")
}
}
return projects, nil
}

func webhookTLS(clientCA string) (*tls.Config, error) {
caBytes, err := os.ReadFile(clientCA)
if err != nil {
Expand Down
51 changes: 26 additions & 25 deletions config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,43 @@ entitlements, ServiceAvailability resources, and publication rules must referenc
`metal`. See the [API architecture](../docs/architecture/README.md) for group separation
and breaking alpha rename constraints.

The repository publishes two production manifest roots. They target different
API servers and must be reconciled independently.
The repository publishes Milo and management-cluster manifest roots. They
target different API servers and must be reconciled independently.

| Root | Destination | Contents |
| --- | --- | --- |
| `config/milo` | Milo root control plane | Fleet CRDs (including the `fleet.datumapis.com` inventory kinds), IAM protected resources and roles, service/quota registration, and the mandatory capacity-registration webhook |
| `config/milo` | Milo root control plane | Fleet CRDs (including the `fleet.datumapis.com` inventory kinds), IAM protected resources and roles, service/quota registration, and the mandatory capacity-registration webhook. Devices can be deleted. |
| `config/overlays/management-plane` | Fleet management cluster | Fleet CRDs, manager and inert-registration workloads and RBAC, private-record namespaces, and admission fences |
| `config/overlays/synthetic-staging` | Fleet management cluster (non-production only) | Management-plane resources plus an explicit synthetic allocator/provider integration |

The synthetic staging overlay explicitly excludes the inert-registration
service and its retention policies. Pair it with `config/milo-synthetic` in a
**separate non-production Milo control plane**, not production `config/milo`.
That root preserves the pre-registration synthetic API contract. There is no
request field, actor exemption, or runtime switch that bypasses production
registration admission. Never point synthetic lifecycle handlers at the
production registration authority or its private ledger.
`config/components/device-deletion-protection` is a reusable component: a
ValidatingAdmissionPolicy and binding that deny a Device `DELETE` unless the
Device is `Retired` or its namespace is being deleted, with no exemptions.
Production-specific configuration lives in the deploying repository, which
opts in by adding the component to the root it applies to Milo. No root in this
repository includes it, and `hack/validate-overlay-isolation.sh` fails if one
does or if the component's policy is weakened. See
[Device deletion protection](../docs/development/inventory-capacity-registration.md#device-deletion-protection).

The synthetic staging overlay excludes the inert-registration service. Pair it
with `config/milo-synthetic` in a **separate non-production Milo control
plane**, not production `config/milo`. That root preserves the
pre-registration synthetic API contract. There is no request field, actor
exemption, or runtime switch that bypasses production registration admission.

The one `fleet-manager` Deployment serves every Milo project that consumes the
`metal` service; see [project discovery](#project-discovery).

The [signed expansion and transport-first contract](../docs/development/registration-storage-rollout.md)
defines the required operator public-key ConfigMap, retained segments, activation
gate, byte budgets and ordered parent infrastructure work. Pod TCP readiness is
transport-only; it must not enable UI registration.

The separate `fleet-registration` Deployment serves inert inventory-backed
capacity admission only. Its TLS trust, read/SAR credentials, webhook serving CA
and one-time private ledger bootstrap are environment-owned. Read the
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
[registration rollout contract](../docs/development/inventory-capacity-registration.md#production-packaging-and-rollout)
before applying either root: an unavailable authority blocks capacity writes
globally, and fences Device writes and protected lifetime deletions in provider
or ambiguous inventory contexts. Admission-time trusted-context conditions keep
proven unrelated Project inventory independent of webhook availability. All four webhook
entries require the same serving CA and endpoint; their scope must match the
private ledger, which must never be reset by GitOps. This does not enable
production allocation or provisioning.
before applying either root: an unavailable service blocks capacity writes
globally, and nothing else. Pod TCP readiness is transport-only; it must not
enable UI registration. This does not enable production allocation or
provisioning.

`config/components/service-catalog-staging` is a Kustomize component with
staging's Bare Metal prices: committed servers and server setup, which
Expand Down Expand Up @@ -118,7 +119,7 @@ synthetic claim before treating persistent-state recovery as verified in staging
Do not delete the PVC as a recovery shortcut.


Render both production roots before publishing the Kustomize bundle:
Render the Milo and management-cluster roots before publishing the Kustomize bundle:

```sh
kustomize build config/milo >/dev/null
Expand Down
8 changes: 3 additions & 5 deletions config/base/registration/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ spec:
app.kubernetes.io/name: fleet-registration
spec:
serviceAccountName: fleet-registration
# The service reads Milo through mounted credentials only; it needs no
# host Kubernetes API access.
automountServiceAccountToken: false
securityContext:
runAsNonRoot: true
runAsUser: 65532
Expand Down Expand Up @@ -66,12 +69,7 @@ spec:
- {name: root, mountPath: /var/run/fleet/milo, readOnly: true}
- {name: projects, mountPath: /var/run/fleet/projects, readOnly: true}
- {name: tls, mountPath: /etc/fleet/registration, readOnly: true}
- {name: control, mountPath: /etc/fleet/registration-control, readOnly: true}
volumes:
- name: control
configMap:
name: fleet-registration-control
defaultMode: 0440
- name: config
configMap:
name: fleet-manager-config
Expand Down
2 changes: 0 additions & 2 deletions config/base/registration/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment.yaml
- rbac.yaml
- protection.yaml
Loading
Loading