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

[WIP] Add document explaining certificates and PKI for Kubernetes #8232

Closed
wants to merge 3 commits into from

Conversation

liztio
Copy link
Contributor

@liztio liztio commented Apr 30, 2018

This file is intended to help people understand the PKI around Kubernetes and how it can be configured when not delegating management to automated scripts.

I don't need to be on the approvers list, I just didn't know who else to put there.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 30, 2018
@liztio
Copy link
Contributor Author

liztio commented Apr 30, 2018

/cc @Bradamant3

@k8s-ci-robot k8s-ci-robot requested a review from Bradamant3 April 30, 2018 20:41
@k8sio-netlify-preview-bot
Copy link
Collaborator

k8sio-netlify-preview-bot commented Apr 30, 2018

Deploy preview for kubernetes-io-master-staging failed.

Built with commit b1f3cd3

https://app.netlify.com/sites/kubernetes-io-master-staging/deploys/5b6d97b6fdd72a5ddc772fc8

@Bradamant3
Copy link
Contributor

/assign

@liztio
Copy link
Contributor Author

liztio commented Apr 30, 2018

Needs inroads from existing documentation as well.

@Bradamant3
Copy link
Contributor

Travis CI build is failing bc TOC entry is missing -- this is by design at this point. I told Liz I'd work with her to figure out the best place to put it -- not immediately obvious. Incoming links per previous comment also important, yes. Modifying PR title and putting hold accordingly

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 30, 2018
@Bradamant3 Bradamant3 changed the title Add document explaining certificates and PKI for Kubernetes [WIP] Add document explaining certificates and PKI for Kubernetes Apr 30, 2018
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 30, 2018
@Bradamant3
Copy link
Contributor

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 30, 2018
@tengqm
Copy link
Contributor

tengqm commented May 1, 2018

The content of this page is mostly about kubeadm although the text sometimes is trying to make kubeadm just an example. I'd suggest this to be moved over to the kubeadm subtopic. The certificates topic is more than what kubeadm has implemented/supported, and there are many cases where people deploy their clusters using other tools. If we believe the generic concepts in the page can be extracted out as a top level reference topic, please do it.

@liztio
Copy link
Contributor Author

liztio commented May 1, 2018

@tengqm if you've got suggestions about how this could be made more generally applicable I'd love to hear them!

Copy link
Member

@detiber detiber left a comment

Choose a reason for hiding this comment

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

Great work on putting this together.


# Introduction

A tool like [kubeadm][kubeadm] can be used to generate your configuration for you.
Copy link
Member

Choose a reason for hiding this comment

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

Did you mean to use certificates here instead of configuration?

1. Client certificates for the kubelet to authenticate to the master
2. Server certificate for the api server endpoint
3. Client certificates for administrators of the cluster authenticating to the API server
4. Client certificates for service accounts authenticating to the API server.
Copy link
Member

Choose a reason for hiding this comment

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

This is being a bit pedantic, but technically the service accounts are using a generated public/private keypair only.

Copy link
Member

Choose a reason for hiding this comment

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

Certificates are also used for the following:

  • client certificate for the api server to talk to the kubelets
  • client certificate for the api server to talk to etcd
  • client certificate/kubeconfig for controller manager to talk to api server
  • client certificate/kubeconfig for scheduler to talk to api server

Copy link
Member

Choose a reason for hiding this comment

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

It may be good to mention the use of the front-proxy certs here as well, which are used to enable extension api servers as described here: https://kubernetes.io/docs/concepts/api-extension/apiserver-aggregation/


## Where they're used

Kubernetes uses kubeadm for four primary things:
Copy link
Member

Choose a reason for hiding this comment

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

s/kubeadm/certificates/

## Where they're used

Kubernetes uses kubeadm for four primary things:
1. Client certificates for the kubelet to authenticate to the master
Copy link
Member

Choose a reason for hiding this comment

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

s/master/api server/

3. Client certificates for administrators of the cluster authenticating to the API server
4. Client certificates for service accounts authenticating to the API server.

In addition, etcd uses mutual TLS for authenticating peers (in an HA cluster).$
Copy link
Member

