Skip to main content

功能

通过本脚本可以为阿里云的 CDN 以及 直播服务 域名申请配置以及自动续期免费的 let's encrypt 证书。 DOC EN

安装和配置

本脚本仅支持 Python 3

pip install aliyun-cert

需要配置阿里云 ram 账号的 access key,并至少赋予用户如下权限:

  • AliyunDNSFullAccess
  • AliyunCDNFullAccess
  • AliyunYundunCertFullAccess

如需同时配置直播 CDN 的证书,还需赋予如下权限:

  • AliyunLiveFullAccess

access key 记录在一个文件中,比如 ~/.serects/aliyun.ini,格式如下

dns_aliyun_key_id = xxx
dns_aliyun_key_secret = yyy

申请并配置证书

证书支持多域名,以及通配符域名,根据自己情况替换下面的 example.com 以及 *.example.com

certbot certonly \
  --authenticator dns-aliyun \
  --dns-aliyun-propagation-seconds 30 \
  --dns-aliyun-credentials ~/.secrets/aliyun.ini \
  -d example.com -d *.example.com

为阿里云配置证书

# 上传证书到阿里云 cas 服务
aliyun-cert upload-cert --domain example.com /etc/letsencrypt/live/example.com/fullchain.pem /etc/letsencrypt/live/example.com/privkey.pem

# 为 CDN 域名配置证书,cert-id 为上一步返回的 id
aliyun-cert set-cert --cert-id 123456 --domain cdn.example.com --service cdn

查看证书情况

# 显示阿里云证书服务上所有上传上去的证书
aliyun-cert list-certs

# 显示所有开通了 HTTPS 的 CDN 域名及其证书情况
aliyun-cert lish-domains --cdn

证书续期

创建 crontab 文件 /etc/cron.d/certbot

0 0,12 * * * root sleep 1471 && certbot renew -q

创建 certbot 的 deploy hook 脚本,每次 certbot 成功续期续期证书后都会自动调用改脚本上传证书并配置阿里云的服务 /etc/letsencrypt/renewal-hooks/deploy/09-deploy-aliyun.sh

#!/bin/bash

aliyun-cert certbot-deploy-hook --cdn --delete-old-cert

Metadata

Release files for aliyun-cert 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aliyun-cert 0.1.4
File Size Uploaded Provenance Actions
aliyun_cert-0.1.4.tar.gz 22.6 kB With provenance Details for aliyun_cert-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aliyun-cert 0.1.4
File Interpreter ABI Platform Actions
aliyun_cert-0.1.4-py3-none-any.whl Python 3 none any Details for aliyun_cert-0.1.4-py3-none-any.whl

Total release size: 44.4 kB

Release files / aliyun_cert-0.1.4.tar.gz

Download URL aliyun_cert-0.1.4.tar.gz
Size 22.6 kB
Tags Source
SHA-256 checksum
How to use checksums
84296c2965f939a12823f8be13376f53ba63d1c7ee50bd478eeabe336d19a56e
BLAKE2b-256 checksum
How to use checksums
5ce3920d0eff02a222da14872f211a52cd407ff6c4bb0f4bac0d241fc4c608ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 27, 2025.

Transparency log

Release files / aliyun_cert-0.1.4-py3-none-any.whl

Download URL aliyun_cert-0.1.4-py3-none-any.whl
Size 21.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ed47f91cfb23f7864955a194b2a5c8deab334f4b530691c34a033df65fd6985a
BLAKE2b-256 checksum
How to use checksums
7bdf481ea27f925fd90ab6d297d9a95ef2847fbca94215782a3c4ce98c8253cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 27, 2025.

Transparency log

Security for aliyun-cert 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for aliyun_cert-0.1.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 27, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page