Skip to content

Commit eb4f5b5

Browse files
committed
feat: support overriding ext_auth path
Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>
1 parent d80fb5b commit eb4f5b5

23 files changed

Lines changed: 752 additions & 5 deletions

api/v1alpha1/ext_auth_types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ type GRPCExtAuthService struct {
171171
// +kubebuilder:validation:XValidation:message="backendRef or backendRefs needs to be set",rule="has(self.backendRef) || self.backendRefs.size() > 0"
172172
// +kubebuilder:validation:XValidation:message="BackendRefs only supports Service, ServiceImport, and Backend kind.",rule="has(self.backendRefs) ? self.backendRefs.all(f, f.kind == 'Service' || f.kind == 'ServiceImport' || f.kind == 'Backend') : true"
173173
// +kubebuilder:validation:XValidation:message="BackendRefs only supports Core, multicluster.x-k8s.io, and gateway.envoyproxy.io groups.",rule="has(self.backendRefs) ? (self.backendRefs.all(f, f.group == \"\" || f.group == 'multicluster.x-k8s.io' || f.group == 'gateway.envoyproxy.io')) : true"
174+
// +kubebuilder:validation:XValidation:message="only one of path or pathOverride can be specified",rule="!(has(self.path) && has(self.pathOverride))"
174175
type HTTPExtAuthService struct {
175176
// Only Service kind is supported for now.
176177
BackendCluster `json:",inline"`
@@ -183,9 +184,19 @@ type HTTPExtAuthService struct {
183184
// For example, if the original request path is "/hello", and the path specified here is "/auth",
184185
// then the path of the authorization request will be "/auth/hello". If the path is not specified,
185186
// the path of the authorization request will be "/hello".
187+
// Only one of Path or PathOverride can be set.
186188
// +optional
187189
Path *string `json:"path,omitempty"`
188190

191+
// PathOverride replaces the original request path in the authorization request.
192+
// If set, the path will be overridden to this value during authorization.
193+
// For example, if the original request path is "/hello", and PathOverride is set to "/auth",
194+
// then the path of the authorization request will be "/auth".
195+
// Only one of Path or PathOverride can be set.
196+
//
197+
// +optional
198+
PathOverride *string `json:"pathOverride,omitempty"`
199+
189200
// HeadersToBackend are the authorization response headers that will be added
190201
// to the original client request before sending it to the backend server.
191202
// Note that coexisting headers will be overridden.

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_securitypolicies.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3509,6 +3509,15 @@ spec:
35093509
For example, if the original request path is "/hello", and the path specified here is "/auth",
35103510
then the path of the authorization request will be "/auth/hello". If the path is not specified,
35113511
the path of the authorization request will be "/hello".
3512+
Only one of Path or PathOverride can be set.
3513+
type: string
3514+
pathOverride:
3515+
description: |-
3516+
PathOverride replaces the original request path in the authorization request.
3517+
If set, the path will be overridden to this value during authorization.
3518+
For example, if the original request path is "/hello", and PathOverride is set to "/auth",
3519+
then the path of the authorization request will be "/auth".
3520+
Only one of Path or PathOverride can be set.
35123521
type: string
35133522
type: object
35143523
x-kubernetes-validations:
@@ -3524,6 +3533,8 @@ spec:
35243533
rule: 'has(self.backendRefs) ? (self.backendRefs.all(f, f.group
35253534
== "" || f.group == ''multicluster.x-k8s.io'' || f.group ==
35263535
''gateway.envoyproxy.io'')) : true'
3536+
- message: only one of path or pathOverride can be specified
3537+
rule: '!(has(self.path) && has(self.pathOverride))'
35273538
includeRouteMetadata:
35283539
description: |-
35293540
IncludeRouteMetadata sends Envoy Gateway's built-in route metadata to the

charts/gateway-helm/charts/crds/crds/generated/gateway.envoyproxy.io_securitypolicies.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3508,6 +3508,15 @@ spec:
35083508
For example, if the original request path is "/hello", and the path specified here is "/auth",
35093509
then the path of the authorization request will be "/auth/hello". If the path is not specified,
35103510
the path of the authorization request will be "/hello".
3511+
Only one of Path or PathOverride can be set.
3512+
type: string
3513+
pathOverride:
3514+
description: |-
3515+
PathOverride replaces the original request path in the authorization request.
3516+
If set, the path will be overridden to this value during authorization.
3517+
For example, if the original request path is "/hello", and PathOverride is set to "/auth",
3518+
then the path of the authorization request will be "/auth".
3519+
Only one of Path or PathOverride can be set.
35113520
type: string
35123521
type: object
35133522
x-kubernetes-validations:
@@ -3523,6 +3532,8 @@ spec:
35233532
rule: 'has(self.backendRefs) ? (self.backendRefs.all(f, f.group
35243533
== "" || f.group == ''multicluster.x-k8s.io'' || f.group ==
35253534
''gateway.envoyproxy.io'')) : true'
3535+
- message: only one of path or pathOverride can be specified
3536+
rule: '!(has(self.path) && has(self.pathOverride))'
35263537
includeRouteMetadata:
35273538
description: |-
35283539
IncludeRouteMetadata sends Envoy Gateway's built-in route metadata to the

