Skip to content

Commit

Permalink
CEL Support (#495)
Browse files Browse the repository at this point in the history
* CEL Support!

Signed-off-by: Alex Snaps <alex@wcgw.dev>

---------

Signed-off-by: Alex Snaps <alex@wcgw.dev>
Signed-off-by: Guilherme Cassolato <guicassolato@gmail.com>
Signed-off-by: KevFan <chfan@redhat.com>
Co-authored-by: Guilherme Cassolato <guicassolato@gmail.com>
Co-authored-by: KevFan <chfan@redhat.com>
  • Loading branch information
3 people authored Oct 30, 2024
1 parent 8e530e5 commit 82d7619
Show file tree
Hide file tree
Showing 44 changed files with 1,108 additions and 326 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ controller-gen: ## Installs controller-gen in $PROJECT_DIR/bin

KUSTOMIZE = $(PROJECT_DIR)/bin/kustomize
kustomize: ## Installs kustomize in $PROJECT_DIR/bin
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v4@v4.5.5)
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5@v5.5.0)

ENVTEST = $(PROJECT_DIR)/bin/setup-envtest
envtest: ## Installs setup-envtest in $PROJECT_DIR/bin
Expand Down Expand Up @@ -118,11 +118,11 @@ vet: ## Runs go vet against code
go vet ./...

generate: vendor controller-gen ## Generates types deepcopy code
controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
$(MAKE) fmt vet

manifests: controller-gen kustomize ## Generates the manifests in $PROJECT_DIR/install
controller-gen crd:crdVersions=v1 rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=install/crd output:rbac:artifacts:config=install/rbac && $(KUSTOMIZE) build install > $(AUTHORINO_MANIFESTS)
$(CONTROLLER_GEN) crd:crdVersions=v1 rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=install/crd output:rbac:artifacts:config=install/rbac && $(KUSTOMIZE) build install > $(AUTHORINO_MANIFESTS)
$(MAKE) patch-webhook

run:git_sha=$(shell git rev-parse HEAD)
Expand Down
18 changes: 15 additions & 3 deletions api/v1beta3/auth_config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,19 @@ type PatternExpression struct {
Value string `json:"value,omitempty"`
}

type CelExpression string

type CelPredicate struct {
Predicate string `json:"predicate,omitempty"`
}

// +kubebuilder:validation:Enum:=eq;neq;incl;excl;matches
type PatternExpressionOperator string

type PatternExpressionOrRef struct {
PatternExpression `json:",omitempty"`
PatternRef `json:",omitempty"`

CelPredicate `json:",omitempty"`
// A list of pattern expressions to be evaluated as a logical AND.
All []UnstructuredPatternExpressionOrRef `json:"all,omitempty"`
// A list of pattern expressions to be evaluated as a logical OR.
Expand Down Expand Up @@ -199,6 +205,8 @@ type ValueOrSelector struct {
// Any pattern supported by https://pkg.go.dev/github.com/tidwall/gjson can be used.
// The following Authorino custom modifiers are supported: @extract:{sep:" ",pos:0}, @replace{old:"",new:""}, @case:upper|lower, @base64:encode|decode and @strip.
Selector string `json:"selector,omitempty"`

Expression CelExpression `json:"expression,omitempty"`
}

type CommonEvaluatorSpec struct {
Expand Down Expand Up @@ -401,7 +409,9 @@ type PlainIdentitySpec struct {
// Simple path selector to fetch content from the authorization JSON (e.g. 'request.method') or a string template with variables that resolve to patterns (e.g. "Hello, {auth.identity.name}!").
// Any pattern supported by https://pkg.go.dev/github.com/tidwall/gjson can be used.
// The following Authorino custom modifiers are supported: @extract:{sep:" ",pos:0}, @replace{old:"",new:""}, @case:upper|lower, @base64:encode|decode and @strip.
Selector string `json:"selector"`
Selector string `json:"selector,omitempty"`

Expression CelExpression `json:"expression,omitempty"`
}

type AnonymousAccessSpec struct{}
Expand Down Expand Up @@ -437,7 +447,9 @@ type HttpEndpointSpec struct {
// The value can include variable placeholders in the format "{selector}", where "selector" is any pattern supported
// by https://pkg.go.dev/github.com/tidwall/gjson and selects value from the authorization JSON.
// E.g. https://ext-auth-server.io/metadata?p={request.path}
Url string `json:"url"`
Url string `json:"url,omitempty"`

UrlExpression CelExpression `json:"urlExpression,omitempty"`

// HTTP verb used in the request to the service. Accepted values: GET (default), POST.
// When the request method is POST, the authorization JSON is passed in the body of the request.
Expand Down
16 changes: 16 additions & 0 deletions api/v1beta3/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 82d7619

Please sign in to comment.