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

Add missing checkpoint permissions to system:kubelet-api-admin #126724

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions plugin/pkg/auth/authorizer/rbac/bootstrappolicy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,17 +387,6 @@ func ClusterRoles() []rbacv1.ClusterRole {
eventsRule(),
},
},
{
// a role to use for full access to the kubelet API
ObjectMeta: metav1.ObjectMeta{Name: "system:kubelet-api-admin"},
Rules: []rbacv1.PolicyRule{
// Allow read-only access to the Node API objects
rbacv1helpers.NewRule("get", "list", "watch").Groups(legacyGroup).Resources("nodes").RuleOrDie(),
// Allow all API calls to the nodes
rbacv1helpers.NewRule("proxy").Groups(legacyGroup).Resources("nodes").RuleOrDie(),
rbacv1helpers.NewRule("*").Groups(legacyGroup).Resources("nodes/proxy", "nodes/metrics", "nodes/stats", "nodes/log").RuleOrDie(),
},
},
{
// a role to use for bootstrapping a node's client certificates
ObjectMeta: metav1.ObjectMeta{Name: "system:node-bootstrapper"},
Expand Down Expand Up @@ -515,6 +504,24 @@ func ClusterRoles() []rbacv1.ClusterRole {
},
}...)

kubeletAPIAdminRules := []rbacv1.PolicyRule{
// Allow read-only access to the Node API objects
rbacv1helpers.NewRule("get", "list", "watch").Groups(legacyGroup).Resources("nodes").RuleOrDie(),
// Allow all API calls to the nodes
rbacv1helpers.NewRule("proxy").Groups(legacyGroup).Resources("nodes").RuleOrDie(),
rbacv1helpers.NewRule("*").Groups(legacyGroup).Resources("nodes/proxy", "nodes/metrics", "nodes/stats", "nodes/log").RuleOrDie(),
}

if utilfeature.DefaultFeatureGate.Enabled(features.ContainerCheckpoint) {
vinayakankugoyal marked this conversation as resolved.
Show resolved Hide resolved
kubeletAPIAdminRules = append(kubeletAPIAdminRules, rbacv1helpers.NewRule("*").Groups(legacyGroup).Resources("nodes/checkpoint").RuleOrDie())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: prefer a specific verb if the kubelet only supports a single verb on the checkpoint subresource

}

roles = append(roles, rbacv1.ClusterRole{
// a role to use for full access to the kubelet API
ObjectMeta: metav1.ObjectMeta{Name: "system:kubelet-api-admin"},
Rules: kubeletAPIAdminRules,
})

// Add the cluster role for reading the ServiceAccountIssuerDiscovery endpoints
// Also allow slash-ended URLs to allow clients generated from published openapi docs prior to fixing the trailing slash to work properly
roles = append(roles, rbacv1.ClusterRole{
Expand Down
69 changes: 69 additions & 0 deletions plugin/pkg/auth/authorizer/rbac/bootstrappolicy/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ import (
v1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/sets"
utilfeature "k8s.io/apiserver/pkg/util/feature"
featuregatetesting "k8s.io/component-base/featuregate/testing"
"k8s.io/component-helpers/auth/rbac/validation"
"k8s.io/kubernetes/pkg/api/legacyscheme"
api "k8s.io/kubernetes/pkg/apis/core"
_ "k8s.io/kubernetes/pkg/apis/core/install"
_ "k8s.io/kubernetes/pkg/apis/rbac/install"
rbacv1helpers "k8s.io/kubernetes/pkg/apis/rbac/v1"
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/plugin/pkg/auth/authorizer/rbac/bootstrappolicy"
)

Expand Down Expand Up @@ -259,6 +263,71 @@ func testObjects(t *testing.T, list *api.List, fixtureFilename string) {
}
}

func TestClusterRoleKubeletAPIAdmin(t *testing.T) {
testCases := []struct {
name string
featureGate bool
wantClusterRole rbacv1.ClusterRole
}{
{
name: "Checkpoint feature gate disabled",
featureGate: false,
wantClusterRole: rbacv1.ClusterRole{
// a role to use for full access to the kubelet API
ObjectMeta: metav1.ObjectMeta{
Name: "system:kubelet-api-admin",
Labels: map[string]string{"kubernetes.io/bootstrapping": "rbac-defaults"},
Annotations: map[string]string{"rbac.authorization.kubernetes.io/autoupdate": "true"},
},
Rules: []rbacv1.PolicyRule{
// Allow read-only access to the Node API objects
rbacv1helpers.NewRule("get", "list", "watch").Groups("").Resources("nodes").RuleOrDie(),
// Allow all API calls to the nodes
rbacv1helpers.NewRule("proxy").Groups("").Resources("nodes").RuleOrDie(),
rbacv1helpers.NewRule("*").Groups("").Resources("nodes/proxy", "nodes/metrics", "nodes/stats", "nodes/log").RuleOrDie(),
},
},
},
{
name: "Checkpoint feature gate enabled",
featureGate: true,
wantClusterRole: rbacv1.ClusterRole{
// a role to use for full access to the kubelet API
ObjectMeta: metav1.ObjectMeta{
Name: "system:kubelet-api-admin",
Labels: map[string]string{"kubernetes.io/bootstrapping": "rbac-defaults"},
Annotations: map[string]string{"rbac.authorization.kubernetes.io/autoupdate": "true"},
},
Rules: []rbacv1.PolicyRule{
// Allow read-only access to the Node API objects
rbacv1helpers.NewRule("get", "list", "watch").Groups("").Resources("nodes").RuleOrDie(),
// Allow all API calls to the nodes
rbacv1helpers.NewRule("proxy").Groups("").Resources("nodes").RuleOrDie(),
rbacv1helpers.NewRule("*").Groups("").Resources("nodes/proxy", "nodes/metrics", "nodes/stats", "nodes/log").RuleOrDie(),
rbacv1helpers.NewRule("*").Groups("").Resources("nodes/checkpoint").RuleOrDie(),
},
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ContainerCheckpoint, tc.featureGate)
clusterRoles := bootstrappolicy.ClusterRoles()
for _, cr := range clusterRoles {
if cr.GetName() != "system:kubelet-api-admin" {
continue
}

if diff := cmp.Diff(tc.wantClusterRole, cr); diff != "" {
t.Errorf("Unexpected diff \n%s", diff)
}
}
})
}

}

func TestClusterRoleLabel(t *testing.T) {
roles := bootstrappolicy.ClusterRoles()
for i := range roles {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,12 @@ items:
- nodes/stats
verbs:
- '*'
- apiGroups:
- ""
resources:
- nodes/checkpoint
verbs:
- '*'
- apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
Expand Down