Coder Social home page Coder Social logo

infinityofspace / certbot_dns_porkbun Goto Github PK

View Code? Open in Web Editor NEW
52.0 3.0 5.0 124 KB

Plugin for certbot to obtain certificates using a DNS TXT record for Porkbun domains

License: MIT License

Python 78.62% Dockerfile 10.60% Shell 10.78%
certbot certbot-dns-plugin porkbun dns-01-challange

certbot_dns_porkbun's Introduction

Certbot DNS Porkbun Plugin

Plugin for certbot to obtain certificates using a DNS TXT record for Porkbun domains


PyPI - Python Version GitHub

PyPI PyPI - Downloads GitHub Workflow Status

Docker Image Version (latest semver) Docker Pulls Docker Image Size (tag) GitHub Workflow Status

certbot-dns-porkbun


Table of Contents

  1. About
  2. Installation
    1. Prerequirements
    2. With pip (recommend)
    3. From source
    4. Snap
  3. Usage
    1. Local installation
    2. Credentials file or cli parameters
    3. Docker
  4. FAQ
  5. Third party notices
  6. License

About

certbot_dns_porkbun is a plugin for certbot. It handles the TXT record for the DNS-01 challenge for Porkbun domains. The plugin takes care of the creation and deletion of the TXT record using the Porkbun API.

Installation

Prerequirements

If you want to use the docker image, then you don't need any requirements other than a working docker installation and can proceed directly with the usage

You need at least version 3.7 of Python installed. If you want to install the plugin with pip, then you must also have pip installed beforehand.

If you already have certbot installed, make sure you have at least version 1.18.0 installed. When you installed certbot as snap then you have to use the snap installation of the plugin.

You can check what version of certbot is installed with this command:

certbot --version

If you don't have certbot installed yet, then the PyPI version of certbot will be installed automatically during the installation.

Note: If you want to run certbot with root privileges, then you need to install the plugin as root too. Otherwise, certbot cannot find the plugin.

With pip (recommend)

Use the following command to install certbot_dns_porkbun with pip:

pip3 install certbot_dns_porkbun

You can also very easily update to the newest version:

pip3 install certbot_dns_porkbun -U

From source

If you prefer to install the plugin from the source code:

git clone https://github.com/infinityofspace/certbot_dns_porkbun.git
cd certbot_dns_porkbun
pip3 install .

Snap

If you use the certbot as snap package then you have to install certbot_dns_porkbun as a snap too:

snap install certbot-dns-porkbun

Now connect the certbot snap installation with the plugin snap installation:

sudo snap connect certbot:plugin certbot-dns-porkbun

The following command should now list dns-porkbun as an installed plugin:

certbot plugins

Usage

Note: By default, Porkbun domains cannot be controlled through the API. This will cause an error when you generate certificates. Ensure that you have enabled API Access in your domain's settings to avoid this. If you haven't already, be sure to also delete the (default) parked domain ALIAS records, as not doing so may cause errors.

Local installation

To check if the plugin is installed and detected properly by certbot, you can use the following command:

certbot plugins

The resulting list should include dns-porkbun if everything went fine.

Credentials file or cli parameters

You can either use cli parameters to pass authentication information to certbot:

...
--dns-porkbun-key <your-porkbun-api-key> \
--dns-porkbun-secret <your-porkbun-api-secret>

Or to prevent your credentials from showing up in your bash history, you can also create a credentials-file porkbun.ini (the name does not matter) with the following content:

dns_porkbun_key=<your-porkbun-api-key>
dns_porkbun_secret=<your-porkbun-api-secret>

And then instead of using the --dns-porkbun-key and --dns-porkbun-secret parameters above you can use

...
--dns-porkbun-credentials </path/to/your/porkbun.ini>

You can also mix these usages, though the cli parameters always take precedence over the ini file.

Examples

Below are some examples of how to use the plugin.


Generate a certificate with a DNS-01 challenge for the domain example.org:

certbot certonly \
  --non-interactive \
  --agree-tos \
  --email <your-email-address> \
  --preferred-challenges dns \
  --authenticator dns-porkbun \
  --dns-porkbun-key <your-porkbun-api-key> \
  --dns-porkbun-secret <your-porkbun-api-secret> \
  --dns-porkbun-propagation-seconds 60 \
  -d "example.com"

Generate a wildcard certificate with a DNS-01 challenge for all subdomains *.example.com (Note: the wildcard certificate does not contain the root domain itself):

