mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #106891 from neolit123/1.24-kubeadm-fix-external-etcd-ca-validation
kubeadm: validate local etcd certficates during expiration checks
This commit is contained in:
commit
f98f27bc2f
@ -381,6 +381,38 @@ func UsingExternalFrontProxyCA(cfg *kubeadmapi.ClusterConfiguration) (bool, erro
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UsingExternalEtcdCA determines whether the user is relying on an external etcd CA. We currently implicitly determine this is the case
|
||||||
|
// when the etcd CA Cert is present but the etcd CA Key is not.
|
||||||
|
// In case we are using an external etcd CA, the function validates the certificates signed by etcd CA that should be provided by the user.
|
||||||
|
func UsingExternalEtcdCA(cfg *kubeadmapi.ClusterConfiguration) (bool, error) {
|
||||||
|
if err := validateCACert(certKeyLocation{cfg.CertificatesDir, kubeadmconstants.EtcdCACertAndKeyBaseName, "", "etcd CA"}); err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
path := filepath.Join(cfg.CertificatesDir, kubeadmconstants.EtcdCAKeyName)
|
||||||
|
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := validateSignedCert(certKeyLocation{cfg.CertificatesDir, kubeadmconstants.EtcdCACertAndKeyBaseName, kubeadmconstants.APIServerEtcdClientCertAndKeyBaseName, "apiserver etcd client"}); err != nil {
|
||||||
|
return true, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := validateSignedCert(certKeyLocation{cfg.CertificatesDir, kubeadmconstants.EtcdCACertAndKeyBaseName, kubeadmconstants.EtcdServerCertAndKeyBaseName, "etcd server"}); err != nil {
|
||||||
|
return true, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := validateSignedCert(certKeyLocation{cfg.CertificatesDir, kubeadmconstants.EtcdCACertAndKeyBaseName, kubeadmconstants.EtcdPeerCertAndKeyBaseName, "etcd peer"}); err != nil {
|
||||||
|
return true, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := validateSignedCert(certKeyLocation{cfg.CertificatesDir, kubeadmconstants.EtcdCACertAndKeyBaseName, kubeadmconstants.EtcdHealthcheckClientCertAndKeyBaseName, "etcd health-check client"}); err != nil {
|
||||||
|
return true, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
// validateCACert tries to load a x509 certificate from pkiDir and validates that it is a CA
|
// validateCACert tries to load a x509 certificate from pkiDir and validates that it is a CA
|
||||||
func validateCACert(l certKeyLocation) error {
|
func validateCACert(l certKeyLocation) error {
|
||||||
// Check CA Cert
|
// Check CA Cert
|
||||||
|
@ -166,6 +166,7 @@ func NewManager(cfg *kubeadmapi.ClusterConfiguration, kubernetesDir string) (*Ma
|
|||||||
LongName: kubeConfig.longName,
|
LongName: kubeConfig.longName,
|
||||||
FileName: kubeConfig.fileName,
|
FileName: kubeConfig.fileName,
|
||||||
CABaseName: kubeadmconstants.CACertAndKeyBaseName, // all certificates in kubeConfig files are signed by the Kubernetes CA
|
CABaseName: kubeadmconstants.CACertAndKeyBaseName, // all certificates in kubeConfig files are signed by the Kubernetes CA
|
||||||
|
CAName: kubeadmconstants.CACertAndKeyBaseName,
|
||||||
readwriter: kubeConfigReadWriter,
|
readwriter: kubeConfigReadWriter,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -374,7 +375,11 @@ func (rm *Manager) IsExternallyManaged(caBaseName string) (bool, error) {
|
|||||||
}
|
}
|
||||||
return externallyManaged, nil
|
return externallyManaged, nil
|
||||||
case kubeadmconstants.EtcdCACertAndKeyBaseName:
|
case kubeadmconstants.EtcdCACertAndKeyBaseName:
|
||||||
return false, nil
|
externallyManaged, err := certsphase.UsingExternalEtcdCA(rm.cfg)
|
||||||
|
if err != nil {
|
||||||
|
return false, errors.Wrapf(err, "Error checking external CA condition for %s certificate authority", caBaseName)
|
||||||
|
}
|
||||||
|
return externallyManaged, nil
|
||||||
default:
|
default:
|
||||||
return false, errors.Errorf("unknown certificate authority %s", caBaseName)
|
return false, errors.Errorf("unknown certificate authority %s", caBaseName)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user