|
| 1 | +/* |
| 2 | +Copyright 2019 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package e2e_kubeadm |
| 18 | + |
| 19 | +import ( |
| 20 | + corev1 "k8s.io/api/core/v1" |
| 21 | + rbacv1 "k8s.io/api/rbac/v1" |
| 22 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 23 | + "k8s.io/kubernetes/test/e2e/framework" |
| 24 | + |
| 25 | + . "github.com/onsi/ginkgo" |
| 26 | + . "github.com/onsi/gomega" |
| 27 | +) |
| 28 | + |
| 29 | +const ( |
| 30 | + bootstrapTokensGroup = "system:bootstrappers:kubeadm:default-node-token" |
| 31 | + bootstrapTokensAllowPostCSRClusterRoleBinding = "kubeadm:kubelet-bootstrap" |
| 32 | + bootstrapTokensAllowPostCSRClusterRoleName = "system:node-bootstrapper" |
| 33 | + bootstrapTokensCSRAutoApprovalClusterRoleBinding = "kubeadm:node-autoapprove-bootstrap" |
| 34 | + bootstrapTokensCSRAutoApprovalClusterRoleName = "system:certificates.k8s.io:certificatesigningrequests:nodeclient" |
| 35 | +) |
| 36 | + |
| 37 | +// Define container for all the test specification aimed at verifying |
| 38 | +// that kubeadm creates the bootstrap token, the system:bootstrappers:kubeadm:default-node-token group |
| 39 | +// and that all the related RBAC rules are in place |
| 40 | +var _ = KubeadmDescribe("bootstrap token", func() { |
| 41 | + |
| 42 | + // Get an instance of the k8s test framework |
| 43 | + f := framework.NewDefaultFramework("bootstrap token") |
| 44 | + |
| 45 | + // Tests in this container are not expected to create new objects in the cluster |
| 46 | + // so we are disabling the creation of a namespace in order to get a faster execution |
| 47 | + f.SkipNamespaceCreation = true |
| 48 | + |
| 49 | + It("should exist and be properly configured", func() { |
| 50 | + secrets, err := f.ClientSet.CoreV1(). |
| 51 | + Secrets(kubeSystemNamespace). |
| 52 | + List(metav1.ListOptions{}) |
| 53 | + framework.ExpectNoError(err, "error reading Secrets") |
| 54 | + |
| 55 | + tokenNum := 0 |
| 56 | + for _, s := range secrets.Items { |
| 57 | + if s.Type == corev1.SecretTypeBootstrapToken { |
| 58 | + //TODO: might be we want to further check tokens (auth-extra-groups, usage etc) |
| 59 | + tokenNum++ |
| 60 | + } |
| 61 | + } |
| 62 | + Expect(tokenNum).Should(BeNumerically(">", 0), "At least one bootstrap token should exist") |
| 63 | + }) |
| 64 | + |
| 65 | + It("should be allowed to post CSR for kubelet certificates on joining nodes", func() { |
| 66 | + ExpectClusterRoleBindingWithSubjectAndRole(f.ClientSet, |
| 67 | + bootstrapTokensAllowPostCSRClusterRoleBinding, |
| 68 | + rbacv1.GroupKind, bootstrapTokensGroup, |
| 69 | + bootstrapTokensAllowPostCSRClusterRoleName, |
| 70 | + ) |
| 71 | + //TODO: check if possible to verify "allowed to post CSR" using subject asses review as well |
| 72 | + }) |
| 73 | + |
| 74 | + It("should be allowed to auto approve CSR for kubelet certificates on joining nodes", func() { |
| 75 | + ExpectClusterRoleBindingWithSubjectAndRole(f.ClientSet, |
| 76 | + bootstrapTokensCSRAutoApprovalClusterRoleBinding, |
| 77 | + rbacv1.GroupKind, bootstrapTokensGroup, |
| 78 | + bootstrapTokensCSRAutoApprovalClusterRoleName, |
| 79 | + ) |
| 80 | + //TODO: check if possible to verify "allowed to auto approve CSR" using subject asses review as well |
| 81 | + }) |
| 82 | +}) |
0 commit comments