I have a certbot server that pushes certs to servers. In the case of a couple, it can't get the private key into the directory (/etc/ssl/private). I can not run commands as root, but must run as user certbot. I have tried to copy to /tmp and /home/certbot on the destination Apache server, but this fails too.
How do people copy cert and privkey to Apache servers, and restart Apache? No matter how permissive I make the destination dir, it won't copy (rsync).
My domain is: ipa.prd.locatnet.io
I ran this command: su certbot -c "rsync -azvL /etc/letsencrypt/live/ipa.prd.localnet.io/privkey.pem ply-jenkins01.ipa.prd.localnet.io:/home/certbot"
It produced this output: rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1207) [sender=3.1.3]
My web server is (include version): Apache/2.4.18 (Ubuntu)
The operating system my web server runs on is (include version): Ubuntu 16.04.3 LTS
My hosting provider, if applicable, is: NA
I can login to a root shell on my machine (yes or no, or I don't know): yes
I'm using a control panel to manage my site (no, or provide the name and version of the control panel): NO
The version of my client is (e.g. output of certbot --version or certbot-auto --version if you're using Certbot): certbot 1.27.0
The live pem is a symlink to the file in archive, which is
4 -rw------- 1 root root 1708 Dec 19 17:06 privkey1.pem
Yes, the target file on the Jenkins/Apache server is there in /etc/ssl/private from my manual copy of the file. Until now I have been manually putting the cert and priv key files on the Jenkins server, and restarting Apache, but trying to automate it.
I think the issue is, for whatever reason, when certbot creates the cert for this domain, it has different perms than certs created for other domains on this same certbot server.
Push - I write a script using Fabric (https://www.fabfile.org/) to automatically SSH into the remote server and restart apache. That is invoked as a Certbot hook.
Pull - The remote servers have a cronjob. They poll for new certificates, and copy/restart as needed.
For large systems, I use nginx to dynamically load (or request) certificates from an internal HTTP API and cache them into the server for a few hours.
In your situation... you could potentially run Certbot as a certbot user with an alternate --config-dir, and have a cronjob reset permissions on that directory (if needed). This works well if you run Certbot in standalone mode on a higher port (-http-01-port=8080) and then proxy the ./well-known/acme-challenge traffic onto that higher port.
the recommendation to copy the source private key, and manipulate that file (and leave ownership & permissions alone on the orig /etc/letsencrypt/ alone) worked.
I copied the priv key to a new file name in /etc/letsencrypt/live/, and altered it's permissions, such that I can now remote cp it. I then do some other remote commands on the client to get the file where it needs to be, and with the right ownership/permissions, and am able to reload Apache2.