Skip to content

Commit a18ecb5

Browse files
authored
Merge pull request #14 from benkorichard/cert_expiry
Configure certificates expiration date with a new environment variable.
2 parents e6328f7 + 949b9e4 commit a18ecb5

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ Your Docker Remote API is available on port 2376 via https. The client needs to
4343
The docker-remote-api image can generate CA, certificates and keys for you automatically.
4444
Create a docker-compose.yml file, specifying a password and the hostname, on which the remote api will be accessible later on. The hostname will be written to the server's certificate.
4545

46-
Optionally, the cert password can be provided as a docker secret. In this case use the `CERTS_PASSWORD_FILE` variable with the absolute path of secret file: `CERTS_PASSWORD_FILE=/run/secrets/<secret_name>`. If both `CREATE_CERTS_WITH_PW` and `CERTS_PASSWORD_FILE` are provided, `CERTS_PASSWORD_FILE` takes precedence.
47-
4846
```yml
4947
version: "3.4"
5048
services:
@@ -64,6 +62,22 @@ Now run the container with `docker-compose up -d` or `docker stack deploy --comp
6462
Certificates will be created in `<local cert dir>`.
6563
You will find the client-certs in `<local cert dir>/client/`. The files are `ca.pem`, `cert.pem` and `key.pem`.
6664

65+
## Environment variables
66+
67+
#### `CREATE_CERTS_WITH_PW`
68+
Passphrase to encrypt the certificate.
69+
70+
#### `CERTS_PASSWORD_FILE`
71+
Certificate passphrase will be read from this docker secret. Absolute path of the secret file has to be provided i.e. `CERTS_PASSWORD_FILE=/run/secrets/<secret_name>`.
72+
73+
If both passphrase and secret file are set, the secret file takes precedence.
74+
75+
#### `CERT_EXPIRATION`
76+
Certificate expiration in days. If not set, the default value 365 is applied.
77+
78+
#### `CERT_HOSTNAME`
79+
Domain name of the docker server.
80+
6781
## Setup client
6882

6983
See [Run commands on remote Docker host](https://gist.github.com/kekru/4e6d49b4290a4eebc7b597c07eaf61f2) for instructions how to setup a client to communicate with the remote api.

resources/entrypoint.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/sh
22

3+
CERT_EXPIRATION_DAYS=${CERT_EXPIRATION:-365}
4+
35
if [ -n "$CERTS_PASSWORD_FILE" ]; then
46
echo "Using cert password from $CERTS_PASSWORD_FILE"
57
CREATE_CERTS_WITH_PW="$(cat $CERTS_PASSWORD_FILE)"
@@ -11,9 +13,9 @@ if [ -n $CREATE_CERTS_WITH_PW ]; then
1113
echo "Create CA cert"
1214
/script/create-certs.sh -m ca -pw $CREATE_CERTS_WITH_PW -t $CERTS_DIR -e 900
1315
echo "Create server cert"
14-
/script/create-certs.sh -m server -h $CERT_HOSTNAME -pw $CREATE_CERTS_WITH_PW -t $CERTS_DIR -e 365
16+
/script/create-certs.sh -m server -h $CERT_HOSTNAME -pw $CREATE_CERTS_WITH_PW -t $CERTS_DIR -e $CERT_EXPIRATION_DAYS
1517
echo "Create client cert"
16-
/script/create-certs.sh -m client -h testClient -pw $CREATE_CERTS_WITH_PW -t $CERTS_DIR -e 365
18+
/script/create-certs.sh -m client -h testClient -pw $CREATE_CERTS_WITH_PW -t $CERTS_DIR -e $CERT_EXPIRATION_DAYS
1719

1820
mkdir $CERTS_DIR/client
1921
mv $CERTS_DIR/ca.pem $CERTS_DIR/ca-cert.pem

0 commit comments

Comments
 (0)