74 lines
2.6 KiB
Markdown
Raw Normal View History

2017-06-27 14:09:51 +02:00
# Traefik Certificate Extractor
2018-08-04 19:49:58 +02:00
Forked from [DanielHuisman/traefik-certificate-extractor](https://github.com/DanielHuisman/traefik-certificate-extractor)
Tool to extract Let's Encrypt certificates from Traefik's ACME storage file. Can automatically restart containers using the docker API.
2017-06-27 14:09:51 +02:00
## Installation
2018-08-05 01:22:53 +02:00
```shell
2018-08-04 19:49:58 +02:00
git clone https://github.com/snowmb/traefik-certificate-extractor
2017-06-27 14:29:41 +02:00
cd traefik-certificate-extractor
2017-06-27 14:09:51 +02:00
```
## Usage
2018-08-05 01:22:53 +02:00
```shell
usage: extractor.py [-h] [-c CERTIFICATE] [-d DIRECTORY] [-f] [-r] [--dry-run]
[--include [INCLUDE [INCLUDE ...]] | --exclude
[EXCLUDE [EXCLUDE ...]]]
Extract traefik letsencrypt certificates.
optional arguments:
-h, --help show this help message and exit
-c CERTIFICATE, --certificate CERTIFICATE
file that contains the traefik certificates (default
acme.json)
-d DIRECTORY, --directory DIRECTORY
output folder
-f, --flat outputs all certificates into one folder
-r, --restart_container
uses the docker API to restart containers that are
labeled accordingly
--dry-run Don't write files and do not start docker containers.
--include [INCLUDE [INCLUDE ...]]
--exclude [EXCLUDE [EXCLUDE ...]]
2017-06-27 14:09:51 +02:00
```
2018-08-04 19:49:58 +02:00
Default file is `./data/acme.json`. The output directories are `./certs` and `./certs_flat`.
2017-06-27 14:09:51 +02:00
2017-06-27 14:29:41 +02:00
## Docker
2018-08-04 19:49:58 +02:00
There is a Docker image available for this tool: [snowmb/traefik-certificate-extractor](https://hub.docker.com/r/snowmb/traefik-certificate-extractor/).
2017-06-27 14:29:41 +02:00
Example run:
2018-08-05 01:22:53 +02:00
```shell
2018-08-04 19:49:58 +02:00
docker run --name extractor -d \
-v /opt/traefik:/app/data \
-v ./certs:/app/certs \
2018-11-11 21:00:39 +01:00
-v /var/run/docker.socket:/var/run/docker.sock \
2018-08-05 19:22:54 +02:00
snowmb/traefik-certificate-extractor
2017-06-27 14:29:41 +02:00
```
2018-08-05 19:22:54 +02:00
Mount the whole folder containing the traefik certificate file (`acme.json`) as `/app/data`. The extracted certificates are going to be written to `/app/certs`.
2018-08-04 19:49:58 +02:00
The docker socket is used to find any containers with this label: `com.github.SnowMB.traefik-certificate-extractor.restart_domain=<DOMAIN>`.
If the domains of an extracted certificate and the restart domain matches, the container is restarted. Multiple domains can be given seperated by `,`.
2017-06-27 14:29:41 +02:00
2017-06-27 14:09:51 +02:00
## Output
```
certs/
example.com/
cert.pem
chain.pem
fullchain.pem
privkey.pem
sub.example.nl/
cert.pem
chain.pem
fullchain.pem
privkey.pem
2017-06-27 15:56:54 +02:00
certs_flat/
example.com.crt
example.com.key
example.com.chain.pem
sub.example.nl.crt
sub.example.nl.key
sub.example.nl.chain.pem
2017-06-27 14:09:51 +02:00
```