emailengine-app 2.80.0 → 2.80.1
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/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +24 -0
- package/README.md +6 -0
- package/data/google-crawlers.json +1 -1
- package/lib/api-routes/account-routes.js +81 -1
- package/lib/api-routes/blocklist-routes.js +24 -0
- package/lib/api-routes/delivery-test-routes.js +6 -0
- package/lib/api-routes/gateway-routes.js +30 -0
- package/lib/api-routes/license-routes.js +10 -0
- package/lib/api-routes/mcp-oauth-routes.js +3 -3
- package/lib/api-routes/mcp-routes.js +39 -21
- package/lib/api-routes/oauth2-app-routes.js +38 -1
- package/lib/api-routes/outbox-routes.js +6 -0
- package/lib/api-routes/permission-map.js +208 -43
- package/lib/api-routes/pubsub-routes.js +8 -0
- package/lib/api-routes/route-helpers.js +58 -11
- package/lib/api-routes/settings-routes.js +50 -4
- package/lib/api-routes/stats-routes.js +6 -0
- package/lib/api-routes/template-routes.js +21 -0
- package/lib/api-routes/token-routes.js +34 -2
- package/lib/api-routes/webhook-route-routes.js +13 -0
- package/lib/email-client/base-client.js +6 -3
- package/lib/email-client/credential-errors.js +4 -0
- package/lib/email-client/imap/login-failure.js +52 -0
- package/lib/email-client/imap/subconnection.js +2 -1
- package/lib/email-client/imap-client.js +3 -6
- package/lib/enum-descriptions.js +12 -2
- package/lib/imapproxy/imap-server.js +1 -1
- package/lib/mcp/oauth.js +46 -8
- package/lib/mcp/protocol.js +78 -35
- package/lib/mcp/tools.js +53 -17
- package/lib/privileged-settings.js +147 -0
- package/lib/schemas.js +60 -16
- package/lib/settings.js +13 -0
- package/lib/tls/catalog.js +428 -0
- package/lib/tls/context.js +87 -161
- package/lib/tls/listeners.js +62 -0
- package/lib/tls/status.js +128 -79
- package/lib/tls/store.js +3 -2
- package/lib/token-permission-view.js +252 -102
- package/lib/token-permissions.js +176 -26
- package/lib/tokens.js +7 -6
- package/lib/tools.js +4 -3
- package/lib/ui-routes/admin-config-routes.js +41 -21
- package/lib/ui-routes/admin-entities-routes.js +23 -13
- package/lib/ui-routes/mcp-consent-routes.js +72 -31
- package/lib/ui-routes/tls-config-routes.js +121 -74
- package/package.json +12 -12
- package/sbom.json +1 -1
- package/server.js +7 -1
- package/static/css/flyonui.css +1 -1
- package/static/js/ui.js +89 -36
- package/static/licenses.html +46 -28
- package/translations/messages.pot +74 -68
- package/views/account/login-redirect.hbs +1 -1
- package/views/account/passkeys.hbs +2 -2
- package/views/accounts/account.hbs +2 -2
- package/views/accounts/browse.hbs +1 -1
- package/views/accounts/edit.hbs +1 -1
- package/views/accounts/register/imap-server.hbs +1 -1
- package/views/config/ai.hbs +1 -1
- package/views/config/branding.hbs +2 -2
- package/views/config/document-store/chat.hbs +1 -1
- package/views/config/document-store/index.hbs +1 -1
- package/views/config/imap-proxy.hbs +1 -1
- package/views/config/license.hbs +1 -1
- package/views/config/mcp.hbs +88 -52
- package/views/config/network.hbs +1 -1
- package/views/config/oauth/app.hbs +2 -2
- package/views/config/service.hbs +1 -1
- package/views/config/smtp.hbs +1 -1
- package/views/config/tls.hbs +266 -165
- package/views/config/webhooks.hbs +2 -2
- package/views/internals/index.hbs +1 -1
- package/views/layout/app.hbs +6 -6
- package/views/layout/login.hbs +5 -5
- package/views/layout/main.hbs +2 -2
- package/views/layout/prompt.hbs +3 -3
- package/views/layout/public.hbs +1 -1
- package/views/mcp/authorize.hbs +47 -45
- package/views/partials/ace_assets.hbs +1 -1
- package/views/partials/add_account_modal.hbs +1 -1
- package/views/partials/filter_editor_js.hbs +2 -2
- package/views/partials/gateway_js.hbs +1 -1
- package/views/partials/mcp_access_levels.hbs +16 -9
- package/views/partials/mcp_tool_count.hbs +15 -14
- package/views/partials/oauth_form.hbs +1 -1
- package/views/partials/public_theme_init.hbs +1 -1
- package/views/partials/template_form.hbs +1 -1
- package/views/partials/theme_init.hbs +1 -1
- package/views/partials/webhooks_editor_functions.hbs +1 -1
- package/views/reference/index.hbs +1 -1
- package/views/reference/redirect.hbs +1 -1
- package/views/reference/tag.hbs +1 -1
- package/views/reference/token.hbs +1 -1
- package/views/templates/template.hbs +1 -1
- package/views/tokens/new.hbs +175 -74
- package/views/unsubscribe.hbs +1 -1
- package/views/webhooks/webhook.hbs +1 -1
- package/workers/api.js +9 -8
- package/workers/smtp.js +1 -1
package/lib/token-permissions.js
CHANGED
|
@@ -2,18 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
// Narrowing check for an access token that carries a `permissions` record.
|
|
4
4
|
//
|
|
5
|
-
// Two
|
|
6
|
-
// touch, and
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
5
|
+
// Two forms, both subtractive. The two-axis form is the original: `actions` says what the token may
|
|
6
|
+
// do, `groups` says what it may touch, and an operation has to pass both, so the record means the
|
|
7
|
+
// cross product of the two lists. The pair-list form, `grants`, names exact (action, group) pairs
|
|
8
|
+
// instead, for the narrowing the cross product cannot express - read on one section and write on
|
|
9
|
+
// another - and stands alone: a record carrying it beside an axis is refused rather than
|
|
10
|
+
// intersected. The vocabulary for both lives in lib/api-routes/permission-map.js. This function
|
|
11
|
+
// only ever SUBTRACTS from what `scopes` and the account binding already allow - there is no value
|
|
12
|
+
// of `permissions` that grants anything, so it is safe to run after those checks rather than
|
|
13
|
+
// instead of them.
|
|
14
|
+
//
|
|
15
|
+
// An absent `actions` axis means every action. An absent `groups` axis means IMPLICIT_GROUPS - the
|
|
16
|
+
// sections that existed when the two-axis form shipped - and NOT every grantable group: the groups
|
|
17
|
+
// the admin split made grantable have to be named, so a record written before they existed keeps
|
|
18
|
+
// exactly the reach it had.
|
|
10
19
|
//
|
|
11
20
|
// Shared by both enforcement points on the same precedent that put lib/auth-token.js in one place:
|
|
12
21
|
// the api-token strategy in workers/api.js for HTTP, and lib/auth-token.js for the SMTP submission
|
|
13
22
|
// and IMAP proxy surfaces. A policy change that landed on one and missed the other would be a hole
|
|
14
23
|
// in whichever surface was forgotten.
|
|
15
24
|
|
|
16
|
-
const { NEVER_GRANTABLE, ACTION_VALUES, GROUP_VALUES } = require('./api-routes/permission-map');
|
|
25
|
+
const { NEVER_GRANTABLE, ACTION_VALUES, GROUP_VALUES, IMPLICIT_GROUPS, grantKey } = require('./api-routes/permission-map');
|
|
26
|
+
|
|
27
|
+
// One parse per record object. check() runs once per tool for every tools/list and once per
|
|
28
|
+
// MCP-dispatched request, over the same msgpack-decoded record each time, and the pair-list form
|
|
29
|
+
// validates and copies every entry on each parse. Keyed weakly on the record object itself, so a
|
|
30
|
+
// record lives in the cache exactly as long as the token data it came from; primitives (which
|
|
31
|
+
// are always malformed) are not cached and cost nothing to re-read.
|
|
32
|
+
const parsedRecords = new WeakMap();
|
|
17
33
|
|
|
18
34
|
// The axes a record may carry, and the vocabulary each accepts. Anything else is a record this
|
|
19
35
|
// version does not understand.
|
|
@@ -24,6 +40,15 @@ const AXIS_VALUES = {
|
|
|
24
40
|
|
|
25
41
|
const AXES = Object.keys(AXIS_VALUES);
|
|
26
42
|
|
|
43
|
+
// The pair-list form. Listed apart from the axes because it is not one: it replaces both.
|
|
44
|
+
const GRANTS_KEY = 'grants';
|
|
45
|
+
const RECORD_KEYS = AXES.concat(GRANTS_KEY);
|
|
46
|
+
|
|
47
|
+
// The two keys a grant entry carries, and no other. An entry with an extra key is refused the same
|
|
48
|
+
// way a record with an extra axis is: a later version may give the pair a third field, and this
|
|
49
|
+
// one must deny rather than honour the two halves it understands.
|
|
50
|
+
const GRANT_KEYS = ['action', 'group'];
|
|
51
|
+
|
|
27
52
|
// Why a request was refused. Reported to the caller rather than rendered here, because HTTP, SMTP
|
|
28
53
|
// and IMAP each say "no" differently.
|
|
29
54
|
const REASON = {
|
|
@@ -40,9 +65,52 @@ const REASON = {
|
|
|
40
65
|
RESTRICTED: 'restricted',
|
|
41
66
|
|
|
42
67
|
ACTION: 'action',
|
|
43
|
-
GROUP: 'group'
|
|
68
|
+
GROUP: 'group',
|
|
69
|
+
|
|
70
|
+
// No pair in a `grants` list covers the operation. One reason rather than two, because a pair
|
|
71
|
+
// list has no axes to name.
|
|
72
|
+
GRANT: 'grant'
|
|
44
73
|
};
|
|
45
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Reads a `grants` list, or reports that it cannot be read.
|
|
77
|
+
*
|
|
78
|
+
* Every entry is checked the way the axes are: own keys only, exactly the two the pair is made of,
|
|
79
|
+
* and both values in the vocabulary. The entries are copied out rather than kept, so the caller
|
|
80
|
+
* holds plain pairs and not whatever object msgpack decoded.
|
|
81
|
+
*
|
|
82
|
+
* @param {*} value - the record's `grants` field
|
|
83
|
+
* @returns {{pairs: Array, keys: Set}|null} the pairs and their `action:group` keys, or null when
|
|
84
|
+
* the list is not one this version can read
|
|
85
|
+
*/
|
|
86
|
+
function parseGrants(value) {
|
|
87
|
+
if (!Array.isArray(value)) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const pairs = [];
|
|
92
|
+
const keys = new Set();
|
|
93
|
+
for (const entry of value) {
|
|
94
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const own = Object.keys(entry);
|
|
99
|
+
if (own.length !== GRANT_KEYS.length || !GRANT_KEYS.every(key => Object.hasOwn(entry, key))) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (!ACTION_VALUES.has(entry.action) || !GROUP_VALUES.has(entry.group)) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
pairs.push({ action: entry.action, group: entry.group });
|
|
108
|
+
keys.add(grantKey(entry));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return { pairs, keys };
|
|
112
|
+
}
|
|
113
|
+
|
|
46
114
|
/**
|
|
47
115
|
* Reads a `permissions` record, or reports that it cannot be read.
|
|
48
116
|
*
|
|
@@ -56,33 +124,62 @@ const REASON = {
|
|
|
56
124
|
* `permissions` value can reach a record without ever passing route validation.
|
|
57
125
|
*
|
|
58
126
|
* @param {*} permissions - the record's `permissions` field
|
|
59
|
-
* @returns {{narrowed: Boolean,
|
|
127
|
+
* @returns {{narrowed: Boolean, actions: (Set|null), groups: (Set|null), grants: (Object|null), malformed: Boolean}}
|
|
128
|
+
* for the two-axis form, `actions` is null when the axis is absent (every action) and
|
|
129
|
+
* `groups` is always resolved (IMPLICIT_GROUPS when absent)
|
|
60
130
|
*/
|
|
61
131
|
function parsePermissions(permissions) {
|
|
62
132
|
if (permissions === null || typeof permissions === 'undefined') {
|
|
63
|
-
return { narrowed: false,
|
|
133
|
+
return { narrowed: false, actions: null, groups: null, grants: null, malformed: false };
|
|
64
134
|
}
|
|
65
135
|
|
|
136
|
+
const malformed = { narrowed: true, actions: null, groups: null, grants: null, malformed: true };
|
|
137
|
+
|
|
66
138
|
if (typeof permissions !== 'object' || Array.isArray(permissions)) {
|
|
67
|
-
return
|
|
139
|
+
return malformed;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
let parsed = parsedRecords.get(permissions);
|
|
143
|
+
if (!parsed) {
|
|
144
|
+
parsed = parseRecord(permissions, malformed);
|
|
145
|
+
parsedRecords.set(permissions, parsed);
|
|
68
146
|
}
|
|
147
|
+
return parsed;
|
|
148
|
+
}
|
|
69
149
|
|
|
150
|
+
function parseRecord(permissions, malformed) {
|
|
70
151
|
const keys = Object.keys(permissions);
|
|
71
152
|
|
|
72
|
-
// An unknown key is refused rather than ignored. That is what
|
|
73
|
-
//
|
|
74
|
-
// of honouring a narrowing it cannot apply.
|
|
75
|
-
if (keys.some(key => !
|
|
76
|
-
return
|
|
153
|
+
// An unknown key is refused rather than ignored. That is what let `grants` be added to a model
|
|
154
|
+
// that already had tokens in the field, and what lets the next key be added the same way: an
|
|
155
|
+
// older release denies the request instead of honouring a narrowing it cannot apply.
|
|
156
|
+
if (keys.some(key => !RECORD_KEYS.includes(key))) {
|
|
157
|
+
return malformed;
|
|
77
158
|
}
|
|
78
159
|
|
|
79
160
|
// `{}` is ambiguous between "no narrowing" and "grant nothing". The joi schema refuses it so it
|
|
80
161
|
// never reaches a record through the API, and anything that gets in another way is denied.
|
|
81
162
|
if (!keys.length) {
|
|
82
|
-
return
|
|
163
|
+
return malformed;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (Object.hasOwn(permissions, GRANTS_KEY)) {
|
|
167
|
+
// The pair list stands alone. Beside an axis it would be two records claiming one token,
|
|
168
|
+
// and neither "intersect them" nor "the list wins" is a reading a reader could predict.
|
|
169
|
+
if (keys.length !== 1) {
|
|
170
|
+
return malformed;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const grants = parseGrants(permissions[GRANTS_KEY]);
|
|
174
|
+
if (!grants) {
|
|
175
|
+
return malformed;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// An empty list is well-formed and grants nothing, exactly like an empty axis
|
|
179
|
+
return { narrowed: true, actions: null, groups: null, grants, malformed: false };
|
|
83
180
|
}
|
|
84
181
|
|
|
85
|
-
const axes = {};
|
|
182
|
+
const axes = { actions: null, groups: null };
|
|
86
183
|
for (const axis of AXES) {
|
|
87
184
|
// Object.hasOwn rather than `in`: this record was msgpack-decoded from Redis by a path with
|
|
88
185
|
// no schema, and `in` walks the prototype chain, so a payload that got something onto the
|
|
@@ -93,7 +190,7 @@ function parsePermissions(permissions) {
|
|
|
93
190
|
|
|
94
191
|
const value = permissions[axis];
|
|
95
192
|
if (!Array.isArray(value) || value.some(entry => !AXIS_VALUES[axis].has(entry))) {
|
|
96
|
-
return
|
|
193
|
+
return malformed;
|
|
97
194
|
}
|
|
98
195
|
|
|
99
196
|
// An empty array is well-formed and grants nothing: an allowlist that lists nothing allows
|
|
@@ -102,7 +199,16 @@ function parsePermissions(permissions) {
|
|
|
102
199
|
axes[axis] = value;
|
|
103
200
|
}
|
|
104
201
|
|
|
105
|
-
|
|
202
|
+
// Resolved once per record, here, so the two readers below share one meaning of an absent
|
|
203
|
+
// axis: every action, and IMPLICIT_GROUPS. Sets, because check() runs per tool on every
|
|
204
|
+
// tools/list.
|
|
205
|
+
return {
|
|
206
|
+
narrowed: true,
|
|
207
|
+
actions: axes.actions && new Set(axes.actions),
|
|
208
|
+
groups: new Set(axes.groups || IMPLICIT_GROUPS),
|
|
209
|
+
grants: null,
|
|
210
|
+
malformed: false
|
|
211
|
+
};
|
|
106
212
|
}
|
|
107
213
|
|
|
108
214
|
/**
|
|
@@ -134,19 +240,27 @@ function check({ tokenData, operation }) {
|
|
|
134
240
|
}
|
|
135
241
|
|
|
136
242
|
// Checked before the axes, and independently of them, so no value of `groups` can reach these.
|
|
137
|
-
// This is the rule the rest of the model rests on: while it holds, a narrowed token cannot
|
|
138
|
-
//
|
|
139
|
-
//
|
|
140
|
-
//
|
|
243
|
+
// This is the rule the rest of the model rests on: while it holds, a narrowed token cannot mint
|
|
244
|
+
// a token and cannot read a live provider credential, so it cannot widen itself (the settings
|
|
245
|
+
// that would let it are refused per key, see assertNoPrivilegedSettings() in
|
|
246
|
+
// lib/api-routes/route-helpers.js). Encoded as a deny set rather than as an absence from the
|
|
247
|
+
// grantable list so that widening the grantable list can never quietly reopen it.
|
|
141
248
|
if (NEVER_GRANTABLE.has(group)) {
|
|
142
249
|
return { allowed: false, reason: REASON.RESTRICTED, required };
|
|
143
250
|
}
|
|
144
251
|
|
|
145
|
-
if (parsed.
|
|
252
|
+
if (parsed.grants) {
|
|
253
|
+
if (!parsed.grants.keys.has(grantKey(required))) {
|
|
254
|
+
return { allowed: false, reason: REASON.GRANT, required };
|
|
255
|
+
}
|
|
256
|
+
return { allowed: true, reason: null, required };
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (parsed.actions && !parsed.actions.has(action)) {
|
|
146
260
|
return { allowed: false, reason: REASON.ACTION, required };
|
|
147
261
|
}
|
|
148
262
|
|
|
149
|
-
if (
|
|
263
|
+
if (!parsed.groups.has(group)) {
|
|
150
264
|
return { allowed: false, reason: REASON.GROUP, required };
|
|
151
265
|
}
|
|
152
266
|
|
|
@@ -169,4 +283,40 @@ function inspect(tokenData) {
|
|
|
169
283
|
return { narrowed, malformed };
|
|
170
284
|
}
|
|
171
285
|
|
|
172
|
-
|
|
286
|
+
/**
|
|
287
|
+
* The (action, group) pairs a record allows, whichever form it is written in.
|
|
288
|
+
*
|
|
289
|
+
* The two-axis form expands to its cross product, an absent axis read as parseRecord() resolved
|
|
290
|
+
* it. The pair form is returned as it is. The never-grantable groups are left out either way,
|
|
291
|
+
* because check() refuses them before it reads the record, so a pair naming one is not something
|
|
292
|
+
* the record allows.
|
|
293
|
+
*
|
|
294
|
+
* For consumers that describe a record rather than enforce it: the admin listing summarises a
|
|
295
|
+
* pair-list record through this rather than holding its own reading of the form.
|
|
296
|
+
*
|
|
297
|
+
* @param {*} permissions - the record's `permissions` field
|
|
298
|
+
* @returns {Array<{action: String, group: String}>|null} the pairs, or null when the record narrows
|
|
299
|
+
* nothing or cannot be read (inspect() tells those two apart)
|
|
300
|
+
*/
|
|
301
|
+
function effectiveGrants(permissions) {
|
|
302
|
+
const parsed = parsePermissions(permissions);
|
|
303
|
+
if (!parsed.narrowed || parsed.malformed) {
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (parsed.grants) {
|
|
308
|
+
return parsed.grants.pairs.filter(grant => !NEVER_GRANTABLE.has(grant.group)).map(grant => ({ action: grant.action, group: grant.group }));
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const grants = [];
|
|
312
|
+
for (const action of parsed.actions || ACTION_VALUES) {
|
|
313
|
+
for (const group of parsed.groups) {
|
|
314
|
+
if (!NEVER_GRANTABLE.has(group)) {
|
|
315
|
+
grants.push({ action, group });
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return grants;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
module.exports = { check, inspect, effectiveGrants, REASON };
|
package/lib/tokens.js
CHANGED
|
@@ -504,9 +504,10 @@ module.exports = {
|
|
|
504
504
|
* @param {Boolean} [opts.all] - every token on the instance, bound or not. Reads the token hash
|
|
505
505
|
* directly rather than walking one index per account: the account is stored on each record, so
|
|
506
506
|
* the union is already there, and enumerating accounts would be a round trip each.
|
|
507
|
-
* @param {String} [opts.scope] - keep only tokens whose scope list names
|
|
508
|
-
* membership on purpose: a '*' token would also serve the surface, but
|
|
509
|
-
* answer "which tokens were minted for it", and those carry the scope by
|
|
507
|
+
* @param {String|Array<String>} [opts.scope] - keep only tokens whose scope list names one of
|
|
508
|
+
* these scopes. Literal membership on purpose: a '*' token would also serve the surface, but
|
|
509
|
+
* the filter exists to answer "which tokens were minted for it", and those carry the scope by
|
|
510
|
+
* name. A list because the MCP pages ask for both MCP scopes at once.
|
|
510
511
|
*/
|
|
511
512
|
async list(account, page, pageSize, query, opts) {
|
|
512
513
|
page = Math.max(Number(page) || 0, 0);
|
|
@@ -518,10 +519,10 @@ module.exports = {
|
|
|
518
519
|
// single space in the search box on the read-everything path with no filter to show for it.
|
|
519
520
|
query = (query || '').toString().trim();
|
|
520
521
|
|
|
521
|
-
const
|
|
522
|
+
const scopes = [].concat((opts && opts.scope) || []).filter(Boolean);
|
|
522
523
|
// Either filter forces the read-everything path: the fields they match on live on the
|
|
523
524
|
// record and nowhere else
|
|
524
|
-
const filtered = !!(query ||
|
|
525
|
+
const filtered = !!(query || scopes.length);
|
|
525
526
|
|
|
526
527
|
let startPos = page * pageSize;
|
|
527
528
|
|
|
@@ -588,7 +589,7 @@ module.exports = {
|
|
|
588
589
|
|
|
589
590
|
// Before the entry is built: on a scope-filtered read of every record, the
|
|
590
591
|
// date coercion and the copy below would mostly construct throwaways
|
|
591
|
-
if (
|
|
592
|
+
if (scopes.length && !(Array.isArray(tokenData.scopes) && scopes.some(scope => tokenData.scopes.includes(scope)))) {
|
|
592
593
|
continue;
|
|
593
594
|
}
|
|
594
595
|
|
package/lib/tools.js
CHANGED
|
@@ -6,6 +6,7 @@ const msgpack = require('./msgpack');
|
|
|
6
6
|
const enumMessageFlags = require('./enum-message-flags');
|
|
7
7
|
const Joi = require('joi');
|
|
8
8
|
const packageData = require('../package.json');
|
|
9
|
+
const { TLS_CERTIFICATE_SETTINGS } = require('./tls/listeners');
|
|
9
10
|
const settings = require('./settings');
|
|
10
11
|
// Safe to require at load time despite db.js opening Redis clients: settings.js above already
|
|
11
12
|
// requires it, so db.js is in this file's dependency graph either way. db.js does not require
|
|
@@ -534,13 +535,13 @@ async function reloadTlsCertificates(call, logger, context) {
|
|
|
534
535
|
}
|
|
535
536
|
|
|
536
537
|
// The settings a listener's certificate is resolved from: which stored sources are admitted
|
|
537
|
-
// (tlsProvisioning),
|
|
538
|
-
//
|
|
538
|
+
// (tlsProvisioning), which names are served (tlsHostnames, plus the service URL's own hostname),
|
|
539
|
+
// and which certificate each listener presents by default. Changing any of them changes what a running listener should be offering, and none of
|
|
539
540
|
// that depends on a certificate being ordered - the reconciler returns immediately for every mode
|
|
540
541
|
// but `acme`, and even there it only reloads when an order produced new material. So whoever writes
|
|
541
542
|
// one of these keys hands the result to the listeners, the same way HTTP_PROXY_SETTINGS above is
|
|
542
543
|
// what makes a proxy change reach the dispatchers.
|
|
543
|
-
const TLS_MATERIAL_SETTINGS = ['tlsProvisioning', 'tlsHostnames', 'serviceUrl'];
|
|
544
|
+
const TLS_MATERIAL_SETTINGS = ['tlsProvisioning', 'tlsHostnames', 'serviceUrl'].concat(TLS_CERTIFICATE_SETTINGS);
|
|
544
545
|
|
|
545
546
|
/**
|
|
546
547
|
* Reloads the listeners when the settings that were just written change what they serve.
|
|
@@ -39,7 +39,18 @@ const { mcpFeatureEnabled } = require('../mcp');
|
|
|
39
39
|
const { mcpResource } = require('../mcp/oauth');
|
|
40
40
|
const { getToolRegistry } = require('../mcp/tools');
|
|
41
41
|
const { serverUrl } = require('../openapi');
|
|
42
|
-
const {
|
|
42
|
+
const { MCP_SECTIONS } = require('../token-permission-view');
|
|
43
|
+
const { ACTION } = require('../api-routes/permission-map');
|
|
44
|
+
|
|
45
|
+
// How the MCP config page badges a tool: by the action it dispatches under, read off the grant
|
|
46
|
+
// rather than the annotation hints - openWorldHint does not imply sending, the lookups and
|
|
47
|
+
// connection tests declare it too
|
|
48
|
+
const TOOL_BADGES = {
|
|
49
|
+
[ACTION.SEND]: { label: 'sends email', variant: 'warning' },
|
|
50
|
+
[ACTION.DESTRUCTIVE]: { label: 'destructive', variant: 'error' },
|
|
51
|
+
[ACTION.READ]: { label: 'read-only', variant: 'success' },
|
|
52
|
+
[ACTION.WRITE]: { label: 'write', variant: 'info' }
|
|
53
|
+
};
|
|
43
54
|
const { locales } = require('../translations');
|
|
44
55
|
const { settingsSchema } = require('../schemas');
|
|
45
56
|
const { getOpenAiModels, OPEN_AI_MODELS, getExampleDocumentsPayloads, mcpToolGrants } = require('./route-helpers');
|
|
@@ -619,22 +630,32 @@ function init(args) {
|
|
|
619
630
|
// into the one action they were derived from.
|
|
620
631
|
const mcpTools = mcpToolGrants(server, request.logger);
|
|
621
632
|
|
|
622
|
-
|
|
633
|
+
// The catalog, split the way the scopes split it: one bucket per access section in
|
|
634
|
+
// section order, each tool filed under the first section whose scope covers it (so
|
|
635
|
+
// the account reads both scopes share sit under management, marked as shared), and
|
|
636
|
+
// anything no scope covers in a bucket of its own - a guardrail keeps that one empty,
|
|
637
|
+
// and the page says so rather than filing such a tool under a scope it did not check.
|
|
638
|
+
const toolCatalog = { sections: [], unreached: [] };
|
|
623
639
|
try {
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
640
|
+
const grantsByName = new Map(mcpTools.map(entry => [entry.name, entry]));
|
|
641
|
+
const buckets = new Map(Object.values(MCP_SECTIONS).map(section => [section.scope, { label: section.label, scope: section.scope, tools: [] }]));
|
|
642
|
+
for (const tool of getToolRegistry(server).tools) {
|
|
643
|
+
const grant = grantsByName.get(tool.name);
|
|
644
|
+
const surfaces = (grant && grant.surfaces) || [];
|
|
645
|
+
const entry = {
|
|
646
|
+
name: tool.name,
|
|
647
|
+
description: tool.description,
|
|
648
|
+
badge: (grant && TOOL_BADGES[grant.action]) || TOOL_BADGES[ACTION.WRITE],
|
|
649
|
+
shared: surfaces.length > 1
|
|
650
|
+
};
|
|
651
|
+
const bucket = [...buckets.keys()].find(scope => surfaces.includes(scope));
|
|
652
|
+
(bucket ? buckets.get(bucket).tools : toolCatalog.unreached).push(entry);
|
|
653
|
+
}
|
|
654
|
+
toolCatalog.sections = [...buckets.values()];
|
|
635
655
|
} catch (err) {
|
|
636
656
|
request.logger.error({ msg: 'Failed to derive the MCP tool catalog', err });
|
|
637
657
|
}
|
|
658
|
+
toolCatalog.total = toolCatalog.sections.reduce((sum, section) => sum + section.tools.length, toolCatalog.unreached.length);
|
|
638
659
|
|
|
639
660
|
const serviceUrlConfigured = !!configuredOrigin;
|
|
640
661
|
|
|
@@ -664,15 +685,14 @@ function init(args) {
|
|
|
664
685
|
oauthMethodBlocker,
|
|
665
686
|
toolCatalog,
|
|
666
687
|
// The same catalog reduced to what the tool count needs: one entry per tool with
|
|
667
|
-
// the operation it dispatches under
|
|
688
|
+
// the operation it dispatches under, the scopes that reach it and whether it can
|
|
689
|
+
// be bound to an account
|
|
668
690
|
mcpTools,
|
|
669
|
-
// The
|
|
670
|
-
//
|
|
671
|
-
//
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
// partial, from the same table the consent prompt offers
|
|
675
|
-
accessOptions: MCP_ACCESS_LEVEL_OPTIONS,
|
|
691
|
+
// The two access sections with their levels and what each mints: the generator's
|
|
692
|
+
// radio groups render through the shared mcp_access_levels partial and its script
|
|
693
|
+
// mints from the same table the consent prompt does, so a level added there is
|
|
694
|
+
// offered here without a second list to update
|
|
695
|
+
mcpSections: MCP_SECTIONS,
|
|
676
696
|
// The same gate as the token pages: minting needs an authenticated admin
|
|
677
697
|
// session on this request, not just a password existing in Redis
|
|
678
698
|
canProvision: request.auth.isAuthenticated
|
|
@@ -10,6 +10,7 @@ const getSecret = require('../get-secret');
|
|
|
10
10
|
const { failAction, verifyAccountInfo, formatPartialSecretKey } = require('../tools');
|
|
11
11
|
const { templateSchemas, accountIdSchema, tokenPermissionsSchema } = require('../schemas');
|
|
12
12
|
const tokenPermissionView = require('../token-permission-view');
|
|
13
|
+
const { PRIVILEGED_SETTINGS_SUMMARY } = require('../privileged-settings');
|
|
13
14
|
const { Account, accountExists } = require('../account');
|
|
14
15
|
const { isMcpEnabled } = require('../mcp');
|
|
15
16
|
const { Gateway } = require('../gateway');
|
|
@@ -25,7 +26,7 @@ const { DEFAULT_PAGE_SIZE } = consts;
|
|
|
25
26
|
// Every scope the admin token form can mint - one list, because the listing's ?scope= filter
|
|
26
27
|
// validates against the same vocabulary and a scope added to one side must not leave the other
|
|
27
28
|
// behind. Deliberately wider than the /v1/tokens set, which excludes '*' and 'metrics'.
|
|
28
|
-
const ADMIN_TOKEN_SCOPES = ['*', 'api', 'metrics', 'smtp', 'imap-proxy', 'mcp'];
|
|
29
|
+
const ADMIN_TOKEN_SCOPES = ['*', 'api', 'metrics', 'smtp', 'imap-proxy', 'mcp', 'mcp-manage'];
|
|
29
30
|
|
|
30
31
|
const notificationTypes = Object.keys(consts)
|
|
31
32
|
.map(key => {
|
|
@@ -2312,7 +2313,9 @@ return payload;`)
|
|
|
2312
2313
|
query: request.query.query,
|
|
2313
2314
|
// The active scope filter, so the page can say it is showing a subset and
|
|
2314
2315
|
// offer the way out of it
|
|
2315
|
-
|
|
2316
|
+
// Rendered inside 'Tokens with the "..." scope', so a multi-scope filter reads
|
|
2317
|
+
// as the alternatives it is
|
|
2318
|
+
scopeFilter: request.query.scope ? request.query.scope.join('" or "') : null,
|
|
2316
2319
|
// The create button leads to a form that cannot submit without an admin session
|
|
2317
2320
|
canProvision: request.auth.isAuthenticated,
|
|
2318
2321
|
searchHidden: [
|
|
@@ -2362,11 +2365,16 @@ return payload;`)
|
|
|
2362
2365
|
// read every record on the instance and then match all of them
|
|
2363
2366
|
query: Joi.string().empty('').trim().example('prometheus').description('Filter by search term'),
|
|
2364
2367
|
// The vocabulary the token form accepts, so the filter cannot name a scope
|
|
2365
|
-
// no token could carry
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
.
|
|
2369
|
-
|
|
2368
|
+
// no token could carry. Repeatable (?scope=a&scope=b), because the MCP pages
|
|
2369
|
+
// ask for the tokens of both MCP scopes at once.
|
|
2370
|
+
scope: Joi.array()
|
|
2371
|
+
.items(
|
|
2372
|
+
Joi.string()
|
|
2373
|
+
.empty('')
|
|
2374
|
+
.valid(...ADMIN_TOKEN_SCOPES)
|
|
2375
|
+
)
|
|
2376
|
+
.single()
|
|
2377
|
+
.description('Only tokens carrying one of these scopes')
|
|
2370
2378
|
})
|
|
2371
2379
|
}
|
|
2372
2380
|
}
|
|
@@ -2410,16 +2418,18 @@ return payload;`)
|
|
|
2410
2418
|
// is why the mint is refused rather than merely discouraged. Rendering the form
|
|
2411
2419
|
// anyway meant filling it in and losing the work to a 403.
|
|
2412
2420
|
canProvision: request.auth.isAuthenticated,
|
|
2421
|
+
// The settings a restricted token is refused, in the words every description
|
|
2422
|
+
// of that rule uses, rendered from the list the rule reads
|
|
2423
|
+
privilegedSettingsSummary: PRIVILEGED_SETTINGS_SUMMARY,
|
|
2413
2424
|
...permissionModel,
|
|
2414
2425
|
// Handed to the page as data rather than restated in its script
|
|
2415
2426
|
permissionSurfacesJson: JSON.stringify(permissionModel.permissionSurfaces),
|
|
2416
2427
|
mcpTools,
|
|
2417
|
-
// The same
|
|
2418
|
-
// page offer, from the same table, rendered through the same partial. An
|
|
2419
|
-
//
|
|
2420
|
-
//
|
|
2421
|
-
|
|
2422
|
-
mcpAccessPresets: tokenPermissionView.MCP_ACCESS_LEVELS,
|
|
2428
|
+
// The same two access sections the OAuth consent prompt and the MCP config
|
|
2429
|
+
// page offer, from the same table, rendered through the same partial. An MCP
|
|
2430
|
+
// token is minted from three places and the levels have to mean the same
|
|
2431
|
+
// thing in all of them.
|
|
2432
|
+
mcpSections: tokenPermissionView.MCP_SECTIONS,
|
|
2423
2433
|
// Whether the endpoint an mcp-scoped token would talk to is actually serving.
|
|
2424
2434
|
// Both halves of the gate, because a token minted against either one being off
|
|
2425
2435
|
// is a credential for nothing, and the form is the last place to say so.
|