Skip to main content

使用 DuckDNS 域的 DNS TXT 记录获取证书

项目描述

Certbot DNS DuckDNS 插件

用于 certbot 的插件,用于 DuckDNS 域的 DNS-01 质询。


PyPI - Python 版本 GitHub

派皮 PyPI - 下载 GitHub 工作流状态

Docker 镜像版本(最新版本) Docker 镜像大小(最新版本) GitHub 工作流状态

certbot-dns-duckdns


目录

  1. 关于
  2. 安装
    1. 先决条件
    2. 带点(推荐)
    3. 从源头
    4. 折断
  3. 用法
    1. 凭据文件或 cli 参数
    2. 本地安装使用
    3. 码头工人使用
    4. 插件参数
  4. 常问问题
  5. 第三方通知
  6. 执照

关于

certbot_dn_duckdns是 certbot 的插件,用于为DuckDNS域创建 DNS-01 质询。该插件负责通过 DuckDNS API 设置和删除 TXT 条目。

安装

先决条件

如果你想使用 docker 镜像,那么你不需要任何要求,除了一个工作的 docker 安装,可以直接继续使用

如果您更喜欢本地安装,那么您至少需要安装 3.7 版的 Python。如果你想用 pip 安装这个插件,那么你还需要安装 pip3。

如果您已经安装了certbot,请确保您至少1.18.0安装了版本。当您将 certbot安装为 snap 时,您必须使用插件的snap 安装

您可以使用以下命令检查安装了哪个版本的certbot

certbot --version

如果您还没有安装 certbot,那么 PyPI 版本的 certbot 将在安装过程中自动安装。

注意:如果您想以 root 权限运行 certbot,那么您也需要以 root 权限安装插件。否则,certbot 找不到插件。

带点(推荐)

使用以下命令通过 pip 安装certbot_dns_duckdns

pip install certbot_dns_duckdns

您还可以非常轻松地更新到更新版本:

pip install certbot_dns_duckdns -U

从源头

git clone https://github.com/infinityofspace/certbot_dns_duckdns
cd certbot_dns_duckdns
pip install .

折断

如果您使用certbot作为 snap 包,那么您也必须将certbot_dns_duckdns安装为 snap:

snap install certbot-dns-duckdns

现在将certbot snap 安装与插件 snap 安装连接起来:

sudo snap connect certbot:plugin certbot-dns-duckdns

以下命令现在应dns-duckdns列为已安装的插件:

certbot plugins

用法

注意:您不能通过一个 certbot 调用为多个 DuckDNS 域创建证书。这是因为 DuckDNS 只允许一条 TXT 记录。如果应同时为多个域创建证书,则必须创建相同数量的不同 DNS TXT 记录。要解决此问题,您只需为每个域进行单独的 certbot 调用。

请注意,通过 Letsencrypt 生成的证书有速率限制。对于测试,使用附加参数--staging来解决这个问题。

凭据文件或 cli 参数

您可以使用 cli 参数将身份验证信息传递给 certbot:

...
--dns-duckdns-token <your-duckdns-token>

或者为了防止您的凭据出现在您的 bash 历史记录中,您还可以创建一个duckdns.ini包含以下内容的凭据文件(名称无关紧要):

dns_duckdns_token=<your-duckdns-token>

--dns-duckdns-key然后你可以使用而不是使用上面的参数

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

您也可以混合使用这些用法,尽管 cli 参数始终优先于 ini 文件。

本地安装使用

要检查插件是否正确安装并被 certbot 正确检测到,可以使用以下命令:

certbot plugins

以下是如何使用该插件的一些示例:


为域“example.duckdns.org”的 DNS-01 质询生成证书:

certbot certonly \
  --non-interactive \
  --agree-tos \
  --email <your-email> \
  --preferred-challenges dns \
  --authenticator dns-duckdns \
  --dns-duckdns-token <your-duckdns-token> \
  --dns-duckdns-propagation-seconds 60 \
  -d "example.duckdns.org"

为子域“cloud.example.duckdns.org”的 DNS-01 质询生成证书:

certbot certonly \
  --non-interactive \
  --agree-tos \
  --email <your-email> \
  --preferred-challenges dns \
  --authenticator dns-duckdns \
  --dns-duckdns-token <your-duckdns-token> \
  --dns-duckdns-propagation-seconds 60 \
  -d "cloud.example.duckdns.org"

为所有子域“*.example.duckdns.org”的 DNS-01 质询生成通配符证书:

certbot certonly \
  --non-interactive \
  --agree-tos \
  --email <your-email> \
  --preferred-challenges dns \
  --authenticator dns-duckdns \
  --dns-duckdns-token <your-duckdns-token> \
  --dns-duckdns-propagation-seconds 60 \
  -d "*.example.duckdns.org"

使用凭证文件为域“example.duckdns.org”的 DNS-01 质询生成证书:

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

为没有帐户(即没有电子邮件地址)的域“example.duckdns.org”的 DNS-01 质询生成证书:

certbot certonly \
  --non-interactive \
  --agree-tos \
  --register-unsafely-without-email \
  --preferred-challenges dns \
  --authenticator dns-duckdns \
  --dns-duckdns-token <your-duckdns-token> \
  --dns-duckdns-propagation-seconds 60 \
  -d "example.duckdns.org"

为域“example.duckdns.org”的 DNS-01 质询生成暂存证书(即临时测试证书):

