Debian Codegraph @

pkg/authorization/authorizerfactory/delegating.go

raw
1 /*
2 Copyright 2016 The Kubernetes Authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 package authorizerfactory
18
19 import (
20 "errors"
21 "time"
22
23 "k8s.io/apimachinery/pkg/util/wait"
24 "k8s.io/apiserver/pkg/authorization/authorizer"
25 authorizationcel "k8s.io/apiserver/pkg/authorization/cel"
26 "k8s.io/apiserver/plugin/pkg/authorizer/webhook"
27 authorizationclient "k8s.io/client-go/kubernetes/typed/authorization/v1"
28 )
29
30 // DelegatingAuthorizerConfig is the minimal configuration needed to create an authorizer
31 // built to delegate authorization to a kube API server
32 type DelegatingAuthorizerConfig struct {
33 SubjectAccessReviewClient authorizationclient.AuthorizationV1Interface
34
35 // Compiler is the CEL compiler to use for evaluating policies. If nil, a default compiler will be used.
36 Compiler authorizationcel.Compiler
37
38 // AllowCacheTTL is the length of time that a successful authorization response will be cached
39 AllowCacheTTL time.Duration
40
41 // DenyCacheTTL is the length of time that an unsuccessful authorization response will be cached.
42 // You generally want more responsive, "deny, try again" flows.
43 DenyCacheTTL time.Duration
44
45 // WebhookRetryBackoff specifies the backoff parameters for the authorization webhook retry logic.
46 // This allows us to configure the sleep time at each iteration and the maximum number of retries allowed
47 // before we fail the webhook call in order to limit the fan out that ensues when the system is degraded.
48 WebhookRetryBackoff *wait.Backoff
49 }
50
51 func (c DelegatingAuthorizerConfig) New() (authorizer.Authorizer, error) {
52 if c.WebhookRetryBackoff == nil {
53 return nil, errors.New("retry backoff parameters for delegating authorization webhook has not been specified")
54 }
55 compiler := c.Compiler
56 if compiler == nil {
57 compiler = authorizationcel.NewDefaultCompiler()
58 }
59
60 return webhook.NewFromInterface(
61 c.SubjectAccessReviewClient,
62 c.AllowCacheTTL,
63 c.DenyCacheTTL,
64 *c.WebhookRetryBackoff,
65 authorizer.DecisionNoOpinion,
66 NewDelegatingAuthorizerMetrics(),
67 compiler,
68 )
69 }