Obtains certificates from Let's Encrypt, using Lexicon to answer DNS-based challenges
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hook.sh 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/usr/bin/env bash
  2. #
  3. # Example how to deploy a DNS challange using lexicon
  4. set -e
  5. set -u
  6. set -o pipefail
  7. export PROVIDER=${PROVIDER:-"cloudflare"}
  8. function deploy_challenge {
  9. local DOMAIN="${1}" TOKEN_FILENAME="${2}" TOKEN_VALUE="${3}"
  10. echo "deploy_challenge called: ${DOMAIN}, ${TOKEN_FILENAME}, ${TOKEN_VALUE}"
  11. lexicon $PROVIDER create ${DOMAIN} TXT --name="_acme-challenge.${DOMAIN}." --content="${TOKEN_VALUE}"
  12. sleep 30
  13. # This hook is called once for every domain that needs to be
  14. # validated, including any alternative names you may have listed.
  15. #
  16. # Parameters:
  17. # - DOMAIN
  18. # The domain name (CN or subject alternative name) being
  19. # validated.
  20. # - TOKEN_FILENAME
  21. # The name of the file containing the token to be served for HTTP
  22. # validation. Should be served by your web server as
  23. # /.well-known/acme-challenge/${TOKEN_FILENAME}.
  24. # - TOKEN_VALUE
  25. # The token value that needs to be served for validation. For DNS
  26. # validation, this is what you want to put in the _acme-challenge
  27. # TXT record. For HTTP validation it is the value that is expected
  28. # be found in the $TOKEN_FILENAME file.
  29. }
  30. function clean_challenge {
  31. local DOMAIN="${1}" TOKEN_FILENAME="${2}" TOKEN_VALUE="${3}"
  32. echo "clean_challenge called: ${DOMAIN}, ${TOKEN_FILENAME}, ${TOKEN_VALUE}"
  33. lexicon $PROVIDER delete ${DOMAIN} TXT --name="_acme-challenge.${DOMAIN}." --content="${TOKEN_VALUE}"
  34. # This hook is called after attempting to validate each domain,
  35. # whether or not validation was successful. Here you can delete
  36. # files or DNS records that are no longer needed.
  37. #
  38. # The parameters are the same as for deploy_challenge.
  39. }
  40. function invalid_challenge() {
  41. local DOMAIN="${1}" RESPONSE="${2}"
  42. echo "invalid_challenge called: ${DOMAIN}, ${RESPONSE}"
  43. # This hook is called if the challenge response has failed, so domain
  44. # owners can be aware and act accordingly.
  45. #
  46. # Parameters:
  47. # - DOMAIN
  48. # The primary domain name, i.e. the certificate common
  49. # name (CN).
  50. # - RESPONSE
  51. # The response that the verification server returned
  52. }
  53. function deploy_cert {
  54. local DOMAIN="${1}" KEYFILE="${2}" CERTFILE="${3}" FULLCHAINFILE="${4}" CHAINFILE="${5}"
  55. echo "deploy_cert called: ${DOMAIN}, ${KEYFILE}, ${CERTFILE}, ${FULLCHAINFILE}, ${CHAINFILE}"
  56. # This hook is called once for each certificate that has been
  57. # produced. Here you might, for instance, copy your new certificates
  58. # to service-specific locations and reload the service.
  59. #
  60. # Parameters:
  61. # - DOMAIN
  62. # The primary domain name, i.e. the certificate common
  63. # name (CN).
  64. # - KEYFILE
  65. # The path of the file containing the private key.
  66. # - CERTFILE
  67. # The path of the file containing the signed certificate.
  68. # - FULLCHAINFILE
  69. # The path of the file containing the full certificate chain.
  70. # - CHAINFILE
  71. # The path of the file containing the intermediate certificate(s).
  72. }
  73. function unchanged_cert {
  74. local DOMAIN="${1}" KEYFILE="${2}" CERTFILE="${3}" FULLCHAINFILE="${4}" CHAINFILE="${5}"
  75. echo "unchanged_cert called: ${DOMAIN}, ${KEYFILE}, ${CERTFILE}, ${FULLCHAINFILE}, ${CHAINFILE}"
  76. # This hook is called once for each certificate that is still
  77. # valid and therefore wasn't reissued.
  78. #
  79. # Parameters:
  80. # - DOMAIN
  81. # The primary domain name, i.e. the certificate common
  82. # name (CN).
  83. # - KEYFILE
  84. # The path of the file containing the private key.
  85. # - CERTFILE
  86. # The path of the file containing the signed certificate.
  87. # - FULLCHAINFILE
  88. # The path of the file containing the full certificate chain.
  89. # - CHAINFILE
  90. # The path of the file containing the intermediate certificate(s).
  91. }
  92. exit_hook() {
  93. # This hook is called at the end of a dehydrated command and can be used
  94. # to do some final (cleanup or other) tasks.
  95. :
  96. }
  97. startup_hook() {
  98. # This hook is called before the dehydrated command to do some initial tasks
  99. # (e.g. starting a webserver).
  100. :
  101. }
  102. HANDLER=$1; shift; $HANDLER "$@"