Skip to content

Commit 63157c5

Browse files
authored
Merge pull request #46 from nickgerace/days
Allow for default expiration days to be loaded from env
2 parents 27f4642 + 2644a6e commit 63157c5

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

factory/cert_utils.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ import (
1010
"math"
1111
"math/big"
1212
"net"
13+
"os"
14+
"strconv"
1315
"strings"
1416
"time"
1517

1618
"github.com/sirupsen/logrus"
1719
)
1820

1921
const (
20-
CertificateBlockType = "CERTIFICATE"
22+
CertificateBlockType = "CERTIFICATE"
23+
defaultNewSignedCertExpirationDays = 365
2124
)
2225

2326
func NewSelfSignedCACert(key crypto.Signer, cn string, org ...string) (*x509.Certificate, error) {
@@ -82,12 +85,22 @@ func NewSignedCert(signer crypto.Signer, caCert *x509.Certificate, caKey crypto.
8285
return nil, err
8386
}
8487

88+
expirationDays := defaultNewSignedCertExpirationDays
89+
envExpirationDays := os.Getenv("CATTLE_NEW_SIGNED_CERT_EXPIRATION_DAYS")
90+
if envExpirationDays != "" {
91+
if envExpirationDaysInt, err := strconv.Atoi(envExpirationDays); err != nil {
92+
logrus.Infof("[NewSignedCert] expiration days from ENV (%s) could not be converted to int (falling back to default value: %d)", envExpirationDays, defaultExpirationDays)
93+
} else {
94+
expirationDays = envExpirationDaysInt
95+
}
96+
}
97+
8598
parent := x509.Certificate{
8699
DNSNames: domains,
87100
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
88101
IPAddresses: ips,
89102
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
90-
NotAfter: time.Now().Add(time.Hour * 24 * 365).UTC(),
103+
NotAfter: time.Now().Add(time.Hour * 24 * time.Duration(expirationDays)).UTC(),
91104
NotBefore: caCert.NotBefore,
92105
SerialNumber: serialNumber,
93106
Subject: pkix.Name{

0 commit comments

Comments
 (0)