Skip to content

Instantly share code, notes, and snippets.

@colindekker
Created August 12, 2019 22:34
Show Gist options
  • Save colindekker/20d00ddbc08bca34b6b30da191d0c60a to your computer and use it in GitHub Desktop.
Save colindekker/20d00ddbc08bca34b6b30da191d0c60a to your computer and use it in GitHub Desktop.
CertBot manual auth hook for Azure DNS using Azure CLI
#!/bin/bash
# The hook supports 2 actions, 'create' and 'delete', passed as the first argument.
# When 'create' is passed in, a validation TXT record is added,
# 'delete' cleans up that record after validation
ACTION=$1
# The second the name of the Azure Account that contains the DNS Zone Resource
AZ_ACCOUNT=$2
echo $AZ_ACCOUNT
# set the name of the Azure Resource Group that contains the DNS Zone Resource
AZ_GROUP=$3
echo $AZ_GROUP
# the name of the DNS Zone in Azure
AZ_ZONE=$4
echo $AZ_ZONE
AZ_DOMAIN=$CERTBOT_DOMAIN
AZ_RECORD_SET_VALUE=$CERTBOT_VALIDATION
# handle requestts for wildcard DNS entry,
if [ ${AZ_DOMAIN:0:2} == "*." ]; then AZ_DOMAIN=${AZ_DOMAIN:2}; fi
AZ_RECORD_SET="_acme-challenge.${AZ_DOMAIN:0:(($(echo -n $AZ_DOMAIN | wc -m)-$(echo -n $AZ_ZONE | wc -m)-1))}"
if [ "$ACTION" == "create" ]; then
az network dns record-set txt add-record -g "${AZ_GROUP}" -z "${AZ_ZONE}" --record-set-name "${AZ_RECORD_SET}" -v="${AZ_RECORD_SET_VALUE}"
sleep 30;
fi
if [ "$ACTION" == "delete" ]; then
az network dns record-set txt delete -g "${AZ_GROUP}" -z "${AZ_ZONE}" -n "${AZ_RECORD_SET}";
fi
@4ndrej
Copy link

4ndrej commented Sep 9, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment