大网数据广告活动
服务器运维问答

give systemd service access to certificates in protected folder

· 52CE 我爱测

I use certbot to generate certificate files. The certificate files are created in /etc/letsencrypt/live/... . The live folder is created by certbot and is only accessible to admins. In the past, I then copied these files to the f…

问题原文

原帖链接 · bvdb · CC BY-SA 4.0

I use certbot to generate certificate files. The certificate files are created in /etc/letsencrypt/live/.... The live folder is created by certbot and is only accessible to admins.

In the past, I then copied these files to the folder of my application, and that worked fine. But it felt wrong to copy the certificate files.

So, I am wondering if there is a possibility to leave the files where they are. I tried to put this in practice, but I am struggling to give my application access to the folder. I had no problems adjusting the paths, but it has no privileges to access the folder.

I am wondering how I can give my application access to the files.

The application is launched using a systemd configuration file. I originally had this systemd config:

[Unit]
Description=my-service
Documentation=http://documentation.domain.com
After=network.target

[Service]
Type=simple
TimeoutSec=0
User=ubuntu
ExecStart=/usr/bin/node /home/ubuntu/my-service/server.js
Restart=on-failure

[Install]
WantedBy=multi-user.target

I tried adding the following line, but it made no difference.

PermissionsStartOnly=true

已采纳解答

原帖链接 · Anderson Medeiros Gomes · CC BY-SA 4.0

I don't think that copying certificate files from /etc/letsencrypt/live to an application's folder is wrong. I suggest you to do so by defining a custom script in /etc/letsencrypt/renewal-hooks/deploy folder, which would also reload the application each time the corresponding certificate is renewed. For example:

#!/bin/sh

# /etc/letsencrypt/renewal-hooks/deploy/example-com_deploy.sh

set -e

for domain in $RENEWED_DOMAINS; do
        case $domain in
        example.com)
                daemon_cert_root=/etc/some-daemon/certs

                # Make sure the certificate and private key files are
                # never world readable, even just for an instant while
                # we're copying them into daemon_cert_root.
                umask 077

                cp "$RENEWED_LINEAGE/fullchain.pem" "$daemon_cert_root/$domain.cert"
                cp "$RENEWED_LINEAGE/privkey.pem" "$daemon_cert_root/$domain.key"

                # Apply the proper file ownership and permissions for
                # the daemon to read its certificate and key.
                chown some-daemon "$daemon_cert_root/$domain.cert" \
                        "$daemon_cert_root/$domain.key"
                chmod 400 "$daemon_cert_root/$domain.cert" \
                        "$daemon_cert_root/$domain.key"

                service some-daemon restart >/dev/null
                ;;
        esac
done

Please, check this URL for details: https://certbot.eff.org/docs/using.html#renewing-certificates

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-10-11)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。