Skip to content

Commit

Permalink
Improved DOMAINNAME detection for letsencrypt requests
Browse files Browse the repository at this point in the history
  • Loading branch information
richturner committed Mar 9, 2022
1 parent 82d19fc commit 9c4ed2e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/sh

# Regex for IP address or string without a '.'
IP_REGEX='(^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$)|(^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$)|(^[^\.]+$)'

# Configure letsencrypt
export LE_WEB_ROOT="/deployment/acme-webroot"
LE_EXTRA_ARGS=""
Expand Down Expand Up @@ -31,10 +34,12 @@ if [ -n "${LOCAL_CERT_FILE}" ]; then
INIT=false
else
export CERT_FILE="/opt/selfsigned/localhost.pem"
if [ -n "${DOMAINNAME}" ] && [ "${DOMAINNAME}" != "localhost" ]; then

# Domain name must not be an IP address and must contain at least one '.' for cert generation
if [ -n "${DOMAINNAME}" ] && [[ ! "${DOMAINNAME}" =~ $IP_REGEX ]]; then
export CERT_FILE="${LE_CERT_ROOT}/${DOMAINNAME}/haproxy.pem"
fi
if [ ! -f "${CERT_FILE}" ]; then
if [ ! -f "${CERT_FILE}" ]; then
INIT=true
HAPROXY_CONFIG="/etc/haproxy/haproxy-init.cfg"
else
Expand Down Expand Up @@ -390,7 +395,8 @@ die() {
cron_auto_renewal_init() {
log_info "Executing cron_auto_renewal_init at $(date -R)"

if [ -n "${DOMAINNAME}" ] && [ "${DOMAINNAME}" != "localhost" ]; then
# Domain name must not be an IP address and must contain at least one '.' for cert generation
if [ -n "${DOMAINNAME}" ] && [[ ! "${DOMAINNAME}" =~ $IP_REGEX ]]; then
if [ ! -d "${LE_CERT_ROOT}/${DOMAINNAME}" ]; then
log_info "Initialising certificate for '${DOMAINNAME}'..."
rm -rf "${LE_CERT_ROOT}/${DOMAINNAME}"
Expand Down Expand Up @@ -480,4 +486,4 @@ elif [ "${CMD}" = "start-with-certificate" ]; then
start_with_certificate
else
die "Unknown command: ${CMD}"
fi
fi

0 comments on commit 9c4ed2e

Please sign in to comment.