bootstrap_token_test.go 3.1 KB

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