k3s/pkg/util
Kubernetes Submit Queue 337dfe0a9c
Merge pull request #65594 from liggitt/node-csr-addresses-2
Automatic merge from submit-queue (batch tested with PRs 65052, 65594). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Derive kubelet serving certificate CSR template from node status addresses

xref https://github.com/kubernetes/features/issues/267
fixes #55633

Builds on https://github.com/kubernetes/kubernetes/pull/65587

* Makes the cloud provider authoritative when recording node status addresses
* Makes the node status addresses authoritative for the kube-apiserver determining how to speak to a kubelet (stops paying attention to the hostname label when determining how to reach a kubelet, which was only done to support kubelets < 1.5)
* Updates kubelet certificate rotation to be driven from node status
  * Avoids needing to compute node addresses a second time, and differently, in order to request serving certificates.
  * Allows the kubelet to react to changes in its status addresses by updating its serving certificate
  * Allows the kubelet to be driven by external cloud providers recording node addresses on the node status

test procedure:
```sh
# setup
export FEATURE_GATES=RotateKubeletServerCertificate=true
export KUBELET_FLAGS="--rotate-server-certificates=true --cloud-provider=external"

# cleanup from previous runs
sudo rm -fr /var/lib/kubelet/pki/

# startup
hack/local-up-cluster.sh

# wait for a node to register, verify it didn't set addresses
kubectl get nodes 
kubectl get node/127.0.0.1 -o jsonpath={.status.addresses}

# verify the kubelet server isn't available, and that it didn't populate a serving certificate
curl --cacert _output/certs/server-ca.crt -v https://localhost:10250/pods
ls -la /var/lib/kubelet/pki

# set an address on the node
curl -X PATCH http://localhost:8080/api/v1/nodes/127.0.0.1/status \
  -H "Content-Type: application/merge-patch+json" \
  --data '{"status":{"addresses":[{"type":"Hostname","address":"localhost"}]}}'

# verify a csr was submitted with the right SAN, and approve it
kubectl describe csr
kubectl certificate approve csr-...

# verify the kubelet connection uses a cert that is properly signed and valid for the specified hostname, but NOT the IP
curl --cacert _output/certs/server-ca.crt -v https://localhost:10250/pods
curl --cacert _output/certs/server-ca.crt -v https://127.0.0.1:10250/pods
ls -la /var/lib/kubelet/pki

# set an hostname and IP address on the node
curl -X PATCH http://localhost:8080/api/v1/nodes/127.0.0.1/status \
  -H "Content-Type: application/merge-patch+json" \
  --data '{"status":{"addresses":[{"type":"Hostname","address":"localhost"},{"type":"InternalIP","address":"127.0.0.1"}]}}'

# verify a csr was submitted with the right SAN, and approve it
kubectl describe csr
kubectl certificate approve csr-...

# verify the kubelet connection uses a cert that is properly signed and valid for the specified hostname AND IP
curl --cacert _output/certs/server-ca.crt -v https://localhost:10250/pods
curl --cacert _output/certs/server-ca.crt -v https://127.0.0.1:10250/pods
ls -la /var/lib/kubelet/pki
```

