mirror of
https://github.com/rancher/rke.git
synced 2025-08-31 22:46:25 +00:00
Add Rotate certificates command to rke
This commit is contained in:
committed by
Alena Prokharchyk
parent
7582083e7a
commit
3551e6e4b6
@@ -24,12 +24,15 @@ const (
|
||||
StateDeployerContainerName = "cluster-state-deployer"
|
||||
)
|
||||
|
||||
func DeployCertificatesOnPlaneHost(ctx context.Context, host *hosts.Host, rkeConfig v3.RancherKubernetesEngineConfig, crtMap map[string]CertificatePKI, certDownloaderImage string, prsMap map[string]v3.PrivateRegistry) error {
|
||||
func DeployCertificatesOnPlaneHost(ctx context.Context, host *hosts.Host, rkeConfig v3.RancherKubernetesEngineConfig, crtMap map[string]CertificatePKI, certDownloaderImage string, prsMap map[string]v3.PrivateRegistry, rotateCerts bool) error {
|
||||
crtBundle := GenerateRKENodeCerts(ctx, rkeConfig, host.Address, crtMap)
|
||||
env := []string{}
|
||||
for _, crt := range crtBundle {
|
||||
env = append(env, crt.ToEnv()...)
|
||||
}
|
||||
if rotateCerts {
|
||||
env = append(env, "FORCE_DEPLOY=true")
|
||||
}
|
||||
return doRunDeployer(ctx, host, env, certDownloaderImage, prsMap)
|
||||
}
|
||||
|
||||
@@ -153,15 +156,16 @@ func FetchCertificatesFromHost(ctx context.Context, extraHosts []*hosts.Host, ho
|
||||
tmpCerts := make(map[string]CertificatePKI)
|
||||
|
||||
crtList := map[string]bool{
|
||||
CACertName: false,
|
||||
KubeAPICertName: false,
|
||||
KubeControllerCertName: true,
|
||||
KubeSchedulerCertName: true,
|
||||
KubeProxyCertName: true,
|
||||
KubeNodeCertName: true,
|
||||
KubeAdminCertName: false,
|
||||
RequestHeaderCACertName: false,
|
||||
APIProxyClientCertName: false,
|
||||
CACertName: false,
|
||||
KubeAPICertName: false,
|
||||
KubeControllerCertName: true,
|
||||
KubeSchedulerCertName: true,
|
||||
KubeProxyCertName: true,
|
||||
KubeNodeCertName: true,
|
||||
KubeAdminCertName: false,
|
||||
RequestHeaderCACertName: false,
|
||||
APIProxyClientCertName: false,
|
||||
ServiceAccountTokenKeyName: false,
|
||||
}
|
||||
|
||||
for _, etcdHost := range extraHosts {
|
||||
@@ -175,7 +179,8 @@ func FetchCertificatesFromHost(ctx context.Context, extraHosts []*hosts.Host, ho
|
||||
// I will only exit with an error if it's not a not-found-error and this is not an etcd certificate
|
||||
if err != nil && (!strings.HasPrefix(certName, "kube-etcd") &&
|
||||
!strings.Contains(certName, APIProxyClientCertName) &&
|
||||
!strings.Contains(certName, RequestHeaderCACertName)) {
|
||||
!strings.Contains(certName, RequestHeaderCACertName) &&
|
||||
!strings.Contains(certName, ServiceAccountTokenKeyName)) {
|
||||
// IsErrNotFound doesn't catch this because it's a custom error
|
||||
if isFileNotFoundErr(err) {
|
||||
return nil, nil
|
||||
@@ -186,7 +191,8 @@ func FetchCertificatesFromHost(ctx context.Context, extraHosts []*hosts.Host, ho
|
||||
// If I can't find an etcd or api aggregator cert, I will not fail and will create it later.
|
||||
if crt == "" && (strings.HasPrefix(certName, "kube-etcd") ||
|
||||
strings.Contains(certName, APIProxyClientCertName) ||
|
||||
strings.Contains(certName, RequestHeaderCACertName)) {
|
||||
strings.Contains(certName, RequestHeaderCACertName) ||
|
||||
strings.Contains(certName, ServiceAccountTokenKeyName)) {
|
||||
tmpCerts[certName] = CertificatePKI{}
|
||||
continue
|
||||
}
|
||||
@@ -247,45 +253,3 @@ func FetchFileFromHost(ctx context.Context, filePath, image string, host *hosts.
|
||||
|
||||
return file, nil
|
||||
}
|
||||
|
||||
func getTempPath(s string) string {
|
||||
return TempCertPath + path.Base(s)
|
||||
}
|
||||
|
||||
func populateCertMap(tmpCerts map[string]CertificatePKI, localConfigPath string, extraHosts []*hosts.Host) map[string]CertificatePKI {
|
||||
certs := make(map[string]CertificatePKI)
|
||||
// CACert
|
||||
certs[CACertName] = ToCertObject(CACertName, "", "", tmpCerts[CACertName].Certificate, tmpCerts[CACertName].Key)
|
||||
// KubeAPI
|
||||
certs[KubeAPICertName] = ToCertObject(KubeAPICertName, "", "", tmpCerts[KubeAPICertName].Certificate, tmpCerts[KubeAPICertName].Key)
|
||||
// kubeController
|
||||
certs[KubeControllerCertName] = ToCertObject(KubeControllerCertName, "", "", tmpCerts[KubeControllerCertName].Certificate, tmpCerts[KubeControllerCertName].Key)
|
||||
// KubeScheduler
|
||||
certs[KubeSchedulerCertName] = ToCertObject(KubeSchedulerCertName, "", "", tmpCerts[KubeSchedulerCertName].Certificate, tmpCerts[KubeSchedulerCertName].Key)
|
||||
// KubeProxy
|
||||
certs[KubeProxyCertName] = ToCertObject(KubeProxyCertName, "", "", tmpCerts[KubeProxyCertName].Certificate, tmpCerts[KubeProxyCertName].Key)
|
||||
// KubeNode
|
||||
certs[KubeNodeCertName] = ToCertObject(KubeNodeCertName, KubeNodeCommonName, KubeNodeOrganizationName, tmpCerts[KubeNodeCertName].Certificate, tmpCerts[KubeNodeCertName].Key)
|
||||
// KubeAdmin
|
||||
kubeAdminCertObj := ToCertObject(KubeAdminCertName, KubeAdminCertName, KubeAdminOrganizationName, tmpCerts[KubeAdminCertName].Certificate, tmpCerts[KubeAdminCertName].Key)
|
||||
kubeAdminCertObj.Config = tmpCerts[KubeAdminCertName].Config
|
||||
kubeAdminCertObj.ConfigPath = localConfigPath
|
||||
certs[KubeAdminCertName] = kubeAdminCertObj
|
||||
// etcd
|
||||
for _, host := range extraHosts {
|
||||
etcdName := GetEtcdCrtName(host.InternalAddress)
|
||||
etcdCrt, etcdKey := tmpCerts[etcdName].Certificate, tmpCerts[etcdName].Key
|
||||
certs[etcdName] = ToCertObject(etcdName, "", "", etcdCrt, etcdKey)
|
||||
}
|
||||
|
||||
return certs
|
||||
}
|
||||
|
||||
func isFileNotFoundErr(e error) bool {
|
||||
if strings.Contains(e.Error(), "no such file or directory") ||
|
||||
strings.Contains(e.Error(), "Could not find the file") ||
|
||||
strings.Contains(e.Error(), "No such container:path:") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Reference in New Issue
Block a user