Trying something to fix the auto ssl renewal process

This commit is contained in:
Jamie Curnow 2018-03-16 10:32:35 +10:00
parent b38e239fa2
commit b324110c49
6 changed files with 47 additions and 18 deletions

View File

@ -26,7 +26,7 @@ const internalSsl = {
processExpiringHosts: () => {
if (!internalSsl.interval_processing) {
logger.info('Renewing SSL certs close to expiry...');
return utils.exec('/usr/bin/letsencrypt renew')
return utils.exec('/usr/bin/certbot renew --webroot=/config/letsencrypt-acme-challenge')
.then(result => {
logger.info(result);
internalSsl.interval_processing = false;
@ -55,7 +55,7 @@ const internalSsl = {
requestSsl: host => {
logger.info('Requesting SSL certificates for ' + host.hostname);
return utils.exec('/usr/bin/letsencrypt certonly --agree-tos --email "' + host.letsencrypt_email + '" -n -a webroot --webroot-path=' + host.root_path + ' -d "' + host.hostname + '"')
return utils.exec('/usr/bin/letsencrypt certonly --agree-tos --email "' + host.letsencrypt_email + '" -n -a webroot --webroot-path=/config/letsencrypt-acme-challenge -d "' + host.hostname + '"')
.then(result => {
logger.info(result);
return result;
@ -69,7 +69,7 @@ const internalSsl = {
renewSsl: host => {
logger.info('Renewing SSL certificates for ' + host.hostname);
return utils.exec('/usr/bin/letsencrypt renew --force-renewal --disable-hook-validation --cert-name "' + host.hostname + '"')
return utils.exec('/usr/bin/certbot renew --force-renewal --disable-hook-validation --webroot-path=/config/letsencrypt-acme-challenge --cert-name "' + host.hostname + '"')
.then(result => {
logger.info(result);
return result;
@ -83,7 +83,7 @@ const internalSsl = {
deleteCerts: host => {
logger.info('Deleting SSL certificates for ' + host.hostname);
return utils.exec('/usr/bin/letsencrypt delete -n --cert-name "' + host.hostname + '"')
return utils.exec('/usr/bin/certbot delete -n --cert-name "' + host.hostname + '"')
.then(result => {
logger.info(result);
})
@ -101,20 +101,17 @@ const internalSsl = {
let filename = internalNginx.getConfigName(host);
let template_data = host;
template_data.root_path = '/tmp/' + host.hostname;
return new Promise((resolve, reject) => {
try {
template = fs.readFileSync(__dirname + '/../templates/letsencrypt.conf.ejs', {encoding: 'utf8'});
let config_text = ejs.render(template, template_data);
fs.writeFileSync(filename, config_text, {encoding: 'utf8'});
return utils.exec('mkdir -p ' + template_data.root_path)
.then(() => {
try {
template = fs.readFileSync(__dirname + '/../templates/letsencrypt.conf.ejs', {encoding: 'utf8'});
let config_text = ejs.render(template, template_data);
fs.writeFileSync(filename, config_text, {encoding: 'utf8'});
return template_data;
} catch (err) {
throw new error.ConfigurationError(err.message);
}
});
resolve(template_data);
} catch (err) {
reject(new error.ConfigurationError(err.message));
}
});
},
/**

View File

@ -6,6 +6,6 @@ server {
access_log /config/logs/letsencrypt.log proxy;
location / {
root <%- root_path %>;
root /config/letsencrypt-acme-challenge;
}
}

View File

@ -14,6 +14,7 @@ server {
<%- typeof block_exploits !== 'undefined' && block_exploits ? 'include conf.d/include/block-exploits.conf;' : '' %>
<% if (typeof ssl !== 'undefined' && ssl) { -%>
include conf.d/include/letsencrypt-acme-challenge.conf;
include conf.d/include/ssl-ciphers.conf;
ssl_certificate /etc/letsencrypt/live/<%- hostname %>/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/<%- hostname %>/privkey.pem;

View File

@ -0,0 +1,25 @@
# Rule for legitimate ACME Challenge requests (like /.well-known/acme-challenge/xxxxxxxxx)
# We use ^~ here, so that we don't check other regexes (for speed-up). We actually MUST cancel
# other regex checks, because in our other config files have regex rule that denies access to files with dotted names.
location ^~ /.well-known/acme-challenge/ {
# Set correct content type. According to this:
# https://community.letsencrypt.org/t/using-the-webroot-domain-verification-method/1445/29
# Current specification requires "text/plain" or no content header at all.
# It seems that "text/plain" is a safe option.
default_type "text/plain";
# This directory must be the same as in /etc/letsencrypt/cli.ini
# as "webroot-path" parameter. Also don't forget to set "authenticator" parameter
# there to "webroot".
# Do NOT use alias, use root! Target directory is located here:
# /var/www/common/letsencrypt/.well-known/acme-challenge/
root /config/letsencrypt-acme-challenge;
}
# Hide /acme-challenge subdirectory and return 404 on all requests.
# It is somewhat more secure than letting Nginx return 403.
# Ending slash is important!
location = /.well-known/acme-challenge/ {
return 404;
}

View File

@ -1,4 +1,6 @@
#!/usr/bin/with-contenv bash
mkdir -p /config/letsencrypt-acme-challenge
cd /srv/manager
node --abort_on_uncaught_exception --max_old_space_size=250 /srv/manager/src/backend/index.js

View File

@ -0,0 +1,4 @@
text = True
non-interactive = True
authenticator = webroot
webroot-path = /config/letsencrypt-acme-challenge