```release-note
* kubelets that specify `--cloud-provider` now only report addresses in Node status as determined by the cloud provider
* kubelet serving certificate rotation now reacts to changes in reported node addresses, and will request certificates for addresses set by an external cloud provider
```
2018-07-11 22:25:07 -07:00
..
async Run hack/update-bazel.sh 2018-06-22 16:22:57 -07:00
bandwidth Run hack/update-bazel.sh 2018-06-22 16:22:57 -07:00
config Run hack/update-bazel.sh 2018-06-22 16:22:57 -07:00
configz set right Content-Type for configz 2018-03-29 16:07:47 +08:00
conntrack Run hack/update-bazel.sh 2018-06-22 16:22:57 -07:00
dbus Autogenerated: hack/update-bazel.sh 2018-02-16 13:43:01 -08:00
ebtables Autogenerated: hack/update-bazel.sh 2018-02-16 13:43:01 -08:00
env Autogenerated: hack/update-bazel.sh 2018-02-16 13:43:01 -08:00
file Autogenerated: hack/update-bazel.sh 2018-02-16 13:43:01 -08:00
filesystem unpack dynamic kubelet config payloads to files 2018-04-19 09:18:53 -07:00
flag Log the command line flags 2018-02-15 18:04:04 -05:00
flock Update to gazelle 0.12.0 and run hack/update-bazel.sh 2018-06-22 16:22:18 -07:00
goroutinemap Run hack/update-bazel.sh 2018-06-22 16:22:57 -07:00
hash Autogenerated: hack/update-bazel.sh 2018-02-16 13:43:01 -08:00
initsystem Add a 'kubeadm upgrade node config' command and finish up the kubelet integration work 2018-06-06 23:17:04 +03:00
interrupt update BUILD files 2017-10-15 18:18:13 -07:00
io Remove unused io util writer & volume host GetWriter() 2018-07-09 14:09:48 -07:00
ipconfig Autogenerated: hack/update-bazel.sh 2018-02-16 13:43:01 -08:00
ipset fix ipset creation fails on centos. issue 65461 2018-06-27 21:45:33 +08:00
iptables Avoid allocations when parsing iptables 2018-07-08 10:55:19 +02:00
ipvs Run hack/update-bazel.sh 2018-06-22 16:22:57 -07:00
keymutex Autogenerated: hack/update-bazel.sh 2018-02-16 13:43:01 -08:00
labels Run hack/update-bazel.sh 2018-06-22 16:22:57 -07:00
limitwriter Autogenerated: hack/update-bazel.sh 2018-02-16 13:43:01 -08:00
maps update BUILD files 2017-10-15 18:18:13 -07:00
metrics Run hack/update-bazel.sh 2018-06-22 16:22:57 -07:00
mount kubernetes: fix printf format errors 2018-07-11 00:10:15 +03:00
net Auto-updated BUILD files 2018-02-27 11:18:11 -08:00
netsh Autogenerated: hack/update-bazel.sh 2018-02-16 13:43:01 -08:00
node Make node status addresses authoritative for kube-apiserver -> kubelet connections 2018-07-10 14:33:49 -04:00
normalizer Clone documentation utility from //pkg/kubectl/cmd/templates 2017-11-16 10:18:00 +01:00
nsenter Implement fixes for flexvolume when kubelet is contanerized 2018-07-03 14:04:52 -04:00
oom Update to gazelle 0.12.0 and run hack/update-bazel.sh 2018-06-22 16:22:18 -07:00
parsers Autogenerated: hack/update-bazel.sh 2018-02-16 13:43:01 -08:00
pod Run hack/update-bazel.sh 2018-06-22 16:22:57 -07:00
pointer pkg/util/pointer: Update `int` pointer functions 2018-03-27 10:30:01 -04:00
procfs Run hack/update-bazel.sh 2018-06-22 16:22:57 -07:00
reflector/prometheus Run hack/update-bazel.sh 2018-06-22 16:22:57 -07:00
removeall Run hack/update-bazel.sh 2018-06-22 16:22:57 -07:00
resizefs Update to gazelle 0.12.0 and run hack/update-bazel.sh 2018-06-22 16:22:18 -07:00
resourcecontainer Update to gazelle 0.12.0 and run hack/update-bazel.sh 2018-06-22 16:22:18 -07:00
rlimit Update to gazelle 0.12.0 and run hack/update-bazel.sh 2018-06-22 16:22:18 -07:00
selinux Update to gazelle 0.12.0 and run hack/update-bazel.sh 2018-06-22 16:22:18 -07:00
slice Run hack/update-bazel.sh 2018-06-22 16:22:57 -07:00
strings Autogenerated: hack/update-bazel.sh 2018-02-16 13:43:01 -08:00
sysctl update BUILD files 2017-10-15 18:18:13 -07:00
system Run hack/update-bazel.sh 2018-06-22 16:22:57 -07:00
tail Merge pull request #59713 from hanxiaoshuai/fix0211 2018-02-22 23:17:38 -08:00
taints Run hack/update-bazel.sh 2018-06-22 16:22:57 -07:00
template Autogenerated: hack/update-bazel.sh 2018-02-16 13:43:01 -08:00
term Run hack/update-bazel.sh 2018-06-22 16:22:57 -07:00
threading Autogenerated: hack/update-bazel.sh 2018-02-16 13:43:01 -08:00
tolerations Autogenerated: hack/update-bazel.sh 2018-02-16 13:43:01 -08:00
version Autogenerated: hack/update-bazel.sh 2018-02-16 13:43:01 -08:00
workqueue/prometheus Run hack/update-bazel.sh 2018-06-22 16:22:57 -07:00
BUILD add utils to patch pod status 2018-05-30 11:15:47 -07:00
verify-util-pkg.sh Update all script to use /usr/bin/env bash in shebang 2018-04-19 13:20:13 +02:00