Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker support #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vol/
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM certbot/certbot:v2.10.0

# Add register.sh and acme-dns-auth.py to bin (mostly to make register.sh easier to run)
ENV PATH="${PATH}:/opt/certbot-acme-dns/bin"

# Install supercronic so we can auto renew the certs
RUN apk add --no-cache supercronic shadow

# Add the certbot hook/register script
ADD src /opt/certbot-acme-dns/bin/
# and crontab into container
ADD crontab /opt/certbot-acme-dns/

VOLUME ["/etc/letsencrypt", "/var/lib/letsencrypt"]
ENTRYPOINT ["/usr/bin/supercronic", "/opt/certbot-acme-dns/crontab"]
39 changes: 31 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,23 @@ An example [Certbot](https://certbot.eff.org) client hook for [acme-dns](https:/

This authentication hook automatically registers acme-dns accounts and prompts the user to manually add the CNAME records to their main DNS zone on initial run. Subsequent automatic renewals by Certbot cron job / systemd timer run in the background non-interactively.

Requires Certbot >= 0.10, Python requests library.
Requires either
* Docker
* Certbot >= 0.10, Python requests library.

## Installation

### Docker
1) Clone repo

2) Modify the ACMEDNS_URL environment variable (or any other config)

3) Run docker compose to start the container (with the current working directory in the root of the project)
```
docker compose up
```

### Manual
1) Install Certbot using instructions at [https://certbot.eff.org](https://certbot.eff.org)

2) Make sure you have the [python-requests](http://docs.python-requests.org/en/master/) library installed.
Expand All @@ -19,30 +32,40 @@ $ chmod 0700 /etc/letsencrypt/acme-dns-auth.py
```

4) Configure the variables in the beginning of the hook script file to point to your acme-dns instance. The only value that you must change is the `ACMEDNS_URL`, other values are optional.

a) Alternitively you can use environment variables to configure the hook.
```
### EDIT THESE: Configuration values ###

# URL to acme-dns instance
ACMEDNS_URL = "https://auth.acme-dns.io"
ACMEDNS_URL = os.environ.get("ACMEDNS_URL", "https://auth.acme-dns.io")
# Path for acme-dns credential storage
STORAGE_PATH = "/etc/letsencrypt/acmedns.json"
STORAGE_PATH = os.environ.get("STORAGE_PATH", "/etc/letsencrypt/acmedns.json")
# Whitelist for address ranges to allow the updates from
# Example: ALLOW_FROM = ["192.168.10.0/24", "::1/128"]
ALLOW_FROM = []
ALLOW_FROM = os.environ.get("ALLOW_FROM", [])
# Force re-registration. Overwrites the already existing acme-dns accounts.
FORCE_REGISTER = False
FORCE_REGISTER = os.environ.get("FORCE_REGISTER", False)
```

## Usage

### Docker
On initial run:
```
docker compose exec certbot-acme-dns register.sh -d example.org -d \*.example.org
```

### Manual
On initial run:
```
$ certbot certonly --manual --manual-auth-hook /etc/letsencrypt/acme-dns-auth.py \
--preferred-challenges dns --debug-challenges \
certbot certonly --manual --manual-auth-hook /etc/letsencrypt/acme-dns-auth.py \
--preferred-challenges dns --debug-challenges \
-d example.org -d \*.example.org
```
Note that the `--debug-challenges` is mandatory here to pause the Certbot execution before asking Let's Encrypt to validate the records and let you to manually add the CNAME records to your main DNS zone.

### Common steps
After adding the prompted CNAME records to your zone(s), wait for a bit for the changes to propagate over the main DNS zone name servers. This takes anywhere from few seconds up to a few minutes, depending on the DNS service provider software and configuration. Hit enter to continue as prompted to ask Let's Encrypt to validate the records.

After the initial run, Certbot is able to automatically renew your certificates using the stored per-domain acme-dns credentials.
After the initial run, Certbot is able to automatically renew your certificates using the stored per-domain acme-dns credentials. This can be done manualy with the `cerbot renew` command or letting certbot's auto renewal run.
1 change: 1 addition & 0 deletions crontab
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 */12 * * * certbot renew
10 changes: 10 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
certbot-acme-dns:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./vol/etc:/etc/letsencrypt
- ./vol/varlib:/var/lib/letsencrypt
environment:
ACMEDNS_URL: https://auth.acme-dns.io
8 changes: 4 additions & 4 deletions acme-dns-auth.py → src/acme-dns-auth.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
### EDIT THESE: Configuration values ###

# URL to acme-dns instance
ACMEDNS_URL = "https://auth.acme-dns.io"
ACMEDNS_URL = os.environ.get("ACMEDNS_URL", "https://auth.acme-dns.io")
# Path for acme-dns credential storage
STORAGE_PATH = "/etc/letsencrypt/acmedns.json"
STORAGE_PATH = os.environ.get("STORAGE_PATH", "/etc/letsencrypt/acmedns.json")
# Whitelist for address ranges to allow the updates from
# Example: ALLOW_FROM = ["192.168.10.0/24", "::1/128"]
ALLOW_FROM = []
ALLOW_FROM = os.environ.get("ALLOW_FROM", [])
# Force re-registration. Overwrites the already existing acme-dns accounts.
FORCE_REGISTER = False
FORCE_REGISTER = os.environ.get("FORCE_REGISTER", False)

### DO NOT EDIT BELOW THIS POINT ###
### HERE BE DRAGONS ###
Expand Down
16 changes: 16 additions & 0 deletions src/register.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env sh

# Helper script to make initial registration of domains easier
certbot certonly --manual \
--manual-auth-hook /opt/certbot-acme-dns/bin/acme-dns-auth.py \
--preferred-challenges dns \
--debug-challenges \
"$@"


##### Explanation of flags ####
# --manual -- run certbot in manual mode
# --manual-auth-hook /etc/letsencrypt/acme-dns-auth.py -- Tell certbot about the acme-dns auth hook
# --preferred-challenges dns -- dns challenge is the only one that will work with acme-dns
# --debug-challenges -- We need to pause execution before Let's Encrypt validates the records so you can manually add the CNAME records
# "$@" -- Pass any args that are passed to us. This will normally be the domains you want to set up ie -d example.org -d *.example.org