Choose a reason for hiding this comment

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

s/peers/clients and peers/


The CAs needed for this to work are:

| path | CN | description |
Copy link
Member

Choose a reason for hiding this comment

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

should this be "path relative to /etc/kubernetes/pki" instead?

Copy link
Member

Choose a reason for hiding this comment

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

s/CN/default CN/

The actual CN used should not matter for the CAs

| CN | Parent CA | O (in Subject) | kind | hosts (SAN) |
|-------------------------------|---------------------------|----------------|--------|---------------------------------------------|
| kube-etcd | etcd-ca | | server | localhost, 127.0.0.1 |
| kube-etcd-peel | etcd-ca | | peer | <hostname>, <Host IP>, localhost, 127.0.0.1 |
Copy link
Member

Choose a reason for hiding this comment

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

s/peel/peer/


[usage]: https://tools.ietf.org/html/rfc5280#section-4.2.1.3
[kubeadm]: https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm/
[proxy]: https://kubernetes.io/docs/tasks/access-application-cluster/access-cluster/#discovering-builtin-services
Copy link
Member

Choose a reason for hiding this comment

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

@tengqm
Copy link
Contributor

tengqm commented May 2, 2018

@liztio My suggestion is as follows:

@zacharysarah
Copy link
Contributor

@liztio 👋 We've migrated the site's framework to Hugo. Please re-open this PR with changes to files in their post-migration location (/content/en/docs/...) and reference this PR in the new PR's description.

@Bradamant3 Bradamant3 reopened this May 24, 2018
@Bradamant3
Copy link
Contributor

Bradamant3 commented May 24, 2018

Reopening to remind me to help with this one as promised a while ago. PLEASE DO NOT CLOSE AGAIN.

@Bradamant3
Copy link
Contributor

@timothysc timothysc changed the title [WIP] Add document explaining certificates and PKI for Kubernetes Add document explaining certificates and PKI for Kubernetes Jun 13, 2018
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 13, 2018
Copy link
Member

@detiber detiber left a comment

Choose a reason for hiding this comment

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

Overall this is looking great :)

8. Client and server certificates for the [front-proxy][proxy]


In addition, etcd uses mutual TLS for authenticating clients and peers (in an HA cluster).
Copy link
Member

Choose a reason for hiding this comment

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

Since we are generated certificates for the peer regardless of HA/non-HA, we can probably just remove the '(in a HA cluster)' qualifier here. Currently this reads a bit off to me because it's not clear to me that '(in a HA cluster)' only applies to the peer usage.


| Default CN | Parent CA | O (in Subject) | kind | hosts (SAN) |
|-------------------------------|---------------------------|----------------|--------|---------------------------------------------|
| kube-etcd | etcd-ca | | server | localhost, 127.0.0.1 |
Copy link
Member

Choose a reason for hiding this comment

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

Since v1.11 now uses etcd 3.2.x, we currently have to create the etcd serving certificate with both server and client usages. Upstream etcd issue tracking this is here: etcd-io/etcd#9785

|-------------------------------|---------------------------|----------------|--------|---------------------------------------------|
| kube-etcd | etcd-ca | | server | localhost, 127.0.0.1 |
| kube-etcd-peer | etcd-ca | | peer | <hostname>, <Host IP>, localhost, 127.0.0.1 |
| kube-etcd-healthcheck-client | etcd-ca | system:masters | peer | |
Copy link
Member

Choose a reason for hiding this comment

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

kind for the kube-etcd-healthcheck-client cert should be client

Copy link

@JinsYin JinsYin Jun 19, 2018

Choose a reason for hiding this comment

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

Where will the kube-etcd-healthcheck-client CN be used? And it acts as a system:masters subject.

Copy link
Member

@detiber detiber Jun 19, 2018

Choose a reason for hiding this comment

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

It is used by the healthcheck for the etcd static pod deployed by kubeadm.

This is currently how the kube-etcd-healthcheck-client cert is created using kubeadm today.

The system:masters subject here is a bit misleading and isn't necessary. Since this cert is created using the etcd CA it does not grant any additional permissions above and beyond any other cert that is created from that CA since we aren't enabling RBAC for etcd (at least yet).

