Reputation: 587
I have an asp.net core app running on Docker Swarm, what is an efficient way to add SSL capabilities to the app and have the cert update itself through letsencrypt and certbot?
I know about Docker Swarm Secrets, but they are immutable so I can't just change the secret when the cert is updated.
Upvotes: 0
Views: 1295
Reputation: 587
Here is the solution that I came up with! Feel free to chip in with ideas to make it better :)
[Sorry about the formatting, I couldn't get it to do what I wanted]
Update your app with a few necessities for using certs:
docker service update <yourswarmapp> --env-add Kestrel__Certificates__Default__Password="cert-password" --env-add Kestrel__Certificates__Default__Path=/run/secrets/defaultcert
--env-add ASPNETCORE_URLS="https://;"
Install this bash script on your machine to run daily from a root cronjob. (Make sure to set your own domain and passwords)
SecretName=$(date +%Y-%m-%d)
OldSecretName=$(date --date yesterday +%Y-%m-%d)
DomainName=your.domain
AppName=yourswarmapp
cd /etc
cd letsencrypt
cd live
cd $DomainName
openssl pkcs12 -export -out ${DomainName}.pfx -inkey privkey.pem -in cert.pem -certfile chain.pem -passin pass: -passout pass:
sudo docker secret create $SecretName /etc/letsencrypt/archive/$DomainName/${DomainName}.pfx
sudo docker service update --secret-add $SecretName --secret-rm $OldSecretName --env-add Kestrel__Certificates__Default__Path=/run/secrets/$SecretName $AppName
sudo docker secret rm $OldSecretName
Sit back and enjoy your automatically updating and cleaning SSL enabled app.
Upvotes: 1