Skip to content

Commit c75c07c

Browse files
committed
Authorize Node reads via name, not graph
1 parent 69eee1c commit c75c07c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

plugin/pkg/auth/authorizer/node/node_authorizer.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,18 @@ func (r *NodeAuthorizer) authorizeNode(nodeName string, attrs authorizer.Attribu
368368
// Use the NodeRestriction admission plugin to limit a node to creating/updating its own API object.
369369
return authorizer.DecisionAllow, "", nil
370370
case "get", "list", "watch":
371-
return r.authorize(nodeName, nodeVertexType, attrs)
371+
// Compare the name directly, rather than using the graph,
372+
// so kubelets can attempt a read of their Node API object prior to creation.
373+
switch attrs.GetName() {
374+
case nodeName:
375+
return authorizer.DecisionAllow, "", nil
376+
case "":
377+
klog.V(2).Infof("NODE DENY: '%s' %#v", nodeName, attrs)
378+
return authorizer.DecisionNoOpinion, fmt.Sprintf("node '%s' cannot read all nodes, only its own Node object", nodeName), nil
379+
default:
380+
klog.V(2).Infof("NODE DENY: '%s' %#v", nodeName, attrs)
381+
return authorizer.DecisionNoOpinion, fmt.Sprintf("node '%s' cannot read '%s', only its own Node object", nodeName, attrs.GetName()), nil
382+
}
372383
}
373384
case "status":
374385
switch attrs.GetVerb() {

plugin/pkg/auth/authorizer/node/node_authorizer_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ func TestNodeAuthorizer(t *testing.T) {
7070

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

73+
nodeunregistered := &user.DefaultInfo{Name: "system:node:nodeunregistered", Groups: []string{"system:nodes"}}
74+
7375
selectorAuthzDisabled := utilfeature.DefaultFeatureGate.DeepCopy()
7476
featuregatetesting.SetFeatureGateDuringTest(t, selectorAuthzDisabled, genericfeatures.AuthorizeWithSelectors, false)
7577
featuregatetesting.SetFeatureGateDuringTest(t, selectorAuthzDisabled, features.AuthorizeNodeWithSelectors, false)
@@ -585,6 +587,11 @@ func TestNodeAuthorizer(t *testing.T) {
585587

586588
// nodes
587589
// get nodes
590+
{
591+
name: "get related unregistered node",
592+
attrs: authorizer.AttributesRecord{User: nodeunregistered, ResourceRequest: true, Verb: "get", Resource: "nodes", APIGroup: "", Name: "nodeunregistered"},
593+
expect: authorizer.DecisionAllow,
594+
},
588595
{
589596
name: "get related node",
590597
attrs: authorizer.AttributesRecord{User: node0, ResourceRequest: true, Verb: "get", Resource: "nodes", APIGroup: "", Name: "node0"},

0 commit comments

Comments
 (0)