certbot certonly \
  --non-interactive \
  --agree-tos \
  --email <your-email> \
  --preferred-challenges dns \
  --authenticator dns-duckdns \
  --dns-duckdns-token <your-duckdns-token> \
  --dns-duckdns-propagation-seconds 60 \
  -d "example.duckdns.org" \
  --staging

DNS-01 质询允许使用 CNAME 记录或 NS 记录将质询响应委托给其他 DNS 区域。例如,这允许您使用duckdns 域解决另一个提供商的域的DNS 质询。例如,我们有abc.duckdns.org作为duckdns 域和example.com作为我们的其他域。我们可能有一个现有的 DNS 配置,如下所示:

one.example.com. 600 IN CNAME two.example.com.
two.example.com. 600 IN CNAME abc.duckdns.org.

它链接one.example.comtwo.example.com并最终链接到abc.duckdns.org

现在我们要为子域“test.example.com”发出 DNS-01 质询。因此,我们为“_acme-challenge.test.example.com”创建一个指向“one.example.com”的 CNAME 记录。DNS 记录现在如下所示:

_acme-challenge.test.example.com。600 在 CNAME one.example.com 中。
one.example.com. 600 IN CNAME two.example.com.
two.example.com. 600 IN CNAME abc.duckdns.org.

test.example.com现在我们使用 certbot 为带有 DNS 质询的域生成证书:

certbot certonly \
  --non-interactive \
  --agree-tos \
  --email <your-email> \
  --preferred-challenges dns \
  --authenticator dns-duckdns \
  --dns-duckdns-token <your-duckdns-token> \
  --dns-duckdns-propagation-seconds 60 \
  -d "test.example.com" \

在 DNS 记录中可以很好地看到后台发生的情况:

_acme-challenge.test.example.com。600 在 CNAME one.example.com 中。
one.example.com. 600 IN CNAME two.example.com.
two.example.com. 600 IN CNAME abc.duckdns.org.
abc.duckdns.org。60 TXT "asduh9asudhßa97sdhap9sudaisudoi"

在验证 DNS 质询值时,现在遍历所有 CNAME 记录。它从 开始_acme-challenge.test.example.comone.example.com,然后到two.example.com,最后到abc.duckdns.org。这是存储为 TXT 记录的验证令牌。

也可以通过直接从_acme-challenge.test.example.comto 创建 CNAME 条目来缩短该示例abc.duckdns.org。所以我们跳过所有其他的 CNAME 记录。为了明确在验证期间遍历任何 CNAME 记录,在前面的示例中添加了中间部分。


尝试更新所有当前生成的证书:

certbot renew

您可以在 certbot 的官方文档中找到所有可用 certbot cli 选项的列表

码头工人使用

您可以简单地启动一个新容器并使用相同的 certbot 命令来获取新证书:

docker run -v "/etc/letsencrypt:/etc/letsencrypt" -v "/var/log/letsencrypt:/var/log/letsencrypt" infinityofspace/certbot_dns_duckdns:latest \
   certonly \
     --non-interactive \
     --agree-tos \
     --email <your-email> \
     --preferred-challenges dns \
     --authenticator dns-duckdns \
     --dns-duckdns-token <your-duckdns-token> \
     --dns-duckdns-propagation-seconds 60 \
     -d "example.duckdns.org"

或者您可以使用凭证文件:

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

例如,如果您想使用 docker 映像自动更新您的证书,您可以使用主机 cron 来执行此操作。要使用此示例,您必须事先安装 crontab 和 cron。请注意,根据安装情况,您可能需要使用 root 用户的 crontab 来访问 docker 守护程序或文件目录。例如,使用以下 crontab 表达式:

0 3 */8 * * docker run --rm -v "/etc/letsencrypt:/etc/letsencrypt" -v "/var/log/letsencrypt:/var/log/letsencrypt" infinityofspace/certbot_dns_duckdns:latest certbot renew

这将每 8 天凌晨 3 点启动一个临时 docker 容器,并尝试更新即将到期的证书。

可以在此处找到使用 docker-compose 的示例。

插件参数

Obtain certificates using a DNS TXT record for DuckDNS domains

  --dns-duckdns-propagation-seconds DNS_DUCKDNS_PROPAGATION_SECONDS
                        The number of seconds to wait for DNS to propagate before asking the ACME server to verify the DNS record. (default: 30)
  --dns-duckdns-credentials DNS_DUCKDNS_CREDENTIALS
                        DuckDNS credentials INI file. (default: None)
  --dns-duckdns-token DNS_DUCKDNS_TOKEN
                        DuckDNS token (overwrites credentials file) (default: None)
  --dns-duckdns-no-txt-restore
                        Do not restore the original TXT record (default: False)

常问问题

您可以在wiki中的常见问题解答。

第三方通知

该项目使用的所有模块如下所列:

姓名 执照
证书机器人 阿帕奇 2.0
要求 阿帕奇 2.0
安装工具 麻省理工学院
dnspython 国际标准委员会

此外,此自述文件包含Shields.io的嵌入。

执照

麻省理工学院- 版权所有 (c) 2021-2022 Marvin Heptner

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

certbot_dns_duckdns-1.1.tar.gz (13.8 kB 查看哈希

已上传 source

内置分布

certbot_dns_duckdns-1.1-py3-none-any.whl (12.1 kB 查看哈希

已上传 py3