Skip to content

Commit

Permalink
Merge pull request kubernetes#119114 from champtar/automated-cherry-p…
Browse files Browse the repository at this point in the history
…ick-of-#118922-upstream-release-1.26

Automated cherry pick of kubernetes#118922: kubeadm: backdate generated CAs
  • Loading branch information
k8s-ci-robot committed Aug 2, 2023
2 parents 91a8c34 + 8698961 commit 4cf40e5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cmd/kubeadm/app/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const (
// should be joined with KubernetesDir.
TempDirForKubeadm = "tmp"

// CertificateBackdate defines the offset applied to notBefore for CA certificates generated by kubeadm
CertificateBackdate = time.Minute * 5
// CertificateValidity defines the validity for all the signed certificates generated by kubeadm
CertificateValidity = time.Hour * 24 * 365

Expand Down
2 changes: 2 additions & 0 deletions cmd/kubeadm/app/util/pkiutil/pki_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ func NewCertificateAuthority(config *CertConfig) (*x509.Certificate, crypto.Sign
return nil, nil, errors.Wrap(err, "unable to create private key while generating CA certificate")
}

// backdate CA certificate to allow small time jumps
config.Config.NotBefore = time.Now().Add(-kubeadmconstants.CertificateBackdate)
cert, err := certutil.NewSelfSignedCACert(config.Config, key)
if err != nil {
return nil, nil, errors.Wrap(err, "unable to create self-signed CA certificate")
Expand Down
7 changes: 6 additions & 1 deletion staging/src/k8s.io/client-go/util/cert/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Config struct {
Organization []string
AltNames AltNames
Usages []x509.ExtKeyUsage
NotBefore time.Time
}

// AltNames contains the domain names and IP addresses that will be added
Expand All @@ -64,14 +65,18 @@ func NewSelfSignedCACert(cfg Config, key crypto.Signer) (*x509.Certificate, erro
return nil, err
}
serial = new(big.Int).Add(serial, big.NewInt(1))
notBefore := now.UTC()
if !cfg.NotBefore.IsZero() {
notBefore = cfg.NotBefore.UTC()
}
tmpl := x509.Certificate{
SerialNumber: serial,
Subject: pkix.Name{
CommonName: cfg.CommonName,
Organization: cfg.Organization,
},
DNSNames: []string{cfg.CommonName},
NotBefore: now.UTC(),
NotBefore: notBefore,
NotAfter: now.Add(duration365d * 10).UTC(),
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign,
BasicConstraintsValid: true,
Expand Down

0 comments on commit 4cf40e5

Please sign in to comment.