From b2b6681fc4980cc967ecd6139a6c3d01802c47b6 Mon Sep 17 00:00:00 2001 From: Joe Lanford Date: Mon, 8 Aug 2022 21:19:40 -0400 Subject: [PATCH] improve CA and certificate generation Recently during an audit on a user's cluster, it was discovered that OLM's certificate generation functionality has a few minor shortcomings. 1) The generated CA and server cert do not include a common name, which causes some tooling to have trouble tracing the cert chain. 2) The generated CA and server cert include unnecessary key usages, which means those certificates can be used for more than their intended purposes. This commit resolves the above issues by ensuring the certificates include common names and by using the minimal key usages necessary. Signed-off-by: Joe Lanford --- pkg/controller/certs/certs.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/controller/certs/certs.go b/pkg/controller/certs/certs.go index e000ab2c5e..9ece822314 100644 --- a/pkg/controller/certs/certs.go +++ b/pkg/controller/certs/certs.go @@ -71,13 +71,13 @@ func GenerateCA(notAfter time.Time, organization string) (*KeyPair, error) { caDetails := &x509.Certificate{ SerialNumber: serial, Subject: pkix.Name{ + CommonName: fmt.Sprintf("olm-selfsigned-%x", serial), Organization: []string{organization}, }, NotBefore: notBefore, NotAfter: notAfter, IsCA: true, - ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth}, - KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign, + KeyUsage: x509.KeyUsageCertSign, BasicConstraintsValid: true, } @@ -120,12 +120,12 @@ func CreateSignedServingPair(notAfter time.Time, organization string, ca *KeyPai certDetails := &x509.Certificate{ SerialNumber: serial, Subject: pkix.Name{ + CommonName: hosts[0], Organization: []string{organization}, }, NotBefore: notBefore, NotAfter: notAfter, - ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth}, - KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign, + ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, BasicConstraintsValid: true, DNSNames: hosts, }