How to enable full certbot non-interactivity?

I'm trying to make a server instance script that obtains a certificate on the first boot.
I have the entire script but when I test it, the following certbot command fails by asking below:

certbot run --non-interactive --agree-tos \
--no-eff-email \
--no-redirect \
--email 'user@domain.com' \
--dns-google \
--dns-google-credentials /etc/letsencrypt/whitelabel-proxy-certbot.json \
--dns-google-propagation-seconds 120 \
--installer nginx \
--domains "*.domain.com"

This question appears even though I explicitly added --non-interactive flag:

Which server blocks would you like to modify?
File: /etc/nginx/nginx.conf
Addresses: 443 ssl, [::]:443 ssl
Names: x.domain.com
HTTPS: Yes

File: /etc/nginx/nginx.conf
Addresses: 443 ssl, [::]:443 ssl
Names: y.domain.com
HTTPS: Yes

Can I set this answer up-front so it modifies ALL blocks (I have only two) or something similar?

Thanks!

1 Like

Try changing:

to:
-d "x.domain.com,y.domain.com"

and test that out first with the added parameter:
--dry-run

Unless...
What you are really asking is "Can I get one wildcard cert but have certbot install it in more than one nginx server block (automatically)?"
To which the answer might be "no"; you may need to do some manual configuration/installation changes to have the multiple blocks all use that same cert.

1 Like

If I understand your question here, you have multiple virtualhosts for a number of subdomains, but you want a single certificate with a single wildcard hostname for all those subdomains. And certbot is asking you which nginx virtualhosts you want the certificate to be applied to, which is "YES" in all of those questions, right? Or does it ask for a list of virtualhosts? (I don't have experience with this issue to be honest.)

I'm not sure if certbot has that option. It doesn't have a separate "virtualhost" parameters to use in combination with a single wildcard certificate.

However, something I just thought of: perhaps you could run certbot twice? Once with certonly to issue the certificate with the wilcard without actually installing it and running it a second time with certbot install but this time with multiple -d options? This might trigger the nginx installer to automatically install the cert at the right virtualhosts. You should (or could, don't know if it's necessary) use --cert-name with the same certificate name for both runs, so certbot knows which certificate to install.

Edit: The above seems to work. I already had a wildcard certificate (expired, but that doesn't seem to matter to certbot :stuck_out_tongue:) for example.com (not that hostname obvious, but redacted it :wink: It's a 1:1 change, all other things are actually true :slight_smile: ) and I tried to install it:

server nginx # certbot install --nginx --cert-name example.com -d foo.example.com -d bar.example.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator None, Installer nginx
Deploying Certificate to VirtualHost /etc/nginx/nginx.conf
Deploying Certificate to VirtualHost /etc/nginx/nginx.conf

After that there were a bunch of errors about nginx not being able to listen on port 80, which is very true, as Apache was already running.. But it shows it's able to install the certificate perfectly. Without the --cert-name, it asked me which certificate I wanted to install, so I recommend that you use that too.

Also, please note that you should use persistant storage for server instances, so you don't issue new certificates every time the same instance comes up after it might been taken down. There are rate limits preventing this kind of abuse to the Let's Encrypt servers, so make sure once you've gotten a valid certificate, you store it persistantly so it can get used again when the same server instance for that domain is spun up again.

2 Likes

Thanks! Amazing answer.

I ended up with this script:

certbot certonly \
    --non-interactive \
    --agree-tos \
    --no-eff-email \
    --no-redirect \
    --email 'user@domain.com' \
    --dns-google \
    --dns-google-credentials /etc/letsencrypt/clouddns.json \
    --dns-google-propagation-seconds 120 \
    --cert-name whitelabel-proxy \
    --domains "*.domain.com"

certbot install --nginx \
    --no-redirect \
    --cert-name whitelabel-proxy \
    --domains x.domain.com \
    --domains y.domain.com
3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.