blob: 25b5aa9899dc8749375cb83035dd25fa0c855796 [file] [log] [blame]
Matthias Andreas Benkard832a54e2019-01-29 09:27:38 +01001/*
2Copyright 2016 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package authorizerfactory
18
19import (
20 "time"
21
22 "k8s.io/apiserver/pkg/authorization/authorizer"
23 authorizationclient "k8s.io/client-go/kubernetes/typed/authorization/v1beta1"
24
25 "k8s.io/apiserver/plugin/pkg/authorizer/webhook"
26)
27
28// DelegatingAuthorizerConfig is the minimal configuration needed to create an authenticator
29// built to delegate authorization to a kube API server
30type DelegatingAuthorizerConfig struct {
31 SubjectAccessReviewClient authorizationclient.SubjectAccessReviewInterface
32
33 // AllowCacheTTL is the length of time that a successful authorization response will be cached
34 AllowCacheTTL time.Duration
35
36 // DenyCacheTTL is the length of time that an unsuccessful authorization response will be cached.
37 // You generally want more responsive, "deny, try again" flows.
38 DenyCacheTTL time.Duration
39}
40
41func (c DelegatingAuthorizerConfig) New() (authorizer.Authorizer, error) {
42 return webhook.NewFromInterface(
43 c.SubjectAccessReviewClient,
44 c.AllowCacheTTL,
45 c.DenyCacheTTL,
46 )
47}