certbot certonly \
  --non-interactive \
  --agree-tos \
  --email <your-email-address> \
  --preferred-challenges dns \
  --authenticator dns-porkbun \
  --dns-porkbun-key <your-porkbun-api-key> \
  --dns-porkbun-secret <your-porkbun-api-secret> \
  --dns-porkbun-propagation-seconds 60 \
  -d "*.example.com"

Generate a certificate with a DNS-01 challenge for the domain example.org using a credentials ini file:

certbot certonly \
  --non-interactive \
  --agree-tos \
  --email <your-email-address> \
  --preferred-challenges dns \
  --authenticator dns-porkbun \
  --dns-porkbun-credentials </path/to/your/porkbun.ini> \
  --dns-porkbun-propagation-seconds 60 \
  -d "example.com"

Generate a certificate with a DNS-01 challenge for the domain example.com without an account (i.e. without an email address):

certbot certonly \
  --non-interactive \
  --agree-tos \
  --register-unsafely-without-email \
  --preferred-challenges dns \
  --authenticator dns-porkbun \
  --dns-porkbun-key <your-porkbun-api-key> \
  --dns-porkbun-secret <your-porkbun-api-secret> \
  --dns-porkbun-propagation-seconds 60 \
  -d "example.com"

Generate a staging certificate (i.e. temporary testing certificate) with a DNS-01 challenge for the domain example.com:

certbot certonly \
  --non-interactive \
  --agree-tos \
  --email <your-email-address> \
  --preferred-challenges dns \
  --authenticator dns-porkbun \
  --dns-porkbun-key <your-porkbun-api-key> \
  --dns-porkbun-secret <your-porkbun-api-secret> \
  --dns-porkbun-propagation-seconds 60 \
  -d "example.com" \
  --staging

The DNS-01 challenge specification allows to forward the challenge to another domain by CNAME entries and thus to perform the validation from another domain.

For example, we have the domain example.com and mydomain.com. The nameservers of example.com domain are the
Porkbun nameserver and mydomain.com is somewhere else. In order to perform a DNS-01 challenge for the domain mydomain.com, we only need to add this _acme-challenge.mydomain.com to _acme-challenge.example.com CNAME entry in advance:

_acme-challenge.mydomain.com. 600 IN CNAME _acme-challenge.example.com.

Then we can use our Porkbun domain for the actual DNS-01 challenge. The procedure is identical as if we perform a DNS-01 challenge for a Porkbun domain, except that the domain name for which we perform the challenge is now mydomain.com instead of Porkbun's example.com.

certbot certonly \
  --non-interactive \
  --agree-tos \
  --email <your-email-address> \
  --preferred-challenges dns \
  --authenticator dns-porkbun \
  --dns-porkbun-key <your-porkbun-api-key> \
  --dns-porkbun-secret <your-porkbun-api-secret> \
  --dns-porkbun-propagation-seconds 60 \
  -d "mydomain.com"

What happens in the background is that the CNAME entry is followed to the end and then a TXT entry is created with the form _acme-challenge.example.com. for the found example.com Prokbun domain. Thus, during the challenge of this example, the DNS would look like this:

_acme-challenge.mydomain.com. 600 IN CNAME _acme-challenge.example.com.
_acme-challenge.example.com. 60 TXT "a8sdhb09a7sbd08ashd90ashd90a8hsa9usd"

You can find al list of all available certbot cli options in the official documentation of certbot.

Docker

You can simply start a new container and use the same certbot commands to obtain a new certificate:

docker run -v "/etc/letsencrypt:/etc/letsencrypt" -v "/var/log/letsencrypt:/var/log/letsencrypt" infinityofspace/certbot_dns_porkbun:latest \
   certonly \
     --non-interactive \
     --agree-tos \
     --email <your-email-address> \
     --preferred-challenges dns \
     --authenticator dns-porkbun \
     --dns-porkbun-key <your-porkbun-api-key> \
     --dns-porkbun-secret <your-porkbun-api-secret> \
     --dns-porkbun-propagation-seconds 60 \
     -d "example.com"

Or you can use a credentials file:

docker run -v "/etc/letsencrypt:/etc/letsencrypt" -v "/var/log/letsencrypt:/var/log/letsencrypt" -v "/absolute/path/to/your/porkbun.ini:/conf/porkbun.ini" infinityofspace/certbot_dns_porkbun:latest \
   certonly \
     --non-interactive \
     --agree-tos \
     --email <your-email-address> \
     --preferred-challenges dns \
     --authenticator dns-porkbun \
     --dns-porkbun-credentials /conf/porkbun.ini \
     --dns-porkbun-propagation-seconds 60 \
     -d "example.com"

