Skip to content

Commit 1f96c01

Browse files
committed
fix: use one gExt per ingress
Signed-off-by: omar <omar.hammami@solo.io>
1 parent 4fe4c63 commit 1f96c01

3 files changed

Lines changed: 52 additions & 56 deletions

File tree

pkg/i2gw/implementations/kgateway/auth.go

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -150,45 +150,40 @@ func applyExtAuthPolicy(
150150
return false
151151
}
152152

153-
// Use the URL as a key to deduplicate GatewayExtensions.
154-
if _, exists := gatewayExtensions[authURL]; !exists {
155-
// Create GatewayExtension with ExtAuth using HttpService.
156-
extHttpService := &kgateway.ExtHttpService{
157-
BackendRef: gwv1.BackendRef{
158-
BackendObjectReference: gwv1.BackendObjectReference{
159-
Name: gwv1.ObjectName(parsed.service),
160-
Namespace: ptr.To(gwv1.Namespace(parsed.namespace)), // TODO: confirm that different namespace works
161-
Port: ptr.To(gwv1.PortNumber(parsed.port)),
162-
},
153+
// Create GatewayExtension with ExtAuth using HttpService.
154+
extHttpService := &kgateway.ExtHttpService{
155+
BackendRef: gwv1.BackendRef{
156+
BackendObjectReference: gwv1.BackendObjectReference{
157+
Name: gwv1.ObjectName(parsed.service),
158+
Namespace: ptr.To(gwv1.Namespace(parsed.namespace)), // TODO: confirm that different namespace works
159+
Port: ptr.To(gwv1.PortNumber(parsed.port)),
163160
},
164-
PathPrefix: parsed.path,
165-
}
161+
},
162+
PathPrefix: parsed.path,
163+
}
166164

167-
// Set AuthorizationResponse if response headers are specified.
168-
if len(pol.ExtAuth.ResponseHeaders) > 0 {
169-
extHttpService.AuthorizationResponse = &kgateway.AuthorizationResponse{
170-
HeadersToBackend: pol.ExtAuth.ResponseHeaders,
171-
}
165+
// Set AuthorizationResponse if response headers are specified.
166+
if len(pol.ExtAuth.ResponseHeaders) > 0 {
167+
extHttpService.AuthorizationResponse = &kgateway.AuthorizationResponse{
168+
HeadersToBackend: pol.ExtAuth.ResponseHeaders,
172169
}
170+
}
173171

174-
ge := &kgateway.GatewayExtension{
175-
ObjectMeta: metav1.ObjectMeta{
176-
Name: fmt.Sprintf("%s-extauth", parsed.service),
177-
Namespace: namespace,
178-
},
179-
Spec: kgateway.GatewayExtensionSpec{
180-
ExtAuth: &kgateway.ExtAuthProvider{
181-
HttpService: extHttpService,
182-
},
172+
ge := &kgateway.GatewayExtension{
173+
ObjectMeta: metav1.ObjectMeta{
174+
Name: fmt.Sprintf("%s-extauth", ingressName),
175+
Namespace: namespace,
176+
},
177+
Spec: kgateway.GatewayExtensionSpec{
178+
ExtAuth: &kgateway.ExtAuthProvider{
179+
HttpService: extHttpService,
183180
},
184-
}
185-
ge.SetGroupVersionKind(GatewayExtensionGVK)
186-
gatewayExtensions[authURL] = ge
181+
},
187182
}
183+
ge.SetGroupVersionKind(GatewayExtensionGVK)
188184

189185
// Add ExtAuthPolicy to TrafficPolicy.
190186
t := ensureTrafficPolicy(tp, ingressName, namespace)
191-
ge := gatewayExtensions[authURL]
192187

193188
t.Spec.ExtAuth = &kgateway.ExtAuthPolicy{
194189
ExtensionRef: &shared.NamespacedObjectReference{
@@ -197,5 +192,6 @@ func applyExtAuthPolicy(
197192
},
198193
}
199194

195+
gatewayExtensions[ingressName] = ge
200196
return true
201197
}

pkg/i2gw/implementations/kgateway/emitter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (e *Emitter) Emit(ir *intermediate.IR) ([]client.Object, error) {
7878
// Track HTTPListenerPolicies per Gateway (for access logging).
7979
httpListenerPolicies := map[types.NamespacedName]*kgateway.HTTPListenerPolicy{}
8080

81-
// Track GatewayExtensions per auth URL (for external auth).
81+
// Track GatewayExtensions per ingress name (for external auth).
8282
gatewayExtensions := map[string]*kgateway.GatewayExtension{}
8383

8484
for httpRouteKey, httpRouteContext := range ir.HTTPRoutes {

pkg/i2gw/implementations/kgateway/testing/testdata/output/external_auth.yaml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ kind: HTTPRoute
2727
metadata:
2828
annotations:
2929
gateway.networking.k8s.io/generator: ingress2gateway-dev
30-
name: ingress-auth-full-fqdn-app1-example-org
30+
name: ingress-auth-different-ns-app4-example-org
3131
namespace: default
3232
spec:
3333
hostnames:
34-
- app1.example.org
34+
- app4.example.org
3535
parentRefs:
3636
- name: nginx
3737
rules:
3838
- backendRefs:
39-
- name: app1
39+
- name: app4
4040
port: 80
4141
matches:
4242
- path:
@@ -50,16 +50,16 @@ kind: HTTPRoute
5050
metadata:
5151
annotations:
5252
gateway.networking.k8s.io/generator: ingress2gateway-dev
53-
name: ingress-auth-same-ns-app3-example-org
53+
name: ingress-auth-full-fqdn-app1-example-org
5454
namespace: default
5555
spec:
5656
hostnames:
57-
- app3.example.org
57+
- app1.example.org
5858
parentRefs:
5959
- name: nginx
6060
rules:
6161
- backendRefs:
62-
- name: app3
62+
- name: app1
6363
port: 80
6464
matches:
6565
- path:
@@ -73,16 +73,16 @@ kind: HTTPRoute
7373
metadata:
7474
annotations:
7575
gateway.networking.k8s.io/generator: ingress2gateway-dev
76-
name: ingress-auth-different-ns-app4-example-org
76+
name: ingress-auth-same-ns-app3-example-org
7777
namespace: default
7878
spec:
7979
hostnames:
80-
- app4.example.org
80+
- app3.example.org
8181
parentRefs:
8282
- name: nginx
8383
rules:
8484
- backendRefs:
85-
- name: app4
85+
- name: app3
8686
port: 80
8787
matches:
8888
- path:
@@ -94,45 +94,45 @@ status:
9494
apiVersion: gateway.kgateway.dev/v1alpha1
9595
kind: GatewayExtension
9696
metadata:
97-
name: auth-extauth
97+
name: ingress-auth-different-ns-extauth
9898
namespace: default
9999
spec:
100100
extAuth:
101101
httpService:
102102
backendRef:
103103
name: auth
104-
namespace: default
105-
port: 80
106-
pathPrefix: /
104+
namespace: production
105+
port: 8080
106+
pathPrefix: /authz
107107
status: {}
108108
---
109109
apiVersion: gateway.kgateway.dev/v1alpha1
110110
kind: GatewayExtension
111111
metadata:
112-
name: auth-extauth
112+
name: ingress-auth-full-fqdn-extauth
113113
namespace: default
114114
spec:
115115
extAuth:
116116
httpService:
117+
authorizationResponse:
118+
headersToBackend:
119+
- X-Auth-Token
120+
- X-User-ID
117121
backendRef:
118122
name: auth
119-
namespace: production
120-
port: 8080
121-
pathPrefix: /authz
123+
namespace: default
124+
port: 80
125+
pathPrefix: /
122126
status: {}
123127
---
124128
apiVersion: gateway.kgateway.dev/v1alpha1
125129
kind: GatewayExtension
126130
metadata:
127-
name: auth-extauth
131+
name: ingress-auth-same-ns-extauth
128132
namespace: default
129133
spec:
130134
extAuth:
131135
httpService:
132-
authorizationResponse:
133-
headersToBackend:
134-
- X-Auth-Token
135-
- X-User-ID
136136
backendRef:
137137
name: auth
138138
namespace: default
@@ -148,7 +148,7 @@ metadata:
148148
spec:
149149
extAuth:
150150
extensionRef:
151-
name: auth-extauth
151+
name: ingress-auth-different-ns-extauth
152152
namespace: default
153153
targetRefs:
154154
- group: gateway.networking.k8s.io
@@ -165,7 +165,7 @@ metadata:
165165
spec:
166166
extAuth:
167167
extensionRef:
168-
name: auth-extauth
168+
name: ingress-auth-full-fqdn-extauth
169169
namespace: default
170170
targetRefs:
171171
- group: gateway.networking.k8s.io
@@ -182,7 +182,7 @@ metadata:
182182
spec:
183183
extAuth:
184184
extensionRef:
185-
name: auth-extauth
185+
name: ingress-auth-same-ns-extauth
186186
namespace: default
187187
targetRefs:
188188
- group: gateway.networking.k8s.io

0 commit comments

Comments
 (0)