forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpatch_authorizer.go
53 lines (45 loc) · 2.58 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
53
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"
internalinformers "k8s.io/kubernetes/pkg/client/informers/informers_generated/internalversion"
"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(internalInformers internalinformers.SharedInformerFactory, 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,
internalInformers.Core().InternalVersion().Nodes(),
internalInformers.Core().InternalVersion().Pods(),
internalInformers.Core().InternalVersion().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
}