Third party notices

All modules used by this project are listed below:

Name License
certbot Apache 2.0
setuptools MIT
pkb_client MIT
dnspython ISC

Furthermore, this readme file contains embeddings of Shields.io.

License

MIT - Copyright (c) Marvin Heptner

certbot_dns_porkbun's People

Contributors

alexzorin avatar chaptergy avatar dependabot[bot] avatar indexofnull avatar infinityofspace avatar nemchik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

certbot_dns_porkbun's Issues

Release that supports certbot 2.x?

This is not a bug report.

I notice the master branch has updated dependencies in requirements.txt to support newer versions of certbot. The latest release available is locked at certbot>=1.18.0,<2.0

Is there any way a new release that supports certbot 2.x could be pushed?

PluginEntryPoint#dns-porkbun does not provide IPluginFactory, skipping

Describe the bug
I am unable to use dns-porkbun as an authenticator due to the error in the title

PluginEntryPoint#dns-porkbun does not provide IPluginFactory, skipping
PluginEntryPoint#certbot-dns-porkbun:dns-porkbun does not provide IPluginFactory, skipping

To Reproduce

  1. Get a machine with debian 11 installed (preferably fresh)
  2. Install Certbot nala install certbot (or apt but nala is better imo)
  3. Install the certbot plugin pip3 install certbot_dns_porkbun
  4. Run the Certbot command detailed below

Expected behavior
When I run the command it should add a dns record, have certbot validate it, delete it and give me the certs.

Certbot command
certbot certonly --non-interactive --agree-tos --email **********@******.com --preferred-challenges dns --authenticator dns-porkbun --dns-porkbun-credentials /path/to/credentials/domain.extension.ini --dns-porkbun-propagation-seconds 60 -d "domain.extension" -d "*.domain.extension"

Versions (please complete the following version information):

  • certbot: 1.12.0
  • certbot_dns_porkbun: 0.5.1

Error message

PluginEntryPoint#dns-porkbun does not provide IPluginFactory, skipping
PluginEntryPoint#certbot-dns-porkbun:dns-porkbun does not provide IPluginFactory, skipping
PluginEntryPoint#dns-porkbun does not provide IPluginFactory, skipping
PluginEntryPoint#certbot-dns-porkbun:dns-porkbun does not provide IPluginFactory, skipping
usage: 
  certbot [SUBCOMMAND] [options] [-d DOMAIN] [-d DOMAIN] ...

Certbot can obtain and install HTTPS/TLS/SSL certificates.  By default,
it will attempt to use a webserver both for obtaining and installing the
certificate. 
certbot: error: unrecognized arguments: --dns-porkbun-credentials /path/to/credentials/domain.extension.ini --dns-porkbun-propagation-seconds 60

Additional context
Add any other context about the problem here.

Unable to issue / renew cert anymore

I'm hoping this isn't a "me" problem but no matter what I do I am unable to get wildcard to work via porkbun dns / certbot.

It did work but not I get the error:

