learn-heroku
Version:

162 lines (107 loc) • 5.92 kB
Markdown
# Step-by-Step Setup Instructions for Let's Encrypt
## Why?
You have a custom domain for your Heroku app
and now you want an SSL Certificate
to Secure/Encrypt all communications between users and your app.
## What?
Let's Encrypt offers a ***Free*** Automated SLL Certificate Service
see: https://letsencrypt.org/about/
## How?
### Step 1: Install `certbot`
> `certbot` installation instructions for various platforms:
https://letsencrypt.org/getting-started
```sh
brew install certbot
```

(_might take a few minutes to install on a slower internet connection...
be patient..._)
### Step 2: Run `certbot` Command (_Manual Setup_)
Once you've installed `certbot` run the following command:
```sh
sudo certbot certonly --manual
```
Follow the steps and pay _close_ attention!
When you reach the screen that looks like this:

Instructions: (_for reference ONLY see below for modified instructions_)
```
mkdir -p /tmp/certbot/public_html/.well-known/acme-challenge
cd /tmp/certbot/public_html
printf "%s" WgFpodyij_PDzkU0MZ3CzKCI05hjLOcq2tP-1rs6ko0.kURQ5HbILtRXEwJA2QI4W5TdBkjnZNqH2_RHORvmN6w > .well-known/acme-challenge/WgFpodyij_PDzkU0MZ3CzKCI05hjLOcq2tP-1rs6ko0
# run only once per server:
$(command -v python2 || command -v python2.7 || command -v python2.6) -c \
"import BaseHTTPServer, SimpleHTTPServer; \
s = BaseHTTPServer.HTTPServer(('', 80), SimpleHTTPServer.SimpleHTTPRequestHandler); \
s.serve_forever()"
```
You _wont_ be _able_ to run commands on the Heroku instance
so we need to use a _temporary_ node.js server to achieve our objective.
In your `current working director`
Open [`server.js`](https://github.com/dwyl/learn-heroku/blob/master/server.js)
and:
+ update the route that starts with `/.well-known/acme-challenge/`
+ replace the string after `acme-challenge/` with the string you see
in your terminal our case it's: `WgFpodyij_PDzkU0MZ3CzKCI05hjLOcq2tP-1rs6ko0`
+ replace the token (string) in the reply to match what you see in the terminal.
our token is: `WgFpodyij_PDzkU0MZ3CzKCI05hjLOcq2tP-1rs6ko0.kURQ5HbILtRXEwJA2QI4W5TdBkjnZNqH2_RHORvmN6w`
### Set Git Remote
Check what your _current_ `origin` remote is:
```sh
git remote -v
```

Set it to what ever the git url is for your application:
```sh
git remote set-url origin git@github.com:healthlocker/healthlocker.git
```
Push your current branch to the GitHub repo:
```sh
git push --set-upstream origin letsencrypt-temporary-server
```
### _Temporarily_ Change the Branch Heroku Deploys from

Change it to the name of your branch e.g:

It should look something like this:

remember to (_temporarily_) _dissable_ the checkbox `Wait for CI to pass before deploy`.
make a commit on your local branch so you can push to github (_and trigger the heroku build_)
in my case the build failed:

because we are using an Elixir "Build Pack" for the app (_so deploying a node app won't work!_):

So I made a note of the buildpack urls:
+ https://github.com/HashNuke/heroku-buildpack-elixir.git
+ https://github.com/gjaldon/heroku-buildpack-phoenix-static.git
And then `delete` them (_temporarily_):

After I `delete` the build pack and push another commit, it passes:

### Visit the Endpoint in your Browser to confirm it worked:
our is: http://www.healthlocker.uk/.well-known/acme-challenge/WgFpodyij_PDzkU0MZ3CzKCI05hjLOcq2tP-1rs6ko0

### Continue with the Certbot process
When I _attempted_ to `continue` it failed:

Output
```
Waiting for verification...
An unexpected error occurred:
ConnectionError: ('Connection aborted.', error("(60, 'ETIMEDOUT')",))
Please see the logfiles in /var/log/letsencrypt for more details.
IMPORTANT NOTES:
- If you lose your account credentials, you can recover through
e-mails sent to contact.nelsonic@gmail.com.
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.
```
Failed again:

## Background Reading
+ Certbot Manual mode: https://certbot.eff.org/docs/using.html#manual
+ Inspiration tutorial (_Ruby-on-Rails focussed_):
https://collectiveidea.com/blog/archives/2016/01/12/lets-encrypt-with-a-rails-app-on-heroku