Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indicate node authorizer does not support rule resolution #91030

Merged
merged 1 commit into from May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/kubeapiserver/authorizer/config.go
Expand Up @@ -86,6 +86,7 @@ func (config Config) New() (authorizer.Authorizer, authorizer.RuleResolver, erro
)
nodeAuthorizer := node.NewAuthorizer(graph, nodeidentifier.NewDefaultNodeIdentifier(), bootstrappolicy.NodeRules())
authorizers = append(authorizers, nodeAuthorizer)
ruleResolvers = append(ruleResolvers, nodeAuthorizer)

case modes.ModeAlwaysAllow:
alwaysAllowAuthorizer := authorizerfactory.NewAlwaysAllowAuthorizer()
Expand Down
1 change: 1 addition & 0 deletions plugin/pkg/auth/authorizer/node/BUILD
Expand Up @@ -52,6 +52,7 @@ go_library(
"//staging/src/k8s.io/api/rbac/v1:go_default_library",
"//staging/src/k8s.io/api/storage/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/authentication/user:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/authorization/authorizer:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//staging/src/k8s.io/client-go/informers/core/v1:go_default_library",
Expand Down
2 changes: 1 addition & 1 deletion plugin/pkg/auth/authorizer/node/graph_test.go
Expand Up @@ -188,7 +188,7 @@ func TestIndex(t *testing.T) {
g := NewGraph()
g.destinationEdgeThreshold = 3

a := NewAuthorizer(g, nil, nil).(*NodeAuthorizer)
a := NewAuthorizer(g, nil, nil)

addPod := func(podNumber, nodeNumber int) {
t.Helper()
Expand Down
14 changes: 13 additions & 1 deletion plugin/pkg/auth/authorizer/node/node_authorizer.go
Expand Up @@ -24,6 +24,7 @@ import (

rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apiserver/pkg/authentication/user"
"k8s.io/apiserver/pkg/authorization/authorizer"
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/component-base/featuregate"
Expand Down Expand Up @@ -58,8 +59,11 @@ type NodeAuthorizer struct {
features featuregate.FeatureGate
}

var _ = authorizer.Authorizer(&NodeAuthorizer{})
var _ = authorizer.RuleResolver(&NodeAuthorizer{})

// NewAuthorizer returns a new node authorizer
func NewAuthorizer(graph *Graph, identifier nodeidentifier.NodeIdentifier, rules []rbacv1.PolicyRule) authorizer.Authorizer {
func NewAuthorizer(graph *Graph, identifier nodeidentifier.NodeIdentifier, rules []rbacv1.PolicyRule) *NodeAuthorizer {
return &NodeAuthorizer{
graph: graph,
identifier: identifier,
Expand All @@ -79,6 +83,14 @@ var (
csiNodeResource = storageapi.Resource("csinodes")
)

func (r *NodeAuthorizer) RulesFor(user user.Info, namespace string) ([]authorizer.ResourceRuleInfo, []authorizer.NonResourceRuleInfo, bool, error) {
if _, isNode := r.identifier.NodeIdentity(user); isNode {
// indicate nodes do not have fully enumerated permissions
return nil, nil, true, fmt.Errorf("node authorizer does not support user rule resolution")
}
return nil, nil, false, nil
}

func (r *NodeAuthorizer) Authorize(ctx context.Context, attrs authorizer.Attributes) (authorizer.Decision, string, error) {
nodeName, isNode := r.identifier.NodeIdentity(attrs.GetUser())
if !isNode {
Expand Down
4 changes: 2 additions & 2 deletions plugin/pkg/auth/authorizer/node/node_authorizer_test.go
Expand Up @@ -82,7 +82,7 @@ func TestAuthorizer(t *testing.T) {
populate(g, nodes, pods, pvs, attachments)

identifier := nodeidentifier.NewDefaultNodeIdentifier()
authz := NewAuthorizer(g, identifier, bootstrappolicy.NodeRules()).(*NodeAuthorizer)
authz := NewAuthorizer(g, identifier, bootstrappolicy.NodeRules())

node0 := &user.DefaultInfo{Name: "system:node:node0", Groups: []string{"system:nodes"}}

Expand Down Expand Up @@ -671,7 +671,7 @@ func BenchmarkAuthorization(b *testing.B) {
populate(g, nodes, pods, pvs, attachments)

identifier := nodeidentifier.NewDefaultNodeIdentifier()
authz := NewAuthorizer(g, identifier, bootstrappolicy.NodeRules()).(*NodeAuthorizer)
authz := NewAuthorizer(g, identifier, bootstrappolicy.NodeRules())

node0 := &user.DefaultInfo{Name: "system:node:node0", Groups: []string{"system:nodes"}}

Expand Down