You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
knsupdate doesn't accept values from the command line and need to read from files. I modified dns.hook in the following matter. This seems to work. There are probably more secure ways of implementing this though. If there is interest, I am happy to invest more time in implementing this properly with feedback and some mentorship
#!/bin/bash# This is an example DNS hook script which uses the knsupdate utility to update# nameservers. The script waits until updates have propagated to all# nameservers listed for a zone. The script fails if this takes more than 60# seconds by default; this timeout can be adjusted.## The script is ready to use, but to use it you must create# /etc/default/acme-dns or /etc/conf.d/acme-dns and set the following options:## # Needed if using TKIP for updates. If authenticating updates by source IP,# # not necessary.# TKIP_KEY_NAME="hmac-sha256:tk1"# TKIP_KEY="a base64-encoded TKIP key"## # DNS synchronization timeout in seconds. Default is 60.# DNS_SYNC_TIMEOUT=60## # Optional: inject extra arguments and commands to nsupdate.# NSUPDATE_ARGS="-v"# nsupdate_cmds() {# # Usually not necessary:# echo zone example.com.# }## Having done this, rename it to /usr/lib[exec]/acme/hooks/dns.## How to test this script:# ./dns.hook challenge-dns-start example.com "" "foobar"# ./dns.hook challenge-dns-stop example.com "" "foobar"#set -e
KNSUPDATECMDS="knsupdate_cmds.txt"get_apex() {
local name="$1"if [ -z"$name" ];thenecho"$0: couldn't get apex for $name">&2return 1
fiif [ "`dig +noall +answer SOA "${name}."|grep SOA|wc -l`"=="1" ];then
APEX="$name"returnfilocal sname="$(echo $name| sed 's/^[^.]\+\.//')"
get_apex "$sname"
}
waitns() {
local ns="$1"forctrin$(seq 1 "$DNS_SYNC_TIMEOUT");do
[ "$(dig +short "@${ns}" TXT "_acme-challenge.${CH_HOSTNAME}."| grep "$CH_TXT_VALUE"| wc -l)"=="1" ] &&return 0
sleep 1
done# Best effort cleanup.echo$0: timed out waiting ${DNS_SYNC_TIMEOUT}s for nameserver $ns>&2
updns del ||echo$0: failed to clean up records after timing out >&2return 1
}
updns() {
local op="$1"
touch $KNSUPDATECMDS
(
declare -f knsupdate_cmds >/dev/null && knsupdate_cmds
[ -n"$TKIP_KEY" ] &&echo key "$TKIP_KEY_NAME""$TKIP_KEY">>$KNSUPDATECMDSecho"zone ${CH_HOSTNAME}.">>$KNSUPDATECMDSecho$op"_acme-challenge.${CH_HOSTNAME}." 60 IN TXT "\"${CH_TXT_VALUE}\"">>$KNSUPDATECMDSecho"send">>$KNSUPDATECMDSecho"quit">>$KNSUPDATECMDS
) | knsupdate $KNSUPDATECMDS
rm $KNSUPDATECMDS
}
[ -e"/etc/default/acme-dns" ] &&. /etc/default/acme-dns
[ -e"/etc/conf.d/acme-dns" ] &&. /etc/conf.d/acme-dns
# e.g.# TKIP_KEY_NAME="hmac-sha256:tk1"# TKIP_KEY="base64-key-value"
EVENT_NAME="$1"
CH_HOSTNAME="$2"
CH_TARGET_FILENAME="$3"
CH_TXT_VALUE="$4"
[ -z"$DNS_SYNC_TIMEOUT" ] && DNS_SYNC_TIMEOUT=60
case"$EVENT_NAME"in
challenge-dns-start)
get_apex "$CH_HOSTNAME"
updns add
# Wait for all nameservers to update.fornsin$(dig +short NS "${APEX}.");do
waitns "$ns"done
;;
challenge-dns-stop)
get_apex "$CH_HOSTNAME"
updns del
;;
*)
exit 42
;;
esac
The text was updated successfully, but these errors were encountered:
knsupdate doesn't accept values from the command line and need to read from files. I modified dns.hook in the following matter. This seems to work. There are probably more secure ways of implementing this though. If there is interest, I am happy to invest more time in implementing this properly with feedback and some mentorship
The text was updated successfully, but these errors were encountered: