@@ -528,6 +528,18 @@ process_domain_tlsalpn() {
528528 exit 1
529529 fi
530530
531+ # Public DNS being correct is not the same as the gateway acting on it. The
532+ # gateway resolves the app-address TXT itself and caches the answer for the
533+ # record's TTL, so right after the value changes -- which is every time the
534+ # CVM instance is replaced, since the record names the instance -- it can
535+ # still route the challenge to the previous target. Observed exactly that:
536+ # dnsguide passed, then the CA got "Error getting validation data" because
537+ # the gateway was still sending it to the old instance.
538+ if [ " ${DNS_SETTLE_SECONDS:- 30} " -gt 0 ]; then
539+ echo " Waiting ${DNS_SETTLE_SECONDS:- 30} s for the gateway's DNS cache to expire"
540+ sleep " ${DNS_SETTLE_SECONDS:- 30} "
541+ fi
542+
531543 renew-certificate.sh " $domain "
532544}
533545
@@ -591,18 +603,30 @@ ensure_placeholder_certs() {
591603
592604# Obtain certificates once the proxy is already serving, then swap them in.
593605bootstrap_and_reload () {
594- # Nested subshell so an `exit 1` from a process_domain helper is reported as
595- # a failed condition here rather than silently killing this background job.
596- if ( bootstrap ); then
597- build-combined-pems.sh || echo " Combined PEM build failed" >&2
598- if [ -f /var/run/haproxy/haproxy.pid ]; then
599- kill -USR2 " $( cat /var/run/haproxy/haproxy.pid) " &&
600- echo " Certificates installed and HAProxy reloaded"
606+ local attempt=0 delay
607+ while true ; do
608+ attempt=$(( attempt + 1 ))
609+ # Nested subshell so an `exit 1` from a process_domain helper is
610+ # reported as a failed condition here rather than silently killing
611+ # this background job.
612+ if ( bootstrap ); then
613+ build-combined-pems.sh || echo " Combined PEM build failed" >&2
614+ if [ -f /var/run/haproxy/haproxy.pid ]; then
615+ kill -USR2 " $( cat /var/run/haproxy/haproxy.pid) " &&
616+ echo " Certificates installed and HAProxy reloaded"
617+ fi
618+ return 0
601619 fi
602- else
603- echo " Bootstrap failed; the proxy keeps serving the placeholder certificate." >&2
604- echo " Fix the DNS records above; the renewal daemon retries every 12 hours." >&2
605- fi
620+
621+ # Falling through to the 12-hour renewal daemon would be a terrible
622+ # retry interval for a flow whose normal state is "waiting for the
623+ # operator to create a DNS record". Back off, but keep trying.
624+ delay=$(( 60 * attempt))
625+ [ " $delay " -gt 1800 ] && delay=1800
626+ echo " Bootstrap attempt ${attempt} failed; the proxy keeps serving the" >&2
627+ echo " placeholder certificate. Retrying in ${delay} s." >&2
628+ sleep " $delay "
629+ done
606630}
607631
608632# Credentials are now handled by certman.py setup
0 commit comments