@@ -7,17 +7,46 @@ RUN mkdir /tmp/certs
77VOLUME /certs
88
99WORKDIR /tmp/certs
10+
11+ # ---- CA (with proper v3_ca) ----
1012RUN openssl genrsa -aes256 -passout pass:foobar -out ca-key.pem 4096
11- RUN echo "[req]\nprompt=no\ndistinguished_name = req_distinguished_name\n[req_distinguished_name]\ncountryName=AU" > /tmp/config
12- RUN openssl req -new -x509 -passin pass:foobar -config /tmp/config -days 365 -key ca-key.pem -sha256 -out ca.pem
13- RUN openssl genrsa -out server-key.pem -passout pass:foobar 4096
13+ COPY <<'EOF' /tmp/ca.cnf
14+ [req]
15+ prompt = no
16+ distinguished_name = req_distinguished_name
17+ x509_extensions = v3_ca
18+
19+ [req_distinguished_name]
20+ countryName = AU
21+
22+ [v3_ca]
23+ basicConstraints = critical, CA:TRUE
24+ keyUsage = critical, keyCertSign, cRLSign
25+ subjectKeyIdentifier = hash
26+ authorityKeyIdentifier = keyid:always,issuer
27+ EOF
28+ RUN openssl req -new -x509 -passin pass:foobar -config /tmp/ca.cnf -days 365 -key ca-key.pem -sha256 -out ca.pem
29+
30+ # ---- Server cert (SAN + KU/EKU) ----
31+ RUN openssl genrsa -out server-key.pem 4096
1432RUN openssl req -subj "/CN=docker" -sha256 -new -key server-key.pem -out server.csr
15- RUN echo subjectAltName = DNS:docker,DNS:localhost > extfile.cnf
16- RUN openssl x509 -req -days 365 -passin pass:foobar -sha256 -in server.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out server-cert.pem -extfile extfile.cnf
33+ COPY <<'EOF' /tmp/server-ext.cnf
34+ basicConstraints = CA:FALSE
35+ keyUsage = critical, digitalSignature, keyEncipherment
36+ extendedKeyUsage = serverAuth
37+ subjectAltName = DNS:docker, DNS:localhost
38+ EOF
39+ RUN openssl x509 -req -days 365 -passin pass:foobar -sha256 -in server.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out server-cert.pem -extfile /tmp/server-ext.cnf
40+
41+ # ---- Client cert (KU/EKU) ----
1742RUN openssl genrsa -out key.pem 4096
1843RUN openssl req -passin pass:foobar -subj '/CN=client' -new -key key.pem -out client.csr
19- RUN echo extendedKeyUsage = clientAuth > extfile.cnf
20- RUN openssl x509 -req -passin pass:foobar -days 365 -sha256 -in client.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out cert.pem -extfile extfile.cnf
44+ COPY <<'EOF' /tmp/client-ext.cnf
45+ basicConstraints = CA:FALSE
46+ keyUsage = critical, digitalSignature
47+ extendedKeyUsage = clientAuth
48+ EOF
49+ RUN openssl x509 -req -passin pass:foobar -days 365 -sha256 -in client.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out cert.pem -extfile /tmp/client-ext.cnf
2150RUN chmod -v 0400 ca-key.pem key.pem server-key.pem
2251RUN chmod -v 0444 ca.pem server-cert.pem cert.pem
2352
0 commit comments