I’m currently writing an Ansible playbook to automate the installation of a router & transparent proxy running Rocky Linux. I already have this configuration running in our local school, though I’ve done the installation by hand. I’ve documented everything on my tech blog, step by step.
At one point I have to create a certificate like this:
# openssl req -new -newkey rsa:4096 -sha256 -days 3650 -nodes -x509 \
-extensions v3_ca -keyout certificat.pem -out certificat.pem
Generating a RSA private key
.......................++++
.........++++
writing new private key to 'certificat.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]: FR
State or Province Name (full name) []: Gard
Locality Name (eg, city) [Default City]: Montpezat
Organization Name (eg, company) [Default Company Ltd]: Microlinux
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []: squidbox.sandbox.lan
Email Address []: info@microlinux.fr
And then I have to convert this into DER format:
# openssl x509 -in certificat.pem -outform DER -out certificat.der
I don’t know how to go about this with Ansible. There seem to be several certificate-related Ansible modules out there, but I don’t know which one to choose.
So far I managed to translate pretty much everything in my Squid setup into an Ansible playbook. Right now I have a bit of a roadblock with these two steps. I’d be thankful for a little help here.
You can pass parameters to openssl so it doesn’t prompt the user for anything when creating a new certificate.
Searching for “openssl new certificate non-interactive” online will point you to various solutions using parameters like “-subject” “-passin” and “-passout”.
There is also the detail that openssl req creates CSR (Certificate Signing Request) that must then be signed by CA to get the actual certificate. Once CA returns (public and private parts of) certificate, they need to be deployed.
Perhaps one should delegate the CSR creation to the “Ansible control host”?
[req_distinguished_name]
countryName = UA
stateOrProvinceName = Kyiv
localityName = Kyiv
organizationName = Certificate signed by my CA
commonName = xxx.firma.my.ua
this is CA.cnf file:
[ req ]
prompt = no
distinguished_name = req_distinguished_name
[ req_distinguished_name ]
C = UA
ST = Kyiv DC
L = Kyiv
O = MY Certificate Authority Local Center
OU = ITDep
CN = xxx.firma.my.ua
emailAddress = root@xxx.firma.my.ua