Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ext_auth support backendRefs #3469

Merged
merged 9 commits into from
May 29, 2024
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
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Only service Kind is supported for now.
// 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