@aeolus-fleet/trierarch-plugin 0.36.1 → 0.37.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 +9 -1
- package/dist/adapters/crypto/sealed-box-sealer.d.ts +9 -0
- package/dist/adapters/crypto/sealed-box-sealer.js +23 -0
- package/dist/adapters/crypto/sealed-box-sealer.js.map +1 -0
- package/dist/adapters/fleet/core-version.d.ts +1 -1
- package/dist/adapters/fleet/core-version.js +1 -1
- package/dist/adapters/trpc/router.d.ts +11 -1
- package/dist/app.d.ts +6 -0
- package/dist/app.js +63 -0
- package/dist/app.js.map +1 -1
- package/dist/bin/aeolus-trierarch-plugin.js +2 -0
- package/dist/bin/aeolus-trierarch-plugin.js.map +1 -1
- package/dist/config.d.ts +10 -0
- package/dist/config.js +37 -0
- package/dist/config.js.map +1 -1
- package/dist/core/assignment/placement.js +23 -2
- package/dist/core/assignment/placement.js.map +1 -1
- package/dist/core/assignment/tell-model-mismatches.d.ts +1 -1
- package/dist/core/assignment/tell-model-mismatches.js +5 -1
- package/dist/core/assignment/tell-model-mismatches.js.map +1 -1
- package/dist/core/machines/setup-line.d.ts +2 -2
- package/dist/core/machines/setup-line.js +5 -5
- package/dist/core/machines/setup-line.js.map +1 -1
- package/dist/core/mcp-servers/mcp-servers.d.ts +32 -0
- package/dist/core/mcp-servers/mcp-servers.js +86 -0
- package/dist/core/mcp-servers/mcp-servers.js.map +1 -0
- package/dist/core/mcp-servers/ports.d.ts +13 -0
- package/dist/core/mcp-servers/ports.js +2 -0
- package/dist/core/mcp-servers/ports.js.map +1 -0
- package/dist/core/mcp-servers/resend-mcp-servers.d.ts +15 -0
- package/dist/core/mcp-servers/resend-mcp-servers.js +19 -0
- package/dist/core/mcp-servers/resend-mcp-servers.js.map +1 -0
- package/dist/core/mcp-servers/resend-secrets.d.ts +15 -0
- package/dist/core/mcp-servers/resend-secrets.js +19 -0
- package/dist/core/mcp-servers/resend-secrets.js.map +1 -0
- package/dist/core/mcp-servers/sealing-key.d.ts +6 -0
- package/dist/core/mcp-servers/sealing-key.js +20 -0
- package/dist/core/mcp-servers/sealing-key.js.map +1 -0
- package/dist/core/mcp-servers/secrets.d.ts +31 -0
- package/dist/core/mcp-servers/secrets.js +87 -0
- package/dist/core/mcp-servers/secrets.js.map +1 -0
- package/dist/core/mcp-servers/share-mcp-servers.d.ts +25 -0
- package/dist/core/mcp-servers/share-mcp-servers.js +45 -0
- package/dist/core/mcp-servers/share-mcp-servers.js.map +1 -0
- package/dist/core/mcp-servers/share-secrets.d.ts +36 -0
- package/dist/core/mcp-servers/share-secrets.js +71 -0
- package/dist/core/mcp-servers/share-secrets.js.map +1 -0
- package/dist/core/scopes/declare-scopes.d.ts +1 -1
- package/dist/core/scopes/declare-scopes.js +6 -3
- package/dist/core/scopes/declare-scopes.js.map +1 -1
- package/package.json +6 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ShipId } from '@aeolus-fleet/common';
|
|
2
2
|
/**
|
|
3
|
-
* The one ready-to-run line that sets a machine up:
|
|
4
|
-
* takes the fleet's URL, the machine's ship and its secret, and the trierarch
|
|
3
|
+
* The one ready-to-run line that sets a machine up: the install script runs
|
|
4
|
+
* `aeolus-trierarch init`, which takes the fleet's URL, the machine's ship and its secret, and the trierarch
|
|
5
5
|
* plugin's own ship as flags and never parses a prompt. The trierarch takes
|
|
6
6
|
* the trusted repositories only from that ship (aeolus-fleet#384): a ship's
|
|
7
7
|
* type proves nothing. It holds the secret, so it is shown once, never kept.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/** The
|
|
2
|
-
const
|
|
1
|
+
/** The trierarch's install script: it installs the binary, then runs `aeolus-trierarch init` with the flags it is given. */
|
|
2
|
+
const INSTALL_SCRIPT_URL = 'https://raw.githubusercontent.com/ThomasHendrickx/aeolus-fleet-trierarch/main/install.sh';
|
|
3
3
|
/**
|
|
4
|
-
* The one ready-to-run line that sets a machine up:
|
|
5
|
-
* takes the fleet's URL, the machine's ship and its secret, and the trierarch
|
|
4
|
+
* The one ready-to-run line that sets a machine up: the install script runs
|
|
5
|
+
* `aeolus-trierarch init`, which takes the fleet's URL, the machine's ship and its secret, and the trierarch
|
|
6
6
|
* plugin's own ship as flags and never parses a prompt. The trierarch takes
|
|
7
7
|
* the trusted repositories only from that ship (aeolus-fleet#384): a ship's
|
|
8
8
|
* type proves nothing. It holds the secret, so it is shown once, never kept.
|
|
9
9
|
*/
|
|
10
10
|
export function setupLineOf(parts) {
|
|
11
|
-
return `
|
|
11
|
+
return `curl -fsSL ${INSTALL_SCRIPT_URL} | sh -s -- --fleet-url ${parts.fleetUrl} --ship-id ${parts.shipId} --plugin-ship-id ${parts.pluginShipId} --secret ${parts.secret}`;
|
|
12
12
|
}
|
|
13
13
|
//# sourceMappingURL=setup-line.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-line.js","sourceRoot":"","sources":["../../../src/core/machines/setup-line.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"setup-line.js","sourceRoot":"","sources":["../../../src/core/machines/setup-line.ts"],"names":[],"mappings":"AAEA,4HAA4H;AAC5H,MAAM,kBAAkB,GAAG,0FAA0F,CAAC;AAEtH;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,KAAiF;IAC3G,OAAO,cAAc,kBAAkB,2BAA2B,KAAK,CAAC,QAAQ,cAAc,KAAK,CAAC,MAAM,qBAAqB,KAAK,CAAC,YAAY,aAAa,KAAK,CAAC,MAAM,EAAE,CAAC;AAC/K,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type Result } from '../shared/result.js';
|
|
2
|
+
/** What the trierarch's proxy adds to what it forwards to a server: the header, set to the named secret's value verbatim. */
|
|
3
|
+
export interface McpCredential {
|
|
4
|
+
readonly secret: string;
|
|
5
|
+
readonly header: string;
|
|
6
|
+
}
|
|
7
|
+
/** A server on the list, with its credential when it needs one. */
|
|
8
|
+
export interface McpServer {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly url: string;
|
|
11
|
+
readonly tools: readonly string[];
|
|
12
|
+
readonly credential?: McpCredential;
|
|
13
|
+
}
|
|
14
|
+
/** The list as read: by name, each URL one a session may reach and each with the tools it may call. Built only by `readMcpServers`. */
|
|
15
|
+
export interface McpServers {
|
|
16
|
+
readonly servers: readonly McpServer[];
|
|
17
|
+
}
|
|
18
|
+
/** The content type of the message that carries the list to a trierarch. */
|
|
19
|
+
export declare const MCP_SERVERS_CONTENT_TYPE = "application/vnd.aeolus.trierarch.mcp-servers+json";
|
|
20
|
+
/** The content type of the message a trierarch asks for the list again with, as it starts knowing the trierarch plugin's ship. */
|
|
21
|
+
export declare const MCP_SERVERS_REQUEST_CONTENT_TYPE = "application/vnd.aeolus.trierarch.mcp-servers-request+json";
|
|
22
|
+
/**
|
|
23
|
+
* The list from the configuration's object of names to `{ url, tools }`, or
|
|
24
|
+
* why not: each name a trierarch name, each server a credential-free URL with
|
|
25
|
+
* at least one tool, and the whole small enough to reach a trierarch in one
|
|
26
|
+
* message.
|
|
27
|
+
*/
|
|
28
|
+
export declare function readMcpServers(listed: unknown): Result<McpServers, {
|
|
29
|
+
reason: string;
|
|
30
|
+
}>;
|
|
31
|
+
/** The list as a trierarch receives it: `{ "servers": [{ "name", "url", "transport", "tools", "credential"? }] }`. */
|
|
32
|
+
export declare function mcpServersPayload(list: McpServers): string;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The crew-time MCP servers (decisions M2 and M7 of the crew-time MCP servers
|
|
3
|
+
* design): the one list, in the trierarch plugin's configuration, of the
|
|
4
|
+
* remote servers (Streamable HTTP) a session may be crewed with, each by name
|
|
5
|
+
* with its URL and the tools a session may call. It is true across all
|
|
6
|
+
* trierarchs. It holds no credential: a URL has no user, query or fragment.
|
|
7
|
+
* A server that needs one names it (decision M6): a secret of the store by
|
|
8
|
+
* name and the HTTP header the trierarch's proxy sets to its value verbatim.
|
|
9
|
+
*/
|
|
10
|
+
import { PAYLOAD_MAX_BYTES, payloadBytes, trierarchNameSchema } from '@aeolus-fleet/common';
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
import { err, ok } from '../shared/result.js';
|
|
13
|
+
/** The content type of the message that carries the list to a trierarch. */
|
|
14
|
+
export const MCP_SERVERS_CONTENT_TYPE = 'application/vnd.aeolus.trierarch.mcp-servers+json';
|
|
15
|
+
/** The content type of the message a trierarch asks for the list again with, as it starts knowing the trierarch plugin's ship. */
|
|
16
|
+
export const MCP_SERVERS_REQUEST_CONTENT_TYPE = 'application/vnd.aeolus.trierarch.mcp-servers-request+json';
|
|
17
|
+
const BYTES_PER_KB = 1024;
|
|
18
|
+
const URL_REFUSED = 'an MCP server is an http:// or https:// URL with no user, query or fragment, never a credential';
|
|
19
|
+
/** Whether the URL is a remote server's, which carries no credential in itself. */
|
|
20
|
+
function isCredentialFree(url) {
|
|
21
|
+
if (!URL.canParse(url)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const parsed = new URL(url);
|
|
25
|
+
return (parsed.protocol === 'https:' || parsed.protocol === 'http:') && parsed.hostname !== '' && parsed.username === '' && parsed.password === '' && parsed.search === '' && parsed.hash === '';
|
|
26
|
+
}
|
|
27
|
+
/** An HTTP field name: an RFC 9110 token. */
|
|
28
|
+
const HEADER_TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
29
|
+
/** The headers the proxy itself owns, or that frame the request or its session: never a credential's. */
|
|
30
|
+
const HEADERS_REFUSED = new Set(['host', 'content-length', 'transfer-encoding', 'connection', 'upgrade', 'te', 'trailer', 'keep-alive', 'cookie', 'content-type', 'accept', 'accept-encoding', 'last-event-id', 'mcp-session-id', 'mcp-protocol-version']);
|
|
31
|
+
/** Whether a credential may go in the header: a token the proxy does not own. */
|
|
32
|
+
function isCredentialHeader(header) {
|
|
33
|
+
const lower = header.toLowerCase();
|
|
34
|
+
return HEADER_TOKEN.test(header) && !HEADERS_REFUSED.has(lower) && !lower.startsWith('proxy-');
|
|
35
|
+
}
|
|
36
|
+
const credentialSchema = z.strictObject({
|
|
37
|
+
secret: trierarchNameSchema,
|
|
38
|
+
header: z.string().refine(isCredentialHeader, { error: 'a credential header is an HTTP field name the proxy does not set itself' }),
|
|
39
|
+
});
|
|
40
|
+
const serverSchema = z.strictObject({
|
|
41
|
+
url: z.string().refine(isCredentialFree, { error: URL_REFUSED }),
|
|
42
|
+
credential: credentialSchema.optional(),
|
|
43
|
+
tools: z
|
|
44
|
+
.array(z.string().min(1, { error: 'a tool has a name' }))
|
|
45
|
+
.min(1, { error: 'a server lists the tools a session may call' })
|
|
46
|
+
.refine((tools) => new Set(tools).size === tools.length, { error: 'a tool is listed once' }),
|
|
47
|
+
});
|
|
48
|
+
const listedSchema = z.record(z.string(), z.unknown());
|
|
49
|
+
/**
|
|
50
|
+
* The list from the configuration's object of names to `{ url, tools }`, or
|
|
51
|
+
* why not: each name a trierarch name, each server a credential-free URL with
|
|
52
|
+
* at least one tool, and the whole small enough to reach a trierarch in one
|
|
53
|
+
* message.
|
|
54
|
+
*/
|
|
55
|
+
export function readMcpServers(listed) {
|
|
56
|
+
const object = listedSchema.safeParse(listed);
|
|
57
|
+
if (!object.success || Array.isArray(listed)) {
|
|
58
|
+
return err({ reason: 'the MCP servers are an object of names to { url, tools }' });
|
|
59
|
+
}
|
|
60
|
+
const servers = [];
|
|
61
|
+
for (const [name, server] of Object.entries(object.data)) {
|
|
62
|
+
const named = trierarchNameSchema.safeParse(name);
|
|
63
|
+
if (!named.success) {
|
|
64
|
+
return err({ reason: `${name}: ${named.error.issues[0]?.message ?? 'not a name'}` });
|
|
65
|
+
}
|
|
66
|
+
const read = serverSchema.safeParse(server);
|
|
67
|
+
if (!read.success) {
|
|
68
|
+
return err({ reason: `${name}: ${read.error.issues[0]?.message ?? 'not a server'}` });
|
|
69
|
+
}
|
|
70
|
+
const { url, tools, credential } = read.data;
|
|
71
|
+
servers.push(credential === undefined ? { name, url, tools } : { name, url, tools, credential: { secret: credential.secret, header: credential.header } });
|
|
72
|
+
}
|
|
73
|
+
servers.sort((first, second) => first.name.localeCompare(second.name));
|
|
74
|
+
const list = { servers };
|
|
75
|
+
if (payloadBytes(mcpServersPayload(list)) > PAYLOAD_MAX_BYTES) {
|
|
76
|
+
return err({ reason: `the MCP servers do not fit one message of ${String(PAYLOAD_MAX_BYTES / BYTES_PER_KB)} KB` });
|
|
77
|
+
}
|
|
78
|
+
return ok(list);
|
|
79
|
+
}
|
|
80
|
+
/** The one transport a server on the list speaks (decision M8), named in each server of the payload. */
|
|
81
|
+
const TRANSPORT = 'streamable-http';
|
|
82
|
+
/** The list as a trierarch receives it: `{ "servers": [{ "name", "url", "transport", "tools", "credential"? }] }`. */
|
|
83
|
+
export function mcpServersPayload(list) {
|
|
84
|
+
return JSON.stringify({ servers: list.servers.map(({ name, url, tools, credential }) => ({ name, url, transport: TRANSPORT, tools, ...(credential && { credential }) })) });
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=mcp-servers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-servers.js","sourceRoot":"","sources":["../../../src/core/mcp-servers/mcp-servers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC5F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,GAAG,EAAE,EAAE,EAAe,MAAM,qBAAqB,CAAC;AAqB3D,4EAA4E;AAC5E,MAAM,CAAC,MAAM,wBAAwB,GAAG,mDAAmD,CAAC;AAE5F,kIAAkI;AAClI,MAAM,CAAC,MAAM,gCAAgC,GAAG,2DAA2D,CAAC;AAE5G,MAAM,YAAY,GAAG,IAAI,CAAC;AAE1B,MAAM,WAAW,GAAG,iGAAiG,CAAC;AAEtH,mF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,EAAE,6CAA6C,MAAM,CAAC,iBAAiB,GAAG,YAAY,CAAC,KAAK,EAAE,CAAC,CAAC;IACrH,CAAC;IACD,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;AAClB,CAAC;AAED,wGAAwG;AACxG,MAAM,SAAS,GAAG,iBAAiB,CAAC;AAEpC,sHAAsH;AACtH,MAAM,UAAU,iBAAiB,CAAC,IAAgB;IAChD,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,CAAC,UAAU,IAAI,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;AAC9K,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Result } from '../shared/result.js';
|
|
2
|
+
/**
|
|
3
|
+
* Outbound port: seals a value to a trierarch's public key so that only the
|
|
4
|
+
* holder of its private key opens it (decision M5): the NaCl anonymous sealed
|
|
5
|
+
* box, the value as UTF-8, the public key (as `readSealingKey` read it) and
|
|
6
|
+
* the sealed box as standard base64. A key no box can be sealed to, such as a
|
|
7
|
+
* low-order point, is KEY_REFUSED.
|
|
8
|
+
*/
|
|
9
|
+
export interface Sealer {
|
|
10
|
+
seal(value: string, publicKey: string): Promise<Result<string, {
|
|
11
|
+
kind: 'KEY_REFUSED';
|
|
12
|
+
}>>;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ports.js","sourceRoot":"","sources":["../../../src/core/mcp-servers/ports.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ShipId } from '@aeolus-fleet/common';
|
|
2
|
+
import type { PluginDelivery } from '../connection/ports.js';
|
|
3
|
+
/** Whether a delivery to the plugin's ship asked for the MCP servers again; the next pass then sends them to its sender. */
|
|
4
|
+
export type ResendMcpServers = (delivery: PluginDelivery) => boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Use case: a trierarch asks for the MCP servers again
|
|
7
|
+
* (aeolus-fleet-trierarch#120), as one does when it starts knowing the trierarch
|
|
8
|
+
* plugin's ship: a machine set up before took no list until init kept that
|
|
9
|
+
* ship. Its sender is forgotten from what this process sent, so the next pass
|
|
10
|
+
* sends it the list as to a trierarch never sent it. The share pass sends only
|
|
11
|
+
* to trierarch ships, so another ship that asks gets nothing.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createResendMcpServers(deps: {
|
|
14
|
+
shared: Set<ShipId>;
|
|
15
|
+
}): ResendMcpServers;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MCP_SERVERS_REQUEST_CONTENT_TYPE } from './mcp-servers.js';
|
|
2
|
+
/**
|
|
3
|
+
* Use case: a trierarch asks for the MCP servers again
|
|
4
|
+
* (aeolus-fleet-trierarch#120), as one does when it starts knowing the trierarch
|
|
5
|
+
* plugin's ship: a machine set up before took no list until init kept that
|
|
6
|
+
* ship. Its sender is forgotten from what this process sent, so the next pass
|
|
7
|
+
* sends it the list as to a trierarch never sent it. The share pass sends only
|
|
8
|
+
* to trierarch ships, so another ship that asks gets nothing.
|
|
9
|
+
*/
|
|
10
|
+
export function createResendMcpServers(deps) {
|
|
11
|
+
return (delivery) => {
|
|
12
|
+
if (delivery.contentType !== MCP_SERVERS_REQUEST_CONTENT_TYPE) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
deps.shared.delete(delivery.senderShipId);
|
|
16
|
+
return true;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=resend-mcp-servers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resend-mcp-servers.js","sourceRoot":"","sources":["../../../src/core/mcp-servers/resend-mcp-servers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,CAAC;AAKpE;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAA6B;IAClE,OAAO,CAAC,QAAQ,EAAE,EAAE;QAClB,IAAI,QAAQ,CAAC,WAAW,KAAK,gCAAgC,EAAE,CAAC;YAC9D,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ShipId } from '@aeolus-fleet/common';
|
|
2
|
+
import type { PluginDelivery } from '../connection/ports.js';
|
|
3
|
+
/** Whether a delivery to the plugin's ship asked for the secret store again; the next pass then seals it to its sender. */
|
|
4
|
+
export type ResendSecrets = (delivery: PluginDelivery) => boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Use case: a trierarch asks for the secret store again
|
|
7
|
+
* (aeolus-fleet-trierarch#120), once per process, as it asks for the lists.
|
|
8
|
+
* Its sender is forgotten from what this process sealed, so the next pass
|
|
9
|
+
* seals the store to the key its report states, as to a trierarch never sent
|
|
10
|
+
* it. The share pass sends only to trierarch ships, so another ship that asks
|
|
11
|
+
* gets nothing.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createResendSecrets(deps: {
|
|
14
|
+
sealed: Map<ShipId, string>;
|
|
15
|
+
}): ResendSecrets;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SECRETS_REQUEST_CONTENT_TYPE } from './secrets.js';
|
|
2
|
+
/**
|
|
3
|
+
* Use case: a trierarch asks for the secret store again
|
|
4
|
+
* (aeolus-fleet-trierarch#120), once per process, as it asks for the lists.
|
|
5
|
+
* Its sender is forgotten from what this process sealed, so the next pass
|
|
6
|
+
* seals the store to the key its report states, as to a trierarch never sent
|
|
7
|
+
* it. The share pass sends only to trierarch ships, so another ship that asks
|
|
8
|
+
* gets nothing.
|
|
9
|
+
*/
|
|
10
|
+
export function createResendSecrets(deps) {
|
|
11
|
+
return (delivery) => {
|
|
12
|
+
if (delivery.contentType !== SECRETS_REQUEST_CONTENT_TYPE) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
deps.sealed.delete(delivery.senderShipId);
|
|
16
|
+
return true;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=resend-secrets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resend-secrets.js","sourceRoot":"","sources":["../../../src/core/mcp-servers/resend-secrets.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAC;AAK5D;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAqC;IACvE,OAAO,CAAC,QAAQ,EAAE,EAAE;QAClB,IAAI,QAAQ,CAAC,WAAW,KAAK,4BAA4B,EAAE,CAAC;YAC1D,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The public key a trierarch's report states for sealing its secrets to
|
|
3
|
+
* (`details.sealingKey`), or undefined for a trierarch without one or with a
|
|
4
|
+
* key of another scheme or shape, or the all-zero key: it is sent no secret.
|
|
5
|
+
*/
|
|
6
|
+
export declare function readSealingKey(details: unknown): string | undefined;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** The one sealing scheme a trierarch states: the NaCl anonymous sealed box. */
|
|
3
|
+
const SCHEME = 'nacl-sealed-box';
|
|
4
|
+
/** Standard base64 with padding of exactly 32 bytes: 43 characters, the last carrying 4 bits, then one `=`. */
|
|
5
|
+
const PUBLIC_KEY_BASE64 = /^[A-Za-z0-9+/]{42}[AEIMQUYcgkosw048]=$/;
|
|
6
|
+
/** The all-zero key: the identity point, which no box can be sealed to. */
|
|
7
|
+
const ZERO_KEY = `${'A'.repeat(43)}=`;
|
|
8
|
+
const detailsSchema = z.object({
|
|
9
|
+
sealingKey: z.object({ scheme: z.literal(SCHEME), publicKey: z.string().regex(PUBLIC_KEY_BASE64).refine((publicKey) => publicKey !== ZERO_KEY) }),
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* The public key a trierarch's report states for sealing its secrets to
|
|
13
|
+
* (`details.sealingKey`), or undefined for a trierarch without one or with a
|
|
14
|
+
* key of another scheme or shape, or the all-zero key: it is sent no secret.
|
|
15
|
+
*/
|
|
16
|
+
export function readSealingKey(details) {
|
|
17
|
+
const read = detailsSchema.safeParse(details);
|
|
18
|
+
return read.success ? read.data.sealingKey.publicKey : undefined;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=sealing-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sealing-key.js","sourceRoot":"","sources":["../../../src/core/mcp-servers/sealing-key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,gFAAgF;AAChF,MAAM,MAAM,GAAG,iBAAiB,CAAC;AAEjC,+GAA+G;AAC/G,MAAM,iBAAiB,GAAG,wCAAwC,CAAC;AAEnE,2EAA2E;AAC3E,MAAM,QAAQ,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC;AAEtC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7B,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,KAAK,QAAQ,CAAC,EAAE,CAAC;CAClJ,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,OAAgB;IAC7C,MAAM,IAAI,GAAG,aAAa,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAC9C,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Result } from '../shared/result.js';
|
|
2
|
+
import type { McpServers } from './mcp-servers.js';
|
|
3
|
+
/** The store as read: each secret by name with its value, in name order. Built only by `readSecrets`. */
|
|
4
|
+
export interface Secrets {
|
|
5
|
+
readonly secrets: readonly {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly value: string;
|
|
8
|
+
}[];
|
|
9
|
+
}
|
|
10
|
+
/** The content type of the message that carries the store, sealed, to a trierarch. */
|
|
11
|
+
export declare const SECRETS_CONTENT_TYPE = "application/vnd.aeolus.trierarch.secrets+json";
|
|
12
|
+
/** The content type of the message a trierarch asks for the store again with, once per process. */
|
|
13
|
+
export declare const SECRETS_REQUEST_CONTENT_TYPE = "application/vnd.aeolus.trierarch.secrets-request+json";
|
|
14
|
+
/**
|
|
15
|
+
* The store from the configuration's object of names to values, or why not,
|
|
16
|
+
* never naming a value or a name that fails the rules (an entry is told by
|
|
17
|
+
* its position): each name a trierarch name, each value fit for a
|
|
18
|
+
* header, every secret a server's credential names held, and the whole
|
|
19
|
+
* small enough, once sealed, to reach a trierarch in one message.
|
|
20
|
+
*/
|
|
21
|
+
export declare function readSecrets(listed: unknown, servers: McpServers): Result<Secrets, {
|
|
22
|
+
reason: string;
|
|
23
|
+
}>;
|
|
24
|
+
/** The store as a trierarch receives it: sealed to the public key named, each value as base64. */
|
|
25
|
+
export declare function secretsPayload(sealed: {
|
|
26
|
+
publicKey: string;
|
|
27
|
+
secrets: readonly {
|
|
28
|
+
name: string;
|
|
29
|
+
sealed: string;
|
|
30
|
+
}[];
|
|
31
|
+
}): string;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The secret store (decision M5 of the crew-time MCP servers design): the
|
|
3
|
+
* credentials the crew-time MCP servers need, by name, in the trierarch
|
|
4
|
+
* plugin's configuration, one store for every fleet and trierarch. A value
|
|
5
|
+
* leaves the trierarch plugin only sealed to a trierarch's own key, so the
|
|
6
|
+
* fleet stores only what it cannot read; the trierarch's proxy puts it in an
|
|
7
|
+
* HTTP header verbatim, so it holds no CR, LF or NUL.
|
|
8
|
+
*/
|
|
9
|
+
import { PAYLOAD_MAX_BYTES, payloadBytes, trierarchNameSchema } from '@aeolus-fleet/common';
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import { err, ok } from '../shared/result.js';
|
|
12
|
+
/** The content type of the message that carries the store, sealed, to a trierarch. */
|
|
13
|
+
export const SECRETS_CONTENT_TYPE = 'application/vnd.aeolus.trierarch.secrets+json';
|
|
14
|
+
/** The content type of the message a trierarch asks for the store again with, once per process. */
|
|
15
|
+
export const SECRETS_REQUEST_CONTENT_TYPE = 'application/vnd.aeolus.trierarch.secrets-request+json';
|
|
16
|
+
/** The most a value may hold, in bytes of UTF-8, as the trierarch takes it. */
|
|
17
|
+
const VALUE_MAX_BYTES = 8192;
|
|
18
|
+
/** What a sealed box adds to the value: the ephemeral public key and the tag. */
|
|
19
|
+
const SEALED_BOX_OVERHEAD_BYTES = 48;
|
|
20
|
+
/** A public key of the sealing scheme, in bytes. */
|
|
21
|
+
const PUBLIC_KEY_BYTES = 32;
|
|
22
|
+
const BYTES_PER_KB = 1024;
|
|
23
|
+
const VALUE_REFUSED = `a value is 1 to ${String(VALUE_MAX_BYTES)} bytes of UTF-8 with no CR, LF or NUL`;
|
|
24
|
+
const listedSchema = z.record(z.string(), z.unknown());
|
|
25
|
+
/** Whether the value can go in an HTTP header verbatim and the trierarch takes it. */
|
|
26
|
+
function isValue(value) {
|
|
27
|
+
if (typeof value !== 'string') {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const bytes = Buffer.byteLength(value, 'utf8');
|
|
31
|
+
return bytes >= 1 && bytes <= VALUE_MAX_BYTES && !['\r', '\n', '\u0000'].some((refused) => value.includes(refused));
|
|
32
|
+
}
|
|
33
|
+
/** The length of standard base64 with padding of so many bytes. */
|
|
34
|
+
function base64Length(bytes) {
|
|
35
|
+
const BASE64_GROUP_BYTES = 3;
|
|
36
|
+
const BASE64_GROUP_CHARACTERS = 4;
|
|
37
|
+
return Math.ceil(bytes / BASE64_GROUP_BYTES) * BASE64_GROUP_CHARACTERS;
|
|
38
|
+
}
|
|
39
|
+
/** The size of the message that carries the store once sealed, which a sealed box makes exact. */
|
|
40
|
+
function sealedPayloadBytes(store) {
|
|
41
|
+
return payloadBytes(secretsPayload({
|
|
42
|
+
publicKey: 'A'.repeat(base64Length(PUBLIC_KEY_BYTES)),
|
|
43
|
+
secrets: store.secrets.map(({ name, value }) => ({ name, sealed: 'A'.repeat(base64Length(Buffer.byteLength(value, 'utf8') + SEALED_BOX_OVERHEAD_BYTES)) })),
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The store from the configuration's object of names to values, or why not,
|
|
48
|
+
* never naming a value or a name that fails the rules (an entry is told by
|
|
49
|
+
* its position): each name a trierarch name, each value fit for a
|
|
50
|
+
* header, every secret a server's credential names held, and the whole
|
|
51
|
+
* small enough, once sealed, to reach a trierarch in one message.
|
|
52
|
+
*/
|
|
53
|
+
export function readSecrets(listed, servers) {
|
|
54
|
+
const object = listedSchema.safeParse(listed);
|
|
55
|
+
if (!object.success || Array.isArray(listed)) {
|
|
56
|
+
return err({ reason: 'the secrets are an object of names to values' });
|
|
57
|
+
}
|
|
58
|
+
const secrets = [];
|
|
59
|
+
for (const [index, [name, value]] of Object.entries(object.data).entries()) {
|
|
60
|
+
const named = trierarchNameSchema.safeParse(name);
|
|
61
|
+
if (!named.success) {
|
|
62
|
+
// A name that fails the rules may be a value swapped into its place, so the entry is told by position.
|
|
63
|
+
return err({ reason: `entry ${String(index + 1)}: ${named.error.issues[0]?.message ?? 'not a name'}` });
|
|
64
|
+
}
|
|
65
|
+
if (!isValue(value)) {
|
|
66
|
+
return err({ reason: `${name}: ${VALUE_REFUSED}` });
|
|
67
|
+
}
|
|
68
|
+
secrets.push({ name, value });
|
|
69
|
+
}
|
|
70
|
+
secrets.sort((first, second) => first.name.localeCompare(second.name));
|
|
71
|
+
const names = new Set(secrets.map((secret) => secret.name));
|
|
72
|
+
for (const server of servers.servers) {
|
|
73
|
+
if (server.credential !== undefined && !names.has(server.credential.secret)) {
|
|
74
|
+
return err({ reason: `${server.name}: its credential names the secret ${server.credential.secret}, which the store does not hold` });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const store = { secrets };
|
|
78
|
+
if (sealedPayloadBytes(store) > PAYLOAD_MAX_BYTES) {
|
|
79
|
+
return err({ reason: `the secrets do not fit one message of ${String(PAYLOAD_MAX_BYTES / BYTES_PER_KB)} KB once sealed` });
|
|
80
|
+
}
|
|
81
|
+
return ok(store);
|
|
82
|
+
}
|
|
83
|
+
/** The store as a trierarch receives it: sealed to the public key named, each value as base64. */
|
|
84
|
+
export function secretsPayload(sealed) {
|
|
85
|
+
return JSON.stringify({ publicKey: sealed.publicKey, secrets: sealed.secrets.map(({ name, sealed: value }) => ({ name, sealed: value })) });
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=secrets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.js","sourceRoot":"","sources":["../../../src/core/mcp-servers/secrets.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,m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7H,CAAC;IACD,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;AACnB,CAAC;AAED,kGAAkG;AAClG,MAAM,UAAU,cAAc,CAAC,MAAmF;IAChH,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;AAC9I,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { FleetId, ShipId } from '@aeolus-fleet/common';
|
|
2
|
+
import type { ConnectionStore, FleetDoor } from '../connection/ports.js';
|
|
3
|
+
import type { IdempotencyKeys } from '../machines/ports.js';
|
|
4
|
+
import { type DomainError } from '../shared/errors.js';
|
|
5
|
+
import { type Result } from '../shared/result.js';
|
|
6
|
+
import { type McpServers } from './mcp-servers.js';
|
|
7
|
+
export type ShareMcpServers = (fleetId: FleetId) => Promise<Result<{
|
|
8
|
+
shared: number;
|
|
9
|
+
}, DomainError<'NOT_CONNECTED' | 'FLEET_UNAVAILABLE'>>>;
|
|
10
|
+
/**
|
|
11
|
+
* Use case: one pass of sharing the MCP servers with a fleet's
|
|
12
|
+
* trierarchs (aeolus-fleet-trierarch#120). Every trierarch ship that is not retired gets
|
|
13
|
+
* the whole list as a message, once per process: `shared` remembers whom this
|
|
14
|
+
* process sent it, so a restart, which may come with a changed list, sends it
|
|
15
|
+
* to every trierarch again, under a new idempotency key. An empty list is sent
|
|
16
|
+
* too, so a trierarch stops offering what left it. A send the fleet refuses
|
|
17
|
+
* leaves that trierarch for the next pass.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createShareMcpServers(deps: {
|
|
20
|
+
door: FleetDoor;
|
|
21
|
+
connections: ConnectionStore;
|
|
22
|
+
keys: IdempotencyKeys;
|
|
23
|
+
mcpServers: McpServers;
|
|
24
|
+
shared: Set<ShipId>;
|
|
25
|
+
}): ShareMcpServers;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { TRIERARCH_TYPE } from '../machines/join-machine.js';
|
|
2
|
+
import { refuse } from '../shared/errors.js';
|
|
3
|
+
import { ok } from '../shared/result.js';
|
|
4
|
+
import { MCP_SERVERS_CONTENT_TYPE, mcpServersPayload } from './mcp-servers.js';
|
|
5
|
+
/** The refusal that means no answer came: the pass stops, and the next one tries again. */
|
|
6
|
+
const UNAVAILABLE = 'UNAVAILABLE';
|
|
7
|
+
/**
|
|
8
|
+
* Use case: one pass of sharing the MCP servers with a fleet's
|
|
9
|
+
* trierarchs (aeolus-fleet-trierarch#120). Every trierarch ship that is not retired gets
|
|
10
|
+
* the whole list as a message, once per process: `shared` remembers whom this
|
|
11
|
+
* process sent it, so a restart, which may come with a changed list, sends it
|
|
12
|
+
* to every trierarch again, under a new idempotency key. An empty list is sent
|
|
13
|
+
* too, so a trierarch stops offering what left it. A send the fleet refuses
|
|
14
|
+
* leaves that trierarch for the next pass.
|
|
15
|
+
*/
|
|
16
|
+
export function createShareMcpServers(deps) {
|
|
17
|
+
const unavailable = (refusal) => refuse('FLEET_UNAVAILABLE', `The fleet did not answer sharing the MCP servers: ${refusal.message}`);
|
|
18
|
+
const payload = mcpServersPayload(deps.mcpServers);
|
|
19
|
+
return async (fleetId) => {
|
|
20
|
+
const crew = await deps.connections.find(fleetId);
|
|
21
|
+
if (!crew) {
|
|
22
|
+
return refuse('NOT_CONNECTED', 'The trierarch plugin is not connected to this fleet: connect it in the console');
|
|
23
|
+
}
|
|
24
|
+
const listed = await deps.door.listShips(crew.crewToken);
|
|
25
|
+
if (!listed.isOk) {
|
|
26
|
+
return unavailable(listed.error);
|
|
27
|
+
}
|
|
28
|
+
let shared = 0;
|
|
29
|
+
for (const ship of listed.value) {
|
|
30
|
+
if (ship.type !== TRIERARCH_TYPE || ship.status === 'retired' || deps.shared.has(ship.shipId)) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const sent = await deps.door.send(crew.crewToken, { shipId: ship.shipId, contentType: MCP_SERVERS_CONTENT_TYPE, payload, idempotencyKey: deps.keys.next() });
|
|
34
|
+
if (!sent.isOk && sent.error.code === UNAVAILABLE) {
|
|
35
|
+
return unavailable(sent.error);
|
|
36
|
+
}
|
|
37
|
+
if (sent.isOk) {
|
|
38
|
+
deps.shared.add(ship.shipId);
|
|
39
|
+
shared += 1;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return ok({ shared });
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=share-mcp-servers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"share-mcp-servers.js","sourceRoot":"","sources":["../../../src/core/mcp-servers/share-mcp-servers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D,OAAO,EAAE,MAAM,EAAoB,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,EAAE,EAAe,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAmB,MAAM,kBAAkB,CAAC;AAIhG,2FAA2F;AAC3F,MAAM,WAAW,GAAG,aAAa,CAAC;AAElC;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAMrC;IACC,MAAM,WAAW,GAAG,CAAC,OAAqB,EAAE,EAAE,CAAC,MAAM,CAAC,mBAAmB,EAAE,qDAAqD,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IACnJ,MAAM,OAAO,GAAG,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACnD,OAAO,KAAK,EAAE,OAAO,EAAE,EAAE;QACvB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CA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ACJ,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { FleetId, ShipId } from '@aeolus-fleet/common';
|
|
2
|
+
import type { ConnectionStore, FleetDoor } from '../connection/ports.js';
|
|
3
|
+
import type { IdempotencyKeys } from '../machines/ports.js';
|
|
4
|
+
import { type DomainError } from '../shared/errors.js';
|
|
5
|
+
import { type Result } from '../shared/result.js';
|
|
6
|
+
import type { Sealer } from './ports.js';
|
|
7
|
+
import { type Secrets } from './secrets.js';
|
|
8
|
+
export type ShareSecrets = (fleetId: FleetId) => Promise<Result<{
|
|
9
|
+
shared: number;
|
|
10
|
+
unsealable: {
|
|
11
|
+
shipId: ShipId;
|
|
12
|
+
publicKey: string;
|
|
13
|
+
}[];
|
|
14
|
+
}, DomainError<'NOT_CONNECTED' | 'FLEET_UNAVAILABLE'>>>;
|
|
15
|
+
/**
|
|
16
|
+
* Use case: one pass of sharing the secret store with a fleet's trierarchs
|
|
17
|
+
* (decision M5). Every trierarch ship that is not retired and whose report
|
|
18
|
+
* states a sealing key gets the whole store, each value sealed to that key,
|
|
19
|
+
* so the fleet stores only what it cannot read. `sealed` remembers, per
|
|
20
|
+
* trierarch, the key this process last sealed the store to: a trierarch is
|
|
21
|
+
* sent it again only when its report states another key, and a restart,
|
|
22
|
+
* which may come with a changed store, sends it to every trierarch again
|
|
23
|
+
* under a new idempotency key. An empty store is sent too, so a trierarch
|
|
24
|
+
* forgets what left it. A trierarch without a key is sent nothing, and so is
|
|
25
|
+
* one whose key the sealer refuses: it is named in `unsealable` with the key, the pass goes
|
|
26
|
+
* on to the others, and the next pass tries it again. A send the fleet
|
|
27
|
+
* refuses leaves that trierarch for the next pass.
|
|
28
|
+
*/
|
|
29
|
+
export declare function createShareSecrets(deps: {
|
|
30
|
+
door: FleetDoor;
|
|
31
|
+
connections: ConnectionStore;
|
|
32
|
+
keys: IdempotencyKeys;
|
|
33
|
+
secrets: Secrets;
|
|
34
|
+
sealer: Sealer;
|
|
35
|
+
sealed: Map<ShipId, string>;
|
|
36
|
+
}): ShareSecrets;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { TRIERARCH_TYPE } from '../machines/join-machine.js';
|
|
2
|
+
import { refuse } from '../shared/errors.js';
|
|
3
|
+
import { ok } from '../shared/result.js';
|
|
4
|
+
import { readSealingKey } from './sealing-key.js';
|
|
5
|
+
import { SECRETS_CONTENT_TYPE, secretsPayload } from './secrets.js';
|
|
6
|
+
/** The refusal that means no answer came: the pass stops, and the next one tries again. */
|
|
7
|
+
const UNAVAILABLE = 'UNAVAILABLE';
|
|
8
|
+
/**
|
|
9
|
+
* Use case: one pass of sharing the secret store with a fleet's trierarchs
|
|
10
|
+
* (decision M5). Every trierarch ship that is not retired and whose report
|
|
11
|
+
* states a sealing key gets the whole store, each value sealed to that key,
|
|
12
|
+
* so the fleet stores only what it cannot read. `sealed` remembers, per
|
|
13
|
+
* trierarch, the key this process last sealed the store to: a trierarch is
|
|
14
|
+
* sent it again only when its report states another key, and a restart,
|
|
15
|
+
* which may come with a changed store, sends it to every trierarch again
|
|
16
|
+
* under a new idempotency key. An empty store is sent too, so a trierarch
|
|
17
|
+
* forgets what left it. A trierarch without a key is sent nothing, and so is
|
|
18
|
+
* one whose key the sealer refuses: it is named in `unsealable` with the key, the pass goes
|
|
19
|
+
* on to the others, and the next pass tries it again. A send the fleet
|
|
20
|
+
* refuses leaves that trierarch for the next pass.
|
|
21
|
+
*/
|
|
22
|
+
export function createShareSecrets(deps) {
|
|
23
|
+
const unavailable = (refusal) => refuse('FLEET_UNAVAILABLE', `The fleet did not answer sharing the secrets: ${refusal.message}`);
|
|
24
|
+
return async (fleetId) => {
|
|
25
|
+
const crew = await deps.connections.find(fleetId);
|
|
26
|
+
if (!crew) {
|
|
27
|
+
return refuse('NOT_CONNECTED', 'The trierarch plugin is not connected to this fleet: connect it in the console');
|
|
28
|
+
}
|
|
29
|
+
const listed = await deps.door.listShips(crew.crewToken);
|
|
30
|
+
if (!listed.isOk) {
|
|
31
|
+
return unavailable(listed.error);
|
|
32
|
+
}
|
|
33
|
+
let shared = 0;
|
|
34
|
+
const unsealable = [];
|
|
35
|
+
for (const ship of listed.value) {
|
|
36
|
+
if (ship.type !== TRIERARCH_TYPE || ship.status === 'retired') {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const read = await deps.door.getShip(crew.crewToken, { shipId: ship.shipId });
|
|
40
|
+
if (!read.isOk && read.error.code === UNAVAILABLE) {
|
|
41
|
+
return unavailable(read.error);
|
|
42
|
+
}
|
|
43
|
+
const publicKey = read.isOk ? readSealingKey(read.value.report?.details) : undefined;
|
|
44
|
+
if (publicKey === undefined || deps.sealed.get(ship.shipId) === publicKey) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const secrets = [];
|
|
48
|
+
for (const { name, value } of deps.secrets.secrets) {
|
|
49
|
+
const sealed = await deps.sealer.seal(value, publicKey);
|
|
50
|
+
if (!sealed.isOk) {
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
secrets.push({ name, sealed: sealed.value });
|
|
54
|
+
}
|
|
55
|
+
if (secrets.length < deps.secrets.secrets.length) {
|
|
56
|
+
unsealable.push({ shipId: ship.shipId, publicKey });
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const sent = await deps.door.send(crew.crewToken, { shipId: ship.shipId, contentType: SECRETS_CONTENT_TYPE, payload: secretsPayload({ publicKey, secrets }), idempotencyKey: deps.keys.next() });
|
|
60
|
+
if (!sent.isOk && sent.error.code === UNAVAILABLE) {
|
|
61
|
+
return unavailable(sent.error);
|
|
62
|
+
}
|
|
63
|
+
if (sent.isOk) {
|
|
64
|
+
deps.sealed.set(ship.shipId, publicKey);
|
|
65
|
+
shared += 1;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return ok({ shared, unsealable });
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=share-secrets.js.map
|