Skip to content

Commit 734940d

Browse files
authored
Merge pull request #731 from srvrco/acme-dns
Fix CNAME issues and support acme-dns (fixes #722, #308, #646, #600, #585)
2 parents bffa3ee + 3b90477 commit 734940d

24 files changed

+723
-126
lines changed

.github/workflows/run-tests-pebble.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ jobs:
9292
run: docker-compose up -d --build
9393
- name: Run test suite on Ubuntu
9494
run: test/run-test.sh ubuntu
95+
test-ubuntu14:
96+
runs-on: ubuntu-latest
97+
steps:
98+
- uses: actions/checkout@v1
99+
- name: Build the docker-compose stack
100+
run: docker-compose up -d --build
101+
- name: Run test suite on Ubuntu14
102+
run: test/run-test.sh ubuntu14
95103
test-ubuntu16:
96104
runs-on: ubuntu-latest
97105
steps:
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Run all tests using Dynu and acmedns
2+
on:
3+
push:
4+
paths-ignore:
5+
- '.github/workflows/*'
6+
branches:
7+
- master
8+
pull_request:
9+
branches:
10+
- master
11+
workflow_dispatch:
12+
branches:
13+
- master
14+
env:
15+
DYNU_API_KEY: ${{ secrets.DYNU_API_KEY == '' && '65cXefd35XbYf36546eg5dYcZT6X52Y2' || secrets.DYNU_API_KEY }}
16+
jobs:
17+
test-ubuntu-acmedns:
18+
runs-on: ubuntu-latest
19+
if: always()
20+
steps:
21+
- uses: actions/checkout@v2
22+
- name: Build the docker-compose stack
23+
run: docker-compose up -d --build
24+
- name: Run test suite on Ubuntu against Staging using acmedns
25+
run: test/run-test.sh ubuntu-acmedns

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
*.tar.gz
88
*.orig
99
JSON.sh
10+
.vscode/settings.json

dns_scripts/dns_add_acmedns

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
# Need to add your API user and key below or set as env variable
3+
apiuser=${ACMEDNS_API_USER:-''}
4+
apikey=${ACMEDNS_API_KEY:-''}
5+
apisubdomain=${ACMEDNS_SUBDOMAIN:-''}
6+
7+
# This script adds a token to acme-dns.io DNS for the ACME challenge
8+
# usage dns_add_acme-dns "domain name" "token"
9+
# return codes are;
10+
# 0 - success
11+
# 1 - error returned from server
12+
13+
fulldomain="${1}"
14+
token="${2}"
15+
16+
API='https://auth.acme-dns.io/update'
17+
18+
# Check initial parameters
19+
if [[ -z "$fulldomain" ]]; then
20+
echo "DNS script requires full domain name as first parameter"
21+
exit 1
22+
fi
23+
if [[ -z "$token" ]]; then
24+
echo "DNS script requires challenge token as second parameter"
25+
exit 1
26+
fi
27+
28+
curl_params=(
29+
-H "accept: application/json"
30+
-H "X-Api-Key: $apikey"
31+
-H "X-Api-User: $apiuser"
32+
-H 'Content-Type: application/json'
33+
)
34+
35+
generate_post_data()
36+
{
37+
cat <<EOF
38+
{
39+
"subdomain": "$apisubdomain",
40+
"txt": "$token"
41+
}
42+
EOF
43+
}
44+
45+
resp=$(curl --silent \
46+
"${curl_params[@]}" \
47+
-X POST "${API}" \
48+
--data "$(generate_post_data)")
49+
50+
echo $resp
51+
# If adding record failed (returned json includes "error" then print error message
52+
if [[ "$resp" = *"\"error\""* ]]; then
53+
echo "Error: DNS challenge not added: unknown error - ${resp}"
54+
exit 1
55+
fi

dns_scripts/dns_add_cpanel

100644100755
File mode changed.

dns_scripts/dns_add_del_aliyun.sh

100644100755
File mode changed.

dns_scripts/dns_del_acmedns

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
# Need to add your API user and key below or set as env variable
3+
apiuser=${ACMEDNS_API_USER:-''}
4+
apikey=${ACMEDNS_API_KEY:-''}
5+
apisubdomain=${ACMEDNS_SUBDOMAIN:-''}
6+
7+
# This script adds a token to acme-dns.io DNS for the ACME challenge
8+
# usage dns_add_acme-dns "domain name" "token"
9+
# return codes are;
10+
# 0 - success
11+
# 1 - error returned from server
12+
13+
fulldomain="${1}"
14+
token="${2}"
15+
16+
API='https://auth.acme-dns.io/update'
17+
18+
# Check initial parameters
19+
if [[ -z "$fulldomain" ]]; then
20+
echo "DNS script requires full domain name as first parameter"
21+
exit 1
22+
fi
23+
if [[ -z "$token" ]]; then
24+
echo "DNS script requires challenge token as second parameter"
25+
exit 1
26+
fi
27+
28+
curl_params=(
29+
-H "accept: application/json"
30+
-H "X-Api-Key: $apikey"
31+
-H "X-Api-User: $apiuser"
32+
-H 'Content-Type: application/json'
33+
)
34+
35+
generate_post_data()
36+
{
37+
cat <<EOF
38+
{
39+
"subdomain": "$apisubdomain",
40+
"txt": "$token"
41+
}
42+
EOF
43+
}
44+
45+
resp=$(curl --silent \
46+
"${curl_params[@]}" \
47+
-X POST "${API}" \
48+
--data "$(generate_post_data)")
49+
50+
echo $resp
51+
# If adding record failed (returned json includes "error" then print error message
52+
if [[ "$resp" = *"\"error\""* ]]; then
53+
echo "Error: DNS challenge not added: unknown error - ${resp}"
54+
exit 1
55+
fi

dns_scripts/dns_del_cpanel

100644100755
File mode changed.

getssl

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@
276276
# 2021-10-01 Show help if no domain specified (#705)(2.44)
277277
# 2021-10-08 Extract release tag from release api using awk (fix BSD issues)
278278
# 2021-10-11 Fix broken upgrade url (#718)(2.45)
279+
# 2021-10-22 Copy fullchain to DOMAIN_CHAIN_LOCATION (amartin-git)
280+
# 2021-11-10 Detect Solaris and use gnu tools (#701)(miesi)
281+
# 2021-11-12 Support acme-dns and fix CNAME issues (#722)(#308)
279282
# ----------------------------------------------------------------------------------------
280283

281284
case :$SHELLOPTS: in
@@ -536,12 +539,6 @@ check_challenge_completion() { # checks with the ACME server if our challenge is
536539
debug "sleep 5 secs before testing verify again"
537540
sleep 5
538541
done
539-
540-
if [[ "$DEACTIVATE_AUTH" == "true" ]]; then
541-
deactivate_url=$(echo "$responseHeaders" | grep "^Link" | awk -F"[<>]" '{print $2}')
542-
deactivate_url_list="$deactivate_url_list $deactivate_url"
543-
debug "adding url to deactivate list - $deactivate_url"
544-
fi
545542
}
546543

547544
check_challenge_completion_dns() { # perform validation via DNS challenge
@@ -575,10 +572,19 @@ check_challenge_completion_dns() { # perform validation via DNS challenge
575572
# shellcheck disable=SC2086
576573
debug "$DNS_CHECK_FUNC" $DNS_CHECK_OPTIONS TXT "${rr}" "@${ns}"
577574
# shellcheck disable=SC2086
578-
check_result=$($DNS_CHECK_FUNC $DNS_CHECK_OPTIONS TXT "${rr}" "@${ns}" \
579-
| grep -i "^${rr}" \
580-
| grep 'IN\WTXT'|awk -F'"' '{ print $2}')
575+
check_output=$($DNS_CHECK_FUNC $DNS_CHECK_OPTIONS TXT "${rr}" "@${ns}")
576+
check_result=$(grep -i "^${rr}"<<<"${check_output}"|grep 'IN\WTXT'|awk -F'"' '{ print $2}')
581577
debug "check_result=\"$check_result\""
578+
579+
# Check if rr is a CNAME
580+
if [[ -z "$check_result" ]]; then
581+
rr_cname=$(grep -i "^${rr}"<<<"${check_output}"|grep 'IN\WCNAME'|awk '{ print $5}')
582+
debug "cname check=\"$rr_cname\""
583+
if [[ -n "$rr_cname" ]]; then
584+
check_result=$(grep -i "^${rr_cname}"<<<"${check_output}"|grep 'IN\WTXT'|awk -F'"' '{ print $2}' | uniq)
585+
fi
586+
fi
587+
582588
if [[ -z "$check_result" ]]; then
583589
# shellcheck disable=SC2086
584590
debug "$DNS_CHECK_FUNC" $DNS_CHECK_OPTIONS ANY "${rr}" "@${ns}"
@@ -589,14 +595,20 @@ check_challenge_completion_dns() { # perform validation via DNS challenge
589595
debug "check_result=\"$check_result\""
590596
fi
591597
elif [[ "$DNS_CHECK_FUNC" == "host" ]]; then
598+
debug "$DNS_CHECK_FUNC" -t TXT "${rr}" "${ns}"
592599
check_result=$($DNS_CHECK_FUNC -t TXT "${rr}" "${ns}" \
593600
| grep 'descriptive text'|awk -F'"' '{ print $2}')
601+
debug "check_result=\"$check_result\""
594602
else
603+
debug "$DNS_CHECK_FUNC" -type=txt "${rr}" "${ns}"
595604
check_result=$(nslookup -type=txt "${rr}" "${ns}" \
596605
| grep 'text ='|awk -F'"' '{ print $2}')
606+
debug "check_result=\"$check_result\""
597607
if [[ -z "$check_result" ]]; then
608+
debug "$DNS_CHECK_FUNC" -type=any "${rr}" "${ns}"
598609
check_result=$(nslookup -type=any "${rr}" "${ns}" \
599610
| grep 'text ='|awk -F'"' '{ print $2}')
611+
debug "check_result=\"$check_result\""
600612
fi
601613
fi
602614
debug "expecting \"$auth_key\""
@@ -1201,6 +1213,11 @@ create_order() {
12011213
fi
12021214
((dn++))
12031215
done
1216+
if [[ "$DEACTIVATE_AUTH" == "true" ]]; then
1217+
deactivate_url_list+=" $l "
1218+
debug "url added to deactivate list ${l}"
1219+
debug "deactivate list is now $deactivate_url_list"
1220+
fi
12041221
done
12051222
fi
12061223
}
@@ -1352,12 +1369,6 @@ for d in "${alldomains[@]}"; do
13521369

13531370
if [[ $response_status == "valid" ]]; then
13541371
info "$d is already validated"
1355-
if [[ "$DEACTIVATE_AUTH" == "true" ]]; then
1356-
deactivate_url="$(echo "$responseHeaders" | awk ' $1 ~ "^Location" {print $2}' | tr -d "\r")"
1357-
deactivate_url_list+=" $deactivate_url "
1358-
debug "url added to deactivate list ${deactivate_url}"
1359-
debug "deactivate list is now $deactivate_url_list"
1360-
fi
13611372
# increment domain-counter
13621373
((dn++))
13631374
else
@@ -1554,6 +1565,7 @@ get_auth_dns() { # get the authoritative dns server for a domain (sets primary_n
15541565
# domain is a CNAME: resolve it and continue with that
15551566
debug Domain is a CNAME, actual domain is "$cname"
15561567
gad_d=${cname}
1568+
res=
15571569
fi
15581570

15591571
# Use SOA +trace to find the name server
@@ -1629,6 +1641,7 @@ get_auth_dns() { # get the authoritative dns server for a domain (sets primary_n
16291641
primary_ns="$primary_ns $PUBLIC_DNS_SERVER"
16301642
fi
16311643

1644+
debug set primary_ns="$primary_ns"
16321645
return
16331646
fi
16341647
fi
@@ -1639,26 +1652,48 @@ get_auth_dns() { # get the authoritative dns server for a domain (sets primary_n
16391652
# shellcheck disable=SC2086
16401653
res=$(nslookup $DNS_CHECK_OPTIONS -debug -type=soa -type=ns "$gad_d" ${gad_s})
16411654

1655+
# check for CNAME (assumes gad_d is _acme-challenge.{host})
1656+
if [[ "$(grep -c "NXDOMAIN"<<<"$res")" -gt 0 ]]; then
1657+
debug "Cannot find nameserver record for $gad_d, using parent domain ${gad_d#*.}"
1658+
gad_d="${gad_d#*.}"
1659+
debug "nslookup $DNS_CHECK_OPTIONS -debug -type=soa -type=ns $gad_d ${gad_s}"
1660+
# shellcheck disable=SC2086
1661+
res=$(nslookup $DNS_CHECK_OPTIONS -debug -type=soa -type=ns "$gad_d" ${gad_s})
1662+
fi
1663+
16421664
if [[ "$(echo "$res" | grep -c "Non-authoritative")" -gt 0 ]]; then
16431665
# this is a Non-authoritative server, need to check for an authoritative one.
1666+
debug "Response from non-authoritative server looking for authoritative server"
1667+
16441668
gad_s=$(echo "$res" | awk '$2 ~ "nameserver" {print $4; exit }' |sed 's/\.$//g')
1645-
if [[ "$(echo "$res" | grep -c "an't find")" -gt 0 ]]; then
1669+
# If the previous line fails to find the nameserver, use the original
1670+
if [[ -z "$gad_s" ]]; then
1671+
gad_s="$orig_gad_s"
1672+
fi
1673+
1674+
if [[ "$(echo "$res" | grep -c "canonical name")" -gt 0 ]]; then
1675+
debug "$gad_d" appears to be a CNAME
1676+
gad_d=$(echo "$res" | awk ' $2 ~ "canonical" {print $5; exit }' |sed 's/\.$//g')
1677+
debug "Using $gad_d instead"
1678+
elif [[ "$(echo "$res" | grep -c "an't find")" -gt 0 ]]; then
16461679
# if domain name doesn't exist, then find auth servers for next level up
1680+
debug "Couldn't find NS or SOA for domain name, using nslookup $DNS_CHECK_OPTIONS -debug ${gad_d#*.} ${orig_gad_s}"
1681+
# shellcheck disable=SC2086
1682+
res=$(nslookup $DNS_CHECK_OPTIONS -debug "${gad_d#*.}" ${orig_gad_s})
16471683
gad_s=$(echo "$res" | awk '$1 ~ "origin" {print $3; exit }')
16481684
gad_d=$(echo "$res" | awk '$1 ~ "->" {print $2; exit}')
16491685
# handle scenario where awk returns nothing
16501686
if [[ -z "$gad_d" ]]; then
1651-
gad_d="$orig_gad_d"
1687+
gad_d="${orig_gad_d}"
16521688
fi
16531689
fi
16541690

1691+
debug "Using nslookup $DNS_CHECK_OPTIONS -debug -type=soa -type=ns $gad_d ${gad_s}"
16551692
# shellcheck disable=SC2086
16561693
res=$(nslookup $DNS_CHECK_OPTIONS -debug -type=soa -type=ns "$gad_d" ${gad_s})
16571694
fi
16581695

1659-
if [[ "$(echo "$res" | grep -c "canonical name")" -gt 0 ]]; then
1660-
gad_d=$(echo "$res" | awk ' $2 ~ "canonical" {print $5; exit }' |sed 's/\.$//g')
1661-
elif [[ "$(echo "$res" | grep -c "an't find")" -gt 0 ]]; then
1696+
if [[ "$(echo "$res" | grep -c "an't find")" -gt 0 ]]; then
16621697
gad_s=$(echo "$res" | awk ' $1 ~ "origin" {print $3; exit }')
16631698
gad_d=$(echo "$res"| awk '$1 ~ "->" {print $2; exit}')
16641699
# handle scenario where awk returns nothing
@@ -1680,6 +1715,11 @@ get_auth_dns() { # get the authoritative dns server for a domain (sets primary_n
16801715
primary_ns=$(echo "$all_auth_dns_servers" | awk '{print $1}')
16811716
fi
16821717

1718+
if [[ "$CHECK_PUBLIC_DNS_SERVER" == "true" ]]; then
1719+
primary_ns="$primary_ns $PUBLIC_DNS_SERVER"
1720+
fi
1721+
1722+
debug set primary_ns="$primary_ns"
16831723
return
16841724
fi
16851725
fi

test/2-simple-dns01-nslookup.bats

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ setup() {
1414
if [ -f /usr/bin/dig ]; then
1515
mv /usr/bin/dig /usr/bin/dig.getssl.bak
1616
fi
17+
if [ -f /usr/bin/drill ]; then
18+
mv /usr/bin/drill /usr/bin/drill.getssl.bak
19+
fi
1720
if [ -f /usr/bin/host ]; then
1821
mv /usr/bin/host /usr/bin/host.getssl.bak
1922
fi
@@ -25,6 +28,9 @@ teardown() {
2528
if [ -f /usr/bin/dig.getssl.bak ]; then
2629
mv /usr/bin/dig.getssl.bak /usr/bin/dig
2730
fi
31+
if [ -f /usr/bin/drill.getssl.bak ]; then
32+
mv /usr/bin/drill.getssl.bak /usr/bin/drill
33+
fi
2834
if [ -f /usr/bin/host.getssl.bak ]; then
2935
mv /usr/bin/host.getssl.bak /usr/bin/host
3036
fi

test/32-test-upgrade.bats

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ check_github_quota() {
3838

3939

4040
setup_file() {
41+
if [ -n "$STAGING" ]; then
42+
echo "Using staging server, skipping internal test" >&3
43+
return 0
44+
fi
4145
if [ -f $BATS_RUN_TMPDIR/failed.skip ]; then
4246
echo "# Skipping setup due to previous test failure" >&3
4347
return 0

0 commit comments

Comments
 (0)