mirror of
https://github.com/rancher/rke.git
synced 2025-07-07 20:38:58 +00:00
Merge pull request #1977 from mrajashree/kube_ca_check
Validate kube-ca cert before rotating certs
This commit is contained in:
commit
cd8271c976
19
cmd/cert.go
19
cmd/cert.go
@ -2,11 +2,10 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/x509"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
"github.com/rancher/rke/cluster"
|
"github.com/rancher/rke/cluster"
|
||||||
"github.com/rancher/rke/hosts"
|
"github.com/rancher/rke/hosts"
|
||||||
"github.com/rancher/rke/log"
|
"github.com/rancher/rke/log"
|
||||||
@ -14,6 +13,7 @@ import (
|
|||||||
"github.com/rancher/rke/pki/cert"
|
"github.com/rancher/rke/pki/cert"
|
||||||
"github.com/rancher/rke/services"
|
"github.com/rancher/rke/services"
|
||||||
v3 "github.com/rancher/types/apis/management.cattle.io/v3"
|
v3 "github.com/rancher/types/apis/management.cattle.io/v3"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -236,6 +236,21 @@ func rotateRKECertificates(ctx context.Context, kubeCluster *cluster.Cluster, fl
|
|||||||
return nil, fmt.Errorf("Failed to rotate certificates: can't find old certificates")
|
return nil, fmt.Errorf("Failed to rotate certificates: can't find old certificates")
|
||||||
}
|
}
|
||||||
currentCluster.RotateCertificates = kubeCluster.RotateCertificates
|
currentCluster.RotateCertificates = kubeCluster.RotateCertificates
|
||||||
|
if !kubeCluster.RotateCertificates.CACertificates {
|
||||||
|
caCertPKI, ok := rkeFullState.CurrentState.CertificatesBundle[pki.CACertName]
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("Failed to rotate certificates: can't find CA certificate")
|
||||||
|
}
|
||||||
|
caCert := caCertPKI.Certificate
|
||||||
|
if caCert == nil {
|
||||||
|
return nil, fmt.Errorf("Failed to rotate certificates: CA certificate is nil")
|
||||||
|
}
|
||||||
|
certPool := x509.NewCertPool()
|
||||||
|
certPool.AddCert(caCert)
|
||||||
|
if _, err := caCert.Verify(x509.VerifyOptions{Roots: certPool, KeyUsages: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth}}); err != nil {
|
||||||
|
return nil, fmt.Errorf("Failed to rotate certificates: CA certificate is invalid, please use the --rotate-ca flag to rotate CA certificate, error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
if err := cluster.RotateRKECertificates(ctx, currentCluster, flags, rkeFullState); err != nil {
|
if err := cluster.RotateRKECertificates(ctx, currentCluster, flags, rkeFullState); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -206,6 +206,7 @@ func validateCerts(state cluster.State) error {
|
|||||||
} else {
|
} else {
|
||||||
failedErrs = errors.Wrap(failedErrs, fmt.Sprintf("Certificate [%s] is nil", certPKI.Name))
|
failedErrs = errors.Wrap(failedErrs, fmt.Sprintf("Certificate [%s] is nil", certPKI.Name))
|
||||||
}
|
}
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
certPool := x509.NewCertPool()
|
certPool := x509.NewCertPool()
|
||||||
|
Loading…
Reference in New Issue
Block a user