• Kubernetes Submit Queue's avatar
    Merge pull request #65594 from liggitt/node-csr-addresses-2 · 337dfe0a
    Kubernetes Submit Queue authored
    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
    ```
    337dfe0a
Name
Last commit
Last update
..
apis Loading commit data...
cadvisor Loading commit data...
certificate Loading commit data...
checkpoint Loading commit data...
checkpointmanager Loading commit data...
client Loading commit data...
cm Loading commit data...
config Loading commit data...
configmap Loading commit data...
container Loading commit data...
custommetrics Loading commit data...
dockershim Loading commit data...
envvars Loading commit data...
events Loading commit data...
eviction Loading commit data...
images Loading commit data...
kubeletconfig Loading commit data...
kuberuntime Loading commit data...
leaky Loading commit data...
lifecycle Loading commit data...
logs Loading commit data...
metrics Loading commit data...
mountpod Loading commit data...
network Loading commit data...
pleg Loading commit data...
pod Loading commit data...
preemption Loading commit data...
prober Loading commit data...
qos Loading commit data...
remote Loading commit data...
secret Loading commit data...
server Loading commit data...
stats Loading commit data...
status Loading commit data...
sysctl Loading commit data...
token Loading commit data...
types Loading commit data...
util Loading commit data...
volumemanager Loading commit data...
winstats Loading commit data...
BUILD Loading commit data...
OWNERS Loading commit data...
active_deadline.go Loading commit data...
active_deadline_test.go Loading commit data...
cloud_request_manager.go Loading commit data...
cloud_request_manager_test.go Loading commit data...
doc.go Loading commit data...
kubelet.go Loading commit data...
kubelet_getters.go Loading commit data...
kubelet_getters_test.go Loading commit data...
kubelet_network.go Loading commit data...
kubelet_network_test.go Loading commit data...
kubelet_node_status.go Loading commit data...
kubelet_node_status_test.go Loading commit data...
kubelet_pods.go Loading commit data...
kubelet_pods_test.go Loading commit data...
kubelet_pods_windows_test.go Loading commit data...
kubelet_resources.go Loading commit data...
kubelet_resources_test.go Loading commit data...
kubelet_test.go Loading commit data...
kubelet_volumes.go Loading commit data...
kubelet_volumes_test.go Loading commit data...
oom_watcher.go Loading commit data...
oom_watcher_test.go Loading commit data...
pod_container_deletor.go Loading commit data...
pod_container_deletor_test.go Loading commit data...
pod_workers.go Loading commit data...
pod_workers_test.go Loading commit data...
reason_cache.go Loading commit data...
reason_cache_test.go Loading commit data...
runonce.go Loading commit data...
runonce_test.go Loading commit data...
runtime.go Loading commit data...
util.go Loading commit data...
volume_host.go Loading commit data...