CLI tool to automate SSL certificate setup and renewal for letsencrypt and rails (or any other rack based application).
To grant a SSL certificate for a given domain, letsencrypt requires a challenge request to be correctly answered on this domain. To automate this process this gem will perform the following steps for you:
- Register the domain and a contact email with letsencrypt
- Letsencrypt provides the expected challenge request answer
- Make your application answer correctly
- Trigger letsencrypt challenge process
- Download issued certificates from letsencrypt
- Setup certificates for your heroku application
Precondition: make sure the heroku cli is installed on your development machine.
- Install the gems
- Deploy your application
- Write configuration file
- Run
letsencrypt_heroku
on your local machine - Verify SSL is working correctly
gem 'letsencrypt_rack'
gem 'letsencrypt_heroku', require: false
To perform SSL certificate setup and renewal a command line tool is used: letsencrypt_heroku
. This tool will only be needed on your development machine and does not need to be loaded into your production environment.
letsencrypt_rack
contains a tiny rack middleware, that answers challenge request at the following path: /.well-known/acme-challenge
. It serves the contents of the LETSENCRYPT_RESPONSE
environment variable.
You need to add LetsencryptRack::Middleware
to your rack stack:
# in config.ru
use LetsencryptRack::Middleware
Put a configuration file under config/letsencrypt_heroku.yml
that looks like this:
- contact: [email protected]
domains: example.dev www.example.dev
heroku_app: example-dev-application
Each block in this configuration will issue a new certificate, so if you need to retrieve more than one (e.g. for another environment) you can configure more:
- contact: [email protected]
domains: example.dev www.example.dev
heroku_app: example-dev-application
- contact: [email protected]
domains: stg.example.dev
heroku_app: stg-example-dev-application
You can add keep_certs: true
to a block if you need to keep the generated certificate.
Please note that your application will be restarted for every single domain in your config. The restart happens automatically when the heroku challenge response gets set as environment variable.
Run curl -vI https://www.example.dev
and check that it has a section that looks like this:
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: blindlunch.team
* Server certificate: Let's Encrypt Authority X3
* Server certificate: DST Root CA X3
You may also check the results of qualys ssltest.
Once the process ran through the renewal is as simple as: run letsencrypt_heroku
- again.
You'll receive emails from letsencrypt from time to time to remind you to renew your certificates.
# Use a custom config file location
$ letsencrypt_heroku --config=another.yml
# Restrict for which domains the process should be run
$ letsencrypt_heroku --limit=foobar
- https://www.ssllabs.com/ssltest
- https://devcenter.heroku.com/articles/ssl
- https://letsencrypt.org/
- https://github.com/eliotsykes/rails-security-checklist
Bug reports and pull requests are welcome on GitHub at https://github.com/xijo/letsencrypt_heroku.
- document extraordinary configuration options (multiple domain SSL on single application)
- configurable config file location