Plugin for certbot to obtain certificates using a DNS TXT record for Porkbun domains
Project description
Certbot DNS Porkbun Plugin
Plugin for certbot to obtain certificates using a DNS TXT record for Porkbun domains
Table of Contents
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"
Development
Setup environment
First get the source code:
git clone https://github.com/infinityofspace/certbot_dns_porkbun.git
cd certbot_dns_porkbun
Now create a virtual environment, activate it and install all dependencies with the following commands:
python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt
Now you can start developing.
Feel free to contribute to this project by creating a pull request. Before you create a pull request, make sure that you code meets the following requirements (you can use the specified commands to check/fulfill the requirements):
- check unit tests:
python -m unittest tests/*.py - format the code:
ruff format - check linting errors:
flake8 certbot_dns_porkbun --count --ignore E501 --show-source --statistics
pylint certbot_dns_porkbun --disable C0301
Tests
You can run the tests with the following command:
python -m unittest tests/*.py
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 |
| tldextract | BSD 3-Clause |
Furthermore, this readme file contains embeddings of Shields.io.
License
MIT - Copyright (c) Marvin Heptner
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file certbot_dns_porkbun-0.11.0.tar.gz.
File metadata
- Download URL: certbot_dns_porkbun-0.11.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e2aa1ce1788ebdaa3ccdbf5136fbbbebc3c9062eded8407c8ec1ecb36b768c6
|
|
| MD5 |
dbb98cf36df0a6f48ed4f4faf20f2f69
|
|
| BLAKE2b-256 |
b5b77fbe9f3fcbda1f268a3edb304807ad685b10e6769908faec04f97e6c32bf
|
File details
Details for the file certbot_dns_porkbun-0.11.0-py3-none-any.whl.
File metadata
- Download URL: certbot_dns_porkbun-0.11.0-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ca7095745c787b300b778014b049498c70d1be1ba24b5e441c20b3858e6d3c9
|
|
| MD5 |
6e82efa4b3598003bda11f298dfe196f
|
|
| BLAKE2b-256 |
b535186cfce6796026b14d25c26c8fa41e8d7842aa216d80065052dd4e8eebcf
|