Skip to content

Commit 13fa7be

Browse files
authored
improve CA and certificate generation (#2834)
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 <[email protected]>
1 parent 9437498 commit 13fa7be

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

pkg/controller/certs/certs.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ func GenerateCA(notAfter time.Time, organization string) (*KeyPair, error) {
7171
caDetails := &x509.Certificate{
7272
SerialNumber: serial,
7373
Subject: pkix.Name{
74+
CommonName: fmt.Sprintf("olm-selfsigned-%x", serial),
7475
Organization: []string{organization},
7576
},
7677
NotBefore: notBefore,
7778
NotAfter: notAfter,
7879
IsCA: true,
79-
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth},
80-
KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign,
80+
KeyUsage: x509.KeyUsageCertSign,
8181
BasicConstraintsValid: true,
8282
}
8383

@@ -120,12 +120,12 @@ func CreateSignedServingPair(notAfter time.Time, organization string, ca *KeyPai
120120
certDetails := &x509.Certificate{
121121
SerialNumber: serial,
122122
Subject: pkix.Name{
123+
CommonName: hosts[0],
123124
Organization: []string{organization},
124125
},
125126
NotBefore: notBefore,
126127
NotAfter: notAfter,
127-
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth},
128-
KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign,
128+
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
129129
BasicConstraintsValid: true,
130130
DNSNames: hosts,
131131
}

0 commit comments

Comments
 (0)