examples/envoy-ext-auth/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ func authCheckerHandler(w http.ResponseWriter, req *http.Request) {
294294
if len(extracted) == 2 && extracted[0] == "Bearer" {
295295
if user, ok := testUsers[extracted[1]]; ok {
296296
w.Header().Add("x-current-user", user) // this should be set before call WriteHeader
297+
w.Header().Add("x-ext-auth-req-path", req.URL.Path)
297298
w.WriteHeader(http.StatusOK)
298299
return
299300
}

internal/gatewayapi/securitypolicy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,6 +2205,7 @@ func (t *Translator) buildExtAuth(
22052205
Destination: *rd,
22062206
Authority: authority,
22072207
Path: ptr.Deref(http.Path, ""),
2208+
PathOverride: ptr.Deref(http.PathOverride, ""),
22082209
HeadersToBackend: http.HeadersToBackend,
22092210
}
22102211
} else {
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
gateways:
2+
- apiVersion: gateway.networking.k8s.io/v1
3+
kind: Gateway
4+
metadata:
5+
namespace: default
6+
name: gateway-1
7+
spec:
8+
gatewayClassName: envoy-gateway-class
9+
listeners:
10+
- name: http
11+
protocol: HTTP
12+
port: 80
13+
allowedRoutes:
14+
namespaces:
15+
from: All
16+
httpRoutes:
17+
- apiVersion: gateway.networking.k8s.io/v1
18+
kind: HTTPRoute
19+
metadata:
20+
namespace: default
21+
name: httproute-1
22+
spec:
23+
hostnames:
24+
- www.foo.com
25+
parentRefs:
26+
- namespace: default
27+
name: gateway-1
28+
sectionName: http
29+
rules:
30+
- matches:
31+
- path:
32+
value: /foo
33+
backendRefs:
34+
- name: service-1
35+
port: 8080
36+
services:
37+
- apiVersion: v1
38+
kind: Service
39+
metadata:
40+
namespace: envoy-gateway
41+
name: http-backend
42+
spec:
43+
ports:
44+
- port: 80
45+
name: http
46+
protocol: TCP
47+
- apiVersion: v1
48+
kind: Service
49+
metadata:
50+
namespace: default
51+
name: service-1
52+
spec:
53+
ports:
54+
- port: 8080
55+
name: http
56+
protocol: TCP
57+
endpointSlices:
58+
- apiVersion: discovery.k8s.io/v1
59+
kind: EndpointSlice
60+
metadata:
61+
name: endpointslice-http-backend
62+
namespace: envoy-gateway
63+
labels:
64+
kubernetes.io/service-name: http-backend
65+
addressType: IPv4
66+
ports:
67+
- name: http
68+
protocol: TCP
69+
port: 80
70+
endpoints:
71+
- addresses:
72+
- 7.7.7.7
73+
conditions:
74+
ready: true
75+
- apiVersion: discovery.k8s.io/v1
76+
kind: EndpointSlice
77+
metadata:
78+
name: endpointslice-service-1
79+
namespace: default
80+
labels:
81+
kubernetes.io/service-name: service-1
82+
addressType: IPv4
83+
ports:
84+
- name: http
85+
protocol: TCP
86+
port: 8080
87+
endpoints:
88+
- addresses:
89+
- 8.8.8.8
90+
conditions:
91+
ready: true
92+
referenceGrants:
93+
- apiVersion: gateway.networking.k8s.io/v1alpha2
94+
kind: ReferenceGrant
95+
metadata:
96+
namespace: envoy-gateway
97+
name: referencegrant-1
98+
spec:
99+
from:
100+
- group: gateway.envoyproxy.io
101+
kind: SecurityPolicy
102+
namespace: default
103+
to:
104+
- group: ""
105+
kind: Service
106+
securityPolicies:
107+
- apiVersion: gateway.envoyproxy.io/v1alpha1
108+
kind: SecurityPolicy
109+
metadata:
110+
namespace: default
111+
name: policy-for-gateway-1
112+
spec:
113+
targetRef:
114+
group: gateway.networking.k8s.io
115+
kind: Gateway
116+
name: gateway-1
117+
extAuth:
118+
failOpen: false
119+
http:
120+
backendRefs:
121+
- Name: http-backend
122+
Namespace: envoy-gateway
123+
Port: 80
124+
pathOverride: /check
125+
headersToBackend:
126+
- x-user

0 commit comments

Comments
 (0)