Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
Deprecation: deprecate old way to run the container (actually putting…
Browse files Browse the repository at this point in the history
… the real commandline thing) and instead add CMD that will take arguments from the environment
  • Loading branch information
luispabon committed Dec 6, 2019
1 parent 2c611fb commit f955d26
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
43 changes: 22 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ There's an example [kubernetes cronjob](kubernetes/certbot-cronjob.yml) you can
- Deploy container in your environment.
- It will automagically run the updater script every 24th of the month.
- Profit!

### Kong configuration

In order for the challenge to work correctly, you need to open up a service and a route in Kong pointing to the container at a very
specific URL path. It MUST respond on every domain you're requesting certs for.
In order for the challenge to work correctly, you need to open up a service and a route in Kong pointing to the container at a very
specific URL path. It MUST respond on every domain you're requesting certs for.

When it comes the time to run certbot, it will open an HTTP server, put some stuff on a specific path, then ping
When it comes the time to run certbot, it will open an HTTP server, put some stuff on a specific path, then ping
Let's Encrypt, which will attempt to read that from the domain requested. If successful, a certificate is generated.

This is a service definition example in Kong admin:
Expand Down Expand Up @@ -93,7 +93,7 @@ Here's a [kubernetes cronjob example](kubernetes/certbot-cronjob.yml).

### Note

Your k8s service SHOULD always time out since there's nothing listening on HTTP except for when certbot itself is
Your k8s service SHOULD always time out since there's nothing listening on HTTP except for when certbot itself is
running and requesting certs from LE.

## Command line tool
Expand All @@ -103,49 +103,50 @@ it, as it's done on the [kubernetes cronjob example](kubernetes/certbot-cronjob.

```bash
# Get a certificate for three subdomains, and submit to kong
docker run -it --rm phpdockerio/kong-certbot-agent \
./certbot-agent certs:update \
http://kong-admin:8001 \
foo@bar.com \
bar.com,foo.bar.com,www.bar.com
docker run -it --rm
-e KONG_ENDPOINT=http://kong-admin:8001 \
-e EMAIL=foo@bar.com \
-e DOMAINS=bar.com,foo.bar.com,www.bar.com \
phpdockerio/kong-certbot-agent


# Get a TEST certificate for three subdomains, and submit to kong
docker run -it --rm phpdockerio/kong-certbot-agent \
./certbot-agent certs:update \
--test-cert \
http://kong-admin:8001 \
foo@bar.com \
bar.com,foo.bar.com,www.bar.com
docker run -it --rm
-e KONG_ENDPOINT=http://kong-admin:8001 \
-e EMAIL=foo@bar.com \
-e DOMAINS=bar.com,foo.bar.com,www.bar.com \
-e TEST_CERT=true \
phpdockerio/kong-certbot-agent

```

## FAQ

### How many domains can I get certs for?

You can give the agent a pretty big list of domains to acquire certificates for (100), but bear in mind it will be one certificate
You can give the agent a pretty big list of domains to acquire certificates for (100), but bear in mind it will be one certificate
shared among all of them. You might want to set up different cronjobs for different sets of certificates, grouped in a manner
that makes sense to you. Also, if one of the domains you're getting a certificate from fails the HTTP challenge, cert acquisition
for the whole group fails.

### How about wildcard certs?

Unfortunately, certbot does not support http challenges on wildcard certs, needing to resort to other types (like DNS).
Unfortunately, certbot does not support http challenges on wildcard certs, needing to resort to other types (like DNS).
Due to the way certbot agent works, this will never be supported by the agent.

### Any considerations on a first time set up?

Yes. Certbot has a limit of [50 certificate requests per domain per week](https://letsencrypt.org/docs/rate-limits/) - it is very easy to go over this limit during
your initial set up while you manage to get all your stuff lined up together nicely:

* Use test certs initially, allowances are more generous. You can modify the command to `command: [ "/workdir/certbot-agent", "certs:update", "$(KONG_ENDPOINT)", "$(EMAIL)", "$(DOMAINS)", "--test-cert" ]` until you have everything right.
* Ensure your scheduling does not retry a failed command. It's very unlikely it will succeed a second time with the same parameters
and you'll go over the limit quicker than fast, especially in Kubernetes which by default will retry until your cluster goes down. The
and you'll go over the limit quicker than fast, especially in Kubernetes which by default will retry until your cluster goes down. The
[example kubernetes cronjob](kubernetes/certbot-cronjob.yml) specifically stops this from happening

### How often should I renew my certs?

By default, certbot has a limit of 50 certificate requests per domain per week as mentioned earlier, so bear this in mind. Also, certs are good for 3 months. Let's Encrypt themselves recommend once every 60 days. [The example kubernetes cronjob](kubernetes/certbot-cronjob.yml)
is setup like so.
is setup like so.

You can certainly do it more often, but there's no point in spamming Let's Encrypt with extra requests - remember this is a shared resource, free as in freedom and beer, and someone surely pays for it. Be considerate.
13 changes: 6 additions & 7 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/bin/bash
#!/usr/bin/env bash

# Dump environment on to file so that we can load it up on the crontab
printenv > /etc/docker-env
EXTRA_PARAMS=""
if [[ ! -z "${TEST_CERT}" ]]; then
EXTRA_PARAMS="--test-cert"
fi;

# Run cron & tail logs
cron
touch /var/log/cert-update.log
tail -f /var/log/cert-update.log
exec /workdir/certbot-agent certs:update ${EXTRA_PARAMS} ${KONG_ENDPOINT} ${EMAIL} ${DOMAINS}
1 change: 0 additions & 1 deletion kubernetes/certbot-cronjob.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ spec:
containers:
- name: runtime
image: phpdockerio/kong-certbot-agent:3.0.0
command: [ "/workdir/certbot-agent", "certs:update", "$(KONG_ENDPOINT)", "$(EMAIL)", "$(DOMAINS)" ]
ports:
- name: web
containerPort: 80
Expand Down

0 comments on commit f955d26

Please sign in to comment.