/
patch_authorizer.go
52 lines (44 loc) · 2.39 KB
/
patch_authorizer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package openshiftkubeapiserver
import (
"k8s.io/apiserver/pkg/authentication/user"
"k8s.io/apiserver/pkg/authorization/authorizer"
"k8s.io/apiserver/pkg/authorization/authorizerfactory"
authorizerunion "k8s.io/apiserver/pkg/authorization/union"
"k8s.io/client-go/informers"
"k8s.io/kubernetes/pkg/auth/nodeidentifier"
"k8s.io/kubernetes/plugin/pkg/auth/authorizer/node"
rbacauthorizer "k8s.io/kubernetes/plugin/pkg/auth/authorizer/rbac"
kbootstrappolicy "k8s.io/kubernetes/plugin/pkg/auth/authorizer/rbac/bootstrappolicy"
"github.com/openshift/origin/pkg/authorization/authorizer/browsersafe"
"github.com/openshift/origin/pkg/authorization/authorizer/scope"
)
func NewAuthorizer(versionedInformers informers.SharedInformerFactory) authorizer.Authorizer {
rbacInformers := versionedInformers.Rbac().V1()
scopeLimitedAuthorizer := scope.NewAuthorizer(rbacInformers.ClusterRoles().Lister())
kubeAuthorizer := rbacauthorizer.New(
&rbacauthorizer.RoleGetter{Lister: rbacInformers.Roles().Lister()},
&rbacauthorizer.RoleBindingLister{Lister: rbacInformers.RoleBindings().Lister()},
&rbacauthorizer.ClusterRoleGetter{Lister: rbacInformers.ClusterRoles().Lister()},
&rbacauthorizer.ClusterRoleBindingLister{Lister: rbacInformers.ClusterRoleBindings().Lister()},
)
graph := node.NewGraph()
node.AddGraphEventHandlers(
graph,
versionedInformers.Core().V1().Nodes(),
versionedInformers.Core().V1().Pods(),
versionedInformers.Core().V1().PersistentVolumes(),
versionedInformers.Storage().V1beta1().VolumeAttachments(),
)
nodeAuthorizer := node.NewAuthorizer(graph, nodeidentifier.NewDefaultNodeIdentifier(), kbootstrappolicy.NodeRules())
openshiftAuthorizer := authorizerunion.New(
// Wrap with an authorizer that detects unsafe requests and modifies verbs/resources appropriately so policy can address them separately.
// Scopes are first because they will authoritatively deny and can logically be attached to anyone.
browsersafe.NewBrowserSafeAuthorizer(scopeLimitedAuthorizer, user.AllAuthenticated),
// authorizes system:masters to do anything, just like upstream
authorizerfactory.NewPrivilegedGroups(user.SystemPrivilegedGroup),
nodeAuthorizer,
// Wrap with an authorizer that detects unsafe requests and modifies verbs/resources appropriately so policy can address them separately
browsersafe.NewBrowserSafeAuthorizer(kubeAuthorizer, user.AllAuthenticated),
)
return openshiftAuthorizer
}