Commit Graph

23 Commits

Author SHA1 Message Date
Patrick Ohly
d0f5d55191 client-go certificate: context-aware APIs and logging
For NewManager, the Config struct gets changed (not extended!) so that the
caller can provide a logger instead of just a logging function. Breaking the
API was chosen because it avoids having to maintain two different log calls in
various places (one for printf-style logging, one for structured logging).

RequestCertificateWithContext is an extension. It enables getting rid of
context.TODO calls.

NewFileStoreWithLogger also is an extension.

Kubernetes-commit: f9051901cee8d8ff4aed3db27ff495a706f1a487
2024-12-09 12:45:54 +01:00
Paco Xu
6a07cedcd3 kubelet: add key encipherment usage only if it is rsa key
remove allowOmittingUsageKeyEncipherment as it is always true

Signed-off-by: Paco Xu <paco.xu@daocloud.io>

Kubernetes-commit: 160f015ef4affe903f98e74cf42b40fceef15cb9
2022-08-03 16:41:09 +08:00
Antonio Ojea
a6edfabde7 run hack/update-netparse-cve.sh
Kubernetes-commit: 0cd75e8fec62a2531637e80bb950ac9983cac1b0
2021-08-20 01:16:14 +02:00
Clayton Coleman
3faf506116 Add type logging to certificate manager
Kubelet cert rotation involves two certificate manager instances
(one for client and one for server certs) and the log lines are
identical and confusing. Since certificate manager is a utility
library it is also inappropriate to simply assume klog output is
sufficient.

certificate.Manager now accepts a Name and Logf function on its
config struct to identify the purpose of the manager and to
provide a way to redirect where output should go. If Name is
absent, the name is defaulted from the SignerName, and if that
is not found then the name is set to "client auth" if that is
a provided key usage, or "certificate" otherwise. If Logf is
not provided it defaults to klog.V(2). as today. The name is printed
in "foo: bar" form on every line, but can be converted to structured
logging in the future. The log level is not customizable and it
is up to the caller to decide whether that is an issue.

Some log messages are slightly cleaned up to more clearly indicate
their intent. One log message is removed in a utility function that
was already at v(4) and less likely to be needed.

The default behavior of the certificate manager is as before and
the kubelet now identifies the server and client signerName as
separate entities:

I0414 19:07:33.590419    1539 certificate_manager.go:263] kubernetes.io/kube-apiserver-client-kubelet: Rotating certificates
E0414 19:07:33.594154    1539 certificate_manager.go:464] kubernetes.io/kube-apiserver-client-kubelet: Failed while requesting a signed certificate from the master: cannot create certificate signing request: Post "https://...

Kubernetes-commit: 64c669bd0ac8fda39ba97f48ef887ac1f77fb014
2021-04-14 13:30:46 -04:00
卢振兴10069964
b1c481c6d5 code cleanup:remove repeated package import in client-go
Kubernetes-commit: 243dab458753002dae5741042840b21f9b831fbc
2021-04-16 08:40:30 +08:00
Jordan Liggitt
3ab7d09ea9 Switch cert manager to v1 CSR API by default, falling back to v1beta1
Kubernetes-commit: a298c14f18d4973a9ceaf21f1e0dc4e39b4c5bfb
2020-06-03 22:40:02 -04:00
Jack Kleeman
29bb8bf344 Support intermediate certificate in certificate store
Kubernetes-commit: 83a223f5ee3790b7ed54197986d4317e75da1652
2020-03-02 19:48:38 +00:00
Mike Danese
a9af074362 manual fixes
Kubernetes-commit: bfc75d9a5c1673092be1030137319684edd17aa3
2020-02-04 18:02:08 -08:00
Mike Danese
6b3a79f9fc some manual fixes
Kubernetes-commit: 26377722982a8489d2a974db88e7478e54e4eaf0
2019-12-17 00:01:53 -08:00
Samuel Davidson
41735bf478 Changed Kubelet client and serving cert TTL/Expiry certs to use gaugefunc for calculating time remaining.
Kubernetes-commit: aba0b315269dab469694af7fca879438a7f87e41
2019-12-03 16:01:56 -08:00
Samuel Davidson
7bd7ed8621 Added rotation metric to certificate manager
Kubernetes-commit: 7adb18120079016ed8aea1bd40e5cde161827a1d
2019-10-28 14:09:40 -07:00
Sukeesh
94daee0164 Cleanup: Audit log and error capitalization
Kubernetes-commit: 346fdbccf0ac06ab3fa0e51ab3b92fdc041bb4cc
2019-06-30 11:56:27 +09:00
Tomas Nozicka
0dbe75c417 Switch WaitForCertificate to informers to avoid broken watches
Kubernetes-commit: a7588723f7e9b88c2e8b9d601a2391e0f6b19a17
2019-01-17 18:32:36 +01:00
Clayton Coleman
96e95840d4 Restore "Make bootstrap client cert loading part of rotation""
This reverts the revert of commit 34642222676640b3c1dd255cc453000f2743ccde.

Kubernetes-commit: 486577df17570b321a91b223901d7e4fdbb63519
2018-11-17 13:44:58 -05:00
Clayton Coleman
57b75fe80b Revert "Make bootstrap client cert loading part of rotation"
This reverts commit 0af19875add7deb562b2cf7bf6b1d273c44bab1b.

Revert "Ensure the bootstrap rotation code is tested by forcing rotation"

This reverts commit de293b2d7ddb687850258370f2a7f30f224f0ec1.

Kubernetes-commit: 34642222676640b3c1dd255cc453000f2743ccde
2018-11-17 10:24:23 -05:00
Clayton Coleman
39159c379b Make bootstrap client cert loading part of rotation
Ensure that bootstrap+clientcert-rotation in the Kubelet can:

1. happen in the background so that static pods aren't blocked by bootstrap
2. collapse down to a single call path for requesting a CSR
3. reorganize the code to allow future flexibility in retrieving bootstrap creds

Fetching the first certificate and later certificates when the kubelet
is using client rotation and bootstrapping should share the same code
path. We also want to start the Kubelet static pod loop before
bootstrapping completes. Finally, we want to take an incremental step
towards improving how the bootstrap credentials are loaded from disk
(potentially allowing for a CLI call to get credentials, or a remote
plugin that better integrates with cloud providers or KSMs).

Reorganize how the kubelet client config is determined. If rotation is
off, simplify the code path. If rotation is on, load the config
from disk, and then pass that into the cert manager. The cert manager
creates a client each time it tries to request a new cert.

Preserve existing behavior where:

1. bootstrap kubeconfig is used if the current kubeconfig is invalid/expired
2. we create the kubeconfig file based on the bootstrap kubeconfig, pointing to
   the location that new client certs will be placed
3. the newest client cert is used once it has been loaded

Kubernetes-commit: 0af19875add7deb562b2cf7bf6b1d273c44bab1b
2018-10-16 12:52:47 -04:00
Andrew Gunnerson
b9b3f6d2e7 certificate_manager: Check that template differs from current cert before rotation
With the current behavior, when kubelet starts, a `templateChanged`
event is always fired off because it only checks if `getLastRequest`
matches `getTemplate`. The last request only exists in memory and thus
is initially `nil` and can't ever match the current template during
startup.

This causes kubelet to request the signing of a new CSR every time it's
restarted. This commit changes the behavior so that `templateChanged` is
only fired off if the currently template doesn't match both the current
certificate and the last template.

Fixes #69471

Signed-off-by: Andrew Gunnerson <andrew.gunnerson@us.ibm.com>

Kubernetes-commit: b9ab65d689cc48353ca5dae9f210ff408726a0d2
2018-10-08 12:08:32 -04:00
Jordan Liggitt
9936c2e1aa Derive kubelet serving certificate CSR template from node status addresses
Kubernetes-commit: db9d3c2d1057f97a4763987baee00b82718feaa0
2018-06-28 14:44:25 -04:00
Wang Guoliang
a8dc497f30 fix some syntax related errors
Kubernetes-commit: d065157dd74fa02eec87f5849528b079a3736c3d
2018-02-11 19:50:49 +08:00
Clayton Coleman
3f65b38279 Only rotate certificates in the background
The certificate manager originally had a "block on startup" rotation
behavior to ensure at least one rotation happened on startup. However,
since rotation may not succeed within the first time window the code was
changed to simply print the error rather than return it. This meant that
the blocking rotation has no purpose - it cannot cause the kubelet to
fail, and it *does* block the kubelet from starting static pods before
the api server becomes available.

The current block behavior causes a bootstrapped kubelet that is also
set to run static pods to wait several minutes before actually launching
the static pods, which means self-hosted masters using static pods have
a pointless delay on startup.

Since blocking rotation has no benefit and can't actually fail startup,
this commit removes the blocking behavior and simplifies the code at the
same time. The goroutine for rotation now completely owns the deadline,
the shouldRotate() method is removed, and the method that sets
rotationDeadline now returns it. We also explicitly guard against a
negative sleep interval and omit the message.

Should have no impact on bootstrapping except the removal of a long
delay on startup before static pods start.

Also add a guard condition where if the current cert in the store is
expired, we fall back to the bootstrap cert initially (we use the
bootstrap cert to communicate with the server). This is consistent with
when we don't have a cert yet.

Kubernetes-commit: 44493de195d89ec43cc7246af921e626e0002c16
2018-01-28 14:28:28 -05:00
Clayton Coleman
f7a735a8c2 Have the certificate manager decide if the server is healthy
Prevent a Kubelet from shutting down when the server isn't responding to
us but we cannot get a new certificate. This allows a cluster to coast
if the master is unresponsive or a node is partitioned and their client
cert expires.

Kubernetes-commit: b3a11aa635022761637090f4fc8d5cb57f3f0010
2017-10-05 18:57:53 -04:00
Clayton Coleman
bb96050dfb Collapse duplicate code into pkg/util/csr
There is no reason to duplicate this code into two places.

Kubernetes-commit: c3bea24ab6242b084e7d09073c8906c778611243
2017-10-01 16:10:51 -04:00
Jacob Simpson
1bb4ecc0ae Move certificate manager to client.
Kubernetes-commit: 415c4d2c3af1fadb839bf4b73c6ea16db6b8c59f
2017-03-09 16:34:55 -08:00