easy-devops 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -6
- package/dist/ui/assets/index-B6zdwEnG.css +1 -0
- package/dist/ui/assets/index-Cy0oNmul.js +442 -0
- package/dist/ui/assets/socket-DwLPrgsr.js +1 -0
- package/dist/ui/assets/socket-K5ttLD2q.js +65 -0
- package/dist/ui/brand/apple-touch-icon.png +0 -0
- package/dist/ui/brand/favicon-16.png +0 -0
- package/dist/ui/brand/favicon-32.png +0 -0
- package/dist/ui/brand/favicon-light-16.png +0 -0
- package/dist/ui/brand/favicon-light-32.png +0 -0
- package/dist/ui/brand/favicon.ico +0 -0
- package/dist/ui/brand/icon-192.png +0 -0
- package/dist/ui/brand/icon-48.png +0 -0
- package/dist/ui/brand/icon-512.png +0 -0
- package/dist/ui/brand/icon-64-light.png +0 -0
- package/dist/ui/brand/icon-64.png +0 -0
- package/dist/ui/brand/logo-dark.png +0 -0
- package/dist/ui/brand/logo-light.png +0 -0
- package/dist/ui/brand/mark-dark.png +0 -0
- package/dist/ui/brand/mark-light.png +0 -0
- package/dist/ui/index.html +71 -0
- package/install.ps1 +188 -1
- package/install.sh +254 -29
- package/package.json +17 -5
- package/src/cli/dash.js +110 -0
- package/src/cli/index.js +237 -106
- package/src/cli/managers/domain-manager.js +60 -40
- package/src/cli/managers/ssl-manager.js +47 -330
- package/src/cli/menu.js +156 -0
- package/src/cli/menus/cleanup.js +205 -0
- package/src/cli/menus/dashboard.js +93 -2
- package/src/cli/menus/runtime.js +236 -0
- package/src/cli/menus/service.js +764 -0
- package/src/cli/menus/settings.js +176 -8
- package/src/cli/menus/uninstall.js +167 -0
- package/src/cli/menus/update.js +221 -65
- package/src/core/acme-challenge.js +273 -0
- package/src/core/cert-operations.js +189 -0
- package/src/{dashboard/lib → core}/cert-reader.js +2 -2
- package/src/core/cert-renewal.js +494 -0
- package/src/core/channels/discord.js +77 -0
- package/src/core/channels/telegram.js +120 -0
- package/src/core/cleanup.js +600 -0
- package/src/core/config.js +169 -2
- package/src/core/daemon/ipc.js +292 -0
- package/src/core/daemon/lock.js +294 -0
- package/src/core/daemon/run.js +241 -0
- package/src/core/daemon/stopRequest.js +162 -0
- package/src/core/db.js +44 -8
- package/src/core/deploy/apps.js +491 -0
- package/src/core/deploy/domainLink.js +200 -0
- package/src/core/deploy/engine.js +973 -0
- package/src/core/deploy/ezfile.js +361 -0
- package/src/core/deploy/github.js +239 -0
- package/src/core/deploy/githubApi.js +261 -0
- package/src/core/deploy/hookServer.js +325 -0
- package/src/core/deploy/hubCommands.js +267 -0
- package/src/core/deploy/launcher.js +57 -0
- package/src/core/deploy/status.js +91 -0
- package/src/core/deploy/store.js +398 -0
- package/src/core/domainNotifier.js +364 -0
- package/src/core/domains-db.js +234 -0
- package/src/core/events.js +222 -0
- package/src/core/hub/agent.js +842 -0
- package/src/core/hubLink.js +306 -0
- package/src/core/hubPermissions.js +430 -0
- package/src/core/installSource.js +162 -0
- package/src/core/jobs/bus.js +120 -0
- package/src/core/jobs/index.js +371 -0
- package/src/core/jobs/monitors.js +368 -0
- package/src/core/jobs/owner.js +217 -0
- package/src/core/jobs/revisionWatcher.js +106 -0
- package/src/core/nginx-apply.js +213 -0
- package/src/core/nginx-conf-generator.js +253 -17
- package/src/{dashboard/lib → core}/nginx-service.js +18 -9
- package/src/core/notifications/claim.js +214 -0
- package/src/core/notifications/dispatch.js +154 -0
- package/src/core/notifier.js +103 -0
- package/src/core/passwords.js +172 -0
- package/src/core/permissions.js +8 -4
- package/src/core/platform.js +709 -2
- package/src/core/probeCache.js +258 -0
- package/src/core/purge.js +372 -0
- package/src/core/runner.js +488 -0
- package/src/core/service/acl.js +226 -0
- package/src/core/service/dataDir.js +345 -0
- package/src/core/service/index.js +1128 -0
- package/src/core/service/legacy.js +218 -0
- package/src/core/service/runtime.js +446 -0
- package/src/core/service/runtimeUpdate.js +800 -0
- package/src/core/service/systemd.js +458 -0
- package/src/core/service/windowsPersonal.js +530 -0
- package/src/core/service/windowsService.js +576 -0
- package/src/core/service/winsw.js +260 -0
- package/src/core/setupCode.js +331 -0
- package/src/core/shell.js +128 -13
- package/src/core/ssl-issuer.js +627 -0
- package/src/core/updater.js +295 -0
- package/src/core/validators.js +99 -0
- package/src/dashboard/controllers/authController.js +316 -0
- package/src/dashboard/controllers/deploymentsController.js +479 -0
- package/src/dashboard/controllers/domainsController.js +403 -0
- package/src/dashboard/controllers/hubController.js +135 -0
- package/src/dashboard/controllers/nginxController.js +146 -0
- package/src/dashboard/controllers/processesController.js +368 -0
- package/src/dashboard/controllers/settingsController.js +503 -0
- package/src/dashboard/controllers/sslController.js +452 -0
- package/src/dashboard/lib/daemonBridge.js +163 -0
- package/src/dashboard/lib/localRequest.js +235 -0
- package/src/dashboard/lib/loginRateLimit.js +119 -0
- package/src/dashboard/lib/requireAuth.js +80 -0
- package/src/dashboard/public/img/icon.png +0 -0
- package/src/dashboard/public/img/icon_b.png +0 -0
- package/src/dashboard/public/js/app.js +595 -19
- package/src/dashboard/routes/auth.js +14 -33
- package/src/dashboard/routes/deployments.js +46 -0
- package/src/dashboard/routes/domains.js +20 -363
- package/src/dashboard/routes/hub.js +22 -0
- package/src/dashboard/routes/nginx.js +22 -146
- package/src/dashboard/routes/processes.js +29 -0
- package/src/dashboard/routes/settings.js +25 -232
- package/src/dashboard/routes/ssl.js +18 -276
- package/src/dashboard/server.js +279 -165
- package/src/dashboard/socketManager.js +246 -0
- package/src/dashboard/views/index.ejs +1 -0
- package/src/dashboard/views/partials/domain-form.ejs +64 -1
- package/src/dashboard/views/partials/login.ejs +69 -8
- package/src/dashboard/views/partials/processes-panel.ejs +261 -0
- package/src/dashboard/views/partials/settings-panel.ejs +549 -118
- package/src/dashboard/views/partials/sidebar.ejs +3 -1
- package/src/dashboard/lib/domains-db.js +0 -51
- /package/src/{dashboard/routes → core/channels}/.gitkeep +0 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dashboard/controllers/authController.js
|
|
3
|
+
*
|
|
4
|
+
* Login, logout, the session check, and the first-run choice between setting
|
|
5
|
+
* a password and running without one.
|
|
6
|
+
*
|
|
7
|
+
* Rules worth stating, because each replaces something weaker:
|
|
8
|
+
*
|
|
9
|
+
* 1. An EMPTY password is never a valid login. It used to be:
|
|
10
|
+
* `password === dashboardPassword` with both empty meant anyone could
|
|
11
|
+
* sign in by leaving the box blank.
|
|
12
|
+
* 2. "No password" is now an explicit setting (dashboardAuth: 'none'), and
|
|
13
|
+
* only offered when the dashboard is bound to loopback AND the request
|
|
14
|
+
* asking for it came from this machine. An exposed dashboard can never
|
|
15
|
+
* reach that state.
|
|
16
|
+
* 3. Passwords are stored as scrypt hashes (core/passwords.js). An existing
|
|
17
|
+
* plain-text password still works, and is migrated on the next login.
|
|
18
|
+
* 4. Login is rate limited per IP.
|
|
19
|
+
* 5. First-run setup requires a one-time code printed on the server
|
|
20
|
+
* (core/setupCode.js). This endpoint is public by necessity, so without
|
|
21
|
+
* it whoever reaches a freshly started dashboard first owns it. The code
|
|
22
|
+
* itself is never in a response — a client learns only whether one is
|
|
23
|
+
* required.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import {
|
|
27
|
+
loadConfig,
|
|
28
|
+
saveConfig,
|
|
29
|
+
AUTH_MODES,
|
|
30
|
+
isNoAuthAllowed,
|
|
31
|
+
effectiveAuthMode,
|
|
32
|
+
} from '../../core/config.js';
|
|
33
|
+
import {
|
|
34
|
+
verifyPassword,
|
|
35
|
+
hashPassword,
|
|
36
|
+
needsMigration,
|
|
37
|
+
validateNewPassword,
|
|
38
|
+
MIN_PASSWORD_LENGTH,
|
|
39
|
+
} from '../../core/passwords.js';
|
|
40
|
+
import { isLoopbackAddress } from '../lib/localRequest.js';
|
|
41
|
+
import { recordAttempt, clearAttempts } from '../lib/loginRateLimit.js';
|
|
42
|
+
import * as setupCode from '../../core/setupCode.js';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The password currently in force, whatever form it is stored in.
|
|
46
|
+
* @param {Object} config
|
|
47
|
+
* @returns {string} '' when no password has been set
|
|
48
|
+
*/
|
|
49
|
+
function storedSecret(config) {
|
|
50
|
+
if (typeof config.dashboardPasswordHash === 'string' && config.dashboardPasswordHash) {
|
|
51
|
+
return config.dashboardPasswordHash;
|
|
52
|
+
}
|
|
53
|
+
if (typeof config.dashboardPassword === 'string' && config.dashboardPassword) {
|
|
54
|
+
return config.dashboardPassword;
|
|
55
|
+
}
|
|
56
|
+
return '';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** True when a password is required but none has been set yet. */
|
|
60
|
+
function needsSetup(config) {
|
|
61
|
+
return effectiveAuthMode(config) === AUTH_MODES.PASSWORD && storedSecret(config) === '';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Whether this request may choose "no password".
|
|
66
|
+
*
|
|
67
|
+
* Both halves are required. The bind address is the security property; the
|
|
68
|
+
* request's own origin is what makes "this machine only" true for the person
|
|
69
|
+
* actually clicking the button, rather than for someone who tunnelled in.
|
|
70
|
+
*
|
|
71
|
+
* @param {import('express').Request} req
|
|
72
|
+
* @param {Object} config
|
|
73
|
+
* @returns {boolean}
|
|
74
|
+
*/
|
|
75
|
+
function canUseNoPassword(req, config) {
|
|
76
|
+
return isNoAuthAllowed(config) && isLoopbackAddress(req.ip ?? req.socket?.remoteAddress);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
class AuthController {
|
|
80
|
+
/**
|
|
81
|
+
* POST /api/login
|
|
82
|
+
*/
|
|
83
|
+
async login(req, res) {
|
|
84
|
+
const config = loadConfig();
|
|
85
|
+
|
|
86
|
+
// Nothing to log into. Say so plainly rather than failing a password
|
|
87
|
+
// check that does not apply.
|
|
88
|
+
if (effectiveAuthMode(config) === AUTH_MODES.NONE) {
|
|
89
|
+
return res.status(409).json({
|
|
90
|
+
ok: false,
|
|
91
|
+
error: 'This dashboard is configured without a password.',
|
|
92
|
+
authMode: AUTH_MODES.NONE,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Counted before the password is looked at, so a wrong guess and a guess
|
|
97
|
+
// against an unset password cost the attacker the same.
|
|
98
|
+
const limit = recordAttempt(req);
|
|
99
|
+
if (!limit.allowed) {
|
|
100
|
+
res.setHeader('Retry-After', String(limit.retryAfterSeconds));
|
|
101
|
+
return res.status(429).json({
|
|
102
|
+
ok: false,
|
|
103
|
+
error: 'Too many login attempts. Try again later.',
|
|
104
|
+
retryAfterSeconds: limit.retryAfterSeconds,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const { password } = req.body ?? {};
|
|
109
|
+
|
|
110
|
+
// No password set: there is nothing to log in against. Refuse, and tell
|
|
111
|
+
// the client to run setup rather than letting a blank password through.
|
|
112
|
+
if (needsSetup(config)) {
|
|
113
|
+
return res.status(401).json({
|
|
114
|
+
ok: false,
|
|
115
|
+
error: 'No dashboard password is set. Set one to continue.',
|
|
116
|
+
needsSetup: true,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (typeof password !== 'string' || password.length === 0) {
|
|
121
|
+
return res.status(401).json({ ok: false, error: 'Invalid password' });
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const secret = storedSecret(config);
|
|
125
|
+
const ok = await verifyPassword(password, secret);
|
|
126
|
+
|
|
127
|
+
if (!ok) {
|
|
128
|
+
return res.status(401).json({ ok: false, error: 'Invalid password' });
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Upgrade a legacy plain-text password (or a weaker hash) now that we
|
|
132
|
+
// have the cleartext in hand and know it is correct.
|
|
133
|
+
if (needsMigration(secret)) {
|
|
134
|
+
try {
|
|
135
|
+
const hashed = await hashPassword(password);
|
|
136
|
+
saveConfig({
|
|
137
|
+
...loadConfig(),
|
|
138
|
+
dashboardPasswordHash: hashed,
|
|
139
|
+
// Clear the plain-text copy so it stops being readable at rest.
|
|
140
|
+
dashboardPassword: '',
|
|
141
|
+
});
|
|
142
|
+
} catch (err) {
|
|
143
|
+
// A failed migration must not block a valid login; the next one
|
|
144
|
+
// retries.
|
|
145
|
+
console.error('[auth] could not migrate the stored password:', err.message);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Prevents session fixation: a session id that an attacker planted before
|
|
150
|
+
// login must not become an authenticated one.
|
|
151
|
+
return req.session.regenerate((err) => {
|
|
152
|
+
if (err) {
|
|
153
|
+
return res.status(500).json({ ok: false, error: 'Could not start a session' });
|
|
154
|
+
}
|
|
155
|
+
req.session.authenticated = true;
|
|
156
|
+
clearAttempts(req);
|
|
157
|
+
return res.json({ ok: true });
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* GET /api/auth
|
|
163
|
+
* Public: the page needs it to decide between the login form, the first-run
|
|
164
|
+
* screen, and the dashboard itself.
|
|
165
|
+
*/
|
|
166
|
+
check(req, res) {
|
|
167
|
+
const config = loadConfig();
|
|
168
|
+
const mode = effectiveAuthMode(config);
|
|
169
|
+
|
|
170
|
+
// Whether a code is needed, and when it stops being valid. NEVER the code:
|
|
171
|
+
// see the "never leaves the machine" note in core/setupCode.js.
|
|
172
|
+
const code = setupCode.publicState();
|
|
173
|
+
|
|
174
|
+
res.json({
|
|
175
|
+
// With no password configured there is nothing to authenticate, so the
|
|
176
|
+
// page should render the dashboard rather than a login form.
|
|
177
|
+
authenticated: mode === AUTH_MODES.NONE || req.session?.authenticated === true,
|
|
178
|
+
needsSetup: needsSetup(config),
|
|
179
|
+
authMode: mode,
|
|
180
|
+
// Drives the second button on the first-run screen. False from a
|
|
181
|
+
// non-loopback request or a network-bound dashboard, so the option is
|
|
182
|
+
// never even shown where it would be unsafe.
|
|
183
|
+
canUseNoPassword: canUseNoPassword(req, config),
|
|
184
|
+
bindAddress: config.dashboardBindAddress,
|
|
185
|
+
minPasswordLength: MIN_PASSWORD_LENGTH,
|
|
186
|
+
// Only meaningful while needsSetup is true; false otherwise so a client
|
|
187
|
+
// cannot read anything into it after setup is done.
|
|
188
|
+
setupCodeRequired: needsSetup(config) && code.required,
|
|
189
|
+
setupCodeExpiresAt: needsSetup(config) ? code.expiresAt : null,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* POST /api/setup
|
|
195
|
+
* First run only. Body is either:
|
|
196
|
+
* { password: '…' } set a password (mode defaults to password)
|
|
197
|
+
* { mode: 'none' } run without one
|
|
198
|
+
*
|
|
199
|
+
* Refused once the dashboard is already configured, so it can never be used
|
|
200
|
+
* to take over an installation — changing either setting afterwards
|
|
201
|
+
* requires being signed in and goes through Settings.
|
|
202
|
+
*
|
|
203
|
+
* Setting a password also requires the one-time setup code printed on the
|
|
204
|
+
* server. `mode: 'none'` does not: that path is already restricted to a
|
|
205
|
+
* loopback bind AND a loopback request, which is a stronger constraint than
|
|
206
|
+
* the code provides.
|
|
207
|
+
*/
|
|
208
|
+
async setup(req, res) {
|
|
209
|
+
const config = loadConfig();
|
|
210
|
+
|
|
211
|
+
// "Already configured" means a password is set, or 'none' was chosen.
|
|
212
|
+
const configured =
|
|
213
|
+
effectiveAuthMode(config) === AUTH_MODES.NONE || storedSecret(config) !== '';
|
|
214
|
+
if (configured) {
|
|
215
|
+
return res.status(409).json({
|
|
216
|
+
ok: false,
|
|
217
|
+
error: 'This dashboard is already configured. Sign in, then change it in Settings.',
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const { mode, password, setupCode: submittedCode } = req.body ?? {};
|
|
222
|
+
|
|
223
|
+
if (mode === AUTH_MODES.NONE) {
|
|
224
|
+
if (!canUseNoPassword(req, config)) {
|
|
225
|
+
return res.status(400).json({
|
|
226
|
+
ok: false,
|
|
227
|
+
error: isNoAuthAllowed(config)
|
|
228
|
+
? 'Running without a password can only be chosen from this machine.'
|
|
229
|
+
: `Running without a password requires the dashboard to listen on this machine only (currently ${config.dashboardBindAddress}).`,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
saveConfig({ ...loadConfig(), dashboardAuth: AUTH_MODES.NONE });
|
|
234
|
+
return res.json({ ok: true, authMode: AUTH_MODES.NONE });
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Counted before the password is validated, and in its own budget: a
|
|
238
|
+
// guess against the code must cost the same whatever else is wrong with
|
|
239
|
+
// the request, and must not consume the login budget.
|
|
240
|
+
const limit = recordAttempt(req, Date.now(), 'setup');
|
|
241
|
+
if (!limit.allowed) {
|
|
242
|
+
res.setHeader('Retry-After', String(limit.retryAfterSeconds));
|
|
243
|
+
return res.status(429).json({
|
|
244
|
+
ok: false,
|
|
245
|
+
error: 'Too many setup attempts. Try again later.',
|
|
246
|
+
retryAfterSeconds: limit.retryAfterSeconds,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (setupCode.required()) {
|
|
251
|
+
const checked = await setupCode.verify(submittedCode);
|
|
252
|
+
if (!checked.ok) {
|
|
253
|
+
// One message for missing, wrong and malformed, so a probe cannot tell
|
|
254
|
+
// "no code was sent" from "that code was wrong". Expired and burned
|
|
255
|
+
// are told apart, because the user has to be told what to do next.
|
|
256
|
+
const message = checked.reason === 'expired'
|
|
257
|
+
? 'That setup code has expired. Issue a new one on the server: ezz dashboard setup-code'
|
|
258
|
+
: checked.burned
|
|
259
|
+
? 'Too many incorrect setup codes. Issue a new one on the server: ezz dashboard setup-code'
|
|
260
|
+
: 'That setup code is not valid.';
|
|
261
|
+
|
|
262
|
+
if (checked.burned) {
|
|
263
|
+
console.error(
|
|
264
|
+
'[auth] the first-run setup code was invalidated after '
|
|
265
|
+
+ `${checked.failures} failed attempts. Issue a new one with: ezz dashboard setup-code`,
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return res.status(400).json({ ok: false, error: message });
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const problem = validateNewPassword(password);
|
|
274
|
+
if (problem) {
|
|
275
|
+
return res.status(400).json({ ok: false, error: problem });
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
try {
|
|
279
|
+
const hashed = await hashPassword(password);
|
|
280
|
+
saveConfig({
|
|
281
|
+
...loadConfig(),
|
|
282
|
+
dashboardAuth: AUTH_MODES.PASSWORD,
|
|
283
|
+
dashboardPasswordHash: hashed,
|
|
284
|
+
dashboardPassword: '',
|
|
285
|
+
});
|
|
286
|
+
} catch (err) {
|
|
287
|
+
return res.status(500).json({ ok: false, error: 'Could not save the password' });
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Setup is done, so the code has no further purpose. Removed rather than
|
|
291
|
+
// left to expire: an outstanding credential nobody needs is one more thing
|
|
292
|
+
// that can be read.
|
|
293
|
+
setupCode.clear();
|
|
294
|
+
|
|
295
|
+
// Sign the user straight in: they have just proven they can set it.
|
|
296
|
+
return req.session.regenerate((err) => {
|
|
297
|
+
if (err) {
|
|
298
|
+
return res.status(500).json({ ok: false, error: 'Could not start a session' });
|
|
299
|
+
}
|
|
300
|
+
req.session.authenticated = true;
|
|
301
|
+
clearAttempts(req);
|
|
302
|
+
clearAttempts(req, 'setup');
|
|
303
|
+
return res.json({ ok: true, authMode: AUTH_MODES.PASSWORD });
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* POST /api/logout
|
|
309
|
+
*/
|
|
310
|
+
logout(req, res) {
|
|
311
|
+
if (!req.session) return res.json({ ok: true });
|
|
312
|
+
req.session.destroy(() => res.json({ ok: true }));
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export default AuthController;
|