通过 GitHub Actions + acme.sh 免费全自动申请/续签泛域名 SSL 证书

69 天前
 danbao

repo 在此

https://github.com/danbao/auto-ssl

记得不要直接 fork 这个 repo , 用 clone 然后 push 到你自己的 private github repo

Features

3385 次点击
所在节点    分享创造
34 条回复
molezznet
68 天前
看起来方便的。暂时在用免费的微林
lblblong
68 天前
@lblblong 改了下代码已经可以了
lxqxqxq
68 天前
@w292614191 #3 哈哈哈 定时任务 /85 天执行一次
danbao
68 天前
@lblblong 参考 acme.sh 的文档改一下密钥就行了

```yaml
name: DnsPod SSL Certificates

on:
schedule: # execute every 24 hours
- cron: "35 7 * * *"
workflow_dispatch:

env:
ACME: /home/runner/.acme.sh/acme.sh
DP_ID: ${{ secrets.DP_ID }}
DP_KEY: ${{ secrets.DP_KEY }}
EMAIL: ${{ secrets.EMAIL }}

jobs:
build:
runs-on: ubuntu-latest
if: github.event_name == 'schedule' || github.event.repository.owner.id == github.event.sender.id
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install & Configure acme.sh
run: |
curl https://get.acme.sh | sh -s email=$EMAIL
- name: Issue & Deploy Certificates
run: |
export DP_Id=$DP_ID
export DP_Key=$DP_KEY

git config --global user.email $EMAIL
git config --global user.name acme

# 如果想要其他证书发行机构,可以把 acme.sh 的 ca 目录拷贝到 repo 的 ca 目录
# mkdir -p /home/runner/.acme.sh/ca/
# cp -r ca/* /home/runner/.acme.sh/ca/

check_certificate_validity() {
cert_path=$1
if [ -f "$cert_path" ]; then
if openssl x509 -checkend $(( 30 * 86400 )) -noout -in "$cert_path"; then
echo "Certificate at $cert_path is valid for more than 30 days, skipping..."
return 0
else
return 1
fi
else
return 1
fi
}

issue_and_install_certificate() {
domain=$1
cert_type=$2 # "EC" or "RSA"
acme_server=$3 # default choose "letsencrypt" 其他 CA 请参考 https://github.com/acmesh-official/acme.sh/wiki/CA
keylength=$4 # empty for EC, "3072" for RSA

cert_path="./ssl/$domain"
[ "$cert_type" = "RSA" ] && cert_path="$cert_path/rsa"
cert_file="$cert_path/$domain.cer"
key_file="$cert_path/$domain.key"

# Issue certificate
issue_status=0
$ACME --issue --server $acme_server --debug --dns dns_dp -d "$domain" -d "*.$domain" ${keylength:+--keylength $keylength} || issue_status=$?
if [ $issue_status -ne 0 ]; then
echo "Failed to issue $cert_type certificate for $domain, skipping..."
return
fi

# Install certificate
install_status=0
$ACME --installcert -d "$domain" --key-file "$key_file" --fullchain-file "$cert_file" || install_status=$?
if [ $install_status -ne 0 ]; then
echo "Failed to install $cert_type certificate for $domain, skipping..."
return
fi

TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S")
git add $cert_path/
git commit -m "Update $cert_type certificate files for $domain at $TIMESTAMP"
}

while IFS= read -r domain || [ -n "$domain" ]; do
mkdir -p "./ssl/$domain/rsa"

# Check and issue/install EC certificate
if ! check_certificate_validity "./ssl/$domain/$domain.cer"; then
issue_and_install_certificate "$domain" "EC" "letsencrypt" ""
fi

# Check and issue/install RSA certificate
if ! check_certificate_validity "./ssl/$domain/rsa/$domain.cer"; then
issue_and_install_certificate "$domain" "RSA" "letsencrypt" "3072"
fi

done < dnspod_domains_list.txt
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
```
gaojiren
68 天前
我用 AlphaSSL ,泛域名 1 年 30 块钱,花小钱办大事
Actrace
67 天前
vx 有免费的自动续签的 SSL 服务,只需要配置 DNS 就完成配置下证书。
应该是目前最简单的。
wushenlun
67 天前
@totoro625 GCP 有免费服务器吗,细说以下?
blankmiss
67 天前
@gaojiren AlphaSSL 的 30 块钱证书 不已经被回收了? 萌咖那种 ?
jeffma
67 天前
自荐下自己的方案,已经稳定运行两年多了——

借助腾讯云·云函数实现的 ACME Let’s Encrypt SSL 证书自动更新

https://github.com/Jeff2Ma/acme-qcloud-scf
jeffma
67 天前
@lblblong 自荐下自己的方案,已经稳定运行两年多了——

借助腾讯云·云函数实现的 ACME Let’s Encrypt SSL 证书自动更新

https://github.com/Jeff2Ma/acme-qcloud-scf
ilylx2008
67 天前
有自动更新阿里云腾讯云 cdn 的证书么
GoRoad
66 天前
@danbao #18 那老哥是给内网地址解析的域名吗,我现在也是这个问题,直接把域名解析到内网的私有网段了,证书就很苦恼
danbao
65 天前
@GoRoad 按 github action 的方式获取证书还苦恼啥
lblblong
62 天前
@jeffma 🐂🍺老哥

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

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

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

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

© 2021 V2EX