Skip to content

Commit d624049

Browse files
committed
feat(gateway): allow tlsPassthroughListeners under dns01 and existingSecret
The refusal existed because Cilium 1.19.5 served every Gateway port from one Envoy listener matched by SNI alone, so the "*.<apex>" terminate listener of the wildcard modes and a passthrough listener under the apex could reach each other's backend. The shipped Cilium 1.20.2 gives each port its own Envoy listener when SNI overlaps across ports, and Gateway API treats listeners on different ports as compatible, so the pair is served as declared. edge still refuses the field: it renders no TLS listener for an entry to bind to. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent e1319b5 commit d624049

6 files changed

Lines changed: 78 additions & 116 deletions

File tree

‎api/gateway/v1alpha1/tenantgateway_types.go‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,10 @@ type TLSPassthroughListener struct {
184184
// native port (e.g. 5432 for PostgreSQL). Must be 1..65535, unique
185185
// across the list, and neither 80 nor 443 — the Gateway's own http
186186
// (80) and TLS-terminate (443) listeners already own those ports.
187-
// It is not an access boundary: on the Cilium version this
188-
// platform pins, the backend answers this listener's SNI on every
189-
// port the Gateway exposes, so the hostname is what gates reach.
187+
// It is not an access boundary: an implementation may serve every
188+
// port of the Gateway from one proxy listener matched by SNI alone,
189+
// and Cilium does so until the Gateway carries a configuration that
190+
// splits it per port, so the hostname is what gates reach.
190191
// +kubebuilder:validation:Minimum=1
191192
// +kubebuilder:validation:Maximum=65535
192193
// +required
@@ -246,7 +247,7 @@ type TLSPassthroughListener struct {
246247
// +kubebuilder:validation:XValidation:rule="!has(self.tlsPassthroughListeners) || self.tlsPassthroughListeners.all(l, self.tlsPassthroughListeners.filter(o, o.port == l.port).size() == 1)",message="tlsPassthroughListeners: each listener must occupy a distinct port"
247248
// +kubebuilder:validation:XValidation:rule="!has(self.tlsPassthroughListeners) || self.tlsPassthroughListeners.all(l, l.hostname == self.apex || l.hostname.endsWith('.' + self.apex))",message="tlsPassthroughListeners: hostname must equal the tenant apex or be a subdomain of it"
248249
// +kubebuilder:validation:XValidation:rule="!has(self.tlsPassthroughListeners) || !has(self.tlsPassthroughServices) || self.tlsPassthroughListeners.all(l, !(l.name in self.tlsPassthroughServices))",message="tlsPassthroughListeners: name collides with a tlsPassthroughServices entry; both render a tls-<name> Gateway listener"
249-
// +kubebuilder:validation:XValidation:rule="!has(self.tlsPassthroughListeners) || size(self.tlsPassthroughListeners) == 0 || !has(self.certMode) || self.certMode == 'http01'",message="tlsPassthroughListeners: supported with certMode http01 only; dns01 and existingSecret serve the tenant from one wildcard terminate listener that the pinned Cilium cannot keep apart from a passthrough listener under the same apex, and edge terminates TLS upstream and renders no TLS listener to sit beside"
250+
// +kubebuilder:validation:XValidation:rule="!has(self.tlsPassthroughListeners) || size(self.tlsPassthroughListeners) == 0 || !has(self.certMode) || self.certMode != 'edge'",message="tlsPassthroughListeners: unsupported with certMode edge, which terminates TLS upstream and renders no TLS listener to sit beside"
250251
type TenantGatewaySpec struct {
251252
// MaxLength is the DNS ceiling, so it rejects nothing resolvable,
252253
// and it is not cosmetic: it is one of the three bounds the

‎internal/controller/tenantgateway/crdcel_test.go‎

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,14 @@ func TestSpecCELMatchesControllerValidation(t *testing.T) {
210210
certMode: gatewayv1alpha1.CertModeHTTP01,
211211
},
212212
{
213-
name: "dns01 refuses a passthrough listener",
214-
listeners: []listener{{"postgres", 5432, "postgres.foo.example.com"}},
215-
certMode: gatewayv1alpha1.CertModeDNS01,
216-
wantReject: true,
213+
name: "dns01 accepts a passthrough listener",
214+
listeners: []listener{{"postgres", 5432, "postgres.foo.example.com"}},
215+
certMode: gatewayv1alpha1.CertModeDNS01,
217216
},
218217
{
219-
name: "existingSecret refuses a passthrough listener",
220-
listeners: []listener{{"postgres", 5432, "postgres.foo.example.com"}},
221-
certMode: gatewayv1alpha1.CertModeExistingSecret,
222-
wantReject: true,
218+
name: "existingSecret accepts a passthrough listener",
219+
listeners: []listener{{"postgres", 5432, "postgres.foo.example.com"}},
220+
certMode: gatewayv1alpha1.CertModeExistingSecret,
223221
},
224222
{
225223
name: "edge refuses a passthrough listener",
@@ -390,16 +388,14 @@ func TestSpecCELMatchesControllerValidation(t *testing.T) {
390388
// Ready.
391389
func TestEveryCertModeIsJudgedOnPassthroughListeners(t *testing.T) {
392390
// true means the mode renders TLS listeners a passthrough entry can
393-
// sit beside. Only http01 does: it publishes one terminate listener
394-
// per attached hostname, so a passthrough hostname is a name no
395-
// terminate listener answers. dns01 and existingSecret serve the
396-
// whole apex off one wildcard terminate listener that SNI-intersects
397-
// every entry this field can hold, and edge renders no TLS listener
398-
// at all.
391+
// sit beside. The entry has a port of its own, so the wildcard
392+
// terminate listener of dns01 and existingSecret on 443 SNI-overlaps
393+
// it without sharing a port, which Gateway API treats as compatible.
394+
// edge renders no TLS listener at all.
399395
verdicts := map[gatewayv1alpha1.CertMode]bool{
400396
gatewayv1alpha1.CertModeHTTP01: true,
401-
gatewayv1alpha1.CertModeDNS01: false,
402-
gatewayv1alpha1.CertModeExistingSecret: false,
397+
gatewayv1alpha1.CertModeDNS01: true,
398+
gatewayv1alpha1.CertModeExistingSecret: true,
403399
gatewayv1alpha1.CertModeEdge: false,
404400
}
405401

‎internal/controller/tenantgateway/reconciler_test.go‎

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3428,9 +3428,7 @@ func TestValidateTLSPassthroughListenersNamesTheSpecEntry(t *testing.T) {
34283428
//
34293429
// Only http01 is covered. dns01 and existingSecret serve the tenant
34303430
// from one wildcard terminate listener that cannot be withdrawn per
3431-
// hostname, which is why the field is refused there outright, and the
3432-
// same intersection between that listener and tlsPassthroughServices is
3433-
// recorded on cozystack/cozystack#3718.
3431+
// hostname, so they have no names beneath the wildcard to shed.
34343432
func TestReconcile_WildcardPassthroughWithdrawsTheNamesBeneathIt(t *testing.T) {
34353433
const published = "pg.db.foo.example.com"
34363434
s := newScheme(t)
@@ -6366,7 +6364,7 @@ func TestValidateTLSPassthroughListenersReportsApexBeforeOverlap(t *testing.T) {
63666364
// TestRenderGatewayReportsCertModeBeforeTheFieldRules pins the order of
63676365
// two refusals that can both fire on one spec.
63686366
//
6369-
// Under dns01 the field is refused whole, so a bad hostname inside it
6367+
// Under edge the field is refused whole, so a bad hostname inside it
63706368
// decides nothing and naming it sends the reader to edit a value that is
63716369
// not the reason the spec was rejected. Asserting only that the render
63726370
// fails would pass either way, so this asserts which error comes back.
@@ -6379,7 +6377,7 @@ func TestRenderGatewayReportsCertModeBeforeTheFieldRules(t *testing.T) {
63796377
ObjectMeta: metav1.ObjectMeta{Name: "cozystack", Namespace: "tenant-foo"},
63806378
Spec: gatewayv1alpha1.TenantGatewaySpec{
63816379
Apex: "foo.example.com",
6382-
CertMode: gatewayv1alpha1.CertModeDNS01,
6380+
CertMode: gatewayv1alpha1.CertModeEdge,
63836381
GatewayClassName: "cilium",
63846382
TLSPassthroughListeners: []gatewayv1alpha1.TLSPassthroughListener{
63856383
{Name: "pg", Port: 5432, Hostname: "pg.other.example.com"},
@@ -6525,10 +6523,8 @@ func selectsByNamespaceName(t *testing.T, ar *gatewayv1.AllowedRoutes) bool {
65256523
func TestPassthroughListenersMatchTheRenderedGateway(t *testing.T) {
65266524
const apex = "foo.example.com"
65276525
services := []string{"api", "vm-exportproxy"}
6528-
// The native-port listeners ride along under http01 alone:
6529-
// validatePassthroughListenerCertMode refuses the field under every
6530-
// other mode, so asking for them there fails the render instead of
6531-
// comparing sets.
6526+
// Edge refuses the native-port listeners, so asking for them there
6527+
// fails the render instead of comparing sets.
65326528
nativePort := []gatewayv1alpha1.TLSPassthroughListener{
65336529
{Name: "postgres", Port: 5432, Hostname: "postgres." + apex},
65346530
{Name: "kafka", Port: 9092, Hostname: "*.kafka." + apex},
@@ -6545,8 +6541,8 @@ func TestPassthroughListenersMatchTheRenderedGateway(t *testing.T) {
65456541
want int
65466542
}{
65476543
gatewayv1alpha1.CertModeHTTP01: {listeners: nativePort, want: len(services) + len(nativePort)},
6548-
gatewayv1alpha1.CertModeDNS01: {want: len(services)},
6549-
gatewayv1alpha1.CertModeExistingSecret: {wildcardSecret: true, want: len(services)},
6544+
gatewayv1alpha1.CertModeDNS01: {listeners: nativePort, want: len(services) + len(nativePort)},
6545+
gatewayv1alpha1.CertModeExistingSecret: {listeners: nativePort, wildcardSecret: true, want: len(services) + len(nativePort)},
65506546
gatewayv1alpha1.CertModeEdge: {want: 0},
65516547
}
65526548

@@ -6661,12 +6657,8 @@ func TestPassthroughListenersMatchTheRenderedGateway(t *testing.T) {
66616657
// listener sets, and pinning only the default one let the DNS-01 pair
66626658
// ("https" and "https-apex") share a struct undetected.
66636659
func TestReconcile_ListenerAllowedRoutesNotAliased(t *testing.T) {
6664-
// The layer-4 listeners ride along only in HTTP-01:
6665-
// validatePassthroughListenerCertMode refuses them under the
6666-
// wildcard modes, so asking for them here would fail the render
6667-
// instead of comparing pointers. DNS-01 keeps its own supply of
6668-
// listeners to compare, and the two port-443 passthrough ones among
6669-
// them are the class that carried the aliasing this test pins.
6660+
// The two port-443 passthrough listeners in the DNS-01 set are the
6661+
// class that carried the aliasing this test pins.
66706662
modes := []struct {
66716663
name string
66726664
mode gatewayv1alpha1.CertMode
@@ -6677,7 +6669,9 @@ func TestReconcile_ListenerAllowedRoutesNotAliased(t *testing.T) {
66776669
{Name: "postgres", Port: 5432, Hostname: "postgres.foo.example.com"},
66786670
{Name: "mysql", Port: 3306, Hostname: "mysql.foo.example.com"},
66796671
}},
6680-
{name: "DNS01", mode: gatewayv1alpha1.CertModeDNS01, childApexes: []string{"child.foo.example.com"}},
6672+
{name: "DNS01", mode: gatewayv1alpha1.CertModeDNS01, childApexes: []string{"child.foo.example.com"}, passthroughListener: []gatewayv1alpha1.TLSPassthroughListener{
6673+
{Name: "postgres", Port: 5432, Hostname: "postgres.foo.example.com"},
6674+
}},
66816675
}
66826676
for _, m := range modes {
66836677
t.Run(m.name, func(t *testing.T) {
@@ -6916,21 +6910,19 @@ func TestValidateTLSPassthroughListeners(t *testing.T) {
69166910
}
69176911
}
69186912

6919-
// TestValidatePassthroughListenerCertMode pins that the two wildcard
6920-
// certificate modes refuse a passthrough listener outright.
6913+
// TestValidatePassthroughListenerCertMode pins that only edge refuses a
6914+
// passthrough listener.
69216915
//
6922-
// Those modes serve the tenant from one terminate listener for
6923-
// "*.<apex>", and a passthrough hostname has to sit inside the apex, so
6924-
// the wildcard SNI-intersects every entry the field can hold. On the
6925-
// pinned Cilium the Gateway listener port does not survive translation
6926-
// into the Envoy filter-chain match, so the intersection is not academic:
6927-
// a connection on 443 for such a name reaches the passthrough backend.
6928-
// http01 renders per-hostname listeners instead, and the one a
6929-
// passthrough listener already answers is withdrawn.
6916+
// The wildcard terminate listener of dns01 and existingSecret sits on
6917+
// 443 and a passthrough listener on a port of its own. Gateway API
6918+
// treats listeners on different ports as compatible, and the shipped
6919+
// Cilium (v1.20.2) splits the Envoy listeners per port when their SNI
6920+
// overlaps (NeedsCrossProtocolSplit), so the two do not reach each other's
6921+
// backend. edge renders no TLS listener for an entry to bind to.
69306922
//
69316923
// The empty CertMode is the Go zero value, not a mode: the CRD defaults
6932-
// the field, so a stored object always carries one. Refusing only the two
6933-
// named modes keeps this check from inventing a third meaning.
6924+
// the field, so a stored object always carries one, and the render path
6925+
// reads its absence as http01.
69346926
func TestValidatePassthroughListenerCertMode(t *testing.T) {
69356927
one := []gatewayv1alpha1.TLSPassthroughListener{
69366928
{Name: "pg", Port: 5432, Hostname: "pg.foo.example.com"},
@@ -6941,11 +6933,12 @@ func TestValidatePassthroughListenerCertMode(t *testing.T) {
69416933
mode gatewayv1alpha1.CertMode
69426934
wantErr bool
69436935
}{
6944-
{"http01 renders per-hostname listeners", one, gatewayv1alpha1.CertModeHTTP01, false},
6945-
{"dns01 wildcard covers the hostname", one, gatewayv1alpha1.CertModeDNS01, true},
6946-
{"existingSecret wildcard covers the hostname", one, gatewayv1alpha1.CertModeExistingSecret, true},
6947-
{"dns01 without listeners", nil, gatewayv1alpha1.CertModeDNS01, false},
6948-
{"zero value is not a wildcard mode", one, "", false},
6936+
{"http01", one, gatewayv1alpha1.CertModeHTTP01, false},
6937+
{"dns01", one, gatewayv1alpha1.CertModeDNS01, false},
6938+
{"existingSecret", one, gatewayv1alpha1.CertModeExistingSecret, false},
6939+
{"edge renders no TLS listener", one, gatewayv1alpha1.CertModeEdge, true},
6940+
{"edge without listeners", nil, gatewayv1alpha1.CertModeEdge, false},
6941+
{"zero value is http01", one, "", false},
69496942
} {
69506943
t.Run(tc.name, func(t *testing.T) {
69516944
err := validatePassthroughListenerCertMode(tc.listeners, tc.mode)
@@ -6959,23 +6952,24 @@ func TestValidatePassthroughListenerCertMode(t *testing.T) {
69596952
}
69606953
}
69616954

6962-
// TestReconcile_TLSPassthroughListenerWildcardCertModeRejected proves the
6963-
// cert-mode restriction reaches the render path rather than sitting in a
6964-
// function nothing calls, and that it lets HTTP-01 through.
6955+
// TestReconcile_TLSPassthroughListenerCertModes proves the cert-mode
6956+
// rule reaches the render path rather than sitting in a function nothing
6957+
// calls: every TLS-terminating mode reconciles, edge fails.
69656958
//
6966-
// Both wildcard modes are given the configuration they need to render, so
6967-
// the cert-mode rule is the only thing that can fail the reconcile.
6968-
// Leaving DNS01 without its solver config makes the subtest pass on that
6969-
// error instead and stop testing this rule at all.
6970-
func TestReconcile_TLSPassthroughListenerWildcardCertModeRejected(t *testing.T) {
6959+
// Every mode is given the configuration it needs to render, so the
6960+
// cert-mode rule is the only thing that can fail the reconcile. Leaving
6961+
// DNS01 without its solver config would fail that subtest for another
6962+
// reason and stop testing this rule at all.
6963+
func TestReconcile_TLSPassthroughListenerCertModes(t *testing.T) {
69716964
for _, tc := range []struct {
69726965
name string
69736966
mode gatewayv1alpha1.CertMode
69746967
wantErr bool
69756968
}{
6976-
{"dns01", gatewayv1alpha1.CertModeDNS01, true},
6977-
{"existingSecret", gatewayv1alpha1.CertModeExistingSecret, true},
6969+
{"dns01", gatewayv1alpha1.CertModeDNS01, false},
6970+
{"existingSecret", gatewayv1alpha1.CertModeExistingSecret, false},
69786971
{"http01", gatewayv1alpha1.CertModeHTTP01, false},
6972+
{"edge", gatewayv1alpha1.CertModeEdge, true},
69796973
} {
69806974
t.Run(tc.name, func(t *testing.T) {
69816975
s := newScheme(t)

‎internal/controller/tenantgateway/renderers.go‎

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -282,56 +282,29 @@ const maxGatewayListeners = 64
282282
// they are built from are bounded separately from their sum.
283283
const maxGatewayNameLength = 253
284284

285-
// validatePassthroughListenerCertMode refuses passthrough listeners in
286-
// every certificate mode but http01.
285+
// validatePassthroughListenerCertMode refuses passthrough listeners
286+
// under edge, which ends TLS at the class provider and renders no TLS
287+
// listener for an entry to bind to.
287288
//
288289
// It judges the field against a sibling field rather than against
289290
// itself, which is why it is separate from
290-
// validateTLSPassthroughListeners. http01 publishes one terminate
291-
// listener per attached hostname, so a passthrough hostname is simply a
292-
// name no terminate listener answers. dns01 and existingSecret serve the
293-
// tenant from one terminate listener for "*.<apex>" on port 443 instead,
294-
// and a passthrough hostname has to sit inside the apex, so that
295-
// wildcard SNI-intersects every entry this field can hold. Suppression
296-
// cannot answer it either: those modes render no per-hostname listener
297-
// to withdraw, and the wildcard covers the whole apex. edge is refused
298-
// for the opposite reason — it ends TLS at the class provider and
299-
// renders no TLS listener at all, so the entry has nothing to bind to.
291+
// validateTLSPassthroughListeners. The wildcard "*.<apex>" terminate
292+
// listener of dns01 and existingSecret SNI-overlaps every entry, but on
293+
// another port: Gateway API treats listeners on different ports as
294+
// compatible, and the shipped Cilium (v1.20.2) gives each port its own
295+
// Envoy listener when their SNI overlaps (NeedsCrossProtocolSplit in
296+
// operator/pkg/model/model.go), so neither reaches the other's backend.
300297
//
301-
// The intersection matters because the Cilium this repo pins does not
302-
// keep the two apart. v1.19.5 collapses the Gateway into a single Envoy
303-
// listener, and toFilterChainMatch in
304-
// operator/pkg/model/translation/envoy_listener.go matches on
305-
// transport_protocol and server_names only, so the terminate chain for
306-
// "*.<apex>" and the passthrough chain for a name under it end up in one
307-
// listener with an exact match winning over the wildcard. Upstream
308-
// states the consequence above NeedsCrossProtocolSplit in
309-
// operator/pkg/model/model.go as of v1.19.6: a combined Envoy listener
310-
// "would otherwise erase the original Gateway listener port boundary and
311-
// route traffic for one listener to another". A TLS connection arriving
312-
// on 443 for that name reaches the database backend.
313-
//
314-
// v1.19.6 splits the Envoy listeners per port and this stops being
315-
// true, though not unconditionally: NeedsPerPortListeners requires
316-
// more than one HTTPS port, or more than one routed passthrough port,
317-
// or a cross-port SNI overlap. The passthrough side of every term is
318-
// counted from attached routes, so a listener with no TLSRoute behind
319-
// it contributes no port and no filter chain to any of the three, and
320-
// the listener is all this field creates: the split arrives with the
321-
// route rather than with the bump. The HTTPS side is not route-gated,
322-
// but this field adds nothing there.
323-
// Lifting the refusal for one of the wildcard modes means editing two
324-
// copies of it, this one and the matching CEL rule in the CRD, which is
325-
// a schema change even though no field or type moves. The pin is the
326-
// thing to watch: packages/system/cilium/images/cilium/Dockerfile.
298+
// Relaxing or tightening this means editing two copies, this one and
299+
// the matching CEL rule on TenantGatewaySpec.
327300
func validatePassthroughListenerCertMode(listeners []gatewayv1alpha1.TLSPassthroughListener, mode gatewayv1alpha1.CertMode) error {
328301
if len(listeners) == 0 {
329302
return nil
330303
}
331304
if rendersPassthroughListeners(mode) {
332305
return nil
333306
}
334-
return fmt.Errorf("tlsPassthroughListeners: unsupported with certMode %q; only http01 renders the per-hostname terminate listeners a passthrough hostname can sit beside. dns01 and existingSecret serve the whole apex from one wildcard terminate listener, and the pinned Cilium routes both by SNI alone in one Envoy listener, so a connection would reach the passthrough backend; edge terminates TLS at the class provider and renders no TLS listener at all", mode)
307+
return fmt.Errorf("tlsPassthroughListeners: unsupported with certMode %q; edge terminates TLS at the class provider and renders no TLS listener at all", mode)
335308
}
336309

337310
// rendersPassthroughListeners reports whether a certificate mode renders
@@ -344,7 +317,7 @@ func validatePassthroughListenerCertMode(listeners []gatewayv1alpha1.TLSPassthro
344317
// same absence as http01.
345318
func rendersPassthroughListeners(mode gatewayv1alpha1.CertMode) bool {
346319
switch mode {
347-
case gatewayv1alpha1.CertModeHTTP01, "":
320+
case gatewayv1alpha1.CertModeHTTP01, gatewayv1alpha1.CertModeDNS01, gatewayv1alpha1.CertModeExistingSecret, "":
348321
return true
349322
}
350323
return false

0 commit comments

Comments
 (0)