TLS bootstrapping

Overview

This document describes how to set up TLS client certificate bootstrapping for kubelets.Kubernetes 1.4 introduced an API for requesting certificates from a cluster-level Certificate Authority (CA). The original intent of this API is to enable provisioning of TLS client certificates for kubelets. The proposal can be found hereand progress on the feature is being tracked as feature #43.

kube-apiserver configuration

The API server should be configured with an authenticator that can authenticate tokens as a user in the system:bootstrappers group.

This group will later be used in the controller-manager configuration to scope approvals in the default approvalcontroller. As this feature matures, you should ensure tokens are bound to a Role-Based Access Control (RBAC) policy which limits requests(using the bootstrap token) strictly to client requests related to certificate provisioning. With RBAC in place, scoping the tokens to a group allows for great flexibility (e.g. you could disable a particular bootstrap group’s access when you are done provisioning the nodes).

While any authentication strategy can be used for the kubelet’s initial bootstrap credentials, the following two authenticators are recommended for ease of provisioning.

Token authentication file

Tokens are arbitrary but should represent at least 128 bits of entropy derived from a secure random numbergenerator (such as /dev/urandom on most modern systems). There are multiple ways you can generate a token. For example:

head -c 16 /dev/urandom | od -An -t x | tr -d ' '

will generate tokens that look like 02b50b05283e98dd0fd71db496ef01e8

The token file should look like the following example, where the first three values can be anything and the quoted groupname should be as depicted:

  1. 02b50b05283e98dd0fd71db496ef01e8,kubelet-bootstrap,10001,"system:bootstrappers"

Add the —token-auth-file=FILENAME flag to the kube-apiserver command (in your systemd unit file perhaps) to enable the token file.See docs here for further details.

Client certificate CA bundle

Add the —client-ca-file=FILENAME flag to the kube-apiserver command to enable client certificate authentication,referencing a certificate authority bundle containing the signing certificate (e.g. —client-ca-file=/var/lib/kubernetes/ca.pem).

kube-controller-manager configuration

The API for requesting certificates adds a certificate-issuing control loop to the Kubernetes Controller Manager. This takes the form of acfssl local signer using assets on disk. Currently, all certificates issued have one year validity and a default set of key usages.

Signing assets

You must provide a Certificate Authority in order to provide the cryptographic materials necessary to issue certificates.This CA should be trusted by kube-apiserver for authentication with the —client-ca-file=FILENAME flag. The managementof the CA is beyond the scope of this document but it is recommended that you generate a dedicated CA for Kubernetes.Both certificate and key are assumed to be PEM-encoded.

The kube-controller-manager flags are:

  1. --cluster-signing-cert-file="/etc/path/to/kubernetes/ca/ca.crt" --cluster-signing-key-file="/etc/path/to/kubernetes/ca/ca.key"

Approval controller

In 1.7 the experimental “group auto approver” controller is dropped in favor of the new csrapproving controllerthat ships as part of kube-controller-manager and is enabled by default.The controller uses the SubjectAccessReview API to determineif a given user is authorized to request a CSR, then approves based on the authorization outcome. To preventconflicts with other approvers, the builtin approver doesn’t explicitly deny CSRs, only ignoring unauthorized requests.

The controller categorizes CSRs into three subresources:

  • nodeclient - a request by a user for a client certificate with O=system:nodes and CN=system:node:(node name).
  • selfnodeclient - a node renewing a client certificate with the same O and CN.
  • selfnodeserver - a node renewing a serving certificate. (ALPHA, requires feature gate)The checks to determine if a CSR is a selfnodeserver request is currently tied to the kubelet’s credential rotationimplementation, an alpha feature. As such, the definition of selfnodeserver will likely change in a future andrequires the RotateKubeletServerCertificate feature gate on the controller manager. The feature progress can betracked at kubernetes/features#267.
  1. --feature-gates=RotateKubeletServerCertificate=true

The following RBAC ClusterRoles represent the nodeclient, selfnodeclient, and selfnodeserver capabilities. Similar rolesmay be automatically created in future releases.

  1. # A ClusterRole which instructs the CSR approver to approve a user requesting
  2. # node client credentials.
  3. kind: ClusterRole
  4. apiVersion: rbac.authorization.k8s.io/v1
  5. metadata:
  6. name: approve-node-client-csr
  7. rules:
  8. - apiGroups: ["certificates.k8s.io"]
  9. resources: ["certificatesigningrequests/nodeclient"]
  10. verbs: ["create"]
  11. ---
  12. # A ClusterRole which instructs the CSR approver to approve a node renewing its
  13. # own client credentials.
  14. kind: ClusterRole
  15. apiVersion: rbac.authorization.k8s.io/v1
  16. metadata:
  17. name: approve-node-client-renewal-csr
  18. rules:
  19. - apiGroups: ["certificates.k8s.io"]
  20. resources: ["certificatesigningrequests/selfnodeclient"]
  21. verbs: ["create"]
  22. ---
  23. # A ClusterRole which instructs the CSR approver to approve a node requesting a
  24. # serving cert matching its client cert.
  25. kind: ClusterRole
  26. apiVersion: rbac.authorization.k8s.io/v1
  27. metadata:
  28. name: approve-node-server-renewal-csr
  29. rules:
  30. - apiGroups: ["certificates.k8s.io"]
  31. resources: ["certificatesigningrequests/selfnodeserver"]
  32. verbs: ["create"]

