...
1
16
17 package kubeadm
18
19 import (
20 "context"
21
22 corev1 "k8s.io/api/core/v1"
23 rbacv1 "k8s.io/api/rbac/v1"
24 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25 bootstrapapi "k8s.io/cluster-bootstrap/token/api"
26 "k8s.io/kubernetes/test/e2e/framework"
27 admissionapi "k8s.io/pod-security-admission/api"
28
29 "github.com/onsi/ginkgo/v2"
30 "github.com/onsi/gomega"
31 )
32
33 const (
34 bootstrapTokensGroup = "system:bootstrappers:kubeadm:default-node-token"
35 bootstrapTokensAllowPostCSRClusterRoleBinding = "kubeadm:kubelet-bootstrap"
36 bootstrapTokensAllowPostCSRClusterRoleName = "system:node-bootstrapper"
37 bootstrapTokensCSRAutoApprovalClusterRoleBinding = "kubeadm:node-autoapprove-bootstrap"
38 bootstrapTokensCSRAutoApprovalClusterRoleName = "system:certificates.k8s.io:certificatesigningrequests:nodeclient"
39 )
40
41
42
43
44 var _ = Describe("bootstrap token", func() {
45
46
47 f := framework.NewDefaultFramework("bootstrap token")
48 f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged
49
50
51
52 f.SkipNamespaceCreation = true
53
54 ginkgo.It("should exist and be properly configured", func(ctx context.Context) {
55 secrets, err := f.ClientSet.CoreV1().
56 Secrets(kubeSystemNamespace).
57 List(ctx, metav1.ListOptions{})
58 framework.ExpectNoError(err, "error reading Secrets")
59
60 tokenNum := 0
61 for _, s := range secrets.Items {
62
63 if s.Type == corev1.SecretTypeBootstrapToken && string(s.Data[bootstrapapi.BootstrapTokenExtraGroupsKey]) == bootstrapTokensGroup {
64 usageBootstrapAuthentication := string(s.Data[bootstrapapi.BootstrapTokenUsageAuthentication])
65 usageBootstrapSigning := string(s.Data[bootstrapapi.BootstrapTokenUsageSigningKey])
66 gomega.Expect(usageBootstrapAuthentication).Should(gomega.Equal("true"), "the bootstrap token should be able to be used for authentication")
67 gomega.Expect(usageBootstrapSigning).Should(gomega.Equal("true"), "the bootstrap token should be able to be used for signing")
68 tokenNum++
69 }
70 }
71 gomega.Expect(tokenNum).Should(gomega.BeNumerically(">", 0), "At least one bootstrap token should exist")
72 })
73
74 ginkgo.It("should be allowed to post CSR for kubelet certificates on joining nodes", func(ctx context.Context) {
75 ExpectClusterRoleBindingWithSubjectAndRole(f.ClientSet,
76 bootstrapTokensAllowPostCSRClusterRoleBinding,
77 rbacv1.GroupKind, bootstrapTokensGroup,
78 bootstrapTokensAllowPostCSRClusterRoleName,
79 )
80 })
81
82 ginkgo.It("should be allowed to auto approve CSR for kubelet certificates on joining nodes", func(ctx context.Context) {
83 ExpectClusterRoleBindingWithSubjectAndRole(f.ClientSet,
84 bootstrapTokensCSRAutoApprovalClusterRoleBinding,
85 rbacv1.GroupKind, bootstrapTokensGroup,
86 bootstrapTokensCSRAutoApprovalClusterRoleName,
87 )
88 })
89 })
90
View as plain text