[GH-ISSUE #54] [Feature] 建议在申请证书前增加清理DNS记录机制 #41

Closed
opened 2026-03-03 00:30:57 +03:00 by kerem · 1 comment
Owner

Originally created by @o2asdv on GitHub (Sep 20, 2024).
Original GitHub issue: https://github.com/certimate-go/certimate/issues/54

在之前使用LEGO项目进行证书获取时,出现过因CF内有多个"_acme-challenge"导致无法认证成功的问题,建议在添加新的"_acme-challenge"记录前,检查并清理相关记录,并等待一段时间在做下一步验证。

附当时自己写的shell脚本供参考

#!/bin/sh

PATH=/usr/sbin:/usr/bin:/sbin:/bin

DOMAIN=${1}
ZONE_ID=${2}
EMAIL=${3}
API_KEY=${4}

# 获取所有 DNS 记录
RECORDS=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records?type=TXT&name=_acme-challenge.$DOMAIN" \
     -H "X-Auth-Email: $EMAIL" \
     -H "X-Auth-Key: $API_KEY" \
     -H "Content-Type: application/json")

# 遍历所有 _acme-challenge 记录
echo $RECORDS | jq -r '.result[].id' | while read RECORD_ID; do
  echo "=== delete: $RECORD_ID"
  # 删除每一个记录
  curl -q -s -X DELETE "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$RECORD_ID" \
     -H "X-Auth-Email: $EMAIL" \
     -H "X-Auth-Key: $API_KEY" \
     -H "Content-Type: application/json"
done
Originally created by @o2asdv on GitHub (Sep 20, 2024). Original GitHub issue: https://github.com/certimate-go/certimate/issues/54 在之前使用LEGO项目进行证书获取时,出现过因CF内有多个"_acme-challenge"导致无法认证成功的问题,建议在添加新的"_acme-challenge"记录前,检查并清理相关记录,并等待一段时间在做下一步验证。 附当时自己写的shell脚本供参考 ```shell #!/bin/sh PATH=/usr/sbin:/usr/bin:/sbin:/bin DOMAIN=${1} ZONE_ID=${2} EMAIL=${3} API_KEY=${4} # 获取所有 DNS 记录 RECORDS=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records?type=TXT&name=_acme-challenge.$DOMAIN" \ -H "X-Auth-Email: $EMAIL" \ -H "X-Auth-Key: $API_KEY" \ -H "Content-Type: application/json") # 遍历所有 _acme-challenge 记录 echo $RECORDS | jq -r '.result[].id' | while read RECORD_ID; do echo "=== delete: $RECORD_ID" # 删除每一个记录 curl -q -s -X DELETE "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$RECORD_ID" \ -H "X-Auth-Email: $EMAIL" \ -H "X-Auth-Key: $API_KEY" \ -H "Content-Type: application/json" done ```
kerem 2026-03-03 00:30:57 +03:00
Author
Owner

@usual2970 commented on GitHub (Nov 2, 2024):

感谢反馈~ 后续没有这方面的迭代计划

欢迎提交 PR

<!-- gh-comment-id:2452836385 --> @usual2970 commented on GitHub (Nov 2, 2024): 感谢反馈~ 后续没有这方面的迭代计划 欢迎提交 PR
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/certimate#41
No description provided.