2021-05-23 14:24:23,496:DEBUG:urllib3.connectionpool:https://porkbun.com:443 "POST /api/json/v3/dns/create/co.uk HTTP/1.1" 400 None
2021-05-23 14:24:23,499:DEBUG:certbot._internal.error_handler:Encountered exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/dist-packages/certbot_dns_porkbun/cert/client.py", line 87, in _perform
self.record_ids[validation] = self._get_porkbun_client().dns_create(root_domain, "TXT", validation,
File "/usr/local/lib/python3.9/dist-packages/pkb_client/client.py", line 115, in dns_create
raise Exception("ERROR: DNS create api call was not successfully\n"
Exception: ERROR: DNS create api call was not successfully
Status code: 400
Message: Invalid domain.

I have checked and checked but I can not work out what's wrong.

TXT records have TTL of 600 although the min value is 300

A new TXT record have always the TTL of 600 instead of the min allowed 300. So any quick retries might fail if the old TXT is still not fully deleted on the propagated DNS servers. We should always use the shortest TTL for the TXT record to allow quicker cert generation and retires.

Unable to renew certificate

Describe the bug
API calls fail with status 400 and message Invalid domain

To Reproduce

certbot certonly -d '*.domain, domain'

Expected behavior
Complete DNS challenge and renew certificates.

Versions (please complete the following version information):

  • certbot: 1.29.0
  • certbot_dns_porkbun: 0.6

Error message

Encountered exception during recovery: KeyError: 'loooong key'
ERROR: DNS create api call was not successfully
Status code: 400
Message: Invalid domain.

Delete DNS Api Failed

Describe the bug
The acme_challenge records do not get removed once validated.

To Reproduce
Unknown... I have both wildcard and root domains on 1 line with extra -d options????

Expected behavior
The porkbun api doesn't seem to be cleanly handling the delete dns records... unsure why

Certbot command
Docker Compose File

services:
  porkbun-root:
   image: infinityofspace/certbot_dns_porkbun
   platform: linux/arm64/v8
   hostname: cerbot-porkbun-root
   restart: unless-stopped
   volumes:
     - "/storage/docker/certbot/etc/letsencrypt:/etc/letsencrypt"
     - "/storage/docker/certbot/var/lib/letsencrypt:/var/lib/letsencrypt"
     - "/storage/docker/temp-root:/var/log"
     - "/storage/docker/certbot/porkbun/credentials.json:/tmp/credentials.json"
   command: certonly -v --non-interactive --agree-tos --email [email protected] --preferred-challenges dns --authenticator dns-porkbun  --dns-porkbun-credentials /tmp/credentials.json --dns-porkbun-propagation-seconds 600 -d root.xyz -d root.ca -d root.dev -d root.download -d "*.root.xyz"  -d "*.root.ca" -d "*.root.dev" -d "*.root.download"

Versions (please complete the following version information):

  • certbot: 2.4.0
  • certbot_dns_porkbun: docker: infinityofspace/certbot_dns_porkbun:latest Platform linux/arm64/v8 ``(sha256:9a65965e4a72d37cf2c99740291e46a579f4b91f1b31188b93f2e94354883a2c)

Error message

2024-03-30 21:59:56,369:DEBUG:certbot._internal.error_handler:Encountered signals: [15]
2024-03-30 21:59:56,370:DEBUG:certbot._internal.error_handler:Calling registered functions
2024-03-30 21:59:56,370:INFO:certbot._internal.auth_handler:Cleaning up challenges
2024-03-30 21:59:56,976:ERROR:certbot._internal.error_handler:Encountered exception during recovery: certbot.errors.PluginError: ERROR: DNS delete api call was not successfully
2024-03-30 21:59:56,977:DEBUG:certbot._internal.error_handler:Calling signal 15
2024-03-30 21:59:56,977:DEBUG:certbot._internal.log:Exiting abnormally:
2024-03-30 21:59:56,981:ERROR:certbot._internal.log:An unexpected error occurred while handling the authorizations.

Additional context
I have 8 domains using the san feature, 4 of which are the root domains, and 4 are wildcards for the subdomains

DNS CNAME Delegation Bug

Describe the bug
When you try to renew a domain name, it fails due to commit 6003a6f which added DNS challenge delegation. This happens because the function expects there to be one and if there isn't, it throws a plugin error and causes the challenge to fail as it either never makes the txt challenge record or it causes the propogation time to be reduced to 0 (as the dns challenge after the error immediately checks for the record and fails).

To Reproduce

  1. Install certbot 1.12.0(-2) (Version 1.12.0 is the version I have installed, I use debian so the exact version for debian is 1.12.0-2)
  2. Install certbot_dns_porkbun via pip by following https://pypi.org/project/certbot-dns-porkbun/
  3. Run this command with the relevant information substituted
    certbot --authenticator=dns-porkbun --dns-porkbun-credentials /path/to/porkbun/dns/api/credentials.ini -d domain.test -d "*.domain.test"

Expected behavior
If the plugin can not find any acme-challenge delegate dns records, don't raise an exception and just let it continue and make a record for the domain you supplied
The command should work, renew the certificate, create the txt record, wait for propogation seconds then check for the record, then you get the cert

Certbot command
certbot --authenticator=dns-porkbun --dns-porkbun-credentials /path/to/porkbun/dns/api/credentials.ini -d domain.test -d "*.domain.test"

Versions (please complete the following version information):

  • certbot: 1.12.0
  • certbot_dns_porkbun: 0.3

Error message
dns.resolver.NXDOMAIN: The DNS query name does not exist: _acme-challenge.domain.test.

Fix
I was able to fix this by replacing line 123 with
return resolver.resolve(f"{domain}", 'A').canonical_name.to_text().rstrip('.')
and line 132 with
return resolver.resolve(f"{domain}", "AAAA").canonical_name.to_text().rstrip('.')
(i.e removing the {ACME_TXT_PREFIX}. part of both)

Subdomains (incl. wildcards) Cannot be Processed

Describe the bug
The use of -d "domain.tld" works as expected but -d "*.domain.tld" or -d "sub.domain.tld" results in a failed cert generation

To Reproduce
use -d "*.domain.tld" or -d "sub.domain.tld"

Expected behavior
Cert should be processed as expected

Certbot command
certbot certonly --non-interactive --agree-tos --email [email protected] --preferred-challenges dns --authenticator dns-porkbun --dns-porkbun-credentials /config/porkbun.ini --dns-porkbun-propagation-seconds 60 -d "*.domain.tld"

Versions (please complete the following version information):

  • certbot: 1.29.0
  • certbot_dns_porkbun: 0.4

Error message

Encountered exception during recovery: KeyError: 'LONG_RANDOM_ISH_KEY_HERE'

ERROR: DNS create api call was not successfully

Status code: 400

Additional context
client.py potentially removed the "*." replacement:

Add a snap build of the plugin

certbot can be installed using snap, in this case any plugin installed using pip will not be loaded. A snap build of the plugin solves this problem.

Cannot use for domain that uses ALIAS record

Describe the bug
Attempting to update/renew certificate on a domain that uses an ALIAS record fails, because it attempts to update the resolved ALIAS domain instead of the domain requested

To Reproduce

  1. Set an ALIAS record for a root domain, instead of an A/AAAA record
  2. Attempt to create/renew certificate for that domain

Expected behavior
Certificate renewal is successful

Certbot command
certbot certonly -v --test-cert --server https://acme-staging-v02.api.letsencrypt.org/directory --authenticator dns-porkbun --dns-porkbun-credentials /etc/letsencrypt/porkbun/porkbun.ini --cert-name test-d example.com

Versions (please complete the following version information):

  • certbot: 2.4.0
  • certbot_dns_porkbun: 0.8

Error message

2024-01-01 15:29:04,837:DEBUG:urllib3.connectionpool:https://porkbun.com:443 "POST /api/json/v3/dns/create/dyndns.org HTTP/1.1" 400 None
2024-01-01 15:29:04,843:DEBUG:certbot._internal.error_handler:Encountered exception:
Traceback (most recent call last):
  File "/opt/venv/lib/python3.11/site-packages/certbot_dns_porkbun/cert/client.py", line 109, in _perform
    self.record_ids[validation] = self._get_porkbun_client().dns_create(self._root_domain,
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/pkb_client/client.py", line 119, in dns_create
    raise Exception("ERROR: DNS create api call was not successfully\n"
Exception: ERROR: DNS create api call was not successfully
Status code: 400
Message: Invalid domain.

Note trying to request a cert for "dyndns.org" (the root of the domain that my domain is pointing at with an ALIAS record) and not my domain

Support credentials file

I am here through NginxProxyManager/nginx-proxy-manager#1079.

Usually certbot dns plugins are configured with an INI file, which contain the credential information, to prevent the credentials from showing up in the bash history. But this plugin is exclusively configured through command line parameters.

It would be great if a credentials file would also be possible, maybe with command line params taking precedence.

Credentials argument is unrecognized

Describe the bug
Running the certbot with dns-porkbun as authenticator and passing in API keys via --dns-porkbun-credentials results in the error.

To Reproduce

  1. Install certbot and certbot-dns-porkbun
  2. Create a credentials file at /etc/letsencrypt/credentials/app-credentials.ini with the content:
dns_porkbun_key=<your-key>
dns_porkbun_secret=<your-key>
  1. Run the following command:
    sudo certbot certonly --non-interactive --agree-tos --email "[email protected]" --preferred-challenges dns --authenticator dns-porkbun --dns-porkbun-credentials "/etc/letsencrypt/credentials/app-credentials.ini" --dns-porkbun-propagation-seconds 60 -d "*.<domain>.<tld>" -d "<domain>.<tld>"

Expected behavior
Expected it to run without errors.

Versions (please complete the following version information):

  • certbot: 2.7.1
  • certbot_dns_porkbun: 0.8

Error message
certbot: error: unrecognized arguments: --dns-porkbun-credentials /etc/letsencrypt/credentials/app-credentials.ini

Additional context
dns-porkbun does show up when i run sudo certbot plugins. Any help would be greatly appreciated!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.