| kube-etcd-healthcheck-client | etcd-ca | system:masters | peer | |
| kube-apiserver-etcd-client | etcd-ca | system:masters | client | |
| kube-apiserver | kubernetes-ca | | server | <hostname>, <Host IP>, <advertise IP> , [1] |
| kube-apiserver-client | kubernetes-ca | system:master | client | |
Copy link
Member

Choose a reason for hiding this comment

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

I think kube-apiserver-client might be a typo here. I'm not sure if it is extraneous or should be named something else, though.

| filename | credential name | Default CN | O (in Subject) |
|-------------------------|----------------------------|--------------------------------|----------------|
| admin.conf | default-admin | kubernetes-admin | system:masters |
| kubelet.conf | default-auth | system:node:<hostname> | system:nodes |
Copy link
Member

Choose a reason for hiding this comment

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

The credential name for kubelet.conf should be system:node:<nodename>

KUBECONFIG=<path> kubectl config set-cluster default-cluster --server=https://<host ip>:6443 --certificate-authority <path to kubernetes ca> --embed-certs
KUBECONFIG=<path> kubectl config set-credentials <credential-name> --client-key <path-to-key>.pem --client-certificate <path-to-cert>.pem --embed-certs
KUBECONFIG=<path> kubectl config set-context default-system --cluster default-cluster --user <credential-name>
KUBECONFIG=<path> kubectl config use-context default-system
Copy link
Member

Choose a reason for hiding this comment

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

Path is used here, but appears to be referenced below.

| default-admin | admin.conf | kubectl | used by a user to administer the cluster |
| default-auth | kubelet.conf | kubelet | one will be needed for every node in the cluster. |
| default-controller-manager | controller-manager.conf | kube-controller-manager | add to manifest in `manifests/kube-controller-manager.yaml` |
| default-scheduler | scheduler.conf | kube-scheduler | add to manifest in `manifests/kube-scheduler.yaml` |
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest adding path to the above table and removing name from this table.

@chenopis
Copy link
Contributor

@liztio Please respond to the remaining feedback. Thx

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To fully approve this pull request, please assign additional approvers.
We suggest the following additional approver: bradamant3

If they are not already assigned, you can assign the PR to them by writing /assign @bradamant3 in a comment when ready.

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@liztio
Copy link
Contributor Author

liztio commented Aug 2, 2018

@chenopis done, sorry it took so long!

@Bradamant3 Bradamant3 changed the title Add document explaining certificates and PKI for Kubernetes [WIP] Add document explaining certificates and PKI for Kubernetes Aug 10, 2018
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 10, 2018
@Bradamant3
Copy link
Contributor

added WIP to make sure we don't accidentally merge.

Pushed copyedit commit to this version so that @liztio can take a look. I'll then push up new PR based on hugo from their fork. N.B. this version does not resolve the links markup issue in Hugo. (not needed for content review)

In that case, you will also need to make all of these:
| ca.crt,key | kubernetes-ca | Kubernetes general CA |
| etcd/ca.crt,key | etcd-ca | For all etcd-related functions |
| front-proxy-ca.crt,key | kubernetes-front-proxy-ca | For the [front-end proxy][proxy] |
Copy link
Contributor

Choose a reason for hiding this comment

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

It looked as though this and the previous line somehow got reversed in the version that I edited. If I've misunderstood something obscure, my apologies (but if I've misunderstood, we should explain a bit more too).

| kube-apiserver-kubelet-client | kubernetes-ca | system:masters | client | |
| front-proxy-client | kubernetes-front-proxy-ca | | client | |

[1]: `kubernetes`, `kubernetes.default`, `kubernetes.default.svc`, `kubernetes.default.svc.cluster`, `kubernetes.default.svc.cluster.local`
Copy link
Contributor

Choose a reason for hiding this comment

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

Changed markup for this and other notes because they weren't rendering at all in the original.

@Bradamant3
Copy link
Contributor

Finally closing unmerged bc we at long last have the Hugo PR.

@Bradamant3 Bradamant3 closed this Aug 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants