Skip to content

Commit 57108ba

Browse files
authored
Merge pull request #843 from nginx-proxy/fix-761
Trim whitespaces from environment variables
2 parents ec93ec8 + 2f7ac97 commit 57108ba

File tree

2 files changed

+42
-27
lines changed

2 files changed

+42
-27
lines changed

app/letsencrypt_service

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function update_cert {
152152
params_issue_arr+=(--webroot /usr/share/nginx/html)
153153

154154
local -n cert_keysize="LETSENCRYPT_${cid}_KEYSIZE"
155-
if [[ -z "$cert_keysize" || "$cert_keysize" == "<no value>" ]] || \
155+
if [[ -z "$cert_keysize" ]] || \
156156
[[ ! "$cert_keysize" =~ ^(2048|3072|4096|ec-256|ec-384)$ ]]; then
157157
cert_keysize=$DEFAULT_KEY_SIZE
158158
fi
@@ -168,7 +168,7 @@ function update_cert {
168168
local config_home
169169
# If we don't have a LETSENCRYPT_EMAIL from the proxied container
170170
# and DEFAULT_EMAIL is set to a non empty value, use the latter.
171-
if [[ -z "$accountemail" || "$accountemail" == "<no value>" ]]; then
171+
if [[ -z "$accountemail" ]]; then
172172
if [[ -n "${DEFAULT_EMAIL// }" ]]; then
173173
accountemail="$DEFAULT_EMAIL"
174174
else
@@ -184,7 +184,7 @@ function update_cert {
184184
fi
185185

186186
local -n acme_ca_uri="ACME_${cid}_CA_URI"
187-
if [[ -z "$acme_ca_uri" || "$acme_ca_uri" == "<no value>" ]]; then
187+
if [[ -z "$acme_ca_uri" ]]; then
188188
# Use default or user provided ACME end point
189189
acme_ca_uri="$ACME_CA_URI"
190190
fi
@@ -229,15 +229,15 @@ function update_cert {
229229
local -n eab_kid="ACME_${cid}_EAB_KID"
230230
local -n eab_hmac_key="ACME_${cid}_EAB_HMAC_KEY"
231231
local -n zerossl_api_key="ZEROSSL_${cid}_API_KEY"
232-
if [[ -z "$zerossl_api_key" || "$zerossl_api_key" == "<no value>" ]]; then
232+
if [[ -z "$zerossl_api_key" ]]; then
233233
# Try using the default API key
234234
zerossl_api_key="$ZEROSSL_API_KEY"
235235
fi
236236
if [[ ! -f "$account_file" ]]; then
237-
if [[ -n "${eab_kid// }" && "$eab_kid" != "<no value>" && -n "${eab_hmac_key// }" && "$eab_hmac_key" != "<no value>" ]]; then
237+
if [[ -n "${eab_kid}" && -n "${eab_hmac_key}" ]]; then
238238
# Register the ACME account with the per container EAB credentials.
239239
params_register_arr+=(--eab-kid "$eab_kid" --eab-hmac-key "$eab_hmac_key")
240-
elif [[ -n "${zerossl_api_key// }" && "$zerossl_api_key" != "<no value>" ]]; then
240+
elif [[ -n "${zerossl_api_key}" ]]; then
241241
# We have a Zero SSL API key but no per-container EAB kid and hmac key.
242242
# Generate a set of ACME EAB credentials using the ZeroSSL API.
243243
local zerossl_api_response
@@ -293,7 +293,7 @@ function update_cert {
293293
fi
294294

295295
local -n acme_preferred_chain="ACME_${cid}_PREFERRED_CHAIN"
296-
if [[ -n "${acme_preferred_chain// }" && "$acme_preferred_chain" != "<no value>" ]]; then
296+
if [[ -n "${acme_preferred_chain}" ]]; then
297297
# Using amce.sh --preferred-chain to select alternate chain.
298298
params_issue_arr+=(--preferred-chain "$acme_preferred_chain")
299299
fi

app/letsencrypt_service_data.tmpl

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ LETSENCRYPT_CONTAINERS=(
33
{{ if trim $hosts }}
44
{{ range $container := $containers }}
55
{{ if parseBool (coalesce $container.Env.LETSENCRYPT_SINGLE_DOMAIN_CERTS "false") }}
6+
{{/* Explicit per-domain splitting of the certificate */}}
67
{{ range $host := split $hosts "," }}
78
{{ $host := trim $host }}
89
{{- "\t"}}'{{ printf "%.12s" $container.ID }}_{{ sha1 $host }}'
910
{{ end }}
1011
{{ else }}
12+
{{/* Default: multi-domain (SAN) certificate */}}
1113
{{- "\t"}}'{{ printf "%.12s" $container.ID }}'
1214
{{ end }}
1315
{{ end }}
@@ -18,42 +20,55 @@ LETSENCRYPT_CONTAINERS=(
1820
{{ range $hosts, $containers := groupBy $ "Env.LETSENCRYPT_HOST" }}
1921
{{ $hosts := trimSuffix "," $hosts }}
2022
{{ range $container := $containers }}
23+
{{/* Trim spaces and set empty values on per-container environment variables */}}
24+
{{ $KEYSIZE := trim (coalesce $container.Env.LETSENCRYPT_KEYSIZE "") }}
25+
{{ $STAGING := trim (coalesce $container.Env.LETSENCRYPT_TEST "") }}
26+
{{ $EMAIL := trim (coalesce $container.Env.LETSENCRYPT_EMAIL "") }}
27+
{{ $CA_URI := trim (coalesce $container.Env.ACME_CA_URI "") }}
28+
{{ $PREFERRED_CHAIN := trim (coalesce $container.Env.ACME_PREFERRED_CHAIN "") }}
29+
{{ $OCSP := trim (coalesce $container.Env.ACME_OCSP "") }}
30+
{{ $EAB_KID := trim (coalesce $container.Env.ACME_EAB_KID "") }}
31+
{{ $EAB_HMAC_KEY := trim (coalesce $container.Env.ACME_EAB_HMAC_KEY "") }}
32+
{{ $ZEROSSL_API_KEY := trim (coalesce $container.Env.ZEROSSL_API_KEY "") }}
33+
{{ $RESTART_CONTAINER := trim (coalesce $container.Env.LETSENCRYPT_RESTART_CONTAINER "") }}
2134
{{ $cid := printf "%.12s" $container.ID }}
2235
{{ if parseBool (coalesce $container.Env.LETSENCRYPT_SINGLE_DOMAIN_CERTS "false") }}
36+
{{/* Explicit per-domain splitting of the certificate */}}
2337
{{ range $host := split $hosts "," }}
2438
{{ $host := trim $host }}
2539
{{ $host := trimSuffix "." $host }}
2640
{{ $hostHash := sha1 $host }}
2741
{{- "\n" }}LETSENCRYPT_{{ $cid }}_{{ $hostHash }}_HOST=('{{ $host }}')
28-
{{- "\n" }}LETSENCRYPT_{{ $cid }}_{{ $hostHash }}_KEYSIZE="{{ $container.Env.LETSENCRYPT_KEYSIZE }}"
29-
{{- "\n" }}LETSENCRYPT_{{ $cid }}_{{ $hostHash }}_TEST="{{ $container.Env.LETSENCRYPT_TEST }}"
30-
{{- "\n" }}LETSENCRYPT_{{ $cid }}_{{ $hostHash }}_EMAIL="{{ $container.Env.LETSENCRYPT_EMAIL }}"
31-
{{- "\n" }}ACME_{{ $cid }}_{{ $hostHash }}_CA_URI="{{ $container.Env.ACME_CA_URI }}"
32-
{{- "\n" }}ACME_{{ $cid }}_{{ $hostHash }}_PREFERRED_CHAIN="{{ $container.Env.ACME_PREFERRED_CHAIN }}"
33-
{{- "\n" }}ACME_{{ $cid }}_{{ $hostHash }}_OCSP="{{ $container.Env.ACME_OCSP }}"
34-
{{- "\n" }}ACME_{{ $cid }}_{{ $hostHash }}_EAB_KID="{{ $container.Env.ACME_EAB_KID }}"
35-
{{- "\n" }}ACME_{{ $cid }}_{{ $hostHash }}_EAB_HMAC_KEY="{{ $container.Env.ACME_EAB_HMAC_KEY }}"
36-
{{- "\n" }}ZEROSSL_{{ $cid }}_{{ $hostHash }}_API_KEY="{{ $container.Env.ZEROSSL_API_KEY }}"
37-
{{- "\n" }}LETSENCRYPT_{{ $cid }}_{{ $hostHash }}_RESTART_CONTAINER="{{ $container.Env.LETSENCRYPT_RESTART_CONTAINER }}"
42+
{{- "\n" }}LETSENCRYPT_{{ $cid }}_{{ $hostHash }}_KEYSIZE="{{ $KEYSIZE }}"
43+
{{- "\n" }}LETSENCRYPT_{{ $cid }}_{{ $hostHash }}_TEST="{{ $STAGING }}"
44+
{{- "\n" }}LETSENCRYPT_{{ $cid }}_{{ $hostHash }}_EMAIL="{{ $EMAIL }}"
45+
{{- "\n" }}ACME_{{ $cid }}_{{ $hostHash }}_CA_URI="{{ $CA_URI }}"
46+
{{- "\n" }}ACME_{{ $cid }}_{{ $hostHash }}_PREFERRED_CHAIN="{{ $PREFERRED_CHAIN }}"
47+
{{- "\n" }}ACME_{{ $cid }}_{{ $hostHash }}_OCSP="{{ $OCSP }}"
48+
{{- "\n" }}ACME_{{ $cid }}_{{ $hostHash }}_EAB_KID="{{ $EAB_KID }}"
49+
{{- "\n" }}ACME_{{ $cid }}_{{ $hostHash }}_EAB_HMAC_KEY="{{ $EAB_HMAC_KEY }}"
50+
{{- "\n" }}ZEROSSL_{{ $cid }}_{{ $hostHash }}_API_KEY="{{ $ZEROSSL_API_KEY }}"
51+
{{- "\n" }}LETSENCRYPT_{{ $cid }}_{{ $hostHash }}_RESTART_CONTAINER="{{ $RESTART_CONTAINER }}"
3852
{{ end }}
3953
{{ else }}
54+
{{/* Default: multi-domain (SAN) certificate */}}
4055
{{- "\n" }}LETSENCRYPT_{{ $cid }}_HOST=(
4156
{{- range $host := split $hosts "," }}
4257
{{- $host := trim $host }}
4358
{{- $host := trimSuffix "." $host -}}
4459
'{{ $host }}'{{ " " }}
4560
{{- end -}}
4661
)
47-
{{- "\n" }}LETSENCRYPT_{{ $cid }}_KEYSIZE="{{ $container.Env.LETSENCRYPT_KEYSIZE }}"
48-
{{- "\n" }}LETSENCRYPT_{{ $cid }}_TEST="{{ $container.Env.LETSENCRYPT_TEST }}"
49-
{{- "\n" }}LETSENCRYPT_{{ $cid }}_EMAIL="{{ $container.Env.LETSENCRYPT_EMAIL }}"
50-
{{- "\n" }}ACME_{{ $cid }}_CA_URI="{{ $container.Env.ACME_CA_URI }}"
51-
{{- "\n" }}ACME_{{ $cid }}_PREFERRED_CHAIN="{{ $container.Env.ACME_PREFERRED_CHAIN }}"
52-
{{- "\n" }}ACME_{{ $cid }}_OCSP="{{ $container.Env.ACME_OCSP }}"
53-
{{- "\n" }}ACME_{{ $cid }}_EAB_KID="{{ $container.Env.ACME_EAB_KID }}"
54-
{{- "\n" }}ACME_{{ $cid }}_EAB_HMAC_KEY="{{ $container.Env.ACME_EAB_HMAC_KEY }}"
55-
{{- "\n" }}ZEROSSL_{{ $cid }}_API_KEY="{{ $container.Env.ZEROSSL_API_KEY }}"
56-
{{- "\n" }}LETSENCRYPT_{{ $cid }}_RESTART_CONTAINER="{{ $container.Env.LETSENCRYPT_RESTART_CONTAINER }}"
62+
{{- "\n" }}LETSENCRYPT_{{ $cid }}_KEYSIZE="{{ $KEYSIZE }}"
63+
{{- "\n" }}LETSENCRYPT_{{ $cid }}_TEST="{{ $STAGING }}"
64+
{{- "\n" }}LETSENCRYPT_{{ $cid }}_EMAIL="{{ $EMAIL }}"
65+
{{- "\n" }}ACME_{{ $cid }}_CA_URI="{{ $CA_URI }}"
66+
{{- "\n" }}ACME_{{ $cid }}_PREFERRED_CHAIN="{{ $PREFERRED_CHAIN }}"
67+
{{- "\n" }}ACME_{{ $cid }}_OCSP="{{ $OCSP }}"
68+
{{- "\n" }}ACME_{{ $cid }}_EAB_KID="{{ $EAB_KID }}"
69+
{{- "\n" }}ACME_{{ $cid }}_EAB_HMAC_KEY="{{ $EAB_HMAC_KEY }}"
70+
{{- "\n" }}ZEROSSL_{{ $cid }}_API_KEY="{{ $ZEROSSL_API_KEY }}"
71+
{{- "\n" }}LETSENCRYPT_{{ $cid }}_RESTART_CONTAINER="{{ $RESTART_CONTAINER }}"
5772
{{ end }}
5873
{{ end }}
5974
{{ end }}

0 commit comments

Comments
 (0)