| # syntax=docker/dockerfile:1 |
| |
| ARG PYTHON_VERSION=3.12 |
| |
| FROM python:${PYTHON_VERSION} |
| RUN mkdir /tmp/certs |
| VOLUME /certs |
| |
| WORKDIR /tmp/certs |
| |
| # ---- CA (with proper v3_ca) ---- |
| RUN openssl genrsa -aes256 -passout pass:foobar -out ca-key.pem 4096 |
| COPY <<'EOF' /tmp/ca.cnf |
| [req] |
| prompt = no |
| distinguished_name = req_distinguished_name |
| x509_extensions = v3_ca |
| |
| [req_distinguished_name] |
| countryName = AU |
| |
| [v3_ca] |
| basicConstraints = critical, CA:TRUE |
| keyUsage = critical, keyCertSign, cRLSign |
| subjectKeyIdentifier = hash |
| authorityKeyIdentifier = keyid:always,issuer |
| EOF |
| RUN openssl req -new -x509 -passin pass:foobar -config /tmp/ca.cnf -days 365 -key ca-key.pem -sha256 -out ca.pem |
| |
| # ---- Server cert (SAN + KU/EKU) ---- |
| RUN openssl genrsa -out server-key.pem 4096 |
| RUN openssl req -subj "/CN=docker" -sha256 -new -key server-key.pem -out server.csr |
| COPY <<'EOF' /tmp/server-ext.cnf |
| basicConstraints = CA:FALSE |
| keyUsage = critical, digitalSignature, keyEncipherment |
| extendedKeyUsage = serverAuth |
| subjectAltName = DNS:docker, DNS:localhost |
| EOF |
| 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 |
| |
| # ---- Client cert (KU/EKU) ---- |
| RUN openssl genrsa -out key.pem 4096 |
| RUN openssl req -passin pass:foobar -subj '/CN=client' -new -key key.pem -out client.csr |
| COPY <<'EOF' /tmp/client-ext.cnf |
| basicConstraints = CA:FALSE |
| keyUsage = critical, digitalSignature |
| extendedKeyUsage = clientAuth |
| EOF |
| 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 |
| RUN chmod -v 0400 ca-key.pem key.pem server-key.pem |
| RUN chmod -v 0444 ca.pem server-cert.pem cert.pem |
| |
| CMD cp -R /tmp/certs/* /certs && while true; do sleep 1; done |