TLS 证书配置与权限安全最佳实践
启用 HTTPS Web 控制台(端口 10443)与 DoT(端口 853)需要配置 TLS 证书。
[!TIP] 若您仅需要为 Web 管理面板与 DoH 提供 HTTPS 支持,可免去在 DNS Worker 内部配置证书的步骤,直接使用 Caddy 或 Nginx 反向代理
10080(HTTP)端口。详见 使用 Caddy 或 Nginx 反向代理 HTTP。
环境变量配置
Section titled “环境变量配置”在 /etc/dns-worker/.env 中配置证书与私钥路径:
SERVERFULL_TLS_CERT_PATH=/etc/letsencrypt/live/example.com/fullchain.pemSERVERFULL_TLS_KEY_PATH=/etc/letsencrypt/live/example.com/privkey.pemSERVERFULL_DOT_DOMAIN=example.com权限安全问题与最佳实践
Section titled “权限安全问题与最佳实践”为什么会出现 Permission Denied (EACCES)?
Section titled “为什么会出现 Permission Denied (EACCES)?”Certbot 默认生成的私钥文件权限为 0600 (root:root),父目录为 0700。
而 DNS Worker 的后台守护进程默认以普通用户(如 hugo)运行以降低安全风险,直接访问会导致操作系统拒绝访问。
推荐方案 1:使用标准 ssl-cert 用户组授权(最优雅)
Section titled “推荐方案 1:使用标准 ssl-cert 用户组授权(最优雅)”Debian / Ubuntu 原生提供了专用的 ssl-cert 组,可在不提升至 root 的前提下安全授权私钥:
# 1. 确保系统存在 ssl-cert 用户组sudo groupadd -f ssl-cert
# 2. 将运行服务的普通用户加入该组sudo usermod -a -G ssl-cert <username>
# 3. 将证书私钥属组设为 ssl-cert,并严格限制为组只读 (0640)sudo chgrp ssl-cert /etc/letsencrypt/live/<your-domain>/privkey.pemsudo chmod 640 /etc/letsencrypt/live/<your-domain>/privkey.pem
# 4. 允许 ssl-cert 组进入 live 和 archive 目录检索sudo chgrp ssl-cert /etc/letsencrypt/live /etc/letsencrypt/archivesudo chmod 750 /etc/letsencrypt/live /etc/letsencrypt/archive
# 5. 重启服务生效sudo dns-worker service restart推荐方案 2:专有目录隔离 + Certbot Hook(强隔离性)
Section titled “推荐方案 2:专有目录隔离 + Certbot Hook(强隔离性)”将证书部署到专用目录 /etc/dns-worker/certs/,属主直接设为该运行用户并将权限严格锁定为 0600。并通过 Certbot 钩子自动化同步:
sudo mkdir -p /etc/dns-worker/certssudo chown -R <username>:<username> /etc/dns-worker/certssudo chmod 700 /etc/dns-worker/certs
sudo cp /etc/letsencrypt/live/<domain>/fullchain.pem /etc/dns-worker/certs/sudo cp /etc/letsencrypt/live/<domain>/privkey.pem /etc/dns-worker/certs/sudo chown <username>:<username> /etc/dns-worker/certs/*sudo chmod 600 /etc/dns-worker/certs/privkey.pem备选方案 3:独立单机 VPS 直接以 root 运行
Section titled “备选方案 3:独立单机 VPS 直接以 root 运行”如果该服务器是专门运行 DNS Worker 的单机环境(无多用户共享风险),可在安装时直接以 root 运行:
sudo dns-worker service install --user rootDoT 通配符证书要求
Section titled “DoT 通配符证书要求”DoT 协议通过 TLS SNI 识别并路由不同的配置 Profile(格式为 <profileKey>.dns.example.com)。
- 必须配置通配符证书(同时覆盖
*.your.domain和your.domain)。 - 若配置单域名证书,HTTPS Web 面板正常工作,但 DoT 将处于暂停保护状态(
Paused (Requires Wildcard Certificate *.domain))。
Certbot DNS 挑战申请通配符证书示例
Section titled “Certbot DNS 挑战申请通配符证书示例”certbot certonly -d *.your.domain -d your.domain --manual --preferred-challenges dns