Skip to content

Commit 8b2c6ee

Browse files
committed
Use default config for empty DEFAULT_EMAIL only
Then there is no more need to update the default config accounts on DEFAULT_EMAIL changes. No more need for LE_ACMESH_CONFIG either Doc acme.sh.md
1 parent 4b61870 commit 8b2c6ee

File tree

6 files changed

+46
-40
lines changed

6 files changed

+46
-40
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ RUN apk add --update \
3838
# Install docker-gen from build stage
3939
COPY --from=go-builder /go/src/github.com/jwilder/docker-gen/docker-gen /usr/local/bin/
4040

41-
# Install simp_le
41+
# Install acme.sh
4242
COPY /install_acme.sh /app/install_acme.sh
4343
RUN chmod +rx /app/install_acme.sh \
4444
&& sync \

app/entrypoint.sh

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ set -u
55
# shellcheck source=functions.sh
66
source /app/functions.sh
77

8-
function check_deprecated_env_var {
9-
if [[ -n "${ACME_TOS_HASH:-}" ]]; then
10-
echo "Info: the ACME_TOS_HASH environment variable is no longer used by simp_le and has been deprecated."
11-
echo "simp_le now implicitly agree to the ACME CA ToS."
12-
fi
13-
}
14-
158
function check_docker_socket {
169
if [[ $DOCKER_HOST == unix://* ]]; then
1710
socket_file=${DOCKER_HOST#unix://}
@@ -134,23 +127,13 @@ function check_default_cert_key {
134127
set_ownership_and_permissions "/etc/nginx/certs/default.crt"
135128
}
136129

137-
function configure_default_email {
138-
# Configure the email used by the default config
139-
[[ -d /etc/acme.sh/default ]] || mkdir -p /etc/acme.sh/default
130+
function check_default_account {
131+
# The default account is now for empty account email
140132
if [[ -f /etc/acme.sh/default/account.conf ]]; then
141-
if [[ -f /etc/acme.sh/default/ca/acme-v01.api.letsencrypt.org/account.json ]]; then
142-
acme.sh --update-account --accountemail "${DEFAULT_EMAIL:-}"
143-
return 0
144-
elif grep -q ACCOUNT_EMAIL /etc/acme.sh/default/account.conf; then
145-
if grep -q "${DEFAULT_EMAIL:-}" /etc/acme.sh/default/account.conf; then
146-
return 0
147-
else
148-
sed -i "s/^ACCOUNT_EMAIL=.*$/ACCOUNT_EMAIL='${DEFAULT_EMAIL:-}'/g" /etc/acme.sh/default/account.conf
149-
return 0
150-
fi
133+
if grep -q ACCOUNT_EMAIL /etc/acme.sh/default/account.conf; then
134+
sed -i '/ACCOUNT_EMAIL/d' /etc/acme.sh/default/account.conf
151135
fi
152136
fi
153-
echo "ACCOUNT_EMAIL='${DEFAULT_EMAIL:-}'" >> /etc/acme.sh/default/account.conf
154137
}
155138

156139
if [[ "$*" == "/bin/bash /app/start.sh" ]]; then
@@ -177,7 +160,7 @@ if [[ "$*" == "/bin/bash /app/start.sh" ]]; then
177160
check_default_cert_key
178161
check_dh_group
179162
reload_nginx
180-
[[ -n ${DEFAULT_EMAIL:-} ]] && configure_default_email
163+
check_default_account
181164
fi
182165

183166
exec "$@"

app/letsencrypt_service

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ source /app/functions.sh
55

66
seconds_to_wait=3600
77
ACME_CA_URI="${ACME_CA_URI:-https://acme-v02.api.letsencrypt.org/directory}"
8+
ACME_CA_TEST_URI="https://acme-staging-v02.api.letsencrypt.org/directory"
89
DEFAULT_KEY_SIZE="${DEFAULT_KEY_SIZE:-4096}"
910
RENEW_PRIVATE_KEYS="$(lc "${RENEW_PRIVATE_KEYS:-true}")"
1011

@@ -169,26 +170,37 @@ function update_certs {
169170
cert_keysize=$DEFAULT_KEY_SIZE
170171
fi
171172

172-
test_certificate_varname="LETSENCRYPT_${cid}_TEST"
173-
le_staging_uri="https://acme-staging-v02.api.letsencrypt.org/directory"
174-
if [[ $(lc "${!test_certificate_varname:-}") == true ]] || \
175-
[[ "$ACME_CA_URI" == "$le_staging_uri" ]]; then
176-
# Use staging Let's Encrypt ACME end point
177-
acme_ca_uri="$le_staging_uri"
178-
# Prefix test certificate directory with _test_
179-
certificate_dir="/etc/nginx/certs/_test_$base_domain"
180-
else
173+
accountemail_varname="LETSENCRYPT_${cid}_EMAIL"
174+
accountemail="${!accountemail_varname:-"<no-value>"}"
175+
if [[ "$accountemail" == "<no value>" ]]; then
176+
accountemail="${DEFAULT_EMAIL:-}"
177+
fi
178+
config_name="${accountemail:-default}"
179+
180+
acme_ca_uri_varname="LETSENCRYPT_${cid}_ACME_CA_URI"
181+
acme_ca_uri="${!acme_ca_uri_varname}"
182+
if [[ "$acme_ca_uri" == "<no value>" ]]; then
181183
# Use default or user provided ACME end point
182184
acme_ca_uri="$ACME_CA_URI"
183-
certificate_dir="/etc/nginx/certs/$base_domain"
184185
fi
185186

186-
config_varname="LETSENCRYPT_${cid}_ACMESH_CONFIG"
187-
config_name="${!config_varname:-"<no value>"}"
188-
if [[ "$config_name" == "<no value>" ]]; then
189-
config_name=default
187+
test_certificate_varname="LETSENCRYPT_${cid}_TEST"
188+
if [[ $(lc "${!test_certificate_varname:-}") == true || "$acme_ca_uri" == "$ACME_CA_TEST_URI" ]]; then
189+
# Use Let's Encrypt ACME V2 staging end point
190+
# Unset accountemail
191+
# force config dir to 'staging'
192+
acme_ca_uri="ACME_CA_TEST_URI"
193+
accountemail=
194+
config_name=staging
195+
fi
196+
197+
[[ -z "$accountemail" ]] || params_d_arr+=("--accountemail" "$accountemail")
198+
[[ ! -d "/etc/acme.sh/$config_name" ]] && mkdir -p "/etc/acme.sh/$config_name"
199+
200+
if [[ $acme_ca_uri =~ ^https://acme-staging.* ]]; then
201+
certificate_dir="/etc/nginx/certs/_test_$base_domain"
190202
else
191-
[[ ! -d "/etc/acme.sh/$config_name" ]] && mkdir -p "/etc/acme.sh/$config_name"
203+
certificate_dir="/etc/nginx/certs/$base_domain"
192204
fi
193205

194206
[[ "$DEBUG" == 1 ]] && params_d_arr+=("--debug")

app/letsencrypt_service_data.tmpl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ LETSENCRYPT_CONTAINERS=(
2727
LETSENCRYPT_{{ $cid }}_{{ $hostHash }}_HOST=('{{ $host }}')
2828
LETSENCRYPT_{{ $cid }}_{{ $hostHash }}_KEYSIZE="{{ $container.Env.LETSENCRYPT_KEYSIZE }}"
2929
LETSENCRYPT_{{ $cid }}_{{ $hostHash }}_TEST="{{ $container.Env.LETSENCRYPT_TEST }}"
30-
LETSENCRYPT_{{ $cid }}_{{ $hostHash }}_ACMESH_CONFIG="{{ $container.Env.LETSENCRYPT_ACMESH_CONFIG }}"
30+
LETSENCRYPT_{{ $cid }}_{{ $hostHash }}_EMAIL="{{ $container.Env.LETSENCRYPT_EMAIL }}"
31+
LETSENCRYPT_{{ $cid }}_{{ $hostHash }}_ACME_CA_URI="{{ $container.Env.LETSENCRYPT_ACME_CA_URI }}"
3132
LETSENCRYPT_{{ $cid }}_{{ $hostHash }}_RESTART_CONTAINER="{{ $container.Env.LETSENCRYPT_RESTART_CONTAINER }}"
3233
{{ end }}
3334
{{ else }}
3435
LETSENCRYPT_{{ $cid }}_HOST=( {{ range $host := split $hosts "," }}{{ $host := trim $host }}{{ $host := trimSuffix "." $host }}'{{ $host }}' {{ end }})
3536
LETSENCRYPT_{{ $cid }}_KEYSIZE="{{ $container.Env.LETSENCRYPT_KEYSIZE }}"
3637
LETSENCRYPT_{{ $cid }}_TEST="{{ $container.Env.LETSENCRYPT_TEST }}"
37-
LETSENCRYPT_{{ $cid }}_ACMESH_CONFIG="{{ $container.Env.LETSENCRYPT_ACMESH_CONFIG }}"
38+
LETSENCRYPT_{{ $cid }}_EMAIL="{{ $container.Env.LETSENCRYPT_EMAIL }}"
39+
LETSENCRYPT_{{ $cid }}_ACME_CA_URI="{{ $container.Env.LETSENCRYPT_ACME_CA_URI }}"
3840
LETSENCRYPT_{{ $cid }}_RESTART_CONTAINER="{{ $container.Env.LETSENCRYPT_RESTART_CONTAINER }}"
3941
{{ end }}
4042
{{ end }}

docs/acme.sh.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
### Design decisions:
2+
3+
1. Use one acme.sh configuration directory (`--config-home`) per account email address
4+
1. Each acme.sh configuration directory can hold several accounts on different ACME service providers. But only one per servie provider.
5+
1. The `defaut`configuration directory holds the configuration for empty account email address
6+
1. When in testing mode (`LETSENCRYPT_TEST=true`):
7+
1. The directory URL is forced to The Let's Encrypt v2 staging one (`ACME_CA_URI`is ignored)
8+
1. The account email address is forced empty (`DEFAULT_EMAIL`and `LETSENCRYPT_EMAIL` are ignored)

install_acme.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ git checkout "$tag"
1515
# Install acme.sh in /app
1616
./acme.sh --install \
1717
--nocron \
18+
--noprofile \
1819
--auto-upgrade 0 \
1920
--home /app \
2021
--config-home /etc/acme.sh/default

0 commit comments

Comments
 (0)