You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a143c05
Browse filesBrowse the repository at this point in the historyBrowse files
docs(external-database-exposure): correct the admission enforcement point
A ValidatingAdmissionPolicy bound to the typed apps.cozystack.io kinds
does fire, contrary to the previous revision's claim. The kube-apiserver
proxies aggregated writes before its own admission chain, but the
aggregated cozystack-api is built on k8s.io/apiserver RecommendedOptions,
whose delegated admission chain includes the ValidatingAdmissionPolicy
plugin — the extension apiserver evaluates cluster VAPs itself. Verified
at runtime with a scoped deny-all canary policy matching
apps.cozystack.io tenants: it denies the typed-kind write exactly as it
denies a core-resource control, and the existing
cozystack-tenant-host-policy already relies on this path in production.
The plaintext-external rejection therefore ships as a VAP on the typed
kinds, consistent with the existing tenant-isolation policies, with
registry-level validation in cozystack-api as a complement rather than
the only option.
Assisted-By: Claude <[email protected]>
Signed-off-by: Aleksei Sviridkin <[email protected]>
Copy file name to clipboardExpand all lines: design-proposals/external-database-exposure/README.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -224,23 +224,23 @@ The default stays today's per-database LoadBalancer, so no existing external dat
224
224
225
225
The edge never holds the database's private key — the central strength of passthrough over termination. SNI is sent in cleartext on TLS 1.3 except under ECH, which database clients do not use, so the external hostname is observable on the wire; this is no worse than DNS or SNI exposure for any TLS service, and the payload stays encrypted end-to-end. A missing or mis-emitted SNI is a hard connection failure (a passthrough listener has no certificate to fall back to) — fail-closed, which is the secure default.
226
226
227
-
Exposing a database externally with TLS explicitly off is not silently corrected: when `tls.enabled` is left unset the tri-state turns TLS on together with `external`, but an explicit `tls.enabled: false` combined with `external: true` is **rejected at admission**, so a tenant cannot stand up a plaintext external endpoint by accident, and the conflict surfaces as a clear error rather than a silent override. Where that rejection binds deserves precision, because the obvious answer does not work: the database kinds (`apps.cozystack.io/v1alpha1` `Postgres`, `Redis`, …) are served by the **aggregated** `cozystack-api` apiserver, whose writes are proxied past the kube-apiserver admission chain — a `ValidatingAdmissionPolicy` on those typed kinds would never see the request. (The existing tenant-isolation VAPs in `packages/system/cozystack-basics` work because they bind to the *real* CRDs — `Gateway`, `HTTPRoute`, `TLSRoute` — and they enforce hostname isolation, not IP restrictions.) The enforcement point for this rule is therefore `cozystack-api` itself, which owns the typed kinds' write path and their conversion to HelmRelease values — the natural place for typed validation; a CEL policy on the underlying `HelmRelease` objects is the fallback if a policy-shaped guard is preferred. Cross-namespace `backendRef` requires a `ReferenceGrant`, consistent with the existing attached-namespaces model. Because trust rides the `ca.crt`-only object, clients never receive private key material.
227
+
Exposing a database externally with TLS explicitly off is not silently corrected: when `tls.enabled` is left unset the tri-state turns TLS on together with `external`, but an explicit `tls.enabled: false` combined with `external: true` is **rejected at admission**, so a tenant cannot stand up a plaintext external endpoint by accident, and the conflict surfaces as a clear error rather than a silent override. Where that rejection binds deserves precision: the database kinds (`apps.cozystack.io/v1alpha1` `Postgres`, `Redis`, …) are served by the **aggregated** `cozystack-api` apiserver, and the kube-apiserver proxies those writes *before* its own admission chain runs — so it is not kube-apiserver that enforces a policy there. A `ValidatingAdmissionPolicy` bound to the typed kinds still works, because `cozystack-api` is built on the generic apiserver library (`k8s.io/apiserver` `RecommendedOptions`), whose delegated admission chain includes the ValidatingAdmissionPolicy plugin — the extension apiserver evaluates cluster VAPs itself. Verified at runtime, not assumed: a scoped deny-all canary VAP matching `apps.cozystack.io` `tenants` fires on a live cluster exactly as it does on a core resource, and the existing `cozystack-tenant-host-policy` (`packages/system/cozystack-basics`) already relies on this path in production. So the rule ships as a VAP on the typed kinds, consistent with the existing tenant-isolation policies (which enforce hostname isolation — not IP restrictions — via VAPs on the Gateway API kinds and on `tenants`); registry-level validation in `cozystack-api`'s write path remains available as a belt-and-suspenders complement. Cross-namespace `backendRef` requires a `ReferenceGrant`, consistent with the existing attached-namespaces model. Because trust rides the `ca.crt`-only object, clients never receive private key material.
228
228
229
229
## Failure and edge cases
230
230
231
231
- A pre-PG17 (client or server) or non-direct-TLS Postgres client sends no SNI → no route → connection reset/timeout (document the symptom).
232
232
- Any MariaDB/MySQL client dials a passthrough listener → mutual deadlock (client waits for the server greeting, listener waits for a ClientHello) → timeout; prevented by never rendering a MariaDB listener (matrix exclusion).
233
233
- The 64-listener budget is exceeded → the listener is rejected; because listeners are one per engine type this is reached only through child-apex fan-out, and the mitigation is to split that subtree onto its own Gateway (until ListenerSet lands with Cilium 1.20).
234
234
- A flat `*.<apex>` passthrough listener is created on Cilium <1.20 → hostname overlap with the terminate listeners; routing does not isolate correctly. Prevented by the subdomain default; the flat scheme is gated on the platform reaching Cilium 1.20 (Rollout).
235
-
- An explicit `tls.enabled: false` together with `external: true` → rejected at admission in `cozystack-api` (see Security), not silently overridden; an unset `tls` tri-state auto-enables TLS with `external`.
235
+
- An explicit `tls.enabled: false` together with `external: true` → rejected at admission by a ValidatingAdmissionPolicy on the typed kind, evaluated in `cozystack-api`'s admission chain (see Security), not silently overridden; an unset `tls` tri-state auto-enables TLS with `external`.
236
236
- An operator expects multi-Gateway IP sharing → each Gateway still gets its own IP (expected under the Cilium constraint).
237
237
- A database is deleted → its per-release `TLSRoute` is removed; the shared engine-type listener is removed only when its last release is gone, so a single deletion never orphans a listener.
238
238
239
239
## Testing
240
240
241
241
- Helm-template assertions that the certificate SAN includes both `<release>.<engine>.<apex>` and `<release>.<apex>` per engine, mirroring the existing TLS test fixtures.
242
242
- A controller unit test that a `TLSPassthroughListeners` entry renders a shared listener on the native port with `mode: Passthrough`, the `*.<name>.<apex>` default hostname, and `AllowedRoutes` restricted to `TLSRoute`, and that two per-release `TLSRoute` objects on that one listener SNI-route to their respective backends.
243
-
- An admission test that `tls.enabled: false` with `external: true` is rejected in the `cozystack-api` write path, while an unset `tls` is admitted and auto-enables; and that the listener validation contract (name/port uniqueness, port range, 443 collision) is enforced.
243
+
- An admission test that `tls.enabled: false` with `external: true` is rejected by the typed-kind ValidatingAdmissionPolicy on the aggregated path, while an unset `tls` is admitted and auto-enables; and that the listener validation contract (name/port uniqueness, port range, 443 collision) is enforced.
244
244
- An end-to-end test per fitting engine: connect from outside the cluster with SNI and `ca.crt`, and assert that the serial of the presented certificate equals the operator-issued internal certificate — proving reuse, not re-issuance.
245
245
- A negative test: a client without SNI fails closed.
0 commit comments