Skip to content

Commit 877c6be

Browse files
authored
Merge pull request #19 from puertomontt/passthrough
ssl passthrough
2 parents cb63d52 + 370de3d commit 877c6be

14 files changed

Lines changed: 982 additions & 621 deletions

File tree

pkg/i2gw/implementations/kgateway/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ The command should generate Gateway API and Kgateway resources.
6161
- `nginx.ingress.kubernetes.io/proxy-read-timeout`
6262
- `nginx.ingress.kubernetes.io/ssl-redirect`: When set to `"true"`, adds a `RequestRedirect` filter to HTTPRoute rules that redirects HTTP to HTTPS with a 301 status code.
6363
- `nginx.ingress.kubernetes.io/force-ssl-redirect`: When set to `"true"`, adds a `RequestRedirect` filter to HTTPRoute rules that redirects HTTP to HTTPS with a 301 status code. Treated identically to `ssl-redirect`.
64+
- `nginx.ingress.kubernetes.io/ssl-passthrough`: When set to `"true"`, enables TLS passthrough mode. Converts the Ingress to a `TLSRoute` with a Gateway listener using `protocol: TLS` and `tls.mode: Passthrough`. The HTTPRoute that would normally be created is removed.
6465

6566
### Backend Behavior
6667

@@ -114,6 +115,7 @@ Examples:
114115
- Rate limit annotations control `spec.rateLimit.local.tokenBucket`
115116
- Timeout annotations control `spec.timeouts.request` or `streamIdle`
116117
- SSL redirect annotations add `RequestRedirect` filters to HTTPRoute rules
118+
- SSL passthrough annotation converts HTTPRoute to TLSRoute with TLS passthrough Gateway listener
117119

118120
## BackendConfigPolicy Projection
119121

@@ -128,6 +130,19 @@ Currently supported:
128130
If multiple Ingresses target the same Service with conflicting `proxy-connect-timeout` values,
129131
the lowest timeout wins and a warning is emitted.
130132

133+
## TLSRoute Projection
134+
135+
Annotations that require TLS passthrough mode are converted into `TLSRoute` resources instead of `HTTPRoute` resources.
136+
137+
Currently supported:
138+
139+
- `nginx.ingress.kubernetes.io/ssl-passthrough`:
140+
- When enabled, the Ingress is converted to a `TLSRoute` resource
141+
- A Gateway listener is created with `protocol: TLS` and `tls.mode: Passthrough`
142+
- The listener uses port 443 (when hostname is specified) or 8443 (default)
143+
- The HTTPRoute that would normally be created is removed
144+
- Backend services must handle TLS termination themselves
145+
131146
## Backend Projection
132147

133148
Annotations that change how upstreams are represented (rather than how they are load balanced or configured)
@@ -148,6 +163,7 @@ Currently supported:
148163
| Request/response behavior | `TrafficPolicy` |
149164
| Upstream connection behavior | `BackendConfigPolicy` |
150165
| Upstream representation (static IP)| `Backend` |
166+
| TLS passthrough | `TLSRoute` |
151167

152168
## Limitations
153169

