Forked from colindekker/certbot-authhook-az-cli-annotated.sh
Created
September 1, 2020 23:28
-
-
Save 4ndrej/8e35cc5997aaf487400c34c311e54710 to your computer and use it in GitHub Desktop.
CertBot manual auth hook for Azure DNS using Azure CLI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment