kubernetes: apiserver LoopbackClient Server cert expired after 1 year
What happened:
If you never restart your kube-apiserver after 1 year, kube-apiserver can’t works normal anymore.
What you expected to happen:
apiserver renew its LoopbackClient server cert.
How to reproduce it (as minimally and precisely as possible):
For quick reproduce, you can change your os date to 1 years later. Notes that there will be two cert expire, one for kubelet, one for apiserver inner LoopbackClient server cert.
kubelet can renew its cert via bootstrap token or existed kubeconfig, but apiserver seems never renew the in memory LoopbackClient server cert.
apiserver logs like this:
I1223 12:27:07.135552 1 log.go:172] http: TLS handshake error from 172.17.0.2:44484: remote error: tls: bad certificate
I1223 12:27:07.135569 1 log.go:172] http: TLS handshake error from 172.17.0.2:44488: remote error: tls: bad certificate
I1223 12:27:07.136280 1 log.go:172] http: TLS handshake error from 172.17.0.2:44482: remote error: tls: bad certificate
I1223 12:27:07.136658 1 log.go:172] http: TLS handshake error from 172.17.0.2:44486: remote error: tls: bad certificate
I1223 12:27:07.136960 1 log.go:172] http: TLS handshake error from 172.17.0.2:44480: remote error: tls: bad certificate
E1223 12:27:07.308665 1 authentication.go:89] Unable to authenticate the request due to an error: x509: certificate has expired or is not yet valid
E1223 12:27:07.313686 1 authentication.go:89] Unable to authenticate the request due to an error: x509: certificate has expired or is not yet valid
E1223 12:27:07.327876 1 authentication.go:89] Unable to authenticate the request due to an error: x509: certificate has expired or is not yet valid
I1223 12:27:07.582685 1 log.go:172] http: TLS handshake error from 172.17.0.2:44492: remote error: tls: bad certificate
I1223 12:27:08.135832 1 log.go:172] http: TLS handshake error from 172.17.0.2:44500: remote error: tls: bad certificate
I1223 12:27:08.141966 1 log.go:172] http: TLS handshake error from 172.17.0.2:44504: remote error: tls: bad certificate
I1223 12:27:08.142034 1 log.go:172] http: TLS handshake error from 172.17.0.2:44506: remote error: tls: bad certificate
I1223 12:27:08.142077 1 log.go:172] http: TLS handshake error from 172.17.0.2:44502: remote error: tls: bad certificate
I1223 12:27:08.142174 1 log.go:172] http: TLS handshake error from 172.17.0.2:44508: remote error: tls: bad certificate
Anything else we need to know?:
From code and code below, seems that apiserver just new a self-signed cert with 1 year expire date:
// create self-signed cert+key with the fake server.LoopbackClientServerNameOverride and
// let the server return it when the loopback client connects.
certPem, keyPem, err := certutil.GenerateSelfSignedCertKey(server.LoopbackClientServerNameOverride, nil, nil)
if err != nil {
return fmt.Errorf("failed to generate self-signed certificate for loopback connection: %v", err)
}
certProvider, err := dynamiccertificates.NewStaticSNICertKeyContent("self-signed loopback", certPem, keyPem, server.LoopbackClientServerNameOverride)
if err != nil {
return fmt.Errorf("failed to generate self-signed certificate for loopback connection: %v", err)
}
---
// GenerateSelfSignedCertKeyWithFixtures creates a self-signed certificate and key for the given host.
// Host may be an IP or a DNS name. You may also specify additional subject alt names (either ip or dns names)
// for the certificate.
//
// If fixtureDirectory is non-empty, it is a directory path which can contain pre-generated certs. The format is:
// <host>_<ip>-<ip>_<alternateDNS>-<alternateDNS>.crt
// <host>_<ip>-<ip>_<alternateDNS>-<alternateDNS>.key
// Certs/keys not existing in that directory are created.
func GenerateSelfSignedCertKeyWithFixtures(host string, alternateIPs []net.IP, alternateDNS []string, fixtureDirectory string) ([]byte, []byte, error) {
validFrom := time.Now().Add(-time.Hour) // valid an hour earlier to avoid flakes due to clock skew
maxAge := time.Hour * 24 * 365 // one year self-signed certs
Environment:
- Kubernetes version (use
kubectl version): v1.16.3 (maybe affect all release versions) - Cloud provider or hardware configuration:
- OS (e.g:
cat /etc/os-release): - Kernel (e.g.
uname -a): - Install tools:
- Network plugin and version (if this is a network-related bug):
- Others:
/sig apiserver /kind bug
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 18 (14 by maintainers)
First of all, I apologize for the statements that may offend you below.
I agreed that it’s strongly recommended to keep k8s cluster updated or at least use a supported k8s version. I researched the support/valide kubernetes version policy on public kubernetes cloud like GKE AKS and ACK, they do keep limited lifecycle on certain k8s version.
But it’s for the customs or end users to choose whether and when to upgrade their kubernetes cluster. As you can see, you can’t just upgrade k8s version on GKE slightly, while some major version change can affect all their current “Pods” and affect their business.
Version upgrade on public cloud can be easier since you can controller everything and you can hand all the infrastructure change, while that will be difficult for private cloud for their different infrastructure, OEM changes and so on. K8s version upgrade on private cloud can be more slower and have longer lifecycle for each version.
Take
supported for ~9 monthsas a reason seems like that “k8s pods should kill themselves after 1 year since they are too old”As I can see, the community is focusing on the stability of kubernetes. I open this issue because I think it’s hard to find (I found on one custom’s production environment) and may have bad affects like a time bomb.
As you know better than me about kube-apiserver, I can accept that if you explain clearly the impact about cert expiration(if it doesn’t matter), instead of just close this issue.
I do hope and believe kubernetes will be more stable and it will be kept in mind and fixed slightly.
Given a version of the kube-apiserver is supported for ~9 months, requiring a restart once a year seems reasonable.
There is an proposal in progress to support an additional release, bringing the supported versions to ~12-14 months. As part of that, the loopback certificate lifetime should be lengthened slightly, but I don’t really anticipate building in loopback certificate renewal.
/close