Skip to content

Instantly share code, notes, and snippets.

@prashant-shahi
Forked from gaoyifan/certbot-auth-hook.sh
Created August 2, 2023 20:04
Show Gist options
  • Select an option

  • Save prashant-shahi/1ee4d7dfe436bc3cd6867a61254b4e11 to your computer and use it in GitHub Desktop.

Select an option

Save prashant-shahi/1ee4d7dfe436bc3cd6867a61254b4e11 to your computer and use it in GitHub Desktop.

Revisions

  1. @gaoyifan gaoyifan revised this gist Jul 13, 2018. 2 changed files with 6 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions certbot-auth-hook.sh
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,12 @@
    #!/usr/bin/env bash

    # require: git version > 2.3
    # require: `db/letsencrypt` existed in git repo

    if [[ -z "$CERTBOT_DOMAIN" ]] || [[ -z "$CERTBOT_VALIDATION" ]]; then
    echo '$CERTBOT_DOMAIN and $CERTBOT_VALIDATION environment variables required.'
    fi

    # DNSAUTH_SSH_KEY
    # DNSAUTH_GIT_UPSTREAM
    # DNSAUTH_GIT_PATH
    source /etc/letsencrypt/dns-auth.conf

    BIND_DB=${BIND_DB:-"db/letsencrypt"}
    3 changes: 3 additions & 0 deletions dns-auth.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    DNSAUTH_SSH_KEY=/etc/letsencrypt/dnsauth-key
    [email protected]:xxx/xxx.git
    DNSAUTH_GIT_PATH=/etc/letsencrypt/dnsauth-repo
  2. @gaoyifan gaoyifan created this gist Jul 13, 2018.
    38 changes: 38 additions & 0 deletions certbot-auth-hook.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    #!/usr/bin/env bash

    if [[ -z "$CERTBOT_DOMAIN" ]] || [[ -z "$CERTBOT_VALIDATION" ]]; then
    echo '$CERTBOT_DOMAIN and $CERTBOT_VALIDATION environment variables required.'
    fi

    # DNSAUTH_SSH_KEY
    # DNSAUTH_GIT_UPSTREAM
    # DNSAUTH_GIT_PATH
    source /etc/letsencrypt/dns-auth.conf

    BIND_DB=${BIND_DB:-"db/letsencrypt"}

    export GIT_SSH_COMMAND="ssh -i $DNSAUTH_SSH_KEY -o StrictHostKeyChecking=no"

    if [[ ! -d $DNSAUTH_GIT_PATH ]]; then
    git clone $DNSAUTH_GIT_UPSTREAM $DNSAUTH_GIT_PATH
    fi

    cd $DNSAUTH_GIT_PATH

    git fetch --prune origin master
    git reset --hard origin/master

    if [[ -z $CERTBOT_AUTH_OUTPUT ]]; then
    echo "_acme-challenge.${CERTBOT_DOMAIN}. 60 IN TXT \"${CERTBOT_VALIDATION}\"" >> $BIND_DB
    git add $BIND_DB
    git commit -m "Add _acme-challenge.$CERTBOT_DOMAIN"
    git push origin master || exit 1
    sleep 25
    else
    sed -i "/${CERTBOT_DOMAIN}/d" $BIND_DB
    git add $BIND_DB
    git commit -m "Drop _acme-challenge.$CERTBOT_DOMAIN"
    git push origin master || exit 1
    fi


    10 changes: 10 additions & 0 deletions cmd
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    certbot certonly \
    --server https://acme-v02.api.letsencrypt.org/directory \
    --preferred-challenges dns \
    --email [email protected] \
    --manual \
    --manual-auth-hook /etc/letsencrypt/certbot-auth-hook.sh \
    --manual-cleanup-hook /etc/letsencrypt/certbot-auth-hook.sh \
    --manual-public-ip-logging-ok \
    --domain example.com \
    --domain '*.example.com'