diff --git a/packages/system/cozyplane-apiserver/Makefile b/packages/system/cozyplane-apiserver/Makefile index 9e0d58a9c..e59de0064 100644 --- a/packages/system/cozyplane-apiserver/Makefile +++ b/packages/system/cozyplane-apiserver/Makefile @@ -17,7 +17,7 @@ test: # them; keep the three cozyplane packages on the same ref). Makefile and # tests/ are Cozystack-side and survive the vendor, and so does the version # stanza below: Cozystack owns the chart version, upstream keeps 0.0.0. -COZYPLANE_REF=65bade1c310c739edcf230af0a274086b1ac72f9 +COZYPLANE_REF=2608ed75b4c5351a5e418d9e4a61b8575ed90565 CHART_VERSION=0.0.1 update: diff --git a/packages/system/cozyplane-apiserver/values.yaml b/packages/system/cozyplane-apiserver/values.yaml index 1bfd729c5..ef7d5daac 100644 --- a/packages/system/cozyplane-apiserver/values.yaml +++ b/packages/system/cozyplane-apiserver/values.yaml @@ -1,7 +1,7 @@ # Container image (shared with the cozyplane chart — the apiserver binary lives # in the same image). Digest-pinned (no floating tag); keep it equal to # chart/cozyplane/values.yaml's pin. See docs/packaging.md. -image: ghcr.io/lllamnyp/cozyplane@sha256:60111afff00d91883a63183a058d24f81620f250a4526a94dbb26b937bb327e7 +image: ghcr.io/lllamnyp/cozyplane@sha256:880db75719674fc68dc8d1fac2bbbaca17f923ca369cd717d310f91db3ab9ae1 imagePullPolicy: IfNotPresent imagePullSecrets: [] diff --git a/packages/system/cozyplane-kpr/Makefile b/packages/system/cozyplane-kpr/Makefile index ece428cf4..2ae4da369 100644 --- a/packages/system/cozyplane-kpr/Makefile +++ b/packages/system/cozyplane-kpr/Makefile @@ -16,7 +16,7 @@ test: # them; keep the three cozyplane packages on the same ref). Makefile and # tests/ are Cozystack-side and survive the vendor, and so does the version # stanza below: Cozystack owns the chart version, upstream keeps 0.0.0. -COZYPLANE_REF=65bade1c310c739edcf230af0a274086b1ac72f9 +COZYPLANE_REF=2608ed75b4c5351a5e418d9e4a61b8575ed90565 CHART_VERSION=0.1.0 update: diff --git a/packages/system/cozyplane-kpr/templates/daemonset.yaml b/packages/system/cozyplane-kpr/templates/daemonset.yaml index ecc198611..d5cb59425 100644 --- a/packages/system/cozyplane-kpr/templates/daemonset.yaml +++ b/packages/system/cozyplane-kpr/templates/daemonset.yaml @@ -23,10 +23,15 @@ rules: - apiGroups: [""] resources: [events] verbs: [create, patch] - # Cilium's imported cells reconcile their own CRDs (CiliumNode, LB IP pools, …). - - apiGroups: [cilium.io] - resources: ["*"] - verbs: [get, list, watch, create, update, patch, delete] + {{- /* No cilium.io rule. The wired cells watch only Services/EndpointSlices + (the LB reflector) and node-local Pods/Namespaces (the daemon tables). The one + cilium.io consumer compiled in, CiliumLocalRedirectPolicy, registers neither + reflector nor controller: kpr/main.go's stubbed DaemonConfig sets the family + gates and nothing else, so EnableLocalRedirectPolicy keeps its zero value. The + CiliumNode/CiliumEndpoint/policy resource constructors in daemonk8s.ResourcesCell + are in the DI graph but never constructed, nothing in this hive depending on + them. A template comment, not a `#` one: it documents a rule that is absent, so + it has no business shipping inside every applied manifest. */}} --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding diff --git a/packages/system/cozyplane/Makefile b/packages/system/cozyplane/Makefile index 676afd68c..bb916a521 100644 --- a/packages/system/cozyplane/Makefile +++ b/packages/system/cozyplane/Makefile @@ -17,7 +17,7 @@ test: # them; keep the three cozyplane packages on the same ref). Makefile and # tests/ are Cozystack-side and survive the vendor, and so does the version # stanza below: Cozystack owns the chart version, upstream keeps 0.0.0. -COZYPLANE_REF=65bade1c310c739edcf230af0a274086b1ac72f9 +COZYPLANE_REF=2608ed75b4c5351a5e418d9e4a61b8575ed90565 CHART_VERSION=0.3.29 update: diff --git a/packages/system/cozyplane/README.md b/packages/system/cozyplane/README.md index 0b7f02d1f..6a044774e 100644 --- a/packages/system/cozyplane/README.md +++ b/packages/system/cozyplane/README.md @@ -72,3 +72,37 @@ most likely to set: - RBAC for both components, the aggregated tenant roles (`cozyplane-tenant-edit` / `-view`, docs/multitenancy.md), and the export ValidatingAdmissionPolicy. +- `cozyplane-metrics-reader` (ClusterRole): the permission the agents' `/metrics` + authorization checks for. Nothing is bound to it by this chart — see below. + +## Upgrading + +**The agent's `/metrics` is authenticated and single-homed from this version on, +and both halves can take an existing scrape away silently.** + +- `agent.metricsSecure` defaults to `true`, so a scrape must present a + ServiceAccount token whose subject holds `get` on nonResourceURL `/metrics`. + The chart ships `cozyplane-metrics-reader` for that, but **binds it to + nobody** — the monitoring stack's ServiceAccount lives outside this chart. Until + something binds it, a previously anonymous scrape gets `401`, and the per-VPC + counters simply vanish from dashboards. Create the binding as part of the + upgrade: + + ```bash + kubectl create clusterrolebinding cozyplane-metrics-reader \ + --clusterrole=cozyplane-metrics-reader \ + --serviceaccount=: + ``` + + `agent.metricsSecure=false` restores the old anonymous endpoint. On a node with + a public address that serves the counters to anything that can reach it, which + is what the default exists to stop. + +- `agent.metricsBindAddress` defaults to the node's primary InternalIP rather + than every address, so anything that scraped a *secondary* node address stops + resolving. On an IPv6-primary cluster the default still works (the agent + brackets the address itself), but only the primary family is served: a probe or + scrape against the other family's node address finds nothing listening. Set + `agent.metricsBindAddress=":9411"` to listen on every address as before — + `test/policy-e2e.sh` needs that to exercise its v6 pod→node gate rather than + skip it. diff --git a/packages/system/cozyplane/templates/agent.yaml b/packages/system/cozyplane/templates/agent.yaml index da0e6b223..f6ecc1419 100644 --- a/packages/system/cozyplane/templates/agent.yaml +++ b/packages/system/cozyplane/templates/agent.yaml @@ -19,15 +19,11 @@ rules: - apiGroups: [""] resources: ["nodes"] verbs: ["get", "list", "watch", "patch"] - # The plugin (using this SA) reads pod annotations to resolve VPC membership, - # the agent reads pods to distinguish revocation from ordinary teardown, and - # the NetworkPolicy compiler watches them for identities/membership - # (docs/network-policy.md). - # `patch` on pods: the CNI stamps a VPC pod with the address and MAC it just - # allocated (sdn.cozystack.io/vpc-ip / -mac). That is the ONLY way a tenant can - # learn its own network identity — status.podIP is the fabric IP, and the real - # address lives on the cluster-scoped Port, which no tenant may read - # (docs/multitenancy.md R1/R2). + # Pods: the plugin resolves VPC membership from annotations, the agent tells + # revocation from ordinary teardown, the NetworkPolicy compiler watches + # identities (docs/network-policy.md). `patch` is the CNI stamping the + # tenant-readable vpc-ip/-mac annotations — a tenant's only view of its own + # network identity (docs/multitenancy.md §R1). - apiGroups: [""] resources: ["pods"] verbs: ["get", "list", "watch", "patch"] @@ -69,10 +65,9 @@ rules: - apiGroups: ["sdn.cozystack.io"] resources: ["securitygroups"] verbs: ["get", "list", "watch"] - # FabricIPs: the CNI plugin claims and releases underlay addresses through - # this SA (the agent writes its kubeconfig), and the agent watches them. - # deletecollection lets a failed ADD's rollback return the pod's claims in one - # round trip; it reaches nothing the list+delete above could not. + # FabricIPs: the CNI plugin claims/releases underlay addresses through this SA + # (the agent writes its kubeconfig), the agent watches them. deletecollection + # serves a failed ADD's rollback; it reaches nothing list+delete could not. - apiGroups: ["local.sdn.cozystack.io"] resources: ["fabricips"] verbs: ["get", "list", "watch", "create", "delete", "deletecollection"] @@ -92,17 +87,34 @@ rules: - apiGroups: ["sdn.cozystack.io"] resources: ["servicevips"] verbs: ["get", "list", "watch"] - # The split-horizon resolver (responder container) answers headless Services - # annotated into a VPC from their EndpointSlices; the agent reads the - # kube-system/kube-dns Service to discover the cluster DNS address; and the - # LB-uplink watcher ensures the datapath serves the link carrying every - # status.loadBalancer.ingress address (docs/external-addresses.md §9). + # Services/EndpointSlices: the responder's split-horizon answers, cluster-DNS + # discovery, and the LB-uplink watcher (docs/external-addresses.md §9). - apiGroups: [""] resources: ["services"] verbs: ["get", "list", "watch"] - apiGroups: ["discovery.k8s.io"] resources: ["endpointslices"] verbs: ["get", "list", "watch"] + # Delegated auth on /metrics: the agent verifies a scraper's token and its + # get-on-/metrics permission against the kube-apiserver. + - apiGroups: ["authentication.k8s.io"] + resources: ["tokenreviews"] + verbs: ["create"] + - apiGroups: ["authorization.k8s.io"] + resources: ["subjectaccessreviews"] + verbs: ["create"] +--- +# Bind this to the monitoring scraper's ServiceAccount; it is what the agents' +# delegated /metrics authorization checks for (values.yaml, agent.metricsSecure). +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: cozyplane-metrics-reader + labels: + {{- include "cozyplane.labels" . | nindent 4 }} +rules: + - nonResourceURLs: ["/metrics"] + verbs: ["get"] --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding @@ -176,6 +188,10 @@ spec: # (routed to the gateway instead, which proxies DNS / denies the rest). - "--internal-cidrs={{ join "," $internal }}" {{- end }} + # The kubelet expands $(HOST_IP) from the env below (values.yaml, + # agent.metricsBindAddress — how to scrape, and why not 0.0.0.0). + - "--metrics-bind-address={{ .Values.agent.metricsBindAddress }}" + - "--metrics-secure={{ .Values.agent.metricsSecure }}" ports: # Per-VPC traffic metrics (#2), Prometheus text at /metrics. - name: metrics @@ -186,6 +202,10 @@ spec: valueFrom: fieldRef: fieldPath: spec.nodeName + - name: HOST_IP + valueFrom: + fieldRef: + fieldPath: status.hostIP # Gateway-attach is honored only for pods in the agent's namespace. - name: AGENT_NAMESPACE valueFrom: diff --git a/packages/system/cozyplane/templates/controller.yaml b/packages/system/cozyplane/templates/controller.yaml index de27cc68e..911204412 100644 --- a/packages/system/cozyplane/templates/controller.yaml +++ b/packages/system/cozyplane/templates/controller.yaml @@ -164,6 +164,39 @@ subjects: name: cozyplane-controller namespace: {{ .Release.Namespace }} --- +# Leader election: the manager's Lease lives in its own namespace, and the +# elector records events there on transitions. +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: cozyplane-controller-leader-election + namespace: {{ .Release.Namespace }} + labels: + {{- include "cozyplane.labels" . | nindent 4 }} +rules: + - apiGroups: ["coordination.k8s.io"] + resources: ["leases"] + verbs: ["get", "list", "watch", "create", "update", "patch", "delete"] + - apiGroups: [""] + resources: ["events"] + verbs: ["create", "patch"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: cozyplane-controller-leader-election + namespace: {{ .Release.Namespace }} + labels: + {{- include "cozyplane.labels" . | nindent 4 }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: cozyplane-controller-leader-election +subjects: + - kind: ServiceAccount + name: cozyplane-controller + namespace: {{ .Release.Namespace }} +--- apiVersion: apps/v1 kind: Deployment metadata: @@ -191,7 +224,12 @@ spec: imagePullPolicy: {{ .Values.imagePullPolicy }} command: ["/usr/local/bin/sdn-controller"] args: - - --leader-elect=false + # Unconditional: controller.replicas is settable, and two + # uncoordinated managers would both write Services/EndpointSlices/Ports. + # At one replica it costs a Lease, plus up to one lease duration (~15s) + # with no active controller after a restart, while the new pod waits + # for the old holder's Lease to expire. + - --leader-elect=true - --metrics-bind-address=0 - --health-probe-bind-address=:8081 {{- if .Values.egress.clusterCIDR }} diff --git a/packages/system/cozyplane/templates/tenant-rbac.yaml b/packages/system/cozyplane/templates/tenant-rbac.yaml index 13bb096c9..9c4400630 100644 --- a/packages/system/cozyplane/templates/tenant-rbac.yaml +++ b/packages/system/cozyplane/templates/tenant-rbac.yaml @@ -1,17 +1,9 @@ --- -# The TENANT persona (docs/multitenancy.md). -# -# R2 ("a tenant enumerates nothing it does not own") is satisfied STRUCTURALLY, not -# by vigilance: these roles list only NAMESPACED kinds, and a RoleBinding cannot -# grant access to a cluster-scoped resource. So a tenant bound to these in its own -# namespace *cannot* be given `list ports`, `list servicevips` or -# `list hostfirewalls`. -# Those are cluster-scoped precisely because allocation needs a global keyspace, and -# that allocation detail must never become a tenant-visible surface: one `list ports` -# would hand over every other tenant's pods, addresses, MACs and node placement. -# -# They aggregate into the built-in admin/edit/view ClusterRoles, so a namespace -# admin gets cozyplane's tenant surface without anyone wiring it up per tenant. +# The TENANT persona: NAMESPACED kinds only, so a RoleBinding can never reach the +# cluster-scoped allocation surface (Ports, ServiceVIPs, HostFirewalls) — R2 +# holds structurally, not by vigilance (docs/multitenancy.md §R2). Aggregated +# into the built-in admin/edit/view roles, so a namespace admin gets the tenant +# surface without per-tenant wiring. apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: @@ -41,16 +33,14 @@ rules: - floatingips/status verbs: ["get"] - # The virtual verbs on a tenant's OWN VPCs. - # - # `export` gates creating a VPCBinding to a VPC; `peer` gates creating a peering - # half. Granting them here is not an escalation, and this is the whole reason the - # verbs are checked against the VPC rather than the binding: a RoleBinding in the - # tenant's namespace can only ever authorize these on VPCs IN THAT NAMESPACE. - # Reaching into someone else's namespace still needs their consent, from them. - # - # Without `export` a tenant could not attach a pod even to its own VPC (attach is - # default-deny and a VPCBinding is required in every case, including same-namespace). + {{- /* Granting the virtual verbs in an aggregated edit role is not an + escalation — it is the reason they are checked against the VPC rather than the + binding: a RoleBinding in the tenant's namespace can only ever authorize + export/peer on VPCs IN THAT NAMESPACE, so reaching a VPC elsewhere still needs + a grant from its owner, in the owner's namespace (docs/multitenancy.md §R4). */}} + # The virtual verbs on a tenant's OWN VPCs: `export` gates VPCBinding creation, + # `peer` a peering half. Attach is default-deny even same-namespace, so without + # `export` a tenant could not use its own VPC (docs/control-plane.md §6). - apiGroups: ["sdn.cozystack.io"] resources: ["vpcs"] verbs: ["export", "peer"] diff --git a/packages/system/cozyplane/values.yaml b/packages/system/cozyplane/values.yaml index 31e00a803..56ab33f22 100644 --- a/packages/system/cozyplane/values.yaml +++ b/packages/system/cozyplane/values.yaml @@ -2,7 +2,7 @@ # Digest-pinned (no floating tag). Built and published by .github/workflows/ # release.yml on every push to main; see docs/packaging.md for how the digest is # refreshed and why pinning it does not change it. -image: ghcr.io/lllamnyp/cozyplane@sha256:60111afff00d91883a63183a058d24f81620f250a4526a94dbb26b937bb327e7 +image: ghcr.io/lllamnyp/cozyplane@sha256:880db75719674fc68dc8d1fac2bbbaca17f923ca369cd717d310f91db3ab9ae1 imagePullPolicy: IfNotPresent imagePullSecrets: [] @@ -56,6 +56,22 @@ egress: internalCIDRs: [] agent: + # Bind address for the per-VPC Prometheus metrics (/metrics). The kubelet + # resolves $(HOST_IP) to the node's primary InternalIP, so in-cluster + # Prometheus scrapes the agent pods on :9411 as usual (hostNetwork: pod IP == + # host IP) while any other node address — a public one included — serves + # nothing. The agent brackets the host itself, so this is also correct when + # that primary address is IPv6; only the primary FAMILY is served, though, so + # nothing listens on the other family's node address. ":9411" restores + # listening on every address; "" disables metrics. See README.md § Upgrading. + metricsBindAddress: "$(HOST_IP):9411" + # Delegated authn/authz on /metrics (TokenReview + SubjectAccessReview against + # the kube-apiserver): the scraper sends its ServiceAccount token — a standard + # in-cluster prometheus/vmagent scrape with bearerTokenFile, plain HTTP — and + # that ServiceAccount needs `get` on nonResourceURL /metrics, so bind the + # cozyplane-metrics-reader ClusterRole to it. false serves /metrics + # unauthenticated to anything that can reach the bind address. + metricsSecure: true priorityClassName: system-node-critical resources: requests: