SSL 证书再有几年 47 天了,大家有什么自动化方案嘛

128 天前
 kincaid
看到宝塔面板发的视频感觉有点不好玩啊 https://www.bilibili.com/video/BV1Ru5uzMEi9/

之前用免费一年证书,现在买野鸡一年证书,就是不想折腾,以后真到 47 天想不折腾也不行了似乎
看了几个自动化工具,看起来挺好,但是真的懒得动,那么多服务器能动就懒得折腾

宝塔视频推的这个 https://allinssl.com ,好像功能有点少
还有之前的 certd ,certimate ,还有传统的 acme.sh (可惜部署云服务有点难),外加 cerbot ,caddy 那一堆,好像几家大厂也有在插手

好想摆烂,CA/B 这么玩干脆请求一次就签一张证书算了
8647 次点击
所在节点    云计算
88 条回复
vytvex
127 天前
有些不太明白能解釋一下嗎? Cloudflare origin 證書能用 5 年,為甚麼要在意對外的 ssl cert?
eslizn
127 天前
traefik + ingress annotation 很 easy 的解决方案了
EnderAvaritia
127 天前
acme 和 win-acme ,自己去 git 搜
之后用 nginx 统一代理转发
v2er119
126 天前
AI 写脚本,监控+提醒+certbot 自动申请
https://maifeipin.com/archives/zi-dong-bu-shu-xi-tong-jian-kong-jiao-ben
只需替换你的邮箱和 tencentcloud.ini (对应的域名 API key ) 就行了


···
#!/bin/bash

THRESHOLD=7
CREDENTIALS="/etc/letsencrypt/tencentcloud.ini"
EMAIL="yourmail@qq.com"
EMAIL_ARG="--email $EMAIL"
# EMAIL_ARG="--register-unsafely-without-email"

nginx_conf_dirs=(
"/etc/nginx/nginx.conf"
"/etc/nginx/conf.d/"
"/etc/nginx/sites-enabled/"
"/etc/nginx/sites-available/"
"/usr/local/nginx/conf/"
)

nginx_cert_files=$(mktemp)
for conf_dir in "${nginx_conf_dirs[@]}"; do
if [ -d "$conf_dir" ]; then
find "$conf_dir" -type f -name "*.conf" 2>/dev/null | while read -r file; do
grep -E '^\s*ssl_certificate\s+' "$file" | awk '{print $2}' | sed "s/['\";]//g" >> "$nginx_cert_files"
done
elif [ -f "$conf_dir" ]; then
grep -E '^\s*ssl_certificate\s+' "$conf_dir" | awk '{print $2}' | sed "s/['\";]//g" >> "$nginx_cert_files"
fi
done

sort -u "$nginx_cert_files" -o "$nginx_cert_files"

while read -r cert_path; do
if [ -z "$cert_path" ]; then continue; fi
if [ ! -f "$cert_path" ]; then
echo "证书文件: $cert_path (未找到!)"
echo "-----------------------------"
continue
fi

expiry_date=$(openssl x509 -noout -enddate -in "$cert_path" 2>/dev/null | cut -d= -f2)
expiry_epoch=$(date -d "$expiry_date" +%s)
now_epoch=$(date +%s)
days_left=$(( (expiry_epoch - now_epoch) / 86400 ))

all_domains=$(openssl x509 -noout -text -in "$cert_path" 2>/dev/null | grep "DNS:" | sed 's/.*DNS://;s/, /\n/g' | tr '\n' ' ')

if [ $days_left -le $THRESHOLD ]; then
main_domain=$(echo "$all_domains" | awk '{print $1}')
echo "证书文件: $cert_path"
echo " 包含域名: $all_domains"
echo " 过期时间: $expiry_date (剩余 $days_left 天)"
echo " 证书即将过期或已过期,自动续期..."

certbot certonly \
-a dns-tencentcloud \
--dns-tencentcloud-credentials "$CREDENTIALS" \
-d $all_domains \
$EMAIL_ARG \
--non-interactive --agree-tos \
--keep-until-expiring

