forked from z1nkum/docker-letsencrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
save_certs.sh
executable file
·52 lines (42 loc) · 1.27 KB
/
save_certs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# $DOMAINS should contain all domains that this container is responsible for
# renewing. The first one dictates where the cert will live.
# Inside /etc/letsencrypt/live/<domain> we have:
#
# cert.pem chain.pem fullchain.pem privkey.pem
#
# We want to convert fullchain.pem into proxycert
# and privkey.pem into proxykey and then save as a secret!
if [ -z "$SECRET_NAME" ]; then
echo "ERROR: Secret name is empty or unset"
exit 1
fi
CERT_LOCATION='/etc/letsencrypt/live'
DOMAINS=($DOMAINS)
DOMAIN=${DOMAINS[0]}
CERT=$(cat $CERT_LOCATION/$DOMAIN/fullchain.pem | base64 --wrap=0)
KEY=$(cat $CERT_LOCATION/$DOMAIN/privkey.pem | base64 --wrap=0)
PEM=$(cat $CERT_LOCATION/$DOMAIN/fullchain.pem $CERT_LOCATION/$DOMAIN/privkey.pem | base64 --wrap=0)
DHPARAM=$(openssl dhparam 2048 | base64 --wrap=0)
NAMESPACE=${NAMESPACE:-default}
TYPE=${TYPE:-Opaque}
kubectl get secrets --namespace $NAMESPACE $SECRET_NAME && ACTION=replace || ACTION=create;
cat << EOF | kubectl $ACTION -f -
{
"apiVersion": "v1",
"kind": "Secret",
"metadata": {
"name": "$SECRET_NAME",
"namespace": "$NAMESPACE"
},
"data": {
"proxycert": "$CERT",
"proxykey": "$KEY",
"tls.crt": "$CERT",
"tls.key": "$KEY",
"tls.pem": "$PEM",
"dhparam": "$DHPARAM"
},
"type": "$TYPE"
}
EOF