Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions api/v1alpha1/ext_auth_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ type GRPCExtAuthService struct {
// +kubebuilder:validation:XValidation:message="backendRef or backendRefs needs to be set",rule="has(self.backendRef) || self.backendRefs.size() > 0"
// +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"
// +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"
// +kubebuilder:validation:XValidation:message="only one of path or pathOverride can be specified",rule="!(has(self.path) && has(self.pathOverride))"
type HTTPExtAuthService struct {
// Only Service kind is supported for now.
BackendCluster `json:",inline"`
Expand All @@ -183,9 +184,19 @@ type HTTPExtAuthService struct {
// For example, if the original request path is "/hello", and the path specified here is "/auth",
// then the path of the authorization request will be "/auth/hello". If the path is not specified,
// the path of the authorization request will be "/hello".
// Only one of Path or PathOverride can be set.
// +optional
Path *string `json:"path,omitempty"`

// PathOverride replaces the original request path in the authorization request.
// If set, the path will be overridden to this value during authorization.
// For example, if the original request path is "/hello", and PathOverride is set to "/auth",
// then the path of the authorization request will be "/auth".
// Only one of Path or PathOverride can be set.
//
// +optional
PathOverride *string `json:"pathOverride,omitempty"`

// HeadersToBackend are the authorization response headers that will be added
// to the original client request before sending it to the backend server.
// Note that coexisting headers will be overridden.
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3523,6 +3523,15 @@ spec:
For example, if the original request path is "/hello", and the path specified here is "/auth",
then the path of the authorization request will be "/auth/hello". If the path is not specified,
the path of the authorization request will be "/hello".
Only one of Path or PathOverride can be set.
type: string
pathOverride:
description: |-
PathOverride replaces the original request path in the authorization request.
If set, the path will be overridden to this value during authorization.
For example, if the original request path is "/hello", and PathOverride is set to "/auth",
then the path of the authorization request will be "/auth".
Only one of Path or PathOverride can be set.
type: string
type: object
x-kubernetes-validations:
Expand All @@ -3538,6 +3547,8 @@ spec:
rule: 'has(self.backendRefs) ? (self.backendRefs.all(f, f.group
== "" || f.group == ''multicluster.x-k8s.io'' || f.group ==
''gateway.envoyproxy.io'')) : true'
- message: only one of path or pathOverride can be specified
rule: '!(has(self.path) && has(self.pathOverride))'
includeRouteMetadata:
description: |-
IncludeRouteMetadata sends Envoy Gateway's built-in route metadata to the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3522,6 +3522,15 @@ spec:
For example, if the original request path is "/hello", and the path specified here is "/auth",
then the path of the authorization request will be "/auth/hello". If the path is not specified,
the path of the authorization request will be "/hello".
Only one of Path or PathOverride can be set.
type: string
pathOverride:
description: |-
PathOverride replaces the original request path in the authorization request.
If set, the path will be overridden to this value during authorization.
For example, if the original request path is "/hello", and PathOverride is set to "/auth",
then the path of the authorization request will be "/auth".
Only one of Path or PathOverride can be set.
type: string
type: object
x-kubernetes-validations:
Expand All @@ -3537,6 +3546,8 @@ spec:
rule: 'has(self.backendRefs) ? (self.backendRefs.all(f, f.group
== "" || f.group == ''multicluster.x-k8s.io'' || f.group ==
''gateway.envoyproxy.io'')) : true'
- message: only one of path or pathOverride can be specified
rule: '!(has(self.path) && has(self.pathOverride))'
includeRouteMetadata:
description: |-
IncludeRouteMetadata sends Envoy Gateway's built-in route metadata to the
Expand Down
1 change: 1 addition & 0 deletions examples/envoy-ext-auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ func authCheckerHandler(w http.ResponseWriter, req *http.Request) {
if len(extracted) == 2 && extracted[0] == "Bearer" {
if user, ok := testUsers[extracted[1]]; ok {
w.Header().Add("x-current-user", user) // this should be set before call WriteHeader
w.Header().Add("x-ext-auth-req-path", req.URL.Path)
w.WriteHeader(http.StatusOK)
return
}
Expand Down
1 change: 1 addition & 0 deletions internal/gatewayapi/securitypolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2207,6 +2207,7 @@ func (t *Translator) buildExtAuth(
Destination: *rd,
Authority: authority,
Path: ptr.Deref(http.Path, ""),
PathOverride: ptr.Deref(http.PathOverride, ""),
HeadersToBackend: http.HeadersToBackend,
}
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
gateways:
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
namespace: default
name: gateway-1
spec:
gatewayClassName: envoy-gateway-class
listeners:
- name: http
protocol: HTTP
port: 80
allowedRoutes:
namespaces:
from: All
httpRoutes:
- apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
namespace: default
name: httproute-1
spec:
hostnames:
- www.foo.com
parentRefs:
- namespace: default
name: gateway-1
sectionName: http
rules:
- matches:
- path:
value: /foo
backendRefs:
- name: service-1
port: 8080
services:
- apiVersion: v1
kind: Service
metadata:
namespace: envoy-gateway
name: http-backend
spec:
ports:
- port: 80
name: http
protocol: TCP
- apiVersion: v1
kind: Service
metadata:
namespace: default
name: service-1
spec:
ports:
- port: 8080
name: http
protocol: TCP
endpointSlices:
- apiVersion: discovery.k8s.io/v1
kind: EndpointSlice
metadata:
name: endpointslice-http-backend
namespace: envoy-gateway
labels:
kubernetes.io/service-name: http-backend
addressType: IPv4
ports:
- name: http
protocol: TCP
port: 80
endpoints:
- addresses:
- 7.7.7.7
conditions:
ready: true
- apiVersion: discovery.k8s.io/v1
kind: EndpointSlice
metadata:
name: endpointslice-service-1
namespace: default
labels:
kubernetes.io/service-name: service-1
addressType: IPv4
ports:
- name: http
protocol: TCP
port: 8080
endpoints:
- addresses:
- 8.8.8.8
conditions:
ready: true
referenceGrants:
- apiVersion: gateway.networking.k8s.io/v1alpha2
kind: ReferenceGrant
metadata:
namespace: envoy-gateway
name: referencegrant-1
spec:
from:
- group: gateway.envoyproxy.io
kind: SecurityPolicy
namespace: default
to:
- group: ""
kind: Service
securityPolicies:
- apiVersion: gateway.envoyproxy.io/v1alpha1
kind: SecurityPolicy
metadata:
namespace: default
name: policy-for-gateway-1
spec:
targetRef:
group: gateway.networking.k8s.io
kind: Gateway
name: gateway-1
extAuth:
failOpen: false
http:
backendRefs:
- Name: http-backend
Namespace: envoy-gateway
Port: 80
pathOverride: /check
headersToBackend:
- x-user
Loading
Loading