if [ $? -eq 0 ]; then
echo " 证书续期成功"
# 自动覆盖 Nginx 实际用的证书
src_cert="/etc/letsencrypt/live/$main_domain/fullchain.pem"
src_key="/etc/letsencrypt/live/$main_domain/privkey.pem"
if [ -f "$src_cert" ] && [ -f "$src_key" ]; then
# 只在 Nginx 用的路径和 Let’s Encrypt 路径不一致时覆盖
if [ "$cert_path" != "$src_cert" ]; then
cp -f "$src_cert" "$cert_path"
echo " 已覆盖 Nginx 用的证书: $cert_path"
fi
# 查找 key 路径
key_path=$(grep -E '^\s*ssl_certificate_key\s+' /etc/nginx/nginx.conf /etc/nginx/conf.d/*.conf /etc/nginx/sites-enabled/* /etc/nginx/sites-available/* /usr/local/nginx/conf/*.conf 2>/dev/null | grep "$main_domain" | awk '{print $2}' | sed "s/['\";]//g" | head -n1)
if [ -n "$key_path" ] && [ "$key_path" != "$src_key" ]; then
cp -f "$src_key" "$key_path"
echo " 已覆盖 Nginx 用的私钥: $key_path"
fi
fi
systemctl reload nginx
else
echo " 证书续期失败"
fi
else
echo "证书文件: $cert_path"
echo " 包含域名: $all_domains"
echo " 过期时间: $expiry_date (剩余 $days_left 天)"
fi
echo "-----------------------------"
done < "$nginx_cert_files"

rm -f "$nginx_cert_files"

···
irainsoft
126 天前
@vytvex #61 你自己都明白了是 origin ssl ,这是 Cloudflare 边缘节点和你源站服务器之间的通信,其实就是一个内部信任的自签证书而已。如果你拿这个证书去做面向用户的 SSL ,那用户侧看到的就是不受信任的根证书错误( SSL 红屏错误)。如果真的不在意这个,不如自己拿 openssl 签一个 100 年的了。
Alliot
126 天前
certbot 加上 deploy-hook 自己实现。
一个证书管理没必要引入太多依赖。
ysc3839
126 天前
@Damn 不知道,有空我试试
azarasi
126 天前
crontab+certbot 不行吗?
imlonghao
126 天前
@Damn 有的兄弟 `CNAME support by default` https://go-acme.github.io/lego/index.html
imlonghao
126 天前
@iceecream 分组的,多少张证书用一个 CRL 地址
coolfan
126 天前
在用 certd ,狠下心所有服务器配置一遍。(其实也就第一个服务器配置久一点,后面几个都是复制黏贴)
bronyakaka
126 天前
certbot 很稳,别碰 caddy
summer2019
126 天前
@GoodRui 话是这么说,但是填进去用不了。acme.sh 都没问题,它就用不了。腾讯云的填过,dnspod 的也填过,用不了,然后删了
Hantong
126 天前
acme.sh 主要是重复签发,很多台机器都要来一遍好麻烦,功能性非常好了,算是事实上的标准之一?

不知道有没有开源的单机部署然后把证书文件推送到其他机器的方案,然后自动触发服务重载。
vipnetant
125 天前
我用 certd ,非常好用,前期配置好,后面无感。
有报错就发邮件提醒,没错就无感。
dajj
125 天前
cloudflare 边缘证书
imlonghao
125 天前
certd 的 git history 里一堆 chore: 有点难绷
salmon5
125 天前
你们这都是个人的小玩具项目,参考价值不大
有没有阿里、腾讯负责证书的分享下?这么多证书节点,到时候怎么弄?
lyxxxh2
125 天前
宝塔那个续签有毒,还不如让 ai 写。
chutianyao
125 天前
@azarasi 我用 certbot,把自动续期功能也都放到容器了, 不需要再宿主机上执行 crontab 了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1130748

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX