Skip to content

Commit 5fdcef5

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

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
@@ -148,6 +148,7 @@ type GRPCExtAuthService struct {
148148
// +kubebuilder:validation:XValidation:message="backendRef or backendRefs needs to be set",rule="has(self.backendRef) || self.backendRefs.size() > 0"
149149
// +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"
150150
// +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"
151+
// +kubebuilder:validation:XValidation:message="only one of path or pathOverride can be specified",rule="!(has(self.path) && has(self.pathOverride))"
151152
type HTTPExtAuthService struct {
152153
// Only Service kind is supported for now.
153154
BackendCluster `json:",inline"`
@@ -160,9 +161,19 @@ type HTTPExtAuthService struct {
160161
// For example, if the original request path is "/hello", and the path specified here is "/auth",
161162
// then the path of the authorization request will be "/auth/hello". If the path is not specified,
162163
// the path of the authorization request will be "/hello".
164+
// Only one of Path or PathOverride can be set.
163165
// +optional
164166
Path *string `json:"path,omitempty"`
165167

168+
// PathOverride replaces the original request path in the authorization request.
169+
// If set, the path will be overridden to this value during authorization.
170+
// For example, if the original request path is "/hello", and PathOverride is set to "/auth",
171+
// then the path of the authorization request will be "/auth".
172+
// Only one of Path or PathOverride can be set.
173+
//
174+
// +optional
175+
PathOverride *string `json:"pathOverride,omitempty"`
176+
166177
// HeadersToBackend are the authorization response headers that will be added
167178
// to the original client request before sending it to the backend server.
168179
// 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
@@ -3423,6 +3423,15 @@ spec:
34233423
For example, if the original request path is "/hello", and the path specified here is "/auth",
34243424
then the path of the authorization request will be "/auth/hello". If the path is not specified,
34253425
the path of the authorization request will be "/hello".
3426+
Only one of Path or PathOverride can be set.
3427+
type: string
3428+
pathOverride:
3429+
description: |-
3430+
PathOverride replaces the original request path in the authorization request.
3431+
If set, the path will be overridden to this value during authorization.
3432+
For example, if the original request path is "/hello", and PathOverride is set to "/auth",
3433+
then the path of the authorization request will be "/auth".
3434+
Only one of Path or PathOverride can be set.
34263435
type: string
34273436
type: object
34283437
x-kubernetes-validations:
@@ -3438,6 +3447,8 @@ spec:
34383447
rule: 'has(self.backendRefs) ? (self.backendRefs.all(f, f.group
34393448
== "" || f.group == ''multicluster.x-k8s.io'' || f.group ==
34403449
''gateway.envoyproxy.io'')) : true'
3450+
- message: only one of path or pathOverride can be specified
3451+
rule: '!(has(self.path) && has(self.pathOverride))'
34413452
recomputeRoute:
34423453
description: |-
34433454
RecomputeRoute clears the route cache and recalculates the routing decision.

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
@@ -3422,6 +3422,15 @@ spec:
34223422
For example, if the original request path is "/hello", and the path specified here is "/auth",
34233423
then the path of the authorization request will be "/auth/hello". If the path is not specified,
34243424
the path of the authorization request will be "/hello".
3425+
Only one of Path or PathOverride can be set.
3426+
type: string
3427+
pathOverride:
3428+
description: |-
3429+
PathOverride replaces the original request path in the authorization request.
3430+
If set, the path will be overridden to this value during authorization.
3431+
For example, if the original request path is "/hello", and PathOverride is set to "/auth",
3432+
then the path of the authorization request will be "/auth".
3433+
Only one of Path or PathOverride can be set.
34253434
type: string
34263435
type: object
34273436
x-kubernetes-validations:
@@ -3437,6 +3446,8 @@ spec:
34373446
rule: 'has(self.backendRefs) ? (self.backendRefs.all(f, f.group
34383447
== "" || f.group == ''multicluster.x-k8s.io'' || f.group ==
34393448
''gateway.envoyproxy.io'')) : true'
3449+
- message: only one of path or pathOverride can be specified
3450+
rule: '!(has(self.path) && has(self.pathOverride))'
34403451
recomputeRoute:
34413452
description: |-
34423453
RecomputeRoute clears the route cache and recalculates the routing decision.

examples/envoy-ext-auth/main.go

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

internal/gatewayapi/securitypolicy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,6 +2204,7 @@ func (t *Translator) buildExtAuth(
22042204
Destination: *rd,
22052205
Authority: authority,
22062206
Path: ptr.Deref(http.Path, ""),
2207+
PathOverride: ptr.Deref(http.PathOverride, ""),
22072208
HeadersToBackend: http.HeadersToBackend,
22082209
}
22092210
} 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)