diff --git a/design-proposals/unified-tls-pki/README.md b/design-proposals/unified-tls-pki/README.md index 501bb7d..954e197 100644 --- a/design-proposals/unified-tls-pki/README.md +++ b/design-proposals/unified-tls-pki/README.md @@ -142,33 +142,53 @@ The canonical name is therefore `.tenant-ca`, and it is collision-free This is where the label-filtered projection matters. Because `tenantsecrets` delivers the whole Secret `Data`, the helper's fail-closed guard is not a nicety — it is the boundary that keeps a server or CA private key out of a tenant's hands. Kafka's `-clients-ca-cert` is the shape to match: a CA certificate, no key, readable by the tenant. -### 5. Delivery: one engine-agnostic extraction controller +### 5. Delivery: a declared sentinel and one engine-agnostic controller -The contract in §4 fixes the output object. The remaining work is the input path, and it splits on a single question — **does the engine's operator already emit a key-free `ca.crt` object?** +The contract in §4 fixes the output object; this section fixes the input path — how the key-free `.tenant-ca` gets written for an engine whose operator does not already emit it under that name. Everything in this section is **internal**: no tenant and no consumer observes any of it. A tenant still reads exactly the object §4 defines — `.tenant-ca`, containing only `ca.crt` — and nothing here changes what that object is, how it is labelled, or how it is consumed. The delivery mechanism lives entirely below the line §4 draws. -- **Engines that self-publish a key-free CA** need no platform machinery. `kafka` (Strimzi, native) and `redis` (forked operator via `caCertSecretName`) are here: they converge by matching the canonical name and stamping the tenant-resource label. They opt **out** of the controller below simply by not stamping the source label. -- **Every other engine** — nats, qdrant, mariadb, opensearch, rabbitmq (cert-manager chains, chart-rendered, key-bearing CA) and mongodb, postgres (operator-rendered, key-bearing CA, asynchronous) — has a key-bearing CA Secret and no key-free output. None can feed the helper at chart-render time (see "The problem"). These opt **in** via an explicit source label and are served by **one engine-agnostic extraction controller**. +The input path splits on a single question — **does the engine's operator already emit a key-free `ca.crt` object?** — and the platform's standing preference (source from a key-free object where one exists; strip only when forced to) follows from it: + +- **Engines that self-publish a key-free CA.** `kafka` (Strimzi, native) and `redis` (forked operator via `caCertSecretName`) are here. Their CA already lands key-free, but under an engine-specific name (`-clients-ca-cert`, `-ca-cert`) rather than the canonical `.tenant-ca`, so they still declare a projection — one that sources from the key-free object and is a straight copy with nothing to strip. +- **Every other engine** — nats, qdrant, mariadb, opensearch, rabbitmq (cert-manager chains, chart-rendered, key-bearing CA) and mongodb, postgres (operator-rendered, key-bearing CA, asynchronous) — has a key-bearing CA Secret and no key-free output. None can feed the helper at chart-render time (see "The problem"). The projection sources from the key-bearing CA Secret, and the controller strips everything but `ca.crt`. The alternative to one controller is to fork each upstream operator the way redis was forked (adding a `caCertSecretName`-style key-free output). Forking CloudNativePG, PSMDB, mariadb-operator, opster, and the rabbitmq cluster-operator is far more surface to own than a single small controller, and redis's fork was a reaction to a review blocker, not a designed-up-front pattern. So the controller is the target for every non-self-publishing engine. -The controller is deliberately **engine-agnostic**: it does not branch on cert-manager-vs-operator-owned, and it does not key off Secret names. Its contract is three pieces, only the middle of which is new code. +The mechanism is two pieces: a **declaration** the chart renders, and a small **controller** that reconciles it. An earlier revision of this proposal delivered the input path with a *label* on the CA Secret — the owner stamped `publish-ca-cert` and the controller selected sources by that label. An API-owner review of the implementation (`cozystack/cozystack#3299`) found that this emulates object semantics with a label: the thing being declared is "project this Secret's `ca.crt` as a trust anchor", a first-class intent that deserves a first-class object with a name, a status, and its own admission rules — not a boolean smuggled onto someone else's Secret. The mechanism below is that object. + +**(a) The owner declares the projection with a namespaced sentinel.** The app chart renders a small namespaced custom resource — working name `TenantProjection`, group `internal.cozystack.io` — that names the source Secret explicitly instead of stamping a label on it: + +```yaml +apiVersion: internal.cozystack.io/v1alpha1 +kind: TenantProjection +metadata: + name: +spec: + projections: + - type: CACert + sourceSecretName: -ca # the engine's CA-bearing Secret + sourceKey: ca.crt # key to lift (defaults to ca.crt) +``` -**(a) An explicit source-selection label, engine-agnostic, not a name convention.** The owner of the CA-bearing Secret stamps `internal.cozystack.io/publish-ca-cert: "true"`, with an optional `internal.cozystack.io/publish-ca-cert-key` annotation naming the key to lift (default `ca.crt`). It also stamps `internal.cozystack.io/publish-ca-cert-release` with the release name: implementation showed the release cannot be inferred on the label leg, because the platform runs cert-manager with `enableCertificateOwnerRef: false`, so a cert-manager-issued Secret carries no ownerReference back to its owning application and the lineage graph cannot resolve which release it belongs to. The release label supplies that link explicitly. For the cert-manager-minting charts all three markers ride `Certificate.spec.secretTemplate.labels`, so even the asynchronously-created CA Secret carries them from the moment cert-manager writes it. The label, not the name, is the contract — which matters because the CA-bearing Secret names are non-uniform (`-ca`, `-ca-tls`, `-http-ca`, `-ca-cert`) and the name `-ca-cert` is overloaded: key-free for the redis fork, key-bearing for PSMDB. A name convention would mis-handle one of them; the label plus a content check does not. +The sentinel is a **declaration**, not a copy of the data: the chart renders it at template time, so it exists in the Flux digest and is reconciled like any other chart object, even though the source Secret it names is created asynchronously by cert-manager or the DB operator long after render. Naming the source explicitly — rather than relying on a name convention or a label the operator must be coaxed into stamping — is what keeps the mechanism engine-agnostic: the CA-bearing Secret names are non-uniform (`-ca`, `-ca-tls`, `-http-ca`, `-ca-cert`) and `-ca-cert` is overloaded (key-free for the redis fork, key-bearing for PSMDB), and the declaration accommodates all of them because the chart author who knows the source name simply writes it down. It also dissolves the label design's release-attribution problem: cert-manager runs with `enableCertificateOwnerRef: false`, so a cert-manager-issued Secret carries no ownerReference back to its application and the label leg had to add a separate `-release` label to say which release it belonged to; the sentinel is itself a chart object in the release's namespace, attributed to its release the same way every chart object is (see (c)), so no such marker is needed. -**(b) A small extraction controller.** Its watch/upsert skeleton can follow the wildcard-secret reconciler from PR `cozystack/cozystack#2990` (`internal/controller/wildcardsecret/reconciler.go`), but it carries none of that reconciler's copy-marking or prune logic — lineage provides those (part (c)) — and, being **intra-namespace**, it can do something that reconciler cannot. For each selected source Secret it upserts a `type: Opaque` Secret named `.tenant-ca` containing **only** `ca.crt`, re-copying on every source change so a CA rotation propagates without a chart re-render. It does four security-load-bearing things and nothing more: +**(b) A small extraction controller reconciles the sentinel.** The controller watches `TenantProjection` objects (not Secret labels) and the source Secrets they name. For each `CACert` projection it upserts a `type: Opaque` Secret named `.tenant-ca` containing **only** `ca.crt`, re-copying on every source change so a CA rotation propagates without a chart re-render. Its watch/upsert skeleton can follow the wildcard-secret reconciler from PR `cozystack/cozystack#2990` (`internal/controller/wildcardsecret/reconciler.go`), but it carries none of that reconciler's copy-marking or prune logic — ownership and lineage provide those (part (c)). It does four security-load-bearing things and nothing more: -- **Key off the label and the content, never the name.** Select sources by the `publish-ca-cert` label; before writing, verify the lifted value is a CA certificate and carries no `-----BEGIN … PRIVATE KEY-----` header. This is what lets one controller serve a key-free redis source it should ignore and a key-bearing PSMDB source it must strip, both named `-ca-cert`-adjacent, without confusion. -- **Tolerate operator-created, asynchronous sources.** The source may be created by the CNPG or PSMDB operator after the chart renders (not just by cert-manager). The controller waits on the watch event for the labeled source; it does not assume the chart owns the Secret and does not error or busy-loop before the source exists. +- **Read the source the sentinel names, and check its content.** Read only the Secret named in `sourceSecretName`, lift only `sourceKey`, and before writing verify the lifted value is a CA certificate carrying no `-----BEGIN … PRIVATE KEY-----` header. The sentinel says *which* Secret; the content check says *whether to strip* — which is what lets one controller straight-copy a key-free redis source and strip a key-bearing PSMDB source without confusing the two, even though both sit under `-ca-cert`-adjacent names. +- **Tolerate operator-created, asynchronous sources.** The named source may be created by the CNPG or PSMDB operator (or by cert-manager) after the chart renders. The controller waits on the watch event for that source; it does not assume the chart owns the Secret and does not error or busy-loop before the source exists. The sentinel exists from render time, so there is always a durable declaration to reconcile against — and to carry status (part (e)) — while the source is still missing. - **Sanitize at write time, not just render time.** The `cozy-lib.tls.caCertSecret` helper's fail-closed guard runs at *chart-render* time; this controller writes at *runtime*, so it must itself copy only the single `ca.crt` key (an explicit whitelist) and re-assert the no-private-key check on every write. It never copies the whole `Data`. -- **Owner-ref the projected Secret to the release's `HelmRelease`.** An earlier revision of this document said to owner-ref the application instance CR; that is not implementable. The `apps.cozystack.io` kinds are virtual — served by the aggregated apiserver, and a tenant application is *stored* as a `HelmRelease` whose `spec.values` is the application spec verbatim — so there is no application object in etcd and therefore no UID to reference. The `HelmRelease` is the only real object in the chain, and it is enough: deleting the application through the aggregated API deletes the `HelmRelease`, which garbage-collects the projection with it. This is where intra-namespace beats the `cozystack/cozystack#2990` reconciler, which tracks its replicas by a management label plus a back-reference annotation *because* a cross-namespace replica cannot carry a valid `ownerReference`. Our projection is same-namespace, so a real owner-reference is valid and the controller needs no prune logic of its own. `blockOwnerDeletion` stays false: a trust anchor must never delay the teardown of the application it belongs to. (It does not owner-ref the *source* `-ca`: cert-manager and the DB operators do not own their output Secrets, so a walk from the source would dead-end before the app.) +- **Owner-ref the projected Secret to the sentinel.** The projection takes an `ownerReference` to the `TenantProjection` that declared it — not to the application-instance CR, and not to the `HelmRelease` directly. The application-instance CR cannot be referenced: the `apps.cozystack.io` kinds are virtual — served by the aggregated apiserver, with a tenant application *stored* as a `HelmRelease` whose `spec.values` is the application spec verbatim — so there is no application object in etcd and no UID to point at. The sentinel, by contrast, is a real chart-rendered object in the same namespace, so a real owner-reference is valid and garbage collection is native (part (c)). `blockOwnerDeletion` stays false: a trust anchor must never delay the teardown of the application it belongs to. (The projection does not owner-ref the *source* CA Secret: cert-manager and the DB operators do not own their output Secrets, so a walk from the source would dead-end before reaching the app.) + +**(c) Attribution, lineage, and garbage collection: the sentinel is a plain chart object.** The sentinel itself carries **no** `ownerReferences`. Flux stamps every object it renders with the `helm.toolkit.fluxcd.io/name` label naming the release, and that label — not an owner-reference — is how the sentinel is attributed to its release, exactly as for any chart-rendered object. So the lineage walk resolves the chain **Secret → sentinel → HelmRelease → application** with no change to the webhook: the projected Secret owner-refs the sentinel, the sentinel's release label names the `HelmRelease`, and the `HelmRelease` backs the application. Garbage collection is native and needs no delete path in the controller: deleting the application deletes the `HelmRelease`, Flux prunes the chart's objects including the sentinel, and Kubernetes then garbage-collects the projection the sentinel owns. Marking the projection tenant-visible is unchanged from §4 — the controller stamps `internal.cozystack.io/tenant-ca: "true"` on it, one generic `ApplicationDefinition.spec.secrets.include` entry (`matchLabels: {internal.cozystack.io/tenant-ca: "true"}`) matches it by label (`internal/lineagecontrollerwebhook/matcher.go`), and the lineage webhook then walks the projection's owner chain and authoritatively stamps `internal.cozystack.io/tenantresource` to `true` (and to `false` should the Secret ever stop matching). + +**(d) Admission: the sentinel's writer is pinned to helm-controller.** A ValidatingAdmissionPolicy pins writes of `TenantProjection` to Flux's helm-controller service account (`system:serviceaccount:cozy-fluxcd:helm-controller`), so the only way a sentinel enters the cluster is by being rendered into a release. This is **defense-in-depth**, not the primary control: `internal.cozystack.io` resources are already not tenant-writable by RBAC, so a tenant cannot create a sentinel to aim the controller at an arbitrary Secret. The VAP makes that guarantee explicit at admission and narrows the writer to exactly the principal that renders charts. -**(c) Marking stays in `spec.secrets`, by label not by name.** Because `ApplicationDefinition.spec.secrets.include` accepts a label selector (`internal/lineagecontrollerwebhook/matcher.go`), one generic entry — `matchLabels: {internal.cozystack.io/tenant-ca: "true"}`, stamped by the controller on every projected Secret — covers every engine with no per-release `resourceName` templating. The lineage admission webhook then does the rest: on admission it walks the projected Secret's `ownerReferences` to the owning application and authoritatively stamps `internal.cozystack.io/tenantresource` to `true` (and to `false` should the Secret ever stop matching). +**(e) A broken declaration is observable.** The sentinel carries `status.conditions`, and the controller sets `Ready`. When a declaration cannot be satisfied — the named source Secret does not exist, or an upstream bump renames the CA Secret out from under `sourceSecretName` — the controller records `Ready=False, Reason=SourceNotFound` on the sentinel. This is a concrete advantage over the label design, which had no object to carry status: there, a source that never appeared could only make the controller requeue silently, invisible until someone noticed the trust anchor was missing. With the sentinel the failure is a queryable condition on a named object — alertable, and pointing at the exact broken release. -What this *reuses* rather than rebuilds: the label selector in `ApplicationDefinition.spec.secrets` (`internal/lineagecontrollerwebhook/matcher.go`), the lineage webhook's owner-reference walk and authoritative `tenantresource` stamping (`internal/lineagecontrollerwebhook/webhook.go`, `pkg/lineage/lineage.go`), the private-key guard in `cozy-lib.tls.caCertSecret` (`packages/library/cozy-lib/templates/_tls.tpl`), and native Kubernetes garbage collection via the owner reference on the `HelmRelease`. The irreducibly new work is the extraction step itself — read one key, write a key-free copy, re-copy on rotation — the same job an operator does natively on the engines that already ship a key-free CA object (kafka's `-clients-ca-cert`, the redis fork's `-ca-cert`) — those two still need the projection, because their CA lands under an engine-specific name rather than the canonical one; for them the extraction step is a straight copy, with nothing to strip. +What this *reuses* rather than rebuilds: Flux's release-name label and its native pruning (for attribution and garbage collection), the lineage webhook's owner-reference walk and authoritative `tenantresource` stamping (`internal/lineagecontrollerwebhook/webhook.go`, `pkg/lineage/lineage.go`), the label selector in `ApplicationDefinition.spec.secrets` (`internal/lineagecontrollerwebhook/matcher.go`), and the private-key guard in `cozy-lib.tls.caCertSecret` (`packages/library/cozy-lib/templates/_tls.tpl`). The irreducibly new work is the `TenantProjection` sentinel and the extraction step that reconciles it — read one key from the named source, write a key-free copy, re-copy on rotation, report readiness — the same job an operator does natively on the engines that already ship a key-free CA object (kafka's `-clients-ca-cert`, the redis fork's `-ca-cert`). Those two still declare a sentinel, because their CA lands under an engine-specific name rather than the canonical one; for them the extraction step is a straight copy, with nothing to strip. ### 6. Per-engine application order -`postgres` goes first (under the tracking issue `cozystack/cozystack#2814`): it is the engine the epic most wants to see converged, and it exercises the controller against the hardest input — an **operator-created, asynchronous** CA Secret — so validating it there validates the mechanism everywhere. Convergence for postgres means publishing a key-free `.tenant-ca` extracted from CNPG's key-bearing `-ca`, while leaving the passwords-only `-credentials` untouched. `kafka` is already at the target and needs only documentation. `redis` (`cozystack/cozystack#2729`) converges by shape adaptation: its forked operator self-publishes a key-free `-ca-cert` via `caCertSecretName`, which the controller copies verbatim into the canonical `.tenant-ca` — a straight copy with nothing to strip, the same treatment kafka gets. `mongodb`, then the cert-manager-minting engines (nats, qdrant, and then rabbitmq, mariadb, opensearch) adopt the controller via the source label. `kubernetes` (Kamaji) is explicitly out. +`postgres` goes first (under the tracking issue `cozystack/cozystack#2814`): it is the engine the epic most wants to see converged, and it exercises the controller against the hardest input — an **operator-created, asynchronous** CA Secret — so validating it there validates the mechanism everywhere. Convergence for postgres means publishing a key-free `.tenant-ca` extracted from CNPG's key-bearing `-ca`, while leaving the passwords-only `-credentials` untouched. `kafka` is already at the target and needs only documentation. `redis` (`cozystack/cozystack#2729`) converges by shape adaptation: its forked operator self-publishes a key-free `-ca-cert` via `caCertSecretName`, which a sentinel names as its source so the controller copies it verbatim into the canonical `.tenant-ca` — a straight copy with nothing to strip, the same treatment kafka gets. `mongodb`, then the cert-manager-minting engines (nats, qdrant, and then rabbitmq, mariadb, opensearch) converge by declaring a `TenantProjection` sentinel that names their CA Secret. `kubernetes` (Kamaji) is explicitly out. ## User-facing changes @@ -184,35 +204,36 @@ The trust boundary is precise: a tenant receives `ca.crt` and never receives `tl No merged engine leaks a private key to a tenant today. The merged charts withhold their key-bearing Secrets, and the tenant-facing objects (postgres `-credentials`, the nats/qdrant credentials Secrets) are passwords-only. The live instance of the risk is not in `main` — it is in the **in-flight per-app PRs**, several of which currently propose labelling a key-bearing Secret to tenants: mariadb (`cozystack/cozystack#2680`) projects the CA private key `-ca-tls`, mongodb (`cozystack/cozystack#2692`) projects the key-bearing `-ca-cert`, and rabbitmq (`cozystack/cozystack#2683`) and opensearch (`cozystack/cozystack#2682`) project the leaf key. This contract exists to stop them landing that way; the consume object and the extraction controller are what let those PRs deliver `ca.crt` without the key. -Two consequences for the controller. First, it writes at runtime, after chart-render, so it cannot lean on the helper's render-time guard alone: it must whitelist the single `ca.crt` key and re-assert the no-private-key check itself on every write. Second, it adds a new trust surface — read access to per-release CA Secrets, write access for the key-free copy — and must never overwrite a Secret it did not create, surfacing any name collision as a Warning Event rather than failing silently. +Two consequences for the controller. First, it writes at runtime, after chart-render, so it cannot lean on the helper's render-time guard alone: it must whitelist the single `ca.crt` key and re-assert the no-private-key check itself on every write. Second, it adds a new trust surface — read access to per-release CA Secrets, write access for the key-free copy — and must never overwrite a Secret it did not create, surfacing any name collision as a Warning Event rather than failing silently. The declaration that drives it is itself locked down: writes of the `TenantProjection` sentinel are pinned by a ValidatingAdmissionPolicy to Flux's helm-controller (`system:serviceaccount:cozy-fluxcd:helm-controller`), so a tenant cannot forge a declaration aiming the controller at a Secret of their choosing — defense-in-depth on top of RBAC, which already denies tenants write access to `internal.cozystack.io`. ## Failure and edge cases - The helper's input PEM contains a private-key header → render fails closed; the chart does not deploy a key-bearing Secret. - The source `ca.crt` somehow carries a private-key header at runtime → the controller refuses to write the copy (runtime whitelist plus guard); no key-bearing Secret is ever projected. -- The labeled source is a key-free Secret that should be left alone (a self-publishing engine mis-stamped) → the content check sees no private key to strip and the controller still writes only `ca.crt`; no key is ever exposed. -- The per-release CA Secret does not exist yet (operator-created, asynchronous) → the controller waits for the watch event on the labeled source; it does not error or busy-loop. +- The sentinel names a key-free source that should be left alone (a self-publishing engine) → the content check sees no private key to strip and the controller still writes only `ca.crt`; no key is ever exposed. +- The named source Secret does not exist yet (operator-created, asynchronous) → the controller waits for the watch event on that source and records `Ready=False, Reason=SourceNotFound` on the sentinel meanwhile; it does not error or busy-loop. +- An upstream bump renames the CA Secret out from under `sourceSecretName` → the source never reappears under the declared name, and the sentinel surfaces `Ready=False, Reason=SourceNotFound` — a queryable, alertable condition rather than a silent requeue. - A foreign Secret already occupies the target name → the controller leaves it untouched (management-label guard) and emits a Warning Event on the application, so the operator sees the collision. - The CA rotates → the controller re-copies `ca.crt` on the next source change; no chart re-render is required. -- The application is deleted → the projected `.tenant-ca` is garbage-collected by Kubernetes via its owner reference to the `HelmRelease` that backs the application; the controller needs no delete path. +- The application is deleted → Flux prunes the sentinel with the rest of the chart's objects, and Kubernetes garbage-collects the projected `.tenant-ca` via its owner reference to the sentinel; the controller needs no delete path. ## Testing - The helper is already covered by `packages/tests/cozy-lib-tests/tests/tls_cacert_test.yaml`, including the fail-closed assertions. -- The extraction controller gets an envtest/Ginkgo suite (its skeleton mirrors `internal/controller/wildcardsecret/reconciler_test.go`): a labeled source appearing after the consumer (cert-manager and operator-created), a source whose `ca.crt` is swapped (rotation), a key-free source that must be left byte-for-byte (no spurious rewrite), a key-bearing source that must be stripped to `ca.crt`, a foreign-name collision (asserting the Secret is untouched and a Warning Event is emitted), a source value that smuggles a private-key header (asserting the controller refuses to write), and owner-reference-driven garbage collection on app deletion. -- Each per-app pull request adds helm-unittest fixtures asserting the `.tenant-ca` shape and label, plus an end-to-end check under `hack/e2e-apps/` that a tenant can read `ca.crt`, cannot read any object carrying `tls.key`, and can verify the server. +- The extraction controller gets an envtest/Ginkgo suite (its skeleton mirrors `internal/controller/wildcardsecret/reconciler_test.go`): a sentinel whose named source appears after it (cert-manager and operator-created), a source whose `ca.crt` is swapped (rotation), a key-free source that must be left byte-for-byte (no spurious rewrite), a key-bearing source that must be stripped to `ca.crt`, a foreign-name collision (asserting the Secret is untouched and a Warning Event is emitted), a source value that smuggles a private-key header (asserting the controller refuses to write), a sentinel whose source never appears (asserting `Ready=False, Reason=SourceNotFound` on `status.conditions`), and owner-reference-driven garbage collection of the projection when the sentinel is pruned. +- Each per-app pull request adds helm-unittest fixtures asserting the chart renders the `TenantProjection` sentinel with the right `sourceSecretName`, and asserting the projected `.tenant-ca` shape and label, plus an end-to-end check under `hack/e2e-apps/` that a tenant can read `ca.crt`, cannot read any object carrying `tls.key`, and can verify the server. +- A VAP admission fixture asserts a `TenantProjection` write from a principal other than `system:serviceaccount:cozy-fluxcd:helm-controller` is rejected. ## Rollout 1. Edge — `cozystack/cozystack#2988` and `cozystack/cozystack#2989` merged; per-tenant propagation `cozystack/cozystack#2990` still open. 2. This contract — accepted. -3. Extraction controller — implemented and tested. +3. Sentinel CRD and extraction controller — implemented and tested. 4. Per-app convergence — postgres first (tracked by `cozystack/cozystack#2814`), then the remaining per-app TLS pull requests onto the contract. ## Open questions -- **Labelling operator-created sources.** The cert-manager charts stamp the source label via `Certificate.spec.secretTemplate.labels`. Operators that create the CA Secret themselves (CNPG `-ca`, PSMDB `-ca-cert`) may not let the chart label their output. For those, the controller needs either an operator that supports output labels or a small per-engine source-name configuration as a fallback — this is the one place the engine-agnostic label is not yet sufficient, and it should be resolved before postgres/mongodb convergence. -- The exact namespace convention for the `.tenant-ca` object (per-release in the app namespace is assumed here) and the final label/annotation names. This proposal uses `internal.cozystack.io/publish-ca-cert` and `internal.cozystack.io/publish-ca-cert-release` on the source and `internal.cozystack.io/tenant-ca` on the projected copy, matching the `internal.cozystack.io/` convention of the existing `tenantresource` and `managed-by-cozystack` markers. +- The exact namespace convention for the `.tenant-ca` object (per-release in the app namespace is assumed here) and the final names of the new API. This proposal uses the working name `TenantProjection` in group `internal.cozystack.io` for the sentinel and `internal.cozystack.io/tenant-ca` on the projected copy, matching the `internal.cozystack.io/` convention of the existing `tenantresource` and `managed-by-cozystack` markers; the group, kind, and the `spec.projections[].type` vocabulary are not yet frozen. - How this intersects with per-tenant wildcard propagation (issue `cozystack/cozystack#2820`, implemented by PR `cozystack/cozystack#2990`). That is a *cross-namespace* replication problem; the extraction controller here is *intra-namespace, per-release*, so the two do not share a mechanism — but they should share the management-label and foreign-collision conventions. Note that `clustersecret-operator` is packaged in the repo but is not wired into a default bundle, so it is not an installed primitive this design can assume. ## Alternatives considered @@ -223,7 +244,8 @@ Two consequences for the controller. First, it writes at runtime, after chart-re - **Forking each upstream operator (the redis path) to emit a key-free CA.** Rejected as the general mechanism: it works for redis because the fork is small, but applying it to CloudNativePG, PSMDB, mariadb-operator, opster, and the rabbitmq cluster-operator is far more surface to own than one engine-agnostic controller. - **cert-manager `trust-manager`.** Considered and rejected as the mechanism, recorded as the validating prior art. trust-manager is the canonical "watch a CA source, materialize a key-free copy, never touch `tls.key`" operator and confirms the copy-model is the mainstream choice for trust-anchor distribution. But it does not fit operationally: its `Bundle`/`ClusterBundle` is cluster-scoped and fans out to namespaces by selector (not one object per release); it reads its sources from its own trust namespace, not from an arbitrary per-release tenant namespace; and it targets ConfigMaps first (Secret targets are opt-in). Modelling per-release, intra-namespace extraction on it would mean one cluster-scoped Bundle per database release reading a source it cannot natively see — against the grain. The small intra-namespace controller is a better fit. - **External Secrets Operator (kubernetes provider).** The closest prior art of the copy-model options, and mechanically sound end-to-end: a `SecretStore` with `provider.kubernetes` plus a per-release `ExternalSecret` selecting a single key (`data[].remoteRef.property: ca.crt`, not `dataFrom`) materializes exactly the key-free `.tenant-ca` object. Selecting one property is a structural no-private-key whitelist, `target.template` stamps the marker label, `refreshInterval` tolerates the operator-created asynchronous source, and the chart renders a *declaration* of the projection rather than its data — sidestepping the async/render-time wall the same way the controller does. The lineage chain resolves too: ESO owner-refs its output Secret to the `ExternalSecret`, itself a chart-rendered object, so the ownership walk reaches the owning application the way it does for any chart object, and garbage collection follows. Not adopted as the mechanism for one operational reason and two costs: ESO is packaged but **opt-in** — `cozystack.external-secrets-operator` renders only when listed in `bundles.enabledPackages`, which defaults to empty (`packages/core/platform/values.yaml`) — so the platform's trust-anchor contract would hinge on a component an operator may not run, and adopting it means first promoting ESO to a required, always-on platform dependency; each consuming namespace needs a `SecretStore` plus a ServiceAccount with read access to source Secrets (a per-namespace privileged-read fan-out the intra-namespace controller does not add); and refresh is poll-based (`refreshInterval`) where the controller is watch-driven, so rotation propagation is bounded by the polling period. If ESO later graduates to a default platform component, it is the natural retirement path for the extraction controller — recorded with the same status as the field-filter below. -- **A name-convention CA-distribution controller** (the controller watches `-ca` because its name is deterministic, and carries its own marking, garbage-collection, and collision guard). Rejected in favor of §5's explicit source label plus lineage reuse: the CA Secret names are non-uniform and `-ca-cert` is overloaded across engines, so a name convention would mis-handle at least one; and the marking/GC it re-implements is already provided by `spec.secrets` and owner references. +- **A source-selection label on the CA Secret (the earlier design of this proposal, superseded).** The owner stamped `internal.cozystack.io/publish-ca-cert` on its CA Secret and the controller selected sources by that label. It was adopted first, then replaced by the declared `TenantProjection` sentinel of §5 after an API-owner review (`cozystack/cozystack#3299`) found it emulates object semantics: a label carries no name, no status, and no admission surface of its own, so a broken declaration could only requeue silently, and the release a cert-manager Secret belonged to had to be supplied by a second `-release` label because the Secret carried no ownerReference. The declared sentinel is the chosen mechanism — a first-class namespaced object with `status.conditions`, a VAP-pinned writer, and a source named **by name** rather than by label. Declaring the source by name also closes this proposal's former open question "Labelling operator-created CA sources": CNPG and PSMDB need not label their operator-created output at all, because the chart names that Secret in the sentinel's `sourceSecretName`. The implementation briefly carried a second discovery leg alongside the label — a `spec.caCert` field on the cluster-scoped, per-kind `ApplicationDefinition` — with the mirror-image flaw: a cluster-scoped object standing in for a per-namespace, per-release fact. Both legs collapse into the single namespaced sentinel. +- **A name-convention CA-distribution controller** (the controller watches `-ca` because its name is deterministic, and carries its own marking, garbage-collection, and collision guard). Rejected in favor of §5's declared sentinel plus lineage reuse: the CA Secret names are non-uniform and `-ca-cert` is overloaded across engines, so a name convention would mis-handle at least one; the sentinel names the source explicitly instead, and the marking/GC it re-implements is already provided by `spec.secrets` and owner references. - **A field filter on the projection itself (the principled root fix — deferred to its own proposal).** Today `tenantsecrets` delivers the whole Secret `Data`, which is the only reason a key-free *copy* must be materialized at all. A per-key field filter on the projection (or the `spec.secrets` selector) would let a single `ca.crt` key be projected straight out of a key-bearing Secret — no controller, no second object — and would generalize to the operator-owned engines. It is **not** a local change, which is why it is deferred rather than adopted here: the projection is **writable** at the registry level (`pkg/registry/core/tenantsecret/rest.go` implements Create/Update/Patch/Delete), and the write path (`tenantToSecret`) replaces the underlying Secret's `Data` **wholesale** (`out.Data = ts.Data`). A read-side key filter without a matching write-side filter would, the moment any principal with write access used the filtered view, silently drop the keys it could not see. Tenant roles grant only `get/list/watch` today, but that read-only posture lives in a different package (`packages/system/cozystack-basics` clusterroles), so a field filter's safety is entangled with a write path and an RBAC posture defined elsewhere. That makes it a redesign of the tenant-secret API with its own blast-radius analysis — a separate design proposal — not a rider on the TLS rollout. Recorded here as the future simplification the extraction controller could later retire, explicitly **not** a dependency of this proposal. - **A native `ClusterTrustBundle` (KEP-3257).** Considered, recorded as the direction Kubernetes itself is taking for trust anchors (cluster-scoped, world-readable, public-only by construction — the API server rejects PEM with a private key — with central rotation). It does not fit this use case: it is consumed through the pod-mount `clusterTrustBundle` volume projection, whereas a Cozystack tenant reads `.tenant-ca` as a named Secret object through the dashboard and `tenantsecrets`. Different consumer model; a copy object is what an object-by-name consumer needs. - **A general-purpose cluster-secret replication operator / a copy-issuer webhook.** Rejected during the edge work (`cozystack/cozystack#2990`, `cozystack/cozystack#2812`) in favor of native references and a purpose-built reconciler with a tight ownership guard that move only the Secret name, never key material.