pkg/i2gw/implementations/kgateway/emitter_integration_test.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ func runGoldenTest(t *testing.T, inputRel, goldenRel string) {
147147

148148
actual := stdout.Bytes()
149149

150+
// Normalize trivial formatting differences
151+
actualTrimmed := bytes.TrimSpace(actual)
152+
actualCanonicalized := canonicalizeMultiDocYAML(t, actualTrimmed)
153+
150154
// Golden file handling
151155
writeGolden := false
152156
goldenBytes, err := os.ReadFile(goldenPath)
@@ -161,19 +165,16 @@ func runGoldenTest(t *testing.T, inputRel, goldenRel string) {
161165
}
162166

163167
if writeGolden {
164-
if err := os.WriteFile(goldenPath, actual, 0o600); err != nil {
168+
if err := os.WriteFile(goldenPath, actualCanonicalized, 0o600); err != nil {
165169
t.Fatalf("failed to write golden file %q: %v", goldenPath, err)
166170
}
167171
t.Logf("wrote golden file: %s", goldenPath)
168172
return
169173
}
170174

171-
// Normalize trivial formatting differences
172-
actualTrimmed := bytes.TrimSpace(actual)
173175
expectedTrimmed := bytes.TrimSpace(goldenBytes)
174-
175-
got := canonicalizeMultiDocYAML(t, actualTrimmed)
176176
want := canonicalizeMultiDocYAML(t, expectedTrimmed)
177+
got := actualCanonicalized
177178

178179
if diff := cmp.Diff(string(want), string(got)); diff != "" {
179180
t.Fatalf("golden output mismatch (-want +got):\n%s", diff)
@@ -260,6 +261,15 @@ func TestKgatewayIngressNginxIntegration_Golden(t *testing.T) {
260261
"pkg", "i2gw", "implementations", "kgateway", "testing", "testdata", "output", "basic_auth.yaml",
261262
),
262263
},
264+
{
265+
name: "ssl_passthrough",
266+
inputRel: filepath.Join(
267+
"pkg", "i2gw", "implementations", "kgateway", "testing", "testdata", "input", "ssl_passthrough.yaml",
268+
),
269+
goldenRel: filepath.Join(
270+
"pkg", "i2gw", "implementations", "kgateway", "testing", "testdata", "output", "ssl_passthrough.yaml",
271+
),
272+
},
263273
}
264274

265275
for _, tt := range tests {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: Ingress
3+
metadata:
4+
annotations:
5+
ingress2gateway.kubernetes.io/implementation: kgateway
6+
nginx.ingress.kubernetes.io/ssl-passthrough: "true"
7+
name: tls-passthrough
8+
namespace: default
9+
spec:
10+
ingressClassName: nginx
11+
rules:
12+
- host: nginx.example.com
13+
http:
14+
paths:
15+
- backend:
16+
service:
17+
name: my-nginx
18+
port:
19+
number: 443
20+
path: /
21+
pathType: Prefix
Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
1+
apiVersion: gateway.kgateway.dev/v1alpha1
2+
kind: BackendConfigPolicy
3+
metadata:
4+
name: httpbin-insecure-backend-config
5+
namespace: default
6+
spec:
7+
targetRefs:
8+
- group: ""
9+
kind: Service
10+
name: httpbin-insecure
11+
tls:
12+
insecureSkipVerify: true
13+
sni: tls.example.com
14+
status:
15+
ancestors: null
16+
---
17+
apiVersion: gateway.kgateway.dev/v1alpha1
18+
kind: BackendConfigPolicy
19+
metadata:
20+
name: httpbin2-backend-config
21+
namespace: default
22+
spec:
23+
targetRefs:
24+
- group: ""
25+
kind: Service
26+
name: httpbin2
27+
tls:
28+
secretRef:
29+
name: base-certificate-tls
30+
sni: tls.example.com
31+
status:
32+
ancestors: null
33+
---
134
apiVersion: gateway.networking.k8s.io/v1
235
kind: Gateway
336
metadata:
@@ -8,14 +41,14 @@ metadata:
841
spec:
942
gatewayClassName: kgateway
1043
listeners:
11-
- hostname: insecure-tls.example.org
12-
name: insecure-tls-example-org-http
13-
port: 80
14-
protocol: HTTP
15-
- hostname: tls.example.org
16-
name: tls-example-org-http
17-
port: 80
18-
protocol: HTTP
44+
- hostname: insecure-tls.example.org
45+
name: insecure-tls-example-org-http
46+
port: 80
47+
protocol: HTTP
48+
- hostname: tls.example.org
49+
name: tls-example-org-http
50+
port: 80
51+
protocol: HTTP
1952
status: {}
2053
---
2154
apiVersion: gateway.networking.k8s.io/v1
@@ -27,17 +60,17 @@ metadata:
2760
namespace: default
2861
spec:
2962
hostnames:
30-
- tls.example.org
63+
- tls.example.org
3164
parentRefs:
32-
- name: nginx
65+
- name: nginx
3366
rules:
34-
- backendRefs:
35-
- name: httpbin2
36-
port: 80
37-
matches:
38-
- path:
39-
type: PathPrefix
40-
value: /
67+
- backendRefs:
68+
- name: httpbin2
69+
port: 80
70+
matches:
71+
- path:
72+
type: PathPrefix
73+
value: /
4174
status:
4275
parents: []
4376
---
@@ -50,49 +83,16 @@ metadata:
5083
namespace: default
5184
spec:
5285
hostnames:
53-
- insecure-tls.example.org
86+
- insecure-tls.example.org
5487
parentRefs:
55-
- name: nginx
88+
- name: nginx
5689
rules:
57-
- backendRefs:
58-
- name: httpbin-insecure
59-
port: 80
60-
matches:
61-
- path:
62-
type: PathPrefix
63-
value: /
90+
- backendRefs:
91+
- name: httpbin-insecure
92+
port: 80
93+
matches:
94+
- path:
95+
type: PathPrefix
96+
value: /
6497
status:
6598
parents: []
66-
---
67-
apiVersion: gateway.kgateway.dev/v1alpha1
68-
kind: BackendConfigPolicy
69-
metadata:
70-
name: httpbin-insecure-backend-config
71-
namespace: default
72-
spec:
73-
targetRefs:
74-
- group: ""
75-
kind: Service
76-
name: httpbin-insecure
77-
tls:
78-
insecureSkipVerify: true
79-
sni: tls.example.com
80-
status:
81-
ancestors: null
82-
---
83-
apiVersion: gateway.kgateway.dev/v1alpha1
84-
kind: BackendConfigPolicy
85-
metadata:
86-
name: httpbin2-backend-config
87-
namespace: default
88-
spec:
89-
targetRefs:
90-
- group: ""
91-
kind: Service
92-
name: httpbin2
93-
tls:
94-
secretRef:
95-
name: base-certificate-tls
96-
sni: tls.example.com
97-
status:
98-
ancestors: null

0 commit comments

Comments
 (0)