Skip to content

Commit

Permalink
kubeadm: remove the restriction that the ca.crt can only contain one …
Browse files Browse the repository at this point in the history
…certificate
  • Loading branch information
SataQiu committed Jan 6, 2022
1 parent 9c32425 commit e36b938
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
12 changes: 5 additions & 7 deletions cmd/kubeadm/app/phases/certs/renewal/readwriter.go
Expand Up @@ -82,10 +82,8 @@ func (rw *pkiCertificateReadWriter) Read() (*x509.Certificate, error) {
return nil, errors.Wrapf(err, "failed to load existing certificate %s", rw.baseName)
}

if len(certs) != 1 {
return nil, errors.Errorf("wanted exactly one certificate, got %d", len(certs))
}

// Safely pick the first one because the sender's certificate must come first in the list.
// For details, see: https://www.rfc-editor.org/rfc/rfc4346#section-7.4.2
return certs[0], nil
}

Expand Down Expand Up @@ -145,9 +143,9 @@ func (rw *kubeConfigReadWriter) Read() (*x509.Certificate, error) {
if err != nil {
return nil, errors.Wrapf(err, "failed to load existing certificate %s", rw.baseName)
}
if len(caCerts) != 1 {
return nil, errors.Errorf("wanted exactly one certificate, got %d", len(caCerts))
}

// Safely pick the first one because the sender's certificate must come first in the list.
// For details, see: https://www.rfc-editor.org/rfc/rfc4346#section-7.4.2
rw.caCert = caCerts[0]

// get current context
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubeadm/app/util/config/cluster.go
Expand Up @@ -183,8 +183,8 @@ func getNodeNameFromKubeletConfig(kubeconfigDir string) (string, error) {
return "", errors.Errorf("invalid kubeconfig file %s. x509 certificate expected", fileName)
}

// We are only putting one certificate in the certificate pem file, so it's safe to just pick the first one
// TODO: Support multiple certs here in order to be able to rotate certs
// Safely pick the first one because the sender's certificate must come first in the list.
// For details, see: https://www.rfc-editor.org/rfc/rfc4346#section-7.4.2
cert := certs[0]

// gets the node name from the certificate common name
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubeadm/app/util/pkiutil/pki_helpers.go
Expand Up @@ -291,8 +291,8 @@ func TryLoadCertFromDisk(pkiPath, name string) (*x509.Certificate, error) {
return nil, errors.Wrapf(err, "couldn't load the certificate file %s", certificatePath)
}

// We are only putting one certificate in the certificate pem file, so it's safe to just pick the first one
// TODO: Support multiple certs here in order to be able to rotate certs
// Safely pick the first one because the sender's certificate must come first in the list.
// For details, see: https://www.rfc-editor.org/rfc/rfc4346#section-7.4.2
cert := certs[0]

return cert, nil
Expand Down

0 comments on commit e36b938

Please sign in to comment.