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
package/backend/lib/session.js
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
// Operator session handling (multi-user, Google sign-in only; SQLite-backed via lib/db.js):
|
|
2
|
-
// the signed session cookie/JWT. Authorization is NOT here — it all goes through lib/authz
|
|
3
|
-
// (see docs/auth-model.md and .claude/rules/single-authz-engine.md).
|
|
4
|
-
|
|
5
|
-
const db = require('./db');
|
|
6
|
-
const jwt = require('./jwt');
|
|
7
|
-
const config = require('../config');
|
|
8
|
-
|
|
9
|
-
function createSessionToken(user) {
|
|
10
|
-
return jwt.sign(
|
|
11
|
-
{ sub: String(user.id), cv: String(user.credentials_version) },
|
|
12
|
-
config.SESSION_SECRET,
|
|
13
|
-
config.SESSION_MAX_AGE_SECONDS,
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function parseCookies(req) {
|
|
18
|
-
const header = req.headers.cookie || '';
|
|
19
|
-
const out = {};
|
|
20
|
-
header.split(';').forEach((pair) => {
|
|
21
|
-
const idx = pair.indexOf('=');
|
|
22
|
-
if (idx === -1) return;
|
|
23
|
-
out[pair.slice(0, idx).trim()] = decodeURIComponent(pair.slice(idx + 1).trim());
|
|
24
|
-
});
|
|
25
|
-
return out;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Returns the authenticated user row, or null. credentials_version is embedded per-user
|
|
29
|
-
// in the JWT (rather than one hub-wide version field) so a future per-user invalidation
|
|
30
|
-
// path only ever signs out the affected user, not everyone. jwt.verify already checks
|
|
31
|
-
// the token's own `exp` claim, so an already-issued token isn't extended just because
|
|
32
|
-
// PULSE_SESSION_MAX_AGE_SECONDS was raised after the fact — it dies at the lifetime it
|
|
33
|
-
// was actually signed with.
|
|
34
|
-
function getSessionUser(req) {
|
|
35
|
-
const token = parseCookies(req)['session'];
|
|
36
|
-
if (!token) return null;
|
|
37
|
-
const claims = jwt.verify(token, config.SESSION_SECRET);
|
|
38
|
-
if (!claims) return null;
|
|
39
|
-
const user = db.getUserById(claims.sub);
|
|
40
|
-
if (!user || String(user.credentials_version) !== claims.cv) return null;
|
|
41
|
-
return user;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
module.exports = {
|
|
45
|
-
createSessionToken,
|
|
46
|
-
parseCookies,
|
|
47
|
-
getSessionUser,
|
|
48
|
-
};
|
|
1
|
+
// Operator session handling (multi-user, Google sign-in only; SQLite-backed via lib/db.js):
|
|
2
|
+
// the signed session cookie/JWT. Authorization is NOT here — it all goes through lib/authz
|
|
3
|
+
// (see docs/auth-model.md and .claude/rules/single-authz-engine.md).
|
|
4
|
+
|
|
5
|
+
const db = require('./db');
|
|
6
|
+
const jwt = require('./jwt');
|
|
7
|
+
const config = require('../config');
|
|
8
|
+
|
|
9
|
+
function createSessionToken(user) {
|
|
10
|
+
return jwt.sign(
|
|
11
|
+
{ sub: String(user.id), cv: String(user.credentials_version) },
|
|
12
|
+
config.SESSION_SECRET,
|
|
13
|
+
config.SESSION_MAX_AGE_SECONDS,
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function parseCookies(req) {
|
|
18
|
+
const header = req.headers.cookie || '';
|
|
19
|
+
const out = {};
|
|
20
|
+
header.split(';').forEach((pair) => {
|
|
21
|
+
const idx = pair.indexOf('=');
|
|
22
|
+
if (idx === -1) return;
|
|
23
|
+
out[pair.slice(0, idx).trim()] = decodeURIComponent(pair.slice(idx + 1).trim());
|
|
24
|
+
});
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Returns the authenticated user row, or null. credentials_version is embedded per-user
|
|
29
|
+
// in the JWT (rather than one hub-wide version field) so a future per-user invalidation
|
|
30
|
+
// path only ever signs out the affected user, not everyone. jwt.verify already checks
|
|
31
|
+
// the token's own `exp` claim, so an already-issued token isn't extended just because
|
|
32
|
+
// PULSE_SESSION_MAX_AGE_SECONDS was raised after the fact — it dies at the lifetime it
|
|
33
|
+
// was actually signed with.
|
|
34
|
+
function getSessionUser(req) {
|
|
35
|
+
const token = parseCookies(req)['session'];
|
|
36
|
+
if (!token) return null;
|
|
37
|
+
const claims = jwt.verify(token, config.SESSION_SECRET);
|
|
38
|
+
if (!claims) return null;
|
|
39
|
+
const user = db.getUserById(claims.sub);
|
|
40
|
+
if (!user || String(user.credentials_version) !== claims.cv) return null;
|
|
41
|
+
return user;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
module.exports = {
|
|
45
|
+
createSessionToken,
|
|
46
|
+
parseCookies,
|
|
47
|
+
getSessionUser,
|
|
48
|
+
};
|
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
// Authorization middleware — attaches authz context and gate factory to requests
|
|
2
|
-
const crypto = require('crypto');
|
|
3
|
-
const authz = require('../lib/authz');
|
|
4
|
-
const audit = require('../lib/audit');
|
|
5
|
-
|
|
6
|
-
// Request ID middleware (should run first)
|
|
7
|
-
function requestId(req, res, next) {
|
|
8
|
-
req.id = crypto.randomUUID();
|
|
9
|
-
next();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// Attach authz context to request (runs after sessionGate)
|
|
13
|
-
function attachAuthz(req, res, next) {
|
|
14
|
-
if (!req.sessionUser) {
|
|
15
|
-
req.authz = authz.forRequest(null);
|
|
16
|
-
} else {
|
|
17
|
-
req.authz = authz.forRequest(req.sessionUser);
|
|
18
|
-
}
|
|
19
|
-
next();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Gate factory for ?instance= routes (metrics, processes, logs — plain and SSE).
|
|
23
|
-
// Requires servers.view on the instance AND `action` on it, deny-by-default: a user whose
|
|
24
|
-
// policies don't grant `action` for this instance gets a 403 and the handler never runs.
|
|
25
|
-
// Service-scoped actions (metrics.view / logs.view) may be granted only for some services,
|
|
26
|
-
// so the check can't use can(action, {instanceId}) (that has no service name to match) —
|
|
27
|
-
// it resolves the service matchers instead. On success `req.serviceMatchers` is null
|
|
28
|
-
// (unrestricted) or a non-empty matcher list the handler must apply to process/app names
|
|
29
|
-
// (see relay-state.js's filterMetricsForProcesses / serviceAllowed).
|
|
30
|
-
function gate(action) {
|
|
31
|
-
return (req, res, next) => {
|
|
32
|
-
const instanceId = req.query.instance;
|
|
33
|
-
if (!instanceId) {
|
|
34
|
-
return res.status(400).json({ error: 'Missing instance parameter' });
|
|
35
|
-
}
|
|
36
|
-
if (!req.authz.can('servers.view', { instanceId })) {
|
|
37
|
-
return res.status(403).json({ error: 'Access denied to this server' });
|
|
38
|
-
}
|
|
39
|
-
const matchers = req.authz.serviceMatchersFor(action, instanceId);
|
|
40
|
-
// null = unrestricted; [] = no rule grants `action` on this instance at all.
|
|
41
|
-
if (matchers !== null && matchers.length === 0) {
|
|
42
|
-
if (authz.ACTIONS.find((a) => a.id === action && a.powerful)) {
|
|
43
|
-
audit.record(
|
|
44
|
-
{
|
|
45
|
-
action,
|
|
46
|
-
targetType: 'instance',
|
|
47
|
-
targetId: instanceId,
|
|
48
|
-
outcome: 'denied',
|
|
49
|
-
summary: `Denied ${action}`,
|
|
50
|
-
},
|
|
51
|
-
req,
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
return res.status(403).json({ error: 'Access denied' });
|
|
55
|
-
}
|
|
56
|
-
req.serviceMatchers = matchers;
|
|
57
|
-
next();
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
module.exports = {
|
|
62
|
-
requestId,
|
|
63
|
-
attachAuthz,
|
|
64
|
-
gate,
|
|
65
|
-
};
|
|
1
|
+
// Authorization middleware — attaches authz context and gate factory to requests
|
|
2
|
+
const crypto = require('crypto');
|
|
3
|
+
const authz = require('../lib/authz');
|
|
4
|
+
const audit = require('../lib/audit');
|
|
5
|
+
|
|
6
|
+
// Request ID middleware (should run first)
|
|
7
|
+
function requestId(req, res, next) {
|
|
8
|
+
req.id = crypto.randomUUID();
|
|
9
|
+
next();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Attach authz context to request (runs after sessionGate)
|
|
13
|
+
function attachAuthz(req, res, next) {
|
|
14
|
+
if (!req.sessionUser) {
|
|
15
|
+
req.authz = authz.forRequest(null);
|
|
16
|
+
} else {
|
|
17
|
+
req.authz = authz.forRequest(req.sessionUser);
|
|
18
|
+
}
|
|
19
|
+
next();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Gate factory for ?instance= routes (metrics, processes, logs — plain and SSE).
|
|
23
|
+
// Requires servers.view on the instance AND `action` on it, deny-by-default: a user whose
|
|
24
|
+
// policies don't grant `action` for this instance gets a 403 and the handler never runs.
|
|
25
|
+
// Service-scoped actions (metrics.view / logs.view) may be granted only for some services,
|
|
26
|
+
// so the check can't use can(action, {instanceId}) (that has no service name to match) —
|
|
27
|
+
// it resolves the service matchers instead. On success `req.serviceMatchers` is null
|
|
28
|
+
// (unrestricted) or a non-empty matcher list the handler must apply to process/app names
|
|
29
|
+
// (see relay-state.js's filterMetricsForProcesses / serviceAllowed).
|
|
30
|
+
function gate(action) {
|
|
31
|
+
return (req, res, next) => {
|
|
32
|
+
const instanceId = req.query.instance;
|
|
33
|
+
if (!instanceId) {
|
|
34
|
+
return res.status(400).json({ error: 'Missing instance parameter' });
|
|
35
|
+
}
|
|
36
|
+
if (!req.authz.can('servers.view', { instanceId })) {
|
|
37
|
+
return res.status(403).json({ error: 'Access denied to this server' });
|
|
38
|
+
}
|
|
39
|
+
const matchers = req.authz.serviceMatchersFor(action, instanceId);
|
|
40
|
+
// null = unrestricted; [] = no rule grants `action` on this instance at all.
|
|
41
|
+
if (matchers !== null && matchers.length === 0) {
|
|
42
|
+
if (authz.ACTIONS.find((a) => a.id === action && a.powerful)) {
|
|
43
|
+
audit.record(
|
|
44
|
+
{
|
|
45
|
+
action,
|
|
46
|
+
targetType: 'instance',
|
|
47
|
+
targetId: instanceId,
|
|
48
|
+
outcome: 'denied',
|
|
49
|
+
summary: `Denied ${action}`,
|
|
50
|
+
},
|
|
51
|
+
req,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
return res.status(403).json({ error: 'Access denied' });
|
|
55
|
+
}
|
|
56
|
+
req.serviceMatchers = matchers;
|
|
57
|
+
next();
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
module.exports = {
|
|
62
|
+
requestId,
|
|
63
|
+
attachAuthz,
|
|
64
|
+
gate,
|
|
65
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
|
|
2
|
-
<rect width="32" height="32" rx="7" fill="#059669" />
|
|
3
|
-
<rect x="8" y="14" width="3.4" height="8" rx="1.7" fill="#ffffff" />
|
|
4
|
-
<rect x="14.3" y="7" width="3.4" height="18" rx="1.7" fill="#ffffff" />
|
|
5
|
-
<rect x="20.6" y="11" width="3.4" height="11" rx="1.7" fill="#ffffff" />
|
|
6
|
-
</svg>
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
|
|
2
|
+
<rect width="32" height="32" rx="7" fill="#059669" />
|
|
3
|
+
<rect x="8" y="14" width="3.4" height="8" rx="1.7" fill="#ffffff" />
|
|
4
|
+
<rect x="14.3" y="7" width="3.4" height="18" rx="1.7" fill="#ffffff" />
|
|
5
|
+
<rect x="20.6" y="11" width="3.4" height="11" rx="1.7" fill="#ffffff" />
|
|
6
|
+
</svg>
|