Skip to content

Commit 65d14ed

Browse files
authored
Merge pull request #896 from chinkung/main
Add DEFAULT_RENEW variable
2 parents f43e425 + 65cd374 commit 65d14ed

File tree

5 files changed

+73
-5
lines changed

5 files changed

+73
-5
lines changed

app/letsencrypt_service

+9-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ACME_CA_URI="${ACME_CA_URI:-"https://acme-v02.api.letsencrypt.org/directory"}"
88
ACME_CA_TEST_URI="https://acme-staging-v02.api.letsencrypt.org/directory"
99
DEFAULT_KEY_SIZE="${DEFAULT_KEY_SIZE:-4096}"
1010
RENEW_PRIVATE_KEYS="$(lc "${RENEW_PRIVATE_KEYS:-true}")"
11+
DEFAULT_RENEW="${DEFAULT_RENEW:-60}"
1112

1213
# Backward compatibility environment variable
1314
REUSE_PRIVATE_KEYS="$(lc "${REUSE_PRIVATE_KEYS:-false}")"
@@ -259,7 +260,7 @@ function update_cert {
259260
else
260261
# If we did not get any email at all, use the default (empty mail) config
261262
config_home="/etc/acme.sh/default"
262-
fi
263+
fi
263264

264265
local -n acme_ca_uri="ACME_${cid}_CA_URI"
265266
if [[ -z "$acme_ca_uri" ]]; then
@@ -368,13 +369,13 @@ function update_cert {
368369
fi
369370
else
370371
# We don't have a Zero SSL ACME account, EAB credentials, a ZeroSSL API key or an account email :
371-
# skip certificate account registration and certificate issuance.
372+
# skip certificate account registration and certificate issuance.
372373
echo "Error: usage of ZeroSSL require an email bound account. No EAB credentials, ZeroSSL API key or email were provided for this certificate, creation aborted."
373374
return 1
374-
fi
375+
fi
375376
fi
376377
fi
377-
378+
378379
# Account registration and update if required
379380
if [[ ! -f "$account_file" ]]; then
380381
params_register_arr=("${params_base_arr[@]}" "${params_register_arr[@]}")
@@ -418,7 +419,7 @@ function update_cert {
418419
params_issue_arr+=(--preferred-chain "$acme_preferred_chain")
419420
fi
420421
if [[ "$RENEW_PRIVATE_KEYS" != 'false' && "$REUSE_PRIVATE_KEYS" != 'true' ]]; then
421-
params_issue_arr+=(--always-force-new-domain-key)
422+
params_issue_arr+=(--always-force-new-domain-key)
422423
fi
423424
[[ "${2:-}" == "--force-renew" ]] && params_issue_arr+=(--force)
424425

@@ -435,6 +436,9 @@ function update_cert {
435436
fi
436437
done
437438

439+
# Allow to override day to renew cert
440+
params_issue_arr+=(--days "$DEFAULT_RENEW")
441+
438442
params_issue_arr=("${params_base_arr[@]}" "${params_issue_arr[@]}")
439443
[[ "$DEBUG" == 1 ]] && echo "Calling acme.sh --issue with the following parameters : ${params_issue_arr[*]}"
440444
echo "Creating/renewal $base_domain certificates... (${hosts_array[*]})"

docs/Container-configuration.md

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ You can also create test certificates per container (see [Test certificates](./L
3434

3535
* `ACME_POST_HOOK` - The provided command will be run after every certificate issuance. The action is limited to the commands available inside the **acme-companion** container. For example `--env "ACME_POST_HOOK=echo 'end'"`. For more information see [Pre- and Post-Hook](./Hooks.md)
3636

37+
* `DEFAULT_RENEW` - 60 days by default, this defines the number of days between certificate renewals attempts. For certificates issued by certain Certificate Authorities, such as Buypass, which have a lifespan of 180 days, it may be advisable to initiate the renewal process on day 170 rather than the default day 60. See [BuyPass.com CA](https://github.com/acmesh-official/acme.sh/wiki/BuyPass.com-CA) for more detail.
38+
3739
* `ACME_HTTP_CHALLENGE_LOCATION` - Previously **acme-companion** automatically added the ACME HTTP challenge location to the nginx configuration through files generated in `/etc/nginx/vhost.d`. Recent versions of **nginx-proxy** (>= `1.6`) already include the required location configuration, which remove the need for **acme-companion** to attempt to dynamically add them. If you're running and older version of **nginx-proxy** (or **docker-gen** with an older version of the `nginx.tmpl` file), you can re-enable this behaviour by setting `ACME_HTTP_CHALLENGE_LOCATION` to `true`.
3840

3941
* `RELOAD_NGINX_ONLY_ONCE` - The companion reload nginx configuration after every new or renewed certificate. Previously this was done only once per service loop, at the end of the loop (this was causing delayed availability of HTTPS enabled application when multiple new certificates where requested at once, see [issue #1147](https://github.com/nginx-proxy/acme-companion/issues/1147)). You can restore the previous behaviour if needed by setting the environment variable `RELOAD_NGINX_ONLY_ONCE` to `true`.
42+

test/config.sh

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ globalTests+=(
1717
permissions_custom
1818
symlinks
1919
acme_hooks
20+
certs_default_renew
2021
ocsp_must_staple
2122
)
2223

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

test/tests/certs_default_renew/run.sh

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
## Test for the DEFAULT_RENEW function.
4+
5+
if [[ -z $GITHUB_ACTIONS ]]; then
6+
le_container_name="$(basename "${0%/*}")_$(date "+%Y-%m-%d_%H.%M.%S")"
7+
else
8+
le_container_name="$(basename "${0%/*}")"
9+
fi
10+
11+
default_renew=170
12+
run_le_container "${1:?}" "$le_container_name" \
13+
--cli-args "--env DEFAULT_RENEW=$default_renew"
14+
15+
# Create the $domains array from comma separated domains in TEST_DOMAINS.
16+
IFS=',' read -r -a domains <<< "$TEST_DOMAINS"
17+
18+
# Cleanup function with EXIT trap
19+
function cleanup {
20+
# Remove the Nginx container silently.
21+
docker rm --force "${domains[0]}" &> /dev/null
22+
# Cleanup the files created by this run of the test to avoid foiling following test(s).
23+
docker exec "$le_container_name" /app/cleanup_test_artifacts
24+
# Stop the LE container
25+
docker stop "$le_container_name" > /dev/null
26+
}
27+
trap cleanup EXIT
28+
29+
container_email="contact@${domains[0]}"
30+
acme_config_file="/etc/acme.sh/$container_email/${domains[0]}/${domains[0]}.conf"
31+
32+
# Run a nginx container for ${domains[0]} with LETSENCRYPT_EMAIL set.
33+
run_nginx_container --hosts "${domains[0]}" \
34+
--cli-args "--env LETSENCRYPT_EMAIL=${container_email}"
35+
36+
# Wait for a symlink at /etc/nginx/certs/${domains[0]}.crt
37+
wait_for_symlink "${domains[0]}" "$le_container_name"
38+
39+
acme_cert_create_time_key="Le_CertCreateTime="
40+
acme_renewal_days_key="Le_RenewalDays="
41+
acme_next_renew_time_key="Le_NextRenewTime="
42+
43+
# Check if the default command is deliverd properly in /etc/acme.sh
44+
if docker exec "$le_container_name" [[ ! -f "$acme_config_file" ]]; then
45+
echo "The $acme_config_file file does not exist."
46+
fi
47+
48+
cert_create_time="$(docker exec "$le_container_name" grep "$acme_cert_create_time_key" "$acme_config_file" | cut -f2 -d\')"
49+
expected_renewal_days="${acme_renewal_days_key}'$default_renew'"
50+
expected_next_renew_time="${acme_next_renew_time_key}'$(($cert_create_time + $default_renew * 24 * 60 * 60 - 86400))'"
51+
actual_renewal_days="$(docker exec "$le_container_name" grep "$acme_renewal_days_key" "$acme_config_file")"
52+
actual_next_renew_time="$(docker exec "$le_container_name" grep "$acme_next_renew_time_key" "$acme_config_file")"
53+
54+
if [[ "$expected_renewal_days" != "$actual_renewal_days" ]]; then
55+
echo "Renewal days is not correct"
56+
fi
57+
if [[ "$expected_next_renew_time" != "$actual_next_renew_time" ]]; then
58+
echo "Next renewal time is not correct"
59+
fi

0 commit comments

Comments
 (0)