mirror of
https://github.com/rancher/rke.git
synced 2025-08-22 16:45:57 +00:00
Merge pull request #48 from moelsayed/fix_37
Generate new KubeAPI certificate for new nodes using the same key
This commit is contained in:
commit
b204a2d2ed
@ -37,7 +37,8 @@ func regenerateAPICertificate(c *Cluster, certificates map[string]pki.Certificat
|
|||||||
kubeAPIAltNames := pki.GetAltNames(c.ControlPlaneHosts, c.ClusterDomain, c.KubernetesServiceIP)
|
kubeAPIAltNames := pki.GetAltNames(c.ControlPlaneHosts, c.ClusterDomain, c.KubernetesServiceIP)
|
||||||
caCrt := certificates[pki.CACertName].Certificate
|
caCrt := certificates[pki.CACertName].Certificate
|
||||||
caKey := certificates[pki.CACertName].Key
|
caKey := certificates[pki.CACertName].Key
|
||||||
kubeAPICert, kubeAPIKey, err := pki.GenerateKubeAPICertAndKey(caCrt, caKey, kubeAPIAltNames)
|
kubeAPIKey := certificates[pki.KubeAPICertName].Key
|
||||||
|
kubeAPICert, err := pki.GenerateCertWithKey(pki.KubeAPICertName, kubeAPIKey, caCrt, caKey, kubeAPIAltNames)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
14
pki/pki.go
14
pki/pki.go
@ -216,6 +216,20 @@ func GenerateKubeAPICertAndKey(caCrt *x509.Certificate, caKey *rsa.PrivateKey, a
|
|||||||
return kubeCACert, rootKey, nil
|
return kubeCACert, rootKey, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GenerateCertWithKey(commonName string, key *rsa.PrivateKey, caCrt *x509.Certificate, caKey *rsa.PrivateKey, altNames *cert.AltNames) (*x509.Certificate, error) {
|
||||||
|
caConfig := cert.Config{
|
||||||
|
CommonName: commonName,
|
||||||
|
Usages: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth,
|
||||||
|
x509.ExtKeyUsageServerAuth},
|
||||||
|
AltNames: *altNames,
|
||||||
|
}
|
||||||
|
cert, err := cert.NewSignedCert(caConfig, key, caCrt, caKey)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Failed to generate certificate with existing key: %v", err)
|
||||||
|
}
|
||||||
|
return cert, nil
|
||||||
|
}
|
||||||
|
|
||||||
func generateCACertAndKey() (*x509.Certificate, *rsa.PrivateKey, error) {
|
func generateCACertAndKey() (*x509.Certificate, *rsa.PrivateKey, error) {
|
||||||
rootKey, err := cert.NewPrivateKey()
|
rootKey, err := cert.NewPrivateKey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user