pulse-hub 3.5.0 → 3.6.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/CHANGELOG.md +6 -0
- package/backend/.env.example +52 -52
- package/backend/agent.js +372 -372
- package/backend/cli.js +23 -1
- package/backend/emails/env-backup.html +52 -52
- package/backend/emails/invite.html +53 -53
- package/backend/lib/agent-rpc.js +72 -72
- package/backend/lib/async-route.js +17 -17
- package/backend/lib/authz/bootstrap.js +35 -35
- package/backend/lib/authz/catalog.js +291 -291
- package/backend/lib/authz/delegation.js +104 -104
- package/backend/lib/authz/effective.js +104 -104
- package/backend/lib/authz/engine.js +251 -251
- package/backend/lib/authz/index.js +134 -134
- package/backend/lib/authz/migrate.js +871 -871
- package/backend/lib/authz/mutate.js +87 -87
- package/backend/lib/authz/preview.js +327 -327
- package/backend/lib/authz/scope.js +282 -282
- package/backend/lib/env-mask.js +131 -131
- package/backend/lib/invite-helpers.js +83 -83
- package/backend/lib/invites.js +160 -160
- package/backend/lib/logs.js +244 -244
- package/backend/lib/metrics.js +249 -249
- package/backend/lib/relay-state.js +564 -564
- package/backend/lib/session.js +48 -48
- package/backend/middleware/authz.js +65 -65
- package/backend/public/assets/favicon.svg +6 -6
- package/backend/public/assets/index.js +1 -1
- package/backend/public/index.html +23 -24
- package/backend/routes/access.js +123 -123
- package/backend/routes/audit.js +41 -41
- package/backend/routes/auth.js +207 -207
- package/backend/routes/invites-public.js +91 -91
- package/backend/routes/invites.js +121 -121
- package/backend/routes/logs.js +68 -68
- package/backend/routes/metrics.js +76 -76
- package/backend/routes/policies.js +240 -240
- package/backend/routes/teams.js +221 -221
- package/backend/routes/users.js +100 -100
- package/backend/seed-admins.js +68 -68
- package/backend/server.js +106 -106
- package/backend/ws/agent-relay.js +159 -159
- package/package.json +1 -1
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
|
6
|
-
<link rel="icon" type="image/svg+xml" href="assets/favicon.svg">
|
|
7
|
-
<link rel="icon" href="assets/favicon.ico">
|
|
8
|
-
<title>Pulse</title>
|
|
9
|
-
<script>
|
|
10
|
-
// Applies the saved theme before first paint — without this, the page always renders
|
|
11
|
-
// with the default (light) styles for a frame and then flips, which is the visible
|
|
12
|
-
// dark-mode flash on every load/refresh that this is fixing.
|
|
13
|
-
(function () {
|
|
14
|
-
try {
|
|
15
|
-
if (localStorage.getItem('monitor-theme') !== 'light') document.documentElement.classList.add('dark');
|
|
16
|
-
} catch (e) { document.documentElement.classList.add('dark'); }
|
|
17
|
-
})();
|
|
18
|
-
</script>
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
|
6
|
+
<link rel="icon" type="image/svg+xml" href="assets/favicon.svg">
|
|
7
|
+
<link rel="icon" href="assets/favicon.ico">
|
|
8
|
+
<title>Pulse</title>
|
|
9
|
+
<script>
|
|
10
|
+
// Applies the saved theme before first paint — without this, the page always renders
|
|
11
|
+
// with the default (light) styles for a frame and then flips, which is the visible
|
|
12
|
+
// dark-mode flash on every load/refresh that this is fixing.
|
|
13
|
+
(function () {
|
|
14
|
+
try {
|
|
15
|
+
if (localStorage.getItem('monitor-theme') !== 'light') document.documentElement.classList.add('dark');
|
|
16
|
+
} catch (e) { document.documentElement.classList.add('dark'); }
|
|
17
|
+
})();
|
|
18
|
+
</script>
|
|
19
19
|
<script type="module" crossorigin src="./assets/index.js"></script>
|
|
20
20
|
<link rel="stylesheet" crossorigin href="./assets/index.css">
|
|
21
|
-
</head>
|
|
22
|
-
<body>
|
|
23
|
-
<div id="root"></div>
|
|
24
|
-
|
|
25
|
-
</
|
|
26
|
-
</html>
|
|
21
|
+
</head>
|
|
22
|
+
<body>
|
|
23
|
+
<div id="root"></div>
|
|
24
|
+
</body>
|
|
25
|
+
</html>
|
package/backend/routes/access.js
CHANGED
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
// Access visibility and review: the permission catalog, impact preview, "what can X access",
|
|
2
|
-
// and the root-only review queue left behind by the legacy-permissions migration.
|
|
3
|
-
|
|
4
|
-
const express = require('express');
|
|
5
|
-
const db = require('../lib/db');
|
|
6
|
-
const store = require('../lib/authz-store');
|
|
7
|
-
const audit = require('../lib/audit');
|
|
8
|
-
const { ACTIONS } = require('../lib/authz/catalog');
|
|
9
|
-
const { forbidden, readJsonBody } = require('../lib/http-helpers');
|
|
10
|
-
const { sendJson } = require('../lib/authz/mutate');
|
|
11
|
-
const previewLib = require('../lib/authz/preview');
|
|
12
|
-
const { effectiveAccess } = require('../lib/authz/effective');
|
|
13
|
-
|
|
14
|
-
const router = express.Router();
|
|
15
|
-
|
|
16
|
-
// The UI never keeps its own action list — it renders from this.
|
|
17
|
-
router.get('/api/authz/catalog', (req, res) => {
|
|
18
|
-
sendJson(res, 200, {
|
|
19
|
-
actions: ACTIONS.map((a) => ({
|
|
20
|
-
id: a.id,
|
|
21
|
-
feature: a.feature,
|
|
22
|
-
label: a.label,
|
|
23
|
-
description: a.description,
|
|
24
|
-
powerful: !!a.powerful,
|
|
25
|
-
scopeKind: a.scopeKind,
|
|
26
|
-
implies: a.implies,
|
|
27
|
-
})),
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
// Preview needs the permission of the mutation it previews.
|
|
32
|
-
const PREVIEW_PERMISSION = {
|
|
33
|
-
'team.members.set': 'teams.members.manage',
|
|
34
|
-
'team.policies.set': 'teams.policies.manage',
|
|
35
|
-
'policy.update': 'policies.update',
|
|
36
|
-
'policy.delete': 'policies.delete',
|
|
37
|
-
'team.delete': 'teams.delete',
|
|
38
|
-
'access-tags.set': 'servers.tags.manage',
|
|
39
|
-
'invite.create': 'people.invite',
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
router.post('/api/access/preview', async (req, res) => {
|
|
43
|
-
const body = await readJsonBody(req);
|
|
44
|
-
const change = body.change && { ...body.change };
|
|
45
|
-
// The UI sends a generic `id` (the team/policy being changed); the engine wants named keys.
|
|
46
|
-
if (change && change.id !== undefined) {
|
|
47
|
-
if (change.kind && change.kind.startsWith('team.') && change.teamId === undefined)
|
|
48
|
-
change.teamId = change.id;
|
|
49
|
-
if (change.kind && change.kind.startsWith('policy.') && change.policyId === undefined)
|
|
50
|
-
change.policyId = change.id;
|
|
51
|
-
}
|
|
52
|
-
if (!change || !previewLib.CHANGE_KINDS.includes(change.kind))
|
|
53
|
-
return sendJson(res, 400, { error: 'Unknown change kind.' });
|
|
54
|
-
const needed = PREVIEW_PERMISSION[change.kind];
|
|
55
|
-
const allowed =
|
|
56
|
-
change.kind === 'access-tags.set'
|
|
57
|
-
? req.authz.can(needed, { instanceId: change.instanceId })
|
|
58
|
-
: req.authz.can(needed);
|
|
59
|
-
if (!allowed) return forbidden(res, 'You do not have permission to preview that change.');
|
|
60
|
-
try {
|
|
61
|
-
sendJson(res, 200, previewLib.preview(change, req.authz.subject));
|
|
62
|
-
} catch (e) {
|
|
63
|
-
sendJson(res, 400, { error: e.message });
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
router.get('/api/me/access', (req, res) => {
|
|
68
|
-
sendJson(res, 200, effectiveAccess(req.sessionUser));
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
router.get('/api/users/:id/access', (req, res) => {
|
|
72
|
-
const target = db.getUserById(req.params.id);
|
|
73
|
-
if (!target) return sendJson(res, 404, { error: 'No such user.' });
|
|
74
|
-
if (target.id !== req.sessionUser.id && !req.authz.can('people.view'))
|
|
75
|
-
return forbidden(res, 'You do not have permission to view that.');
|
|
76
|
-
sendJson(res, 200, effectiveAccess(target));
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
// ---- review items (root only) ----
|
|
80
|
-
|
|
81
|
-
function requireRoot(req, res) {
|
|
82
|
-
if (req.sessionUser.is_root) return true;
|
|
83
|
-
forbidden(res, 'Only a root user can review migrated access.');
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function shapeItem(i) {
|
|
88
|
-
return {
|
|
89
|
-
id: i.id,
|
|
90
|
-
kind: i.kind,
|
|
91
|
-
userId: i.user_id,
|
|
92
|
-
instanceId: i.instance_id,
|
|
93
|
-
envFileId: i.env_file_id,
|
|
94
|
-
detail: i.detail,
|
|
95
|
-
status: i.status,
|
|
96
|
-
createdAt: i.created_at,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
router.get('/api/access/review', (req, res) => {
|
|
101
|
-
if (!requireRoot(req, res)) return;
|
|
102
|
-
sendJson(res, 200, store.listReviewItems({ status: req.query.status || 'open' }).map(shapeItem));
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
router.post('/api/access/review/:id/resolve', (req, res) => {
|
|
106
|
-
if (!requireRoot(req, res)) return;
|
|
107
|
-
const item = store.getReviewItem(req.params.id);
|
|
108
|
-
if (!item) return sendJson(res, 404, { error: 'No such review item.' });
|
|
109
|
-
store.resolveReviewItem(item.id, req.sessionUser.id);
|
|
110
|
-
audit.record(
|
|
111
|
-
{
|
|
112
|
-
action: 'access.review.resolve',
|
|
113
|
-
targetType: 'review_item',
|
|
114
|
-
targetId: item.id,
|
|
115
|
-
outcome: 'succeeded',
|
|
116
|
-
summary: `Resolved review item (${item.kind})`,
|
|
117
|
-
},
|
|
118
|
-
req,
|
|
119
|
-
);
|
|
120
|
-
sendJson(res, 200, { ok: true });
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
module.exports = router;
|
|
1
|
+
// Access visibility and review: the permission catalog, impact preview, "what can X access",
|
|
2
|
+
// and the root-only review queue left behind by the legacy-permissions migration.
|
|
3
|
+
|
|
4
|
+
const express = require('express');
|
|
5
|
+
const db = require('../lib/db');
|
|
6
|
+
const store = require('../lib/authz-store');
|
|
7
|
+
const audit = require('../lib/audit');
|
|
8
|
+
const { ACTIONS } = require('../lib/authz/catalog');
|
|
9
|
+
const { forbidden, readJsonBody } = require('../lib/http-helpers');
|
|
10
|
+
const { sendJson } = require('../lib/authz/mutate');
|
|
11
|
+
const previewLib = require('../lib/authz/preview');
|
|
12
|
+
const { effectiveAccess } = require('../lib/authz/effective');
|
|
13
|
+
|
|
14
|
+
const router = express.Router();
|
|
15
|
+
|
|
16
|
+
// The UI never keeps its own action list — it renders from this.
|
|
17
|
+
router.get('/api/authz/catalog', (req, res) => {
|
|
18
|
+
sendJson(res, 200, {
|
|
19
|
+
actions: ACTIONS.map((a) => ({
|
|
20
|
+
id: a.id,
|
|
21
|
+
feature: a.feature,
|
|
22
|
+
label: a.label,
|
|
23
|
+
description: a.description,
|
|
24
|
+
powerful: !!a.powerful,
|
|
25
|
+
scopeKind: a.scopeKind,
|
|
26
|
+
implies: a.implies,
|
|
27
|
+
})),
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Preview needs the permission of the mutation it previews.
|
|
32
|
+
const PREVIEW_PERMISSION = {
|
|
33
|
+
'team.members.set': 'teams.members.manage',
|
|
34
|
+
'team.policies.set': 'teams.policies.manage',
|
|
35
|
+
'policy.update': 'policies.update',
|
|
36
|
+
'policy.delete': 'policies.delete',
|
|
37
|
+
'team.delete': 'teams.delete',
|
|
38
|
+
'access-tags.set': 'servers.tags.manage',
|
|
39
|
+
'invite.create': 'people.invite',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
router.post('/api/access/preview', async (req, res) => {
|
|
43
|
+
const body = await readJsonBody(req);
|
|
44
|
+
const change = body.change && { ...body.change };
|
|
45
|
+
// The UI sends a generic `id` (the team/policy being changed); the engine wants named keys.
|
|
46
|
+
if (change && change.id !== undefined) {
|
|
47
|
+
if (change.kind && change.kind.startsWith('team.') && change.teamId === undefined)
|
|
48
|
+
change.teamId = change.id;
|
|
49
|
+
if (change.kind && change.kind.startsWith('policy.') && change.policyId === undefined)
|
|
50
|
+
change.policyId = change.id;
|
|
51
|
+
}
|
|
52
|
+
if (!change || !previewLib.CHANGE_KINDS.includes(change.kind))
|
|
53
|
+
return sendJson(res, 400, { error: 'Unknown change kind.' });
|
|
54
|
+
const needed = PREVIEW_PERMISSION[change.kind];
|
|
55
|
+
const allowed =
|
|
56
|
+
change.kind === 'access-tags.set'
|
|
57
|
+
? req.authz.can(needed, { instanceId: change.instanceId })
|
|
58
|
+
: req.authz.can(needed);
|
|
59
|
+
if (!allowed) return forbidden(res, 'You do not have permission to preview that change.');
|
|
60
|
+
try {
|
|
61
|
+
sendJson(res, 200, previewLib.preview(change, req.authz.subject));
|
|
62
|
+
} catch (e) {
|
|
63
|
+
sendJson(res, 400, { error: e.message });
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
router.get('/api/me/access', (req, res) => {
|
|
68
|
+
sendJson(res, 200, effectiveAccess(req.sessionUser));
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
router.get('/api/users/:id/access', (req, res) => {
|
|
72
|
+
const target = db.getUserById(req.params.id);
|
|
73
|
+
if (!target) return sendJson(res, 404, { error: 'No such user.' });
|
|
74
|
+
if (target.id !== req.sessionUser.id && !req.authz.can('people.view'))
|
|
75
|
+
return forbidden(res, 'You do not have permission to view that.');
|
|
76
|
+
sendJson(res, 200, effectiveAccess(target));
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// ---- review items (root only) ----
|
|
80
|
+
|
|
81
|
+
function requireRoot(req, res) {
|
|
82
|
+
if (req.sessionUser.is_root) return true;
|
|
83
|
+
forbidden(res, 'Only a root user can review migrated access.');
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function shapeItem(i) {
|
|
88
|
+
return {
|
|
89
|
+
id: i.id,
|
|
90
|
+
kind: i.kind,
|
|
91
|
+
userId: i.user_id,
|
|
92
|
+
instanceId: i.instance_id,
|
|
93
|
+
envFileId: i.env_file_id,
|
|
94
|
+
detail: i.detail,
|
|
95
|
+
status: i.status,
|
|
96
|
+
createdAt: i.created_at,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
router.get('/api/access/review', (req, res) => {
|
|
101
|
+
if (!requireRoot(req, res)) return;
|
|
102
|
+
sendJson(res, 200, store.listReviewItems({ status: req.query.status || 'open' }).map(shapeItem));
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
router.post('/api/access/review/:id/resolve', (req, res) => {
|
|
106
|
+
if (!requireRoot(req, res)) return;
|
|
107
|
+
const item = store.getReviewItem(req.params.id);
|
|
108
|
+
if (!item) return sendJson(res, 404, { error: 'No such review item.' });
|
|
109
|
+
store.resolveReviewItem(item.id, req.sessionUser.id);
|
|
110
|
+
audit.record(
|
|
111
|
+
{
|
|
112
|
+
action: 'access.review.resolve',
|
|
113
|
+
targetType: 'review_item',
|
|
114
|
+
targetId: item.id,
|
|
115
|
+
outcome: 'succeeded',
|
|
116
|
+
summary: `Resolved review item (${item.kind})`,
|
|
117
|
+
},
|
|
118
|
+
req,
|
|
119
|
+
);
|
|
120
|
+
sendJson(res, 200, { ok: true });
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
module.exports = router;
|
package/backend/routes/audit.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
// Audit log query (audit.view). Keyset-paginated on id, newest first.
|
|
2
|
-
|
|
3
|
-
const express = require('express');
|
|
4
|
-
const audit = require('../lib/audit');
|
|
5
|
-
const { forbidden } = require('../lib/http-helpers');
|
|
6
|
-
const { sendJson } = require('../lib/authz/mutate');
|
|
7
|
-
|
|
8
|
-
const router = express.Router();
|
|
9
|
-
|
|
10
|
-
router.get('/api/audit', (req, res) => {
|
|
11
|
-
if (!req.authz.can('audit.view')) return forbidden(res, 'You do not have permission to do that.');
|
|
12
|
-
const limit = Math.min(200, Math.max(1, parseInt(req.query.limit, 10) || 50));
|
|
13
|
-
const before = parseInt(req.query.before, 10) || null;
|
|
14
|
-
const rows = audit.query({
|
|
15
|
-
actor: req.query.actor || null,
|
|
16
|
-
instanceId: req.query.instanceId || null,
|
|
17
|
-
action: req.query.action || null,
|
|
18
|
-
outcome: req.query.outcome || null,
|
|
19
|
-
before,
|
|
20
|
-
limit: limit + 1,
|
|
21
|
-
});
|
|
22
|
-
const page = rows.slice(0, limit);
|
|
23
|
-
sendJson(res, 200, {
|
|
24
|
-
events: page.map((r) => ({
|
|
25
|
-
id: r.id,
|
|
26
|
-
ts: r.ts,
|
|
27
|
-
actorUserId: r.actor_user_id,
|
|
28
|
-
actorLabel: r.actor_label,
|
|
29
|
-
action: r.action,
|
|
30
|
-
targetType: r.target_type,
|
|
31
|
-
targetId: r.target_id,
|
|
32
|
-
instanceId: r.instance_id,
|
|
33
|
-
outcome: r.outcome,
|
|
34
|
-
summary: r.summary,
|
|
35
|
-
requestId: r.request_id,
|
|
36
|
-
})),
|
|
37
|
-
nextBefore: rows.length > limit ? page[page.length - 1].id : null,
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
module.exports = router;
|
|
1
|
+
// Audit log query (audit.view). Keyset-paginated on id, newest first.
|
|
2
|
+
|
|
3
|
+
const express = require('express');
|
|
4
|
+
const audit = require('../lib/audit');
|
|
5
|
+
const { forbidden } = require('../lib/http-helpers');
|
|
6
|
+
const { sendJson } = require('../lib/authz/mutate');
|
|
7
|
+
|
|
8
|
+
const router = express.Router();
|
|
9
|
+
|
|
10
|
+
router.get('/api/audit', (req, res) => {
|
|
11
|
+
if (!req.authz.can('audit.view')) return forbidden(res, 'You do not have permission to do that.');
|
|
12
|
+
const limit = Math.min(200, Math.max(1, parseInt(req.query.limit, 10) || 50));
|
|
13
|
+
const before = parseInt(req.query.before, 10) || null;
|
|
14
|
+
const rows = audit.query({
|
|
15
|
+
actor: req.query.actor || null,
|
|
16
|
+
instanceId: req.query.instanceId || null,
|
|
17
|
+
action: req.query.action || null,
|
|
18
|
+
outcome: req.query.outcome || null,
|
|
19
|
+
before,
|
|
20
|
+
limit: limit + 1,
|
|
21
|
+
});
|
|
22
|
+
const page = rows.slice(0, limit);
|
|
23
|
+
sendJson(res, 200, {
|
|
24
|
+
events: page.map((r) => ({
|
|
25
|
+
id: r.id,
|
|
26
|
+
ts: r.ts,
|
|
27
|
+
actorUserId: r.actor_user_id,
|
|
28
|
+
actorLabel: r.actor_label,
|
|
29
|
+
action: r.action,
|
|
30
|
+
targetType: r.target_type,
|
|
31
|
+
targetId: r.target_id,
|
|
32
|
+
instanceId: r.instance_id,
|
|
33
|
+
outcome: r.outcome,
|
|
34
|
+
summary: r.summary,
|
|
35
|
+
requestId: r.request_id,
|
|
36
|
+
})),
|
|
37
|
+
nextBefore: rows.length > limit ? page[page.length - 1].id : null,
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
module.exports = router;
|