Skip to content

Commit cf4bcb5

Browse files
committed
add checks for TLS mode
1 parent 8e94684 commit cf4bcb5

File tree

3 files changed

+81
-2
lines changed

3 files changed

+81
-2
lines changed

pkg/gateway/model/model_build_target_group.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ func (t *targetGroupBuilderImpl) buildTargetGroup(stack core.Stack,
102102
targetGroupProps := backend.ELBV2TargetGroupProps
103103
tgResID := t.buildTargetGroupResourceID(k8s.NamespacedName(gw), k8s.NamespacedName(backend.Service), routeDescriptor.GetRouteNamespacedName(), routeDescriptor.GetRouteKind(), backend.ServicePort.TargetPort)
104104
if tg, exists := t.tgByResID[tgResID]; exists {
105-
fmt.Println("TG already exists. Returning cached version")
106105
return tg, nil
107106
}
108107

pkg/gateway/routeutils/listener_attachment_helper.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,36 @@ func (attachmentHelper *listenerAttachmentHelperImpl) kindCheck(listener gwv1.Li
134134
allowedRoutes.Insert(RouteKind(v.Kind))
135135
}
136136
}
137-
return allowedRoutes.Has(route.GetRouteKind())
137+
138+
isAllowed := allowedRoutes.Has(route.GetRouteKind())
139+
140+
if !isAllowed {
141+
return false
142+
}
143+
144+
if listener.Protocol == gwv1.TLSProtocolType {
145+
146+
var tlsMode *gwv1.TLSModeType
147+
148+
if listener.TLS != nil && listener.TLS.Mode != nil {
149+
tlsMode = listener.TLS.Mode
150+
}
151+
switch route.GetRouteKind() {
152+
case TCPRouteKind:
153+
// Listener must allow termination at lb
154+
return tlsMode == nil || *tlsMode == gwv1.TLSModeTerminate
155+
case TLSRouteKind:
156+
// This is kind of different.
157+
// For AWS NLB, the original TLS will be terminated, however
158+
// the LB will establish a new TLS connection to the backend.
159+
// Users that want to persist the same TLS connection should use TCP
160+
return tlsMode != nil && *tlsMode == gwv1.TLSModePassthrough
161+
}
162+
// Unsupported route type.
163+
return false
164+
}
165+
166+
return true
138167
}
139168

140169
func (attachmentHelper *listenerAttachmentHelperImpl) hostnameCheck(listener gwv1.Listener, route preLoadRouteDescriptor) (bool, error) {

pkg/gateway/routeutils/listener_attachment_helper_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ func Test_namespaceCheck(t *testing.T) {
297297
}
298298

299299
func Test_kindCheck(t *testing.T) {
300+
term := gwv1.TLSModeTerminate
301+
pt := gwv1.TLSModePassthrough
300302
testCases := []struct {
301303
name string
302304
route preLoadRouteDescriptor
@@ -347,6 +349,55 @@ func Test_kindCheck(t *testing.T) {
347349
},
348350
expectedResult: true,
349351
},
352+
{
353+
name: "tls listener, tcp route, terminate by default",
354+
route: &tcpRouteDescription{},
355+
listener: gwv1.Listener{
356+
Protocol: gwv1.TCPProtocolType,
357+
},
358+
expectedResult: true,
359+
},
360+
{
361+
name: "tls listener, tls route, terminate by default",
362+
route: &tlsRouteDescription{},
363+
listener: gwv1.Listener{
364+
Protocol: gwv1.TCPProtocolType,
365+
},
366+
expectedResult: false,
367+
},
368+
{
369+
name: "tls listener, tcp route, terminate specified",
370+
route: &tcpRouteDescription{},
371+
listener: gwv1.Listener{
372+
Protocol: gwv1.TCPProtocolType,
373+
TLS: &gwv1.GatewayTLSConfig{
374+
Mode: &term,
375+
},
376+
},
377+
expectedResult: true,
378+
},
379+
{
380+
name: "tls listener, tcp route, passthrough specified",
381+
route: &tcpRouteDescription{},
382+
listener: gwv1.Listener{
383+
Protocol: gwv1.TLSProtocolType,
384+
TLS: &gwv1.GatewayTLSConfig{
385+
Mode: &pt,
386+
},
387+
},
388+
expectedResult: false,
389+
},
390+
{
391+
name: "tls listener, tls route, passthrough specified",
392+
route: &tlsRouteDescription{},
393+
listener: gwv1.Listener{
394+
Protocol: gwv1.TLSProtocolType,
395+
TLS: &gwv1.GatewayTLSConfig{
396+
Mode: &pt,
397+
},
398+
},
399+
expectedResult: true,
400+
},
350401
}
351402

352403
for _, tc := range testCases {

0 commit comments

Comments
 (0)