Skip to content

Commit

Permalink
ext_auth support backendRefs (#3469)
Browse files Browse the repository at this point in the history
* update API

Signed-off-by: zirain <zirain2009@gmail.com>

* update test

Signed-off-by: zirain <zirain2009@gmail.com>

* implement

Signed-off-by: zirain <zirain2009@gmail.com>

* update

Signed-off-by: zirain <zirain2009@gmail.com>

* yamllint

Signed-off-by: zirain <zirain2009@gmail.com>

* update e2e test

Signed-off-by: zirain <zirain2009@gmail.com>

* fix e2e

Signed-off-by: zirain <zirain2009@gmail.com>

* fix test

Signed-off-by: zirain <zirain2009@gmail.com>

---------

Signed-off-by: zirain <zirain2009@gmail.com>
  • Loading branch information
zirain authored May 29, 2024
1 parent 378c8a8 commit 78fe57a
Show file tree
Hide file tree
Showing 26 changed files with 1,040 additions and 98 deletions.
39 changes: 31 additions & 8 deletions api/v1alpha1/ext_auth_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
)

// ExtAuth defines the configuration for External Authorization.
//
// +kubebuilder:validation:XValidation:rule="(has(self.grpc) || has(self.http))",message="one of grpc or http must be specified"
// +kubebuilder:validation:XValidation:rule="(has(self.grpc) && !has(self.http)) || (!has(self.grpc) && has(self.http))",message="only one of grpc or http can be specified"
// +kubebuilder:validation:XValidation:rule="has(self.grpc) ? (!has(self.grpc.backendRef.group) || self.grpc.backendRef.group == \"\") : true", message="group is invalid, only the core API group (specified by omitting the group field or setting it to an empty string) is supported"
// +kubebuilder:validation:XValidation:rule="has(self.grpc) ? (!has(self.grpc.backendRef.kind) || self.grpc.backendRef.kind == 'Service') : true", message="kind is invalid, only Service (specified by omitting the kind field or setting it to 'Service') is supported"
// +kubebuilder:validation:XValidation:rule="has(self.http) ? (!has(self.http.backendRef.group) || self.http.backendRef.group == \"\") : true", message="group is invalid, only the core API group (specified by omitting the group field or setting it to an empty string) is supported"
// +kubebuilder:validation:XValidation:rule="has(self.http) ? (!has(self.http.backendRef.kind) || self.http.backendRef.kind == 'Service') : true", message="kind is invalid, only Service (specified by omitting the kind field or setting it to 'Service') is supported"
//
// ExtAuth defines the configuration for External Authorization.
// +kubebuilder:validation:XValidation:rule="has(self.grpc) ? (!has(self.grpc.backendRef) || !has(self.grpc.backendRef.group) || self.grpc.backendRef.group == \"\") : true", message="group is invalid, only the core API group (specified by omitting the group field or setting it to an empty string) is supported"
// +kubebuilder:validation:XValidation:rule="has(self.grpc) ? (!has(self.grpc.backendRef) || !has(self.grpc.backendRef.kind) || self.grpc.backendRef.kind == 'Service') : true", message="kind is invalid, only Service (specified by omitting the kind field or setting it to 'Service') is supported"
// +kubebuilder:validation:XValidation:rule="has(self.http) ? (!has(self.http.backendRef) || !has(self.http.backendRef.group) || self.http.backendRef.group == \"\") : true", message="group is invalid, only the core API group (specified by omitting the group field or setting it to an empty string) is supported"
// +kubebuilder:validation:XValidation:rule="has(self.http) ? (!has(self.http.backendRef) || !has(self.http.backendRef.kind) || self.http.backendRef.kind == 'Service') : true", message="kind is invalid, only Service (specified by omitting the kind field or setting it to 'Service') is supported"
type ExtAuth struct {
// GRPC defines the gRPC External Authorization service.
// Either GRPCService or HTTPService must be specified,
Expand Down Expand Up @@ -55,19 +55,42 @@ type ExtAuth struct {
// GRPCExtAuthService defines the gRPC External Authorization service
// The authorization request message is defined in
// https://www.envoyproxy.io/docs/envoy/latest/api-v3/service/auth/v3/external_auth.proto
// +kubebuilder:validation:XValidation:message="backendRef or backendRefs needs to be set",rule="has(self.backendRef) || self.backendRefs.size() > 0"
type GRPCExtAuthService struct {
// BackendRef references a Kubernetes object that represents the
// backend server to which the authorization request will be sent.
// Only service Kind is supported for now.
BackendRef gwapiv1.BackendObjectReference `json:"backendRef"`
// Deprecated: Use BackendRefs instead.
BackendRef *gwapiv1.BackendObjectReference `json:"backendRef,omitempty"`

// BackendRefs references a Kubernetes object that represents the
// backend server to which the authorization request will be sent.
// Only service Kind is supported for now.
//
// +optional
// +kubebuilder:validation:MaxItems=1
// +kubebuilder:validation:XValidation:message="only support Service kind.",rule="self.all(f, f.kind == 'Service')"
BackendRefs []BackendRef `json:"backendRefs,omitempty"`
}

// HTTPExtAuthService defines the HTTP External Authorization service
//
// +kubebuilder:validation:XValidation:message="backendRef or backendRefs needs to be set",rule="has(self.backendRef) || self.backendRefs.size() > 0"
type HTTPExtAuthService struct {
// BackendRef references a Kubernetes object that represents the
// backend server to which the authorization request will be sent.
// Only service Kind is supported for now.
BackendRef gwapiv1.BackendObjectReference `json:"backendRef"`
// Deprecated: Use BackendRefs instead.
BackendRef *gwapiv1.BackendObjectReference `json:"backendRef,omitempty"`

// BackendRefs references a Kubernetes object that represents the
// backend server to which the authorization request will be sent.
// Only service Kind is supported for now.
//
// +optional
// +kubebuilder:validation:MaxItems=1
// +kubebuilder:validation:XValidation:message="only support Service kind.",rule="self.all(f, f.kind == 'Service')"
BackendRefs []BackendRef `json:"backendRefs,omitempty"`

// Path is the path of the HTTP External Authorization service.
// If path is specified, the authorization request will be sent to that path,
Expand Down
18 changes: 18 additions & 0 deletions api/v1alpha1/share_types_helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright Envoy Gateway Authors
// SPDX-License-Identifier: Apache-2.0
// The full text of the Apache license is available in the LICENSE file at
// the root of the repo.

package v1alpha1

import gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"

func ToBackendObjectReference(ref BackendRef) *gwapiv1.BackendObjectReference {
return &gwapiv1.BackendObjectReference{
Group: ref.Group,
Kind: ref.Kind,
Namespace: ref.Namespace,
Name: ref.Name,
Port: ref.Port,
}
}
26 changes: 24 additions & 2 deletions api/v1alpha1/zz_generated.deepcopy.go

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

Loading

0 comments on commit 78fe57a

Please sign in to comment.