Skip to content

Commit 40290ad

Browse files
authored
Merge pull request #6643 from acmesh-official/dev
sync
2 parents 9b30bd5 + 705fbcd commit 40290ad

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ RUN apk --no-cache add -f \
1515
jq \
1616
cronie
1717

18+
ENV LE_WORKING_DIR=/acmebin
19+
1820
ENV LE_CONFIG_HOME=/acme.sh
1921

2022
ARG AUTO_UPGRADE=1
@@ -30,7 +32,7 @@ COPY ./notify /install_acme.sh/notify
3032
RUN cd /install_acme.sh && ([ -f /install_acme.sh/acme.sh ] && /install_acme.sh/acme.sh --install || curl https://get.acme.sh | sh) && rm -rf /install_acme.sh/
3133

3234

33-
RUN ln -s /root/.acme.sh/acme.sh /usr/local/bin/acme.sh && crontab -l | grep acme.sh | sed 's#> /dev/null#> /proc/1/fd/1 2>/proc/1/fd/2#' | crontab -
35+
RUN ln -s $LE_WORKING_DIR/acme.sh /usr/local/bin/acme.sh && crontab -l | grep acme.sh | sed 's#> /dev/null#> /proc/1/fd/1 2>/proc/1/fd/2#' | crontab -
3436

3537
RUN for verb in help \
3638
version \
@@ -64,15 +66,15 @@ RUN for verb in help \
6466
set-default-ca \
6567
set-default-chain \
6668
; do \
67-
printf -- "%b" "#!/usr/bin/env sh\n/root/.acme.sh/acme.sh --${verb} --config-home /acme.sh \"\$@\"" >/usr/local/bin/--${verb} && chmod +x /usr/local/bin/--${verb} \
69+
printf -- "%b" "#!/usr/bin/env sh\n$LE_WORKING_DIR/acme.sh --${verb} --config-home $LE_CONFIG_HOME \"\$@\"" >/usr/local/bin/--${verb} && chmod +x /usr/local/bin/--${verb} \
6870
; done
6971

7072
RUN printf "%b" '#!'"/usr/bin/env sh\n \
7173
if [ \"\$1\" = \"daemon\" ]; then \n \
7274
exec crond -n -s -m off \n \
7375
else \n \
7476
exec -- \"\$@\"\n \
75-
fi\n" >/entry.sh && chmod +x /entry.sh
77+
fi\n" >/entry.sh && chmod +x /entry.sh && chmod -R o+rwx $LE_WORKING_DIR && chmod -R o+rwx $LE_CONFIG_HOME
7678

7779
VOLUME /acme.sh
7880

acme.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5242,6 +5242,16 @@ $_authorizations_map"
52425242
return 1
52435243
fi
52445244
break
5245+
elif _contains "$response" "\"ready\""; then
5246+
_info "Order status is 'ready', let's sleep and retry."
5247+
_retryafter=$(echo "$responseHeaders" | grep -i "^Retry-After *:" | cut -d : -f 2 | tr -d ' ' | tr -d '\r')
5248+
_debug "_retryafter" "$_retryafter"
5249+
if [ "$_retryafter" ]; then
5250+
_info "Sleeping for $_retryafter seconds then retrying"
5251+
_sleep $_retryafter
5252+
else
5253+
_sleep 2
5254+
fi
52455255
elif _contains "$response" "\"processing\""; then
52465256
_info "Order status is 'processing', let's sleep and retry."
52475257
_retryafter=$(echo "$responseHeaders" | grep -i "^Retry-After *:" | cut -d : -f 2 | tr -d ' ' | tr -d '\r')

deploy/panos.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# export PANOS_TEMPLATE="" # Template Name of panorama managed devices
1717
# export PANOS_TEMPLATE_STACK="" # set a Template Stack if certificate should also be pushed automatically
1818
# export PANOS_VSYS="Shared" # name of the vsys to import the certificate
19+
# export PANOS_CERTNAME="" # use a custom certificate name to work around Panorama's 31-character limit
1920
#
2021
# The script will automatically generate a new API key if
2122
# no key is found, or if a saved key has expired or is invalid.
@@ -89,7 +90,7 @@ deployer() {
8990
if [ "$type" = 'cert' ]; then
9091
panos_url="${panos_url}?type=import"
9192
content="--$delim${nl}Content-Disposition: form-data; name=\"category\"\r\n\r\ncertificate"
92-
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"certificate-name\"\r\n\r\n$_cdomain"
93+
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"certificate-name\"\r\n\r\n$_panos_certname"
9394
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"key\"\r\n\r\n$_panos_key"
9495
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"format\"\r\n\r\npem"
9596
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"file\"; filename=\"$(basename "$_cfullchain")\"${nl}Content-Type: application/octet-stream${nl}${nl}$(cat "$_cfullchain")"
@@ -103,11 +104,11 @@ deployer() {
103104
if [ "$type" = 'key' ]; then
104105
panos_url="${panos_url}?type=import"
105106
content="--$delim${nl}Content-Disposition: form-data; name=\"category\"\r\n\r\nprivate-key"
106-
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"certificate-name\"\r\n\r\n$_cdomain"
107+
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"certificate-name\"\r\n\r\n$_panos_certname"
107108
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"key\"\r\n\r\n$_panos_key"
108109
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"format\"\r\n\r\npem"
109110
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"passphrase\"\r\n\r\n123456"
110-
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"file\"; filename=\"$(basename "$_cdomain.key")\"${nl}Content-Type: application/octet-stream${nl}${nl}$(cat "$_ckey")"
111+
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"file\"; filename=\"$(basename "$_panos_certname.key")\"${nl}Content-Type: application/octet-stream${nl}${nl}$(cat "$_ckey")"
111112
if [ "$_panos_template" ]; then
112113
content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"target-tpl\"\r\n\r\n$_panos_template"
113114
fi
@@ -242,13 +243,23 @@ panos_deploy() {
242243
_getdeployconf PANOS_VSYS
243244
fi
244245

246+
# PANOS_CERTNAME
247+
if [ "$PANOS_CERTNAME" ]; then
248+
_debug "Detected ENV variable PANOS_CERTNAME. Saving to file."
249+
_savedeployconf PANOS_CERTNAME "$PANOS_CERTNAME" 1
250+
else
251+
_debug "Attempting to load variable PANOS_CERTNAME from file."
252+
_getdeployconf PANOS_CERTNAME
253+
fi
254+
245255
#Store variables
246256
_panos_host=$PANOS_HOST
247257
_panos_user=$PANOS_USER
248258
_panos_pass=$PANOS_PASS
249259
_panos_template=$PANOS_TEMPLATE
250260
_panos_template_stack=$PANOS_TEMPLATE_STACK
251261
_panos_vsys=$PANOS_VSYS
262+
_panos_certname=$PANOS_CERTNAME
252263

253264
#Test API Key if found. If the key is invalid, the variable _panos_key will be unset.
254265
if [ "$_panos_host" ] && [ "$_panos_key" ]; then
@@ -267,6 +278,12 @@ panos_deploy() {
267278
_err "No password found. If this is your first time deploying, please set PANOS_PASS in ENV variables. You can delete it after you have successfully deployed the certs."
268279
return 1
269280
else
281+
# Use certificate name based on the first domain on the certificate if no custom certificate name is set
282+
if [ -z "$_panos_certname" ]; then
283+
_panos_certname="$_cdomain"
284+
_savedeployconf PANOS_CERTNAME "$_panos_certname" 1
285+
fi
286+
270287
# Generate a new API key if no valid API key is found
271288
if [ -z "$_panos_key" ]; then
272289
_debug "**** Generating new PANOS API KEY ****"

0 commit comments

Comments
 (0)