These powers can be granted to credentials, such as bootstrapping tokens. For example, to replicate the behaviorprovided by the removed auto-approval flag, of approving all CSRs by a single group:

  1. # REMOVED: This flag no longer works as of 1.7.
  2. --insecure-experimental-approve-all-kubelet-csrs-for-group="system:bootstrappers"

An admin would create a ClusterRoleBinding targeting that group.

  1. # Approve all CSRs for the group "system:bootstrappers"
  2. kind: ClusterRoleBinding
  3. apiVersion: rbac.authorization.k8s.io/v1
  4. metadata:
  5. name: auto-approve-csrs-for-group
  6. subjects:
  7. - kind: Group
  8. name: system:bootstrappers
  9. apiGroup: rbac.authorization.k8s.io
  10. roleRef:
  11. kind: ClusterRole
  12. name: approve-node-client-csr
  13. apiGroup: rbac.authorization.k8s.io

To let a node renew its own credentials, an admin can construct a ClusterRoleBinding targetingthat node’s credentials:

  1. kind: ClusterRoleBinding
  2. apiVersion: rbac.authorization.k8s.io/v1
  3. metadata:
  4. name: node1-client-cert-renewal
  5. subjects:
  6. - kind: User
  7. name: system:node:node-1 # Let "node-1" renew its client certificate.
  8. apiGroup: rbac.authorization.k8s.io
  9. roleRef:
  10. kind: ClusterRole
  11. name: approve-node-client-renewal-csr
  12. apiGroup: rbac.authorization.k8s.io

Deleting the binding will prevent the node from renewing its client credentials, effectivelyremoving it from the cluster once its certificate expires.

kubelet configuration

To request a client certificate from kube-apiserver, the kubelet first needs a path to a kubeconfig file that contains thebootstrap authentication token. You can use kubectl config set-cluster, set-credentials, and set-context to build this kubeconfig. Provide the name kubelet-bootstrap to kubectl config set-credentials and include —token=<token-value> as follows:

  1. kubectl config set-credentials kubelet-bootstrap --token=${BOOTSTRAP_TOKEN} --kubeconfig=bootstrap.kubeconfig

When starting the kubelet, if the file specified by —kubeconfig does not exist, the bootstrap kubeconfig is used to request a client certificate from the API server. On approval of the certificate request and receipt back by the kubelet, a kubeconfig file referencing the generated key and obtained certificate is written to the path specified by —kubeconfig. The certificate and key file will be placed in the directory specified by —cert-dir.

注意:

The following flags are required to enable this bootstrapping when starting the kubelet:

  1. bootstrap-kubeconfig="/path/to/bootstrap/kubeconfig"

Additionally, in 1.7 the kubelet implements alpha features for enabling rotation of both its client and/or serving certs.These can be enabled through the respective RotateKubeletClientCertificate and RotateKubeletServerCertificate featureflags on the kubelet, but may change in backward incompatible ways in future releases.

  1. --feature-gates=RotateKubeletClientCertificate=true,RotateKubeletServerCertificate=true

RotateKubeletClientCertificate causes the kubelet to rotate its client certificates by creating new CSRs as its existingcredentials expire. RotateKubeletServerCertificate causes the kubelet to both request a serving certificate afterbootstrapping its client credentials and rotate the certificate. The serving cert currently does not request DNS or IPSANs.

kubectl approval

The signing controller does not immediately sign all certificate requests. Instead, it waits until they have been flagged with an“Approved” status by an appropriately-privileged user. This is intended to eventually be an automated process handled by an externalapproval controller, but for the alpha version of the API it can be done manually by a cluster administrator using kubectl.An administrator can list CSRs with kubectl get csr and describe one in detail with kubectl describe csr <name>. Before the 1.6 release there wereno direct approve/deny commands so an approver had to updatethe Status field directly (rough how-to). Later versions of Kubernetes offer kubectl certificate approve <name> and kubectl certificate deny <name> commands.

反馈

此页是否对您有帮助?

感谢反馈。如果您有一个关于如何使用 Kubernetes 的特定的、需要答案的问题,可以访问Stack Overflow.在 GitHub 仓库上登记新的问题报告问题或者提出改进建议.