# certbot-au-python **Repository Path**: lfveeker/certbot-au-python ## Basic Information - **Project Name**: certbot-au-python - **Description**: 基于certbot、python的用于自动化获取、续期、部署 Let's Encrypt 通配符 SSL 证书的工具,支持阿里云、腾讯云、华为云,可构建Docker镜像 - **Primary Language**: Unknown - **License**: GPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-07-15 - **Last Updated**: 2025-09-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: certbot, Python, SSL证书, 通配符证书, 自动化 ## README ### 功能 不管是申请还是续期,只要是通配符证书,只能采用 dns-01 的方式校验申请者的域名,也就是说 certbot 操作者必须手动添加 DNS TXT 记录。 certbot 提供了一个 hook,可以编写一个 Shell 脚本,让脚本调用 DNS 服务商的 API 接口,动态添加 TXT 记录,这样就无需人工干预了。 在 certbot 官方提供的插件和 hook 例子中,都没有针对国内 DNS 服务器的样例,所以编写了这样一个工具,目前支持**阿里云**、**腾讯云**、**华为云**。 ### 自动申请通配符证书 1:下载 ``` git clone https://gitee.com/lfveeker/certbot-au-python.git ``` 2:配置 (1)dnsau/domain.ini 如果domain.ini文件没有你的根域名,请自行添加。 (2)DNS API 密钥: 由于需要通过 API 操作阿里云、腾讯云、华为云的记录,所以需要去域名服务商那儿获取 API 密钥,然后配置在 dnsau/au.sh 文件中: - ALY_KEY 和 ALY_TOKEN:阿里云 [AccessKey ID 和 AccessKey Secret 申请文档](https://help.aliyun.com/knowledge_detail/38738.html)。 - TXY_KEY 和 TXY_TOKEN:腾讯云 [SecretId 和 SecretKey 申请文档](https://console.cloud.tencent.com/cam/capi)。 - HWY_KEY 和 HWY_TOKEN:华为云 [Access Key Id 和 Secret Access Key 申请文档](https://support.huaweicloud.com/devg-apisign/api-sign-provide.html) (3)构建Docker镜像 ``` cd certbot-au-python docker build -t certbot-au-python:1.0 . ``` 3:申请证书 (1)基于Docker ``` docker run --rm \ -v /usr/local/certbot:/etc/letsencrypt \ certbot-au-python:1.0 certbot certonly --manual \ --preferred-challenges dns \ --agree-tos --non-interactive \ --manual-auth-hook "/app/dnsau/au.sh txy add" \ --manual-cleanup-hook "/app/dnsau/au.sh txy clean" \ --server https://acme-v02.api.letsencrypt.org/directory --email lfveeker@163.com \ -d *.frp.lfveeker.top ``` (2)本地已安装CertBot ``` certbot certonly --manual \ --preferred-challenges dns \ --agree-tos --non-interactive \ --manual-auth-hook "/路径/certbot-au-python/dnsau/au.sh txy add" \ --manual-cleanup-hook "/路径/certbot-au-python/dnsau/au.sh txy clean" \ --server https://acme-v02.api.letsencrypt.org/directory --email lfveeker@163.com \ -d *.frp.lfveeker.top ``` **重要解释:** --manual-auth-hook 和 --manual-cleanup-hook 有2个参数: - 第1个参数代表你的DNS厂商(aly/txy/hwy) - 第2个参数是固定的(--manual-auth-hook中用add,--manual-clean-hook中用clean) 例如使用阿里云时: 可以将 --manual-auth-hook 输入修改为 "/app/dnsau/au.sh aly add",--manual-cleanup-hook 输入修改为 "/app/dnsau/au.sh aly clean" 参数解释(可以不用关心): - certonly:获取或更新证书但不安装 - --manual:手动模式 - --agree-tos 同意ACME订阅协议 - --non-interactive 以非交互式模式运行Certbot - --preferred-challenges dns:表示使用dns验证方式 - --email 换成你自己的邮箱 - --manual-auth-hook 手动模式(--manual)下执行验证(challenge)之前自动运行指定程序或脚本。此处用于自动添加域名的TXT解析 - --manual-cleanup-hook 手动模式(--manual)进行证书申请或更新时,指定一个清理脚本或命令,此处用于验证完成后清除TXT解析 - --server 指明支持acme-v02的Server地址,默认是acme-v01的地址,通常无需更改 - -d:表示需要为那个域名申请证书,可以有多个。 - **Debug:** 操作 DNS API 可能会遇到一系列问题,比如 API token 权限不足,遇到相关问题,可以查看 挂载目录下的 au.log。 - 如果你想为多个域名申请通配符证书(合并在一张证书中,也叫做 **SAN 通配符证书**),直接输入多个 -d 参数即可,比如: ``` docker run --rm \ -v /usr/local/certbot:/etc/letsencrypt \ certbot-au-python:1.0 certbot certonly --manual \ --preferred-challenges dns \ --agree-tos --non-interactive \ --manual-auth-hook "/app/dnsau/au.sh txy add" \ --manual-cleanup-hook "/app/dnsau/au.sh txy clean" \ --server https://acme-v02.api.letsencrypt.org/directory --email lfveeker@163.com \ -d *.frp.lfveeker.top -d *.lfveeker.top -d lfveeker.top ``` ### 续期证书 1:对机器上所有证书 renew ``` docker run --rm \ -v /usr/local/certbot:/etc/letsencrypt \ certbot-au-python:1.0 certbot renew ``` 2:对某一张证书进行续期 ``` docker run --rm \ -v /usr/local/certbot:/etc/letsencrypt \ certbot-au-python:1.0 certbot --cert-name frp.lfveeker.top ``` ### 加入 crontab 编辑文件 /etc/crontab: ``` #证书有效期<30天才会renew,所以crontab可以配置为1天或1周 1 1 */1 * * root docker run --rm -v /usr/local/certbot:/etc/letsencrypt certbot-au-python:1.0 certbot renew ``` **说明:** - 如果觉得剩余30时续签太浪费(8月份开始证书有效期变为47天),可以自行去挂载(Docker)目录下的renewal目录里找到对应域名的配置文件自行设置renew的天数 - 如果使用本地部署certbot请自行修改脚本路径 - 允许商用,但是任何衍生作品必须采用相同协议开放源代码