Skip to content

Commit f60ffd8

Browse files
committed
Remove spammy ssl renewal process and replace with the system checker and run it every 6 hours
1 parent f10d8e4 commit f60ffd8

File tree

10 files changed

+13
-171
lines changed

10 files changed

+13
-171
lines changed

manager/src/backend/internal/host.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,6 @@ const internalHost = {
152152
// SSL was turned off or hostname for ssl has changed so we should remove certs for the original
153153
return internalSsl.deleteCerts(data.original)
154154
.then(() => {
155-
db.hosts.update({_id: data.updated._id}, {ssl_expires: 0}, {
156-
multi: false,
157-
upsert: false
158-
});
159-
data.updated.ssl_expires = 0;
160155
return data;
161156
});
162157
}

manager/src/backend/internal/ssl.js

Lines changed: 13 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
'use strict';
22

3-
const _ = require('lodash');
43
const fs = require('fs');
54
const ejs = require('ejs');
65
const timestamp = require('unix-timestamp');
7-
const batchflow = require('batchflow');
86
const internalNginx = require('./nginx');
97
const logger = require('../logger');
10-
const db = require('../db');
118
const utils = require('../lib/utils');
129
const error = require('../lib/error');
1310

1411
timestamp.round = true;
1512

1613
const internalSsl = {
1714

18-
interval_timeout: 60 * 1000,
15+
interval_timeout: 1000 * 60 * 60 * 6, // 6 hours
1916
interval: null,
2017
interval_processing: false,
2118

@@ -28,42 +25,17 @@ const internalSsl = {
2825
*/
2926
processExpiringHosts: () => {
3027
if (!internalSsl.interval_processing) {
31-
let hosts = db.hosts.find();
32-
33-
if (hosts && hosts.length) {
34-
internalSsl.interval_processing = true;
35-
36-
batchflow(hosts).sequential()
37-
.each((i, host, next) => {
38-
if ((typeof host.is_deleted === 'undefined' || !host.is_deleted) && host.ssl && typeof host.ssl_expires !== 'undefined' && !internalSsl.hasValidSslCerts(host)) {
39-
// This host is due to expire in 1 day, time to renew
40-
logger.info('Host ' + host.hostname + ' is due for SSL renewal');
41-
42-
internalSsl.renewSsl(host)
43-
.then(() => {
44-
// Certificate was requested ok, update the timestamp on the host
45-
db.hosts.update({_id: host._id}, {ssl_expires: timestamp.now('+90d')}, {
46-
multi: false,
47-
upsert: false
48-
});
49-
})
50-
.then(next)
51-
.catch(err => {
52-
logger.error(err);
53-
next(err);
54-
});
55-
} else {
56-
next();
57-
}
58-
})
59-
.error(err => {
60-
logger.error(err);
61-
internalSsl.interval_processing = false;
62-
})
63-
.end((/*results*/) => {
64-
internalSsl.interval_processing = false;
65-
});
66-
}
28+
logger.info('Renewing SSL certs close to expiry...');
29+
return utils.exec('/usr/bin/letsencrypt renew')
30+
.then(result => {
31+
logger.info(result);
32+
internalSsl.interval_processing = false;
33+
return result;
34+
})
35+
.catch(err => {
36+
logger.error(err);
37+
internalSsl.interval_processing = false;
38+
});
6739
}
6840
},
6941

@@ -73,8 +45,7 @@ const internalSsl = {
7345
*/
7446
hasValidSslCerts: host => {
7547
return fs.existsSync('/etc/letsencrypt/live/' + host.hostname + '/fullchain.pem') &&
76-
fs.existsSync('/etc/letsencrypt/live/' + host.hostname + '/privkey.pem') &&
77-
host.ssl_expires > timestamp.now('+1d');
48+
fs.existsSync('/etc/letsencrypt/live/' + host.hostname + '/privkey.pem');
7849
},
7950

8051
/**
@@ -157,10 +128,6 @@ const internalSsl = {
157128
.then(() => {
158129
return internalSsl.requestSsl(data);
159130
});
160-
})
161-
.then(() => {
162-
// Certificate was requested ok, update the timestamp on the host
163-
db.hosts.update({_id: host._id}, {ssl_expires: timestamp.now('+90d')}, {multi: false, upsert: false});
164131
});
165132
}
166133
};

manager/src/backend/routes/api/hosts.js

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -152,38 +152,4 @@ router
152152
.catch(next);
153153
});
154154

155-
/**
156-
* Renew Host Action
157-
*
158-
* /api/hosts/123/renew
159-
*/
160-
router
161-
.route('/:host_id/renew')
162-
.options((req, res) => {
163-
res.sendStatus(204);
164-
})
165-
166-
/**
167-
* POST /api/hosts/123/renew
168-
*/
169-
.post((req, res, next) => {
170-
validator({
171-
required: ['host_id'],
172-
additionalProperties: false,
173-
properties: {
174-
host_id: {
175-
$ref: 'definitions#/definitions/_id'
176-
}
177-
}
178-
}, req.params)
179-
.then(data => {
180-
return internalHost.renew(data.host_id);
181-
})
182-
.then(result => {
183-
res.status(200)
184-
.send(result);
185-
})
186-
.catch(next);
187-
});
188-
189155
module.exports = router;

manager/src/backend/schema/endpoints/hosts.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@
3838
"ssl": {
3939
"type": "boolean"
4040
},
41-
"ssl_expires": {
42-
"type": "integer",
43-
"minimum": 0,
44-
"readonly": true
45-
},
4641
"letsencrypt_email": {
4742
"type": "string",
4843
"format": "email"
@@ -252,9 +247,6 @@
252247
"ssl": {
253248
"$ref": "#/definitions/ssl"
254249
},
255-
"ssl_expires": {
256-
"$ref": "#/definitions/ssl_expires"
257-
},
258250
"letsencrypt_email": {
259251
"$ref": "#/definitions/letsencrypt_email"
260252
},

manager/src/frontend/js/app/api.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,6 @@ module.exports = {
118118
*/
119119
reconfigure: function (_id) {
120120
return fetch('post', 'hosts/' + _id + '/reconfigure');
121-
},
122-
123-
/**
124-
* @param {String} _id
125-
* @returns {Promise}
126-
*/
127-
renew: function (_id) {
128-
return fetch('post', 'hosts/' + _id + '/renew');
129121
}
130122
},
131123

manager/src/frontend/js/app/controller.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,6 @@ module.exports = {
119119
});
120120
},
121121

122-
/**
123-
* Show Renew Host
124-
*
125-
* @param model
126-
*/
127-
showRenewHost: function (model) {
128-
require(['./main', './host/renew'], function (App, View) {
129-
App.UI.showModalDialog(new View({model: model}));
130-
});
131-
},
132-
133122
/**
134123
* Show Advanced Host
135124
*

manager/src/frontend/js/app/dashboard/row.ejs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@
4242
<% } %>
4343
</td>
4444
<td class="text-right">
45-
<% if (ssl) { %>
46-
<button type="button" class="btn btn-default btn-xs renew" title="Renew SSL"><i class="fa fa-shield" aria-hidden="true"></i></button>
47-
<% } %>
4845
<button type="button" class="btn btn-default btn-xs reconfigure" title="Reconfigure Nginx"><i class="fa fa-refresh" aria-hidden="true"></i></button>
4946
<button type="button" class="btn btn-default btn-xs advanced" title="Advanced Configuration"<%- type === 'stream' ? ' disabled' : '' %>><i class="fa fa-code" aria-hidden="true"></i></button>
5047
<button type="button" class="btn btn-warning btn-xs edit" title="Edit"><i class="fa fa-pencil" aria-hidden="true"></i></button>

manager/src/frontend/js/app/dashboard/row.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ module.exports = Mn.View.extend({
1515
delete: 'button.delete',
1616
access_list: 'a.access_list',
1717
reconfigure: 'button.reconfigure',
18-
renew: 'button.renew',
1918
advanced: 'button.advanced'
2019
},
2120

@@ -53,11 +52,6 @@ module.exports = Mn.View.extend({
5352
Controller.showReconfigureHost(this.model);
5453
},
5554

56-
'click @ui.renew': function (e) {
57-
e.preventDefault();
58-
Controller.showRenewHost(this.model);
59-
},
60-
6155
'click @ui.advanced': function (e) {
6256
e.preventDefault();
6357
Controller.showAdvancedHost(this.model);

manager/src/frontend/js/app/host/renew.ejs

Lines changed: 0 additions & 17 deletions
This file was deleted.

manager/src/frontend/js/app/host/renew.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)