mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-06-09 08:55:55 -04:00
Merge pull request #106926 from neolit123/automated-cherry-pick-of-#106891-origin-release-1.23
Automated cherry pick of #106891: kubeadm: validate local etcd certficates during
This commit is contained in:
commit
798266016e
2 changed files with 38 additions and 1 deletions
|
|
@ -381,6 +381,38 @@ func UsingExternalFrontProxyCA(cfg *kubeadmapi.ClusterConfiguration) (bool, erro
|
|||
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
|
||||
func validateCACert(l certKeyLocation) error {
|
||||
// Check CA Cert
|
||||
|
|
|
|||
|
|
@ -166,6 +166,7 @@ func NewManager(cfg *kubeadmapi.ClusterConfiguration, kubernetesDir string) (*Ma
|
|||
LongName: kubeConfig.longName,
|
||||
FileName: kubeConfig.fileName,
|
||||
CABaseName: kubeadmconstants.CACertAndKeyBaseName, // all certificates in kubeConfig files are signed by the Kubernetes CA
|
||||
CAName: kubeadmconstants.CACertAndKeyBaseName,
|
||||
readwriter: kubeConfigReadWriter,
|
||||
}
|
||||
}
|
||||
|
|
@ -374,7 +375,11 @@ func (rm *Manager) IsExternallyManaged(caBaseName string) (bool, error) {
|
|||
}
|
||||
return externallyManaged, nil
|
||||
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:
|
||||
return false, errors.Errorf("unknown certificate authority %s", caBaseName)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue