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 4b2507b
Browse filesBrowse the repository at this point in the historyBrowse files
The comment on the shared CEL string said what the hostname requirement
is but not what it is worth per kind. Two of the three schemas leave
spec.hostnames optional at every version the vendored bundle serves,
so for HTTPRoute and GRPCRoute this policy is the only rejection a
hostname-less route meets; tlsroutes requires the field at v1 and
v1alpha3 and not at v1alpha2, so there the policy closes the gap for
as long as v1alpha2 is served. State that where the requirement is
stated.
The comment on the port-80 allowedRoutes filter credited the
cert-manager namespace entry for letting ACME complete, which the
paragraph above it retracts: the solver route lives in the tenant
namespace, and that is what keeps ACME working. The same sentence
claimed the filter keeps app routes off port 80, and the Layer 1
paragraph of the gateway README claimed it too. It does not. A tenant
that owns its Gateway is its own gateway namespace, so its app routes
are admitted by this very filter; what it excludes is cozy-* and
inheriting children. Both copies now say that.
Nothing said why naming the apex on the redirect costs no coverage,
which is the question a reader has once the route stops matching every
host. It holds because of the other half of this change: the port-80
listener admits routes only from the tenant namespace and
cert-manager's, and the tightened route policy requires every route
there to declare hostnames inside the apex. An inheriting child does
not widen that set either, and the comment now says so at the point
the hostnames are chosen: the gateway hostname policy compares every
listener against the host label of the Gateway's own namespace, so a
child apex outside it never gets its listener, the Gateway write
carrying it being refused at admission whole, in reconcileGateway and
before this route is rendered, while a child apex under this one
passes that check and the wildcard already covers it.
The empty-apex guard in renderHTTPRedirect, and the test pinning it,
both read as though the guard is what spares an operator an unreadable
schema error. It is, but the condition stated for it named the number
of attached routes, which does not enter into it. In HTTP-01 the
listener set is built from route hostnames alone, so reconcileGateway
never reads the apex ahead of the guard however many routes attach.
DNS-01 and existingSecret render an apex listener, and any
tlsPassthroughServices entry builds <service>.<apex>, so in those the
operator meets the equivalent error against the Gateway first. State
that condition once, at the guard, and let the test defer to it rather
than carry a second copy that can drift; the test stays green either
way because the fake client does not validate against the CRD schema.
The e2e suite explained omitting the TLSRoute empty-list probe by the
v1 schema rejecting an empty list. Both halves of that are true and
the conclusion does not follow: the probe runs at v1alpha2, which
marks spec.hostnames neither required nor minItems, so an empty list
reaches admission there exactly as an absent field does. What makes
the omission safe is that all three policies render one byte-identical
CEL string, so the HTTPRoute pair proves that term already.
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <[email protected]>
// HTTPRoute schema. That surfaces as an apiserver validation error
486
486
// naming the route rather than the field, which is a poor thing to
487
487
// hand an operator.
488
+
//
489
+
// This wins the race in HTTP-01 without tlsPassthroughServices: the
490
+
// listener set is built from route hostnames alone there, so however
491
+
// many routes are attached, reconcileGateway never reads the apex
492
+
// ahead of this point. DNS-01 and existingSecret render an apex
493
+
// listener, and any tlsPassthroughServices entry builds
494
+
// "<service>.<apex>", so in those the operator meets the equivalent
495
+
// schema error against the Gateway first.
488
496
iftgw.Spec.Apex=="" {
489
497
returnnil, fmt.Errorf("spec.apex is empty on TenantGateway %s/%s: the http-to-https redirect route derives its hostnames from the apex and cannot be rendered without one", tgw.Namespace, tgw.Name)
Copy file name to clipboardExpand all lines: packages/extra/gateway/README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -103,7 +103,7 @@ The protections below split into three groups by who they defend against:
103
103
-**Defense-in-depth** — Layers 1, 2, 5, 6, 7, 8. These do not protect against tenant-user input (tenants don't hold the relevant RBAC). They guard against bugs in cozystack-controller / Flux, supply-chain compromise of an app chart that emits Gateway API or Ingress resources, and confused-deputy mistakes by a cluster admin. Fail-closed via `failurePolicy: Fail` + `validationActions: [Deny]`. Layers 1-7 cover the opt-in Gateway API dataplane; Layer 8 covers the legacy Ingress dataplane, which is the default (Gateway API is off by default).
104
104
-**Admin-against-themselves** — Layer 3 (`cozystack-gateway-attached-namespaces-policy`). Rejects a `kubectl edit packages.cozystack.io` that would slip a `tenant-*` entry into the platform Package's `gateway.attachedNamespaces`. Layer 6 catches the same misconfiguration at helm render time.
105
105
106
-
1. **Namespace whitelist on listeners.** Every listener carries an `allowedRoutes.namespaces.from: Selector`, and there are two of them. The plain-HTTP port-80 listener selects on the built-in `kubernetes.io/metadata.name` label, which kube-apiserver writes and a namespace cannot forge. The HTTPS-terminate and TLS-passthrough listeners select on `namespace.cozystack.io/gateway`, which is an ordinary namespace label written by the `apps/tenant` chart and by the controller, so it carries no such guarantee on its own: what keeps a namespace from applying it and attaching is that `Namespace` is cluster-scoped and no tenant role grants a verb on it, and what such a namespace could publish if it did is bounded by the route-hostname policies of Layer 2. HTTPS / TLS-passthrough listeners accept routes from the publishing tenant's namespace plus `gateway.attachedNamespaces` in the platform chart, which the controller labels for exactly that purpose (the default list includes the `cozy-*` namespaces for platform services and `default` for the Kubernetes API TLSRoute). A namespace carrying neither the name match nor that label cannot attach any `HTTPRoute` or `TLSRoute` to those listeners. Under `certMode: edge` there are no HTTPS listeners to describe: the Gateway serves port 80 only, every listener carries the same broad selector, and the narrow port-80 rule stated further down this item does not apply — see [edge termination](#opt-in--edge-termination-no-certificates). Which class a tenant may put itself on is itself bounded: `tenant.spec.gatewayClass` is a tenant-writable field, so the gateway chart accepts only the platform default plus the classes listed in `gateway.tenantSelectableClasses`, and fails the tenant's own release otherwise. In every other mode: the plain-HTTP listener (port 80) carries a strictly narrower selector — only the tenant namespace itself and `cozy-cert-manager`. Both the controller-owned http→https redirect HTTPRoute and cert-manager's HTTP-01 challenge route live in the tenant namespace, the latter because cert-manager creates the Challenge, and with it the solver route, in the Certificate's own namespace; the `cozy-cert-manager` entry is not exercised by that path — so app HTTPRoutes attaching by hostname cannot bind to port 80 and serve plaintext. Every port-443 listener, HTTPS-terminate and TLS-passthrough alike, carries the same `allowedRoutes.kinds` of `HTTPRoute` and `TLSRoute` (cilium#45559 collapses port-443 listeners whose kinds diverge), which keeps GRPCRoute / TCPRoute / UDPRoute from attaching there. GRPCRoute reaches the port-80 listener instead, where the route-hostname VAP covers it; TCPRoute and UDPRoute carry no hostname.
106
+
1. **Namespace whitelist on listeners.** Every listener carries an `allowedRoutes.namespaces.from: Selector`, and there are two of them. The plain-HTTP port-80 listener selects on the built-in `kubernetes.io/metadata.name` label, which kube-apiserver writes and a namespace cannot forge. The HTTPS-terminate and TLS-passthrough listeners select on `namespace.cozystack.io/gateway`, which is an ordinary namespace label written by the `apps/tenant` chart and by the controller, so it carries no such guarantee on its own: what keeps a namespace from applying it and attaching is that `Namespace` is cluster-scoped and no tenant role grants a verb on it, and what such a namespace could publish if it did is bounded by the route-hostname policies of Layer 2. HTTPS / TLS-passthrough listeners accept routes from the publishing tenant's namespace plus `gateway.attachedNamespaces` in the platform chart, which the controller labels for exactly that purpose (the default list includes the `cozy-*` namespaces for platform services and `default` for the Kubernetes API TLSRoute). A namespace carrying neither the name match nor that label cannot attach any `HTTPRoute` or `TLSRoute` to those listeners. Under `certMode: edge` there are no HTTPS listeners to describe: the Gateway serves port 80 only, every listener carries the same broad selector, and the narrow port-80 rule stated further down this item does not apply — see [edge termination](#opt-in--edge-termination-no-certificates). Which class a tenant may put itself on is itself bounded: `tenant.spec.gatewayClass` is a tenant-writable field, so the gateway chart accepts only the platform default plus the classes listed in `gateway.tenantSelectableClasses`, and fails the tenant's own release otherwise. In every other mode: the plain-HTTP listener (port 80) carries a strictly narrower selector — only the tenant namespace itself and `cozy-cert-manager`. Both the controller-owned http→https redirect HTTPRoute and cert-manager's HTTP-01 challenge route live in the tenant namespace, the latter because cert-manager creates the Challenge, and with it the solver route, in the Certificate's own namespace; the `cozy-cert-manager` entry is not exercised by that path. That selector keeps routes from the other `cozy-*` namespaces and from inheriting child tenants off port 80; it does not keep off the publishing tenant's own app routes, which live in that same namespace and are admitted by it. Every port-443 listener, HTTPS-terminate and TLS-passthrough alike, carries the same `allowedRoutes.kinds` of `HTTPRoute` and `TLSRoute` (cilium#45559 collapses port-443 listeners whose kinds diverge), which keeps GRPCRoute / TCPRoute / UDPRoute from attaching there. GRPCRoute reaches the port-80 listener instead, where the route-hostname VAP covers it; TCPRoute and UDPRoute carry no hostname.
107
107
2.**`cozystack-gateway-hostname-policy`** — `ValidatingAdmissionPolicy` on `gateway.networking.k8s.io/v1 Gateway` CREATE/UPDATE. Reads `namespaceObject.metadata.labels["namespace.cozystack.io/host"]` and rejects any listener hostname that is not equal to that value or a subdomain of it. `matchConditions` gate the VAP to cozystack-managed namespaces only — Gateways in unrelated namespaces (e.g. `kube-system`) are not touched.
108
108
3.**`cozystack-gateway-attached-namespaces-policy`** — VAP on `cozystack.io/v1alpha1 Package` CREATE/UPDATE. Rejects any `tenant-*` entry in `spec.components.platform.values.gateway.attachedNamespaces`. Catches direct `kubectl edit packages.cozystack.io` that would bypass the helm render-time guard in layer 6.
109
109
4.**`cozystack-tenant-host-policy`** — VAP on `apps.cozystack.io/v1alpha1 Tenant` CREATE/UPDATE. Rejects setting or changing `spec.host` unless the caller's groups contain `system:masters`, `system:serviceaccounts:cozy-system`, `system:serviceaccounts:cozy-cert-manager`, `system:serviceaccounts:cozy-fluxcd` or `system:serviceaccounts:kube-system`. Closes the path where a tenant user sets `spec.host=dashboard.example.org` on their own tenant to have the tenant chart write a hijacked label into the namespace.
0 commit comments