@culture.dev/agents 0.16.2 → 0.17.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 +26 -3
- package/dist/contract-schemas/api.json +324 -1
- package/dist/contract-schemas/fleet.json +114 -0
- package/dist/contract-schemas/reachability.json +51 -0
- package/dist/contract-schemas/remote.json +150 -0
- package/dist/contract-schemas/run.json +17 -3
- package/dist/contract-schemas/unreadable.json +45 -0
- package/dist/contract-schemas/version.json +1 -1
- package/dist/src/contract/api.d.ts +10 -0
- package/dist/src/contract/api.js +18 -0
- package/dist/src/contract/api.js.map +1 -1
- package/dist/src/contract/generated/fleet.d.ts +50 -0
- package/dist/src/contract/generated/fleet.js +3 -0
- package/dist/src/contract/generated/fleet.js.map +1 -0
- package/dist/src/contract/generated/index.d.ts +24 -0
- package/dist/src/contract/generated/reachability.d.ts +20 -0
- package/dist/src/contract/generated/reachability.js +3 -0
- package/dist/src/contract/generated/reachability.js.map +1 -0
- package/dist/src/contract/generated/remote.d.ts +64 -0
- package/dist/src/contract/generated/remote.js +3 -0
- package/dist/src/contract/generated/remote.js.map +1 -0
- package/dist/src/contract/generated/run.d.ts +3 -1
- package/dist/src/contract/generated/unreadable.d.ts +15 -0
- package/dist/src/contract/generated/unreadable.js +3 -0
- package/dist/src/contract/generated/unreadable.js.map +1 -0
- package/dist/src/contract/generated/version.d.ts +1 -1
- package/dist/src/contract/index.d.ts +1 -1
- package/dist/src/contract/index.js +1 -1
- package/dist/src/contract/index.js.map +1 -1
- package/dist/src/daemon/daemon.d.ts +6 -0
- package/dist/src/daemon/daemon.js +2 -0
- package/dist/src/daemon/daemon.js.map +1 -1
- package/dist/src/daemon/fleet-routes.d.ts +40 -0
- package/dist/src/daemon/fleet-routes.js +111 -0
- package/dist/src/daemon/fleet-routes.js.map +1 -0
- package/dist/src/daemon/http.d.ts +2 -2
- package/dist/src/daemon/http.js +5 -4
- package/dist/src/daemon/http.js.map +1 -1
- package/dist/src/daemon/main.js +16 -1
- package/dist/src/daemon/main.js.map +1 -1
- package/dist/src/daemon/ports.d.ts +22 -4
- package/dist/src/daemon/routes.d.ts +6 -1
- package/dist/src/daemon/routes.js +34 -0
- package/dist/src/daemon/routes.js.map +1 -1
- package/dist/src/daemon/secrets.js +2 -0
- package/dist/src/daemon/secrets.js.map +1 -1
- package/dist/src/fleet/aliases.d.ts +17 -0
- package/dist/src/fleet/aliases.js +62 -0
- package/dist/src/fleet/aliases.js.map +1 -0
- package/dist/src/fleet/announce.d.ts +53 -0
- package/dist/src/fleet/announce.js +126 -0
- package/dist/src/fleet/announce.js.map +1 -0
- package/dist/src/fleet/bundle.d.ts +21 -0
- package/dist/src/fleet/bundle.js +88 -0
- package/dist/src/fleet/bundle.js.map +1 -0
- package/dist/src/fleet/cert.d.ts +43 -0
- package/dist/src/fleet/cert.js +110 -0
- package/dist/src/fleet/cert.js.map +1 -0
- package/dist/src/fleet/command.d.ts +5 -0
- package/dist/src/fleet/command.js +71 -0
- package/dist/src/fleet/command.js.map +1 -0
- package/dist/src/fleet/config.d.ts +36 -0
- package/dist/src/fleet/config.js +69 -0
- package/dist/src/fleet/config.js.map +1 -0
- package/dist/src/fleet/index.d.ts +69 -0
- package/dist/src/fleet/index.js +120 -0
- package/dist/src/fleet/index.js.map +1 -0
- package/dist/src/fleet/members.d.ts +47 -0
- package/dist/src/fleet/members.js +131 -0
- package/dist/src/fleet/members.js.map +1 -0
- package/dist/src/fleet/peers.d.ts +18 -0
- package/dist/src/fleet/peers.js +76 -0
- package/dist/src/fleet/peers.js.map +1 -0
- package/dist/src/fleet/remote-attach.d.ts +33 -0
- package/dist/src/fleet/remote-attach.js +109 -0
- package/dist/src/fleet/remote-attach.js.map +1 -0
- package/dist/src/fleet/remote.d.ts +85 -0
- package/dist/src/fleet/remote.js +115 -0
- package/dist/src/fleet/remote.js.map +1 -0
- package/dist/src/fleet/serve-runs.d.ts +56 -0
- package/dist/src/fleet/serve-runs.js +176 -0
- package/dist/src/fleet/serve-runs.js.map +1 -0
- package/dist/src/fleet/transport.d.ts +85 -0
- package/dist/src/fleet/transport.js +243 -0
- package/dist/src/fleet/transport.js.map +1 -0
- package/dist/src/fleet/trust.d.ts +35 -0
- package/dist/src/fleet/trust.js +136 -0
- package/dist/src/fleet/trust.js.map +1 -0
- package/dist/src/harness/stub/backend.js +3 -1
- package/dist/src/harness/stub/backend.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/runs/admission.d.ts +15 -0
- package/dist/src/runs/admission.js +24 -1
- package/dist/src/runs/admission.js.map +1 -1
- package/dist/src/runs/gateway.d.ts +1 -0
- package/dist/src/runs/gateway.js +4 -0
- package/dist/src/runs/gateway.js.map +1 -1
- package/dist/src/runs/keys.js +5 -3
- package/dist/src/runs/keys.js.map +1 -1
- package/dist/src/runs/service.d.ts +6 -5
- package/dist/src/runs/service.js +25 -14
- package/dist/src/runs/service.js.map +1 -1
- package/dist/src/runs/unreadable.d.ts +8 -0
- package/dist/src/runs/unreadable.js +64 -0
- package/dist/src/runs/unreadable.js.map +1 -0
- package/package.json +3 -2
|
@@ -16,6 +16,8 @@ export const INJECTED_SECRETS = [
|
|
|
16
16
|
"CLAUDE_CODE_OAUTH_TOKEN",
|
|
17
17
|
"ANTHROPIC_API_KEY",
|
|
18
18
|
"LOBES_GATEWAY_KEY",
|
|
19
|
+
// The fleet member's private key (fleet/cert.ts), read only when the transport is configured.
|
|
20
|
+
"CULTURE_AGENTS_FLEET_KEY",
|
|
19
21
|
];
|
|
20
22
|
const held = new Map();
|
|
21
23
|
/** Read each named variable once, keep it in memory and delete it from `env` (not from /proc/<pid>/environ). Returns the names deleted. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secrets.js","sourceRoot":"","sources":["../../../src/daemon/secrets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAsB;IACjD,UAAU;I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IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC;YAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC/E,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type AliasFile, type AliasList, type Allowlist } from "../contract/index.js";
|
|
2
|
+
export interface AliasState {
|
|
3
|
+
path: string;
|
|
4
|
+
/** In force: empty unless the file is valid. */
|
|
5
|
+
aliases: AliasFile["aliases"];
|
|
6
|
+
/** Why the file defines nothing, when it exists and is refused. */
|
|
7
|
+
problem: string | null;
|
|
8
|
+
}
|
|
9
|
+
type Env = Readonly<Record<string, string | undefined>>;
|
|
10
|
+
export declare function resolveAliasesPath(env?: Env): string;
|
|
11
|
+
/** Read and check the alias file. Never throws: a refused file is an empty list with a `problem`. */
|
|
12
|
+
export declare function loadAliases(path: string): AliasState;
|
|
13
|
+
/** The path an alias resolves to on this host, or null when this host defines no such alias. */
|
|
14
|
+
export declare function resolveAlias(state: AliasState, alias: string): string | null;
|
|
15
|
+
/** What `GET /v1/fleet/aliases` reports: each alias and the agent and harness pairs the allow-list permits on its path. No path. */
|
|
16
|
+
export declare function aliasList(node: string, state: AliasState, entries: Allowlist["entries"]): AliasList;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The aliases a core gives its checkouts (docs/d2/part-two-design.md, Decision 4): the local file
|
|
3
|
+
* `${XDG_CONFIG_HOME:-$HOME/.config}/culture-agents/fleet/aliases.json`, beside the trust list, as
|
|
4
|
+
* `{ "version": 1, "aliases": [{ "alias": "culture-agents", "repo": "/abs/path" }] }`
|
|
5
|
+
* (contract `remote.json#/$defs/alias_file`). It is local and untracked, like the allow-list.
|
|
6
|
+
*
|
|
7
|
+
* - A member names a repository only by an alias this host defines; the alias resolves to a path on
|
|
8
|
+
* this host, and the allow-list (agent, harness, canonical path) applies to that path unchanged.
|
|
9
|
+
* No path crosses the network: another member sees aliases, never paths.
|
|
10
|
+
* - "The same repository" on two hosts is the operators' claim, made by giving the checkouts the same
|
|
11
|
+
* alias. The core never infers it; it checks only a commit the caller names (serve-runs.ts).
|
|
12
|
+
* - The file is read again on every call, with the trust file's 1 MiB cap. A missing file defines no
|
|
13
|
+
* alias. A file that cannot be read or does not validate defines none either, and says why.
|
|
14
|
+
*/
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
import { validate } from "../contract/index.js";
|
|
17
|
+
import { canonicalRepo } from "../daemon/allowlist.js";
|
|
18
|
+
import { readTrustText, resolveTrustPath } from "./trust.js";
|
|
19
|
+
export function resolveAliasesPath(env = process.env) {
|
|
20
|
+
return join(resolveTrustPath(env), "..", "aliases.json");
|
|
21
|
+
}
|
|
22
|
+
/** Read and check the alias file. Never throws: a refused file is an empty list with a `problem`. */
|
|
23
|
+
export function loadAliases(path) {
|
|
24
|
+
let text;
|
|
25
|
+
try {
|
|
26
|
+
text = readTrustText(path);
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
return { path, aliases: [], problem: e.message };
|
|
30
|
+
}
|
|
31
|
+
if (text === null)
|
|
32
|
+
return { path, aliases: [], problem: null };
|
|
33
|
+
let parsed;
|
|
34
|
+
try {
|
|
35
|
+
parsed = JSON.parse(text);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return { path, aliases: [], problem: `${path} is not valid JSON` };
|
|
39
|
+
}
|
|
40
|
+
const checked = validate("remote#alias_file", parsed);
|
|
41
|
+
if (!checked.ok)
|
|
42
|
+
return { path, aliases: [], problem: `${path}: ${checked.issues[0]?.path || "(root)"} ${checked.issues[0]?.message ?? "is invalid"}` };
|
|
43
|
+
const names = checked.value.aliases.map((a) => a.alias);
|
|
44
|
+
const twice = names.find((name, i) => names.indexOf(name) !== i);
|
|
45
|
+
if (twice !== undefined)
|
|
46
|
+
return { path, aliases: [], problem: `${path} defines alias ${twice} twice` };
|
|
47
|
+
return { path, aliases: checked.value.aliases, problem: null };
|
|
48
|
+
}
|
|
49
|
+
/** The path an alias resolves to on this host, or null when this host defines no such alias. */
|
|
50
|
+
export function resolveAlias(state, alias) {
|
|
51
|
+
return state.aliases.find((a) => a.alias === alias)?.repo ?? null;
|
|
52
|
+
}
|
|
53
|
+
/** What `GET /v1/fleet/aliases` reports: each alias and the agent and harness pairs the allow-list permits on its path. No path. */
|
|
54
|
+
export function aliasList(node, state, entries) {
|
|
55
|
+
const aliases = state.aliases.map((a) => {
|
|
56
|
+
const repo = canonicalRepo(a.repo) ?? a.repo;
|
|
57
|
+
const permits = entries.filter((e) => (canonicalRepo(e.repo) ?? e.repo) === repo).map((e) => ({ agent_id: e.agent_id, harness: e.harness }));
|
|
58
|
+
return { alias: a.alias, permits };
|
|
59
|
+
});
|
|
60
|
+
return { node, aliases };
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=aliases.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aliases.js","sourceRoot":"","sources":["../../../src/fleet/aliases.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,QAAQ,EAAkD,MAAM,sBAAsB,CAAC;AAChG,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAY7D,MAAM,UAAU,kBAAkB,CAAC,MAAW,OAAO,CAAC,GAAG;IACvD,OAAO,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;AAC3D,CAAC;AAED,qGAAqG;AACrG,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,IAAI,IAAmB,CAAC;IACxB,IAAI,CAAC;QACH,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;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transport to each address in the local address list
|
|
4
|
+
* (peers.ts), each call on its own connection with one timeout. The reply is the peer's own
|
|
5
|
+
* announcement, authenticated by the peer's key, and goes into the member list like any other, so
|
|
6
|
+
* two cores list each other when only one knows the other's address. On a clean stop the core
|
|
7
|
+
* announces `leaving` once, with a short timeout, so its peers drop it at once.
|
|
8
|
+
*
|
|
9
|
+
* A call still in flight to an address is not started again. A clean stop waits for the round in
|
|
10
|
+
* flight (at most `LEAVING_TIMEOUT_MS`) before it announces `leaving`, so a late `up` cannot list
|
|
11
|
+
* the stopping core again. Outcomes are logged when they change
|
|
12
|
+
* (reachable, refused, unreachable), never once per interval.
|
|
13
|
+
*/
|
|
14
|
+
import type { KeyObject } from "node:crypto";
|
|
15
|
+
import { type Members } from "./members.js";
|
|
16
|
+
import type { PeerAddress } from "./peers.js";
|
|
17
|
+
import { type FleetCallOptions, type FleetResponse } from "./transport.js";
|
|
18
|
+
import type { TrustList } from "./trust.js";
|
|
19
|
+
/** An announcement and its reply are a few dozen bytes; read no more than this of a reply. */
|
|
20
|
+
export declare const MAX_REPLY_BYTES: number;
|
|
21
|
+
/** How long the `leaving` announcement of a clean stop may take. */
|
|
22
|
+
export declare const LEAVING_TIMEOUT_MS = 1000;
|
|
23
|
+
type Log = (line: string) => void;
|
|
24
|
+
type Call = (o: FleetCallOptions) => Promise<FleetResponse>;
|
|
25
|
+
export interface AnnouncerOptions {
|
|
26
|
+
key: KeyObject;
|
|
27
|
+
/** The trust list, read again for each round (the client checks each peer against it). */
|
|
28
|
+
trust: () => TrustList;
|
|
29
|
+
/** The address list, read again for each round. */
|
|
30
|
+
peers: () => PeerAddress[];
|
|
31
|
+
members: Members;
|
|
32
|
+
log: Log;
|
|
33
|
+
intervalMs?: number;
|
|
34
|
+
/** One call's timeout. Default: one interval, at most the transport's 5 s. */
|
|
35
|
+
timeoutMs?: number;
|
|
36
|
+
/** The transport call (tests inject one). */
|
|
37
|
+
call?: Call;
|
|
38
|
+
}
|
|
39
|
+
export interface Announcer {
|
|
40
|
+
/** One announcement to every address not already in flight; resolves when all have settled. */
|
|
41
|
+
round(): Promise<void>;
|
|
42
|
+
/** Announce now and then every interval. */
|
|
43
|
+
start(): void;
|
|
44
|
+
/** Stop announcing, then announce `leaving` to every address once. Idempotent. */
|
|
45
|
+
stop(): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* The address in the local address list whose last reply came from member `node`, authenticated as
|
|
48
|
+
* that member's key; undefined when none did. A remote call goes only to such an address.
|
|
49
|
+
*/
|
|
50
|
+
addressOf(node: string): PeerAddress | undefined;
|
|
51
|
+
}
|
|
52
|
+
export declare function createAnnouncer(o: AnnouncerOptions): Announcer;
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { API_VERSION_HEADER, validate } from "../contract/index.js";
|
|
2
|
+
import { ANNOUNCE_INTERVAL_MS } from "./members.js";
|
|
3
|
+
import { FLEET_TIMEOUT_MS, fleetCall } from "./transport.js";
|
|
4
|
+
/** An announcement and its reply are a few dozen bytes; read no more than this of a reply. */
|
|
5
|
+
export const MAX_REPLY_BYTES = 16 * 1024;
|
|
6
|
+
/** How long the `leaving` announcement of a clean stop may take. */
|
|
7
|
+
export const LEAVING_TIMEOUT_MS = 1000;
|
|
8
|
+
const label = (p) => (p.host.includes(":") ? `[${p.host}]:${p.port}` : `${p.host}:${p.port}`);
|
|
9
|
+
function errorText(body) {
|
|
10
|
+
try {
|
|
11
|
+
// A refused announcement has its own body (fleet.json `announce_refusal`); any other error is error.json.
|
|
12
|
+
const parsed = JSON.parse(body.toString("utf8"));
|
|
13
|
+
const e = parsed.error ?? parsed;
|
|
14
|
+
return `${String(e.code)}: ${String(e.message)}`.slice(0, 300);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return "an unreadable error body";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** The peer's reply, which must be its own announcement. */
|
|
21
|
+
function replyOf(res) {
|
|
22
|
+
let body;
|
|
23
|
+
try {
|
|
24
|
+
body = JSON.parse(res.body.toString("utf8"));
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
throw new Error("the reply is not JSON");
|
|
28
|
+
}
|
|
29
|
+
if (!validate("fleet#announcement", body).ok)
|
|
30
|
+
throw new Error("the reply is not an announcement");
|
|
31
|
+
return body;
|
|
32
|
+
}
|
|
33
|
+
export function createAnnouncer(o) {
|
|
34
|
+
const call = o.call ?? fleetCall;
|
|
35
|
+
const intervalMs = o.intervalMs ?? ANNOUNCE_INTERVAL_MS;
|
|
36
|
+
const inFlight = new Set();
|
|
37
|
+
const outcome = new Map(); // last logged outcome per address
|
|
38
|
+
const answeredAs = new Map(); // by address: the member whose key last replied there
|
|
39
|
+
let timer = null;
|
|
40
|
+
let stopping = null;
|
|
41
|
+
const note = (where, what, line) => {
|
|
42
|
+
if (outcome.get(where) === what)
|
|
43
|
+
return;
|
|
44
|
+
outcome.set(where, what);
|
|
45
|
+
o.log(`culture-agents core: fleet: ${line}`);
|
|
46
|
+
};
|
|
47
|
+
const send = (peer, state, timeoutMs) => {
|
|
48
|
+
const announcement = o.members.announcement(state);
|
|
49
|
+
const headers = { [API_VERSION_HEADER]: announcement.api_version }; // the rule between cores: same MAJOR (contract/README.md)
|
|
50
|
+
return call({ key: o.key, trust: o.trust(), host: peer.host, port: peer.port, method: "POST", path: "/v1/fleet/announce", body: JSON.stringify(announcement), headers, timeoutMs, maxResponseBytes: MAX_REPLY_BYTES });
|
|
51
|
+
};
|
|
52
|
+
async function announceTo(peer) {
|
|
53
|
+
const where = label(peer);
|
|
54
|
+
try {
|
|
55
|
+
const res = await send(peer, "up", o.timeoutMs ?? Math.min(intervalMs, FLEET_TIMEOUT_MS));
|
|
56
|
+
answeredAs.delete(where);
|
|
57
|
+
if (res.status !== 200) {
|
|
58
|
+
note(where, `refused ${res.status}`, `${where} refused this core's announcement (${res.status}, ${errorText(res.body)})`);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const receipt = o.members.receive(res.member, replyOf(res));
|
|
62
|
+
if (!receipt.ok)
|
|
63
|
+
return;
|
|
64
|
+
answeredAs.set(where, { node: res.member.node, peer });
|
|
65
|
+
note(where, "ok", `announced to ${where}, which is member ${res.member.node}`);
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
answeredAs.delete(where);
|
|
69
|
+
note(where, "failed", `cannot announce to ${where}: ${e.message}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
let current = Promise.resolve();
|
|
73
|
+
async function round() {
|
|
74
|
+
if (stopping)
|
|
75
|
+
return;
|
|
76
|
+
const due = o.peers().filter((p) => !inFlight.has(label(p)));
|
|
77
|
+
current = Promise.allSettled(due.map(async (peer) => {
|
|
78
|
+
inFlight.add(label(peer));
|
|
79
|
+
try {
|
|
80
|
+
await announceTo(peer);
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
inFlight.delete(label(peer));
|
|
84
|
+
}
|
|
85
|
+
}));
|
|
86
|
+
await current;
|
|
87
|
+
}
|
|
88
|
+
const tick = () => {
|
|
89
|
+
round().catch((e) => o.log(`culture-agents core: fleet: an announcement round failed: ${String(e)}`));
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
round,
|
|
93
|
+
addressOf(node) {
|
|
94
|
+
const listed = new Set(o.peers().map(label)); // an address the operator removed is not called
|
|
95
|
+
for (const [where, a] of answeredAs)
|
|
96
|
+
if (a.node === node && listed.has(where))
|
|
97
|
+
return a.peer;
|
|
98
|
+
return undefined;
|
|
99
|
+
},
|
|
100
|
+
start() {
|
|
101
|
+
if (timer || stopping)
|
|
102
|
+
return;
|
|
103
|
+
tick();
|
|
104
|
+
timer = setInterval(tick, intervalMs);
|
|
105
|
+
timer.unref();
|
|
106
|
+
},
|
|
107
|
+
stop() {
|
|
108
|
+
stopping ??= (async () => {
|
|
109
|
+
if (timer)
|
|
110
|
+
clearInterval(timer);
|
|
111
|
+
timer = null;
|
|
112
|
+
// An `up` still in flight could land after the `leaving` and list this core again: let it
|
|
113
|
+
// settle first, waiting no longer than the leaving's own timeout.
|
|
114
|
+
let wait;
|
|
115
|
+
await Promise.race([current, new Promise((resolve) => (wait = setTimeout(resolve, LEAVING_TIMEOUT_MS)))]);
|
|
116
|
+
clearTimeout(wait);
|
|
117
|
+
const results = await Promise.allSettled(o.peers().map((peer) => send(peer, "leaving", LEAVING_TIMEOUT_MS)));
|
|
118
|
+
const told = results.filter((r) => r.status === "fulfilled" && r.value.status === 200).length;
|
|
119
|
+
if (results.length > 0)
|
|
120
|
+
o.log(`culture-agents core: fleet: announced leaving to ${told} of ${results.length} address(es)`);
|
|
121
|
+
})();
|
|
122
|
+
return stopping;
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=announce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"announce.js","sourceRoot":"","sources":["../../../src/fleet/announce.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAqB,MAAM,sBAAsB,CAAC;AACvF,OAAO,EAAE,oBAAoB,EAAgB,MAAM,cAAc,CAAC;AAElE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAA6C,MAAM,gBAAgB,CAAC;AAGxG,8FAA8F;AAC9F,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,GAAG,IAAI,CAAC;AACzC,oEAAoE;AACpE,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAkCvC,MAAM,KAAK,GAAG,CAAC,CAAc,EAAU,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AAEnH,SAAS,SAAS,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CAAC;gBAChC,KAAK,GAAG,IAAI,CAAC;gBACb,0FAA0F;gBAC1F,kEAAkE;gBAClE,IAAI,IAAgC,CAAC;gBACrC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,IAAI,GAAG,UAAU,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC1G,YAAY,CAAC,IAAI,CAAC,CAAC;gBACnB,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC;gBAC7G,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,WAAW,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC,MAAM,CAAC;gBAC9F,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;oBAAE,CAAC,CAAC,GAAG,CAAC,oDAAoD,IAAI,OAAO,OAAO,CAAC,MAAM,cAAc,CAAC,CAAC;YAC7H,CAAC,CAAC,EAAE,CAAC;YACL,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ServerResponse } from "node:http";
|
|
2
|
+
import type { Run, RunResult } from "../contract/index.js";
|
|
3
|
+
import { type CommandRunner } from "../sandbox/host-command.js";
|
|
4
|
+
import type { Remote } from "./remote.js";
|
|
5
|
+
/** The MINOR that added a remote run's result, logs and bundle: a member that announced less does not serve them. */
|
|
6
|
+
export declare const REMOTE_RESULTS_SINCE = "3.3";
|
|
7
|
+
export declare const REMOTE_RESULTS_WHAT = "a remote run's result, logs and bundle";
|
|
8
|
+
export declare const BUNDLE_CONTENT_TYPE = "application/x-git-bundle";
|
|
9
|
+
export declare const SENSITIVITY_HEADER = "Agents-Content-Sensitivity";
|
|
10
|
+
export declare const MAX_BUNDLE_BYTES: number;
|
|
11
|
+
export declare const BUNDLE_TIMEOUT_MS = 60000;
|
|
12
|
+
/** Mark a cross-host response whose content is the executing core's, unredacted. */
|
|
13
|
+
export declare function markUnredacted(res: ServerResponse): void;
|
|
14
|
+
/** Whether `bytes` begins as a git bundle (version 2 or 3) does. */
|
|
15
|
+
export declare function isBundle(bytes: Buffer): boolean;
|
|
16
|
+
/** The bundle of a finished run's branch in its repository: one ref, the commits after its base. */
|
|
17
|
+
export declare function makeRunBundle(run: Run, result: RunResult, node: string, runner?: CommandRunner): Promise<Buffer>;
|
|
18
|
+
/** Executing core: the bundle of a run the caller may read (checked before this is called). */
|
|
19
|
+
export declare function serveRunBundle(run: Run, result: RunResult, node: string, res: ServerResponse): Promise<void>;
|
|
20
|
+
/** Calling core: read a run's bundle from the member that executes it and pass it on unchanged. */
|
|
21
|
+
export declare function relayRunBundle(remote: Remote, node: string, runId: string, res: ServerResponse): Promise<void>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A run's commits across hosts (contract 3.3, spec c39 and h28; docs/d2/run-bundles.md): the
|
|
3
|
+
* executing core serves a finished run's branch as a git bundle over the fleet transport, and the
|
|
4
|
+
* calling core passes it on through its control socket, so the caller's CLI fetches the branch into
|
|
5
|
+
* its own checkout. No shell, account or SSH on the executing host is involved.
|
|
6
|
+
*
|
|
7
|
+
* - **Only that run's ref.** The bundle is `git bundle create <file> refs/heads/runs/<id> ^<base>`:
|
|
8
|
+
* one ref, the run's branch, and only the commits after the run's base commit, which is the
|
|
9
|
+
* bundle's one prerequisite. No other branch, tag or commit of the executing host travels.
|
|
10
|
+
* - **Only to a caller allowed to read the run.** Over the fleet transport, only the member that
|
|
11
|
+
* submitted the run (serve-runs.ts checks this before anything of the run is read); on the
|
|
12
|
+
* control socket, its owner, the local operator. Result and logs follow the same rule.
|
|
13
|
+
* - **Not redacted, but marked.** Logs, attach and the bundle cross hosts as the executing core
|
|
14
|
+
* stored them. Each cross-host response of these carries `Agents-Content-Sensitivity: unredacted`,
|
|
15
|
+
* an HTTP header, so no schema gained a field (the design record's note on t26).
|
|
16
|
+
* - **Bounded.** A bundle is at most 64 MiB, and its one call to the member has 60 s (every other
|
|
17
|
+
* call between cores keeps 5 s). A larger bundle is refused on the executing core before it is sent.
|
|
18
|
+
*/
|
|
19
|
+
import { mkdtemp, readFile, rm, stat } from "node:fs/promises";
|
|
20
|
+
import { tmpdir } from "node:os";
|
|
21
|
+
import { join } from "node:path";
|
|
22
|
+
import { ControlError, notFound, unsupported } from "../daemon/errors.js";
|
|
23
|
+
import { hostEnv, runCommand } from "../sandbox/host-command.js";
|
|
24
|
+
/** The MINOR that added a remote run's result, logs and bundle: a member that announced less does not serve them. */
|
|
25
|
+
export const REMOTE_RESULTS_SINCE = "3.3";
|
|
26
|
+
export const REMOTE_RESULTS_WHAT = "a remote run's result, logs and bundle";
|
|
27
|
+
export const BUNDLE_CONTENT_TYPE = "application/x-git-bundle";
|
|
28
|
+
export const SENSITIVITY_HEADER = "Agents-Content-Sensitivity";
|
|
29
|
+
export const MAX_BUNDLE_BYTES = 64 * 1024 * 1024;
|
|
30
|
+
export const BUNDLE_TIMEOUT_MS = 60_000;
|
|
31
|
+
/** Mark a cross-host response whose content is the executing core's, unredacted. */
|
|
32
|
+
export function markUnredacted(res) {
|
|
33
|
+
res.setHeader(SENSITIVITY_HEADER, "unredacted");
|
|
34
|
+
}
|
|
35
|
+
/** Whether `bytes` begins as a git bundle (version 2 or 3) does. */
|
|
36
|
+
export function isBundle(bytes) {
|
|
37
|
+
const head = bytes.subarray(0, 16).toString("latin1");
|
|
38
|
+
return head === "# v2 git bundle\n" || head === "# v3 git bundle\n";
|
|
39
|
+
}
|
|
40
|
+
function sendBundle(res, bytes) {
|
|
41
|
+
markUnredacted(res);
|
|
42
|
+
res.writeHead(200, { "Content-Type": BUNDLE_CONTENT_TYPE, "Content-Length": bytes.length });
|
|
43
|
+
res.end(bytes);
|
|
44
|
+
}
|
|
45
|
+
/** The bundle of a finished run's branch in its repository: one ref, the commits after its base. */
|
|
46
|
+
export async function makeRunBundle(run, result, node, runner = runCommand) {
|
|
47
|
+
const none = notFound(`Run ${run.id} on ${node} has no commits to fetch.`, { run_id: run.id });
|
|
48
|
+
if (result.branch === null || result.commits.length === 0)
|
|
49
|
+
throw none;
|
|
50
|
+
if (run.base_commit === undefined)
|
|
51
|
+
throw new ControlError("internal", `Run ${run.id} has no recorded base commit.`);
|
|
52
|
+
const dir = await mkdtemp(join(tmpdir(), "culture-agents-bundle-"));
|
|
53
|
+
try {
|
|
54
|
+
const file = join(dir, "run.bundle");
|
|
55
|
+
// Both revisions are checked identifiers (a run id and a 40-hex commit id), never options.
|
|
56
|
+
const made = await runner("git", ["-C", run.repo, "bundle", "create", "--quiet", file, `refs/heads/${result.branch}`, `^${run.base_commit}`], { env: hostEnv(), timeoutMs: BUNDLE_TIMEOUT_MS });
|
|
57
|
+
if (made.code !== 0) {
|
|
58
|
+
if (/empty bundle/i.test(made.stderr))
|
|
59
|
+
throw none;
|
|
60
|
+
process.stderr.write(`culture-agents core: git bundle create for run ${run.id} failed (exit ${made.code}): ${made.stderr.trim().slice(0, 500)}\n`);
|
|
61
|
+
throw new ControlError("internal", `git could not bundle run ${run.id} on ${node}.`);
|
|
62
|
+
}
|
|
63
|
+
if ((await stat(file)).size > MAX_BUNDLE_BYTES) {
|
|
64
|
+
throw unsupported("placement", `The bundle of run ${run.id} on ${node} is larger than 64 MiB, the most one fetch across hosts carries; its operator can hand the branch over another way.`);
|
|
65
|
+
}
|
|
66
|
+
return await readFile(file);
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
await rm(dir, { recursive: true, force: true });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** Executing core: the bundle of a run the caller may read (checked before this is called). */
|
|
73
|
+
export async function serveRunBundle(run, result, node, res) {
|
|
74
|
+
sendBundle(res, await makeRunBundle(run, result, node));
|
|
75
|
+
}
|
|
76
|
+
/** Calling core: read a run's bundle from the member that executes it and pass it on unchanged. */
|
|
77
|
+
export async function relayRunBundle(remote, node, runId, res) {
|
|
78
|
+
const bytes = await remote.fetchBytes(node, {
|
|
79
|
+
path: `/v1/fleet/runs/${encodeURIComponent(runId)}/bundle`,
|
|
80
|
+
maxBytes: MAX_BUNDLE_BYTES,
|
|
81
|
+
timeoutMs: BUNDLE_TIMEOUT_MS,
|
|
82
|
+
since: REMOTE_RESULTS_SINCE,
|
|
83
|
+
what: REMOTE_RESULTS_WHAT,
|
|
84
|
+
accept: isBundle,
|
|
85
|
+
});
|
|
86
|
+
sendBundle(res, bytes);
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.js","sourceRoot":"","sources":["../../../src/fleet/bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE/D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,UAAU,EAAsB,MAAM,4BAA4B,CAAC;AAGrF,qHAAqH;AACrH,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,CAAC;AAC1C,MAAM,CAAC,MAAM,mBAAmB,GAAG,wCAAwC,CAAC;AAC5E,MAAM,CAAC,MAAM,mBAAmB,GAAG,0BAA0B,CAAC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MAAM,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAClD,CAAC;AACH,CAAC;AAED,+FAA+F;AAC/F,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,GAAQ,EAAE,MAAiB,EAAE,IAAY,EAAE,GAAmB;IACjG,UAAU,CAAC,GAAG,EAAE,MAAM,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED,mGAAmG;AACnG,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,MAAc,EAAE,IAAY,EAAE,KAAa,EAAE,GAAmB;IACnG,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE;QAC1C,IAAI,EAAE,kBAAkB,kBAAkB,CAAC,KAAK,CAAC,SAAS;QAC1D,QAAQ,EAAE,gBAAgB;QAC1B,SAAS,EAAE,iBAAiB;QAC5B,KAAK,EAAE,oBAAoB;QAC3B,IAAI,EAAE,mBAAmB;QACzB,MAAM,EAAE,QAAQ;KACjB,CAAC,CAAC;IACH,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A fleet member's key and the certificate derived from it (docs/d2/part-two-design.md, Decisions 1
|
|
3
|
+
* and 2). Node's standard library only.
|
|
4
|
+
*
|
|
5
|
+
* - The private key is Ed25519. It reaches the core as one line, `ed25519:<base64 PKCS#8 DER>`, in
|
|
6
|
+
* `CULTURE_AGENTS_FLEET_KEY`, injected by `grant run --inject`. The core takes it out of its
|
|
7
|
+
* environment at start with the other injected secrets (daemon/secrets.ts). The kernel keeps the
|
|
8
|
+
* environment the process started with, so the key stays readable in `/proc/<core pid>/environ`
|
|
9
|
+
* to processes of the same user for as long as the core runs; other users cannot read it.
|
|
10
|
+
* - The certificate is a self-signed X.509 v3 certificate built in memory. Every field is fixed or
|
|
11
|
+
* derived from the public key, and Ed25519 signatures are deterministic, so one key always gives
|
|
12
|
+
* the same certificate bytes. It is public: it is what an operator adds to another member's trust
|
|
13
|
+
* list. Node can parse a certificate but cannot make one, so the few DER fields are encoded here.
|
|
14
|
+
*/
|
|
15
|
+
import { X509Certificate, type KeyObject } from "node:crypto";
|
|
16
|
+
export declare const FLEET_KEY_ENV = "CULTURE_AGENTS_FLEET_KEY";
|
|
17
|
+
export declare class FleetKeyError extends Error {
|
|
18
|
+
readonly name = "FleetKeyError";
|
|
19
|
+
}
|
|
20
|
+
/** Parse the one-line key form. The error never contains the value. */
|
|
21
|
+
export declare function parseFleetKey(text: string): KeyObject;
|
|
22
|
+
/** The one-line form of a private key. Only the key command prints it, for the operator to store in grant. */
|
|
23
|
+
export declare function fleetKeyText(key: KeyObject): string;
|
|
24
|
+
/** A fresh Ed25519 private key. */
|
|
25
|
+
export declare function newFleetKey(): KeyObject;
|
|
26
|
+
/** SHA-256 of the SubjectPublicKeyInfo DER, hex: the fingerprint an operator compares by eye. */
|
|
27
|
+
export declare function fingerprint(keyOrCert: KeyObject | X509Certificate): string;
|
|
28
|
+
export interface MemberCertificate {
|
|
29
|
+
readonly der: Buffer;
|
|
30
|
+
readonly pem: string;
|
|
31
|
+
/** The certificate DER as one base64 line: the form a trust list holds. */
|
|
32
|
+
readonly text: string;
|
|
33
|
+
}
|
|
34
|
+
/** The self-signed certificate of `key`. The subject is the key's fingerprint, so no two members share one. */
|
|
35
|
+
export declare function certificateFor(key: KeyObject): MemberCertificate;
|
|
36
|
+
/**
|
|
37
|
+
* A trust-list certificate from its one-line form. Refused unless it parses, carries an Ed25519
|
|
38
|
+
* public key and is signed by that key (a member certificate is self-signed).
|
|
39
|
+
*/
|
|
40
|
+
export declare function parseMemberCertificate(text: string): {
|
|
41
|
+
cert: X509Certificate;
|
|
42
|
+
pem: string;
|
|
43
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A fleet member's key and the certificate derived from it (docs/d2/part-two-design.md, Decisions 1
|
|
3
|
+
* and 2). Node's standard library only.
|
|
4
|
+
*
|
|
5
|
+
* - The private key is Ed25519. It reaches the core as one line, `ed25519:<base64 PKCS#8 DER>`, in
|
|
6
|
+
* `CULTURE_AGENTS_FLEET_KEY`, injected by `grant run --inject`. The core takes it out of its
|
|
7
|
+
* environment at start with the other injected secrets (daemon/secrets.ts). The kernel keeps the
|
|
8
|
+
* environment the process started with, so the key stays readable in `/proc/<core pid>/environ`
|
|
9
|
+
* to processes of the same user for as long as the core runs; other users cannot read it.
|
|
10
|
+
* - The certificate is a self-signed X.509 v3 certificate built in memory. Every field is fixed or
|
|
11
|
+
* derived from the public key, and Ed25519 signatures are deterministic, so one key always gives
|
|
12
|
+
* the same certificate bytes. It is public: it is what an operator adds to another member's trust
|
|
13
|
+
* list. Node can parse a certificate but cannot make one, so the few DER fields are encoded here.
|
|
14
|
+
*/
|
|
15
|
+
import { createHash, createPrivateKey, createPublicKey, generateKeyPairSync, sign, X509Certificate } from "node:crypto";
|
|
16
|
+
export const FLEET_KEY_ENV = "CULTURE_AGENTS_FLEET_KEY";
|
|
17
|
+
const KEY_PREFIX = "ed25519:";
|
|
18
|
+
export class FleetKeyError extends Error {
|
|
19
|
+
name = "FleetKeyError";
|
|
20
|
+
}
|
|
21
|
+
/** Parse the one-line key form. The error never contains the value. */
|
|
22
|
+
export function parseFleetKey(text) {
|
|
23
|
+
const trimmed = text.trim();
|
|
24
|
+
if (!trimmed.startsWith(KEY_PREFIX))
|
|
25
|
+
throw new FleetKeyError(`${FLEET_KEY_ENV} must be one line of the form ed25519:<base64 PKCS#8>`);
|
|
26
|
+
let key;
|
|
27
|
+
try {
|
|
28
|
+
key = createPrivateKey({ key: Buffer.from(trimmed.slice(KEY_PREFIX.length), "base64"), format: "der", type: "pkcs8" });
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
throw new FleetKeyError(`${FLEET_KEY_ENV} is not a valid PKCS#8 private key`);
|
|
32
|
+
}
|
|
33
|
+
if (key.asymmetricKeyType !== "ed25519")
|
|
34
|
+
throw new FleetKeyError(`${FLEET_KEY_ENV} must hold an Ed25519 key`);
|
|
35
|
+
return key;
|
|
36
|
+
}
|
|
37
|
+
/** The one-line form of a private key. Only the key command prints it, for the operator to store in grant. */
|
|
38
|
+
export function fleetKeyText(key) {
|
|
39
|
+
return KEY_PREFIX + key.export({ type: "pkcs8", format: "der" }).toString("base64");
|
|
40
|
+
}
|
|
41
|
+
/** A fresh Ed25519 private key. */
|
|
42
|
+
export function newFleetKey() {
|
|
43
|
+
return generateKeyPairSync("ed25519").privateKey;
|
|
44
|
+
}
|
|
45
|
+
/** SHA-256 of the SubjectPublicKeyInfo DER, hex: the fingerprint an operator compares by eye. */
|
|
46
|
+
export function fingerprint(keyOrCert) {
|
|
47
|
+
const pub = keyOrCert instanceof X509Certificate ? keyOrCert.publicKey : createPublicKey(keyOrCert);
|
|
48
|
+
return createHash("sha256").update(pub.export({ type: "spki", format: "der" })).digest("hex");
|
|
49
|
+
}
|
|
50
|
+
// ---------------------------------------------------------------- DER, only what the certificate needs
|
|
51
|
+
function derLength(n) {
|
|
52
|
+
if (n < 0x80)
|
|
53
|
+
return Buffer.from([n]);
|
|
54
|
+
const bytes = [];
|
|
55
|
+
for (let v = n; v > 0; v >>= 8)
|
|
56
|
+
bytes.unshift(v & 0xff);
|
|
57
|
+
return Buffer.from([0x80 | bytes.length, ...bytes]);
|
|
58
|
+
}
|
|
59
|
+
const tlv = (tag, body) => Buffer.concat([Buffer.from([tag]), derLength(body.length), body]);
|
|
60
|
+
const seq = (...parts) => tlv(0x30, Buffer.concat(parts));
|
|
61
|
+
const set = (...parts) => tlv(0x31, Buffer.concat(parts));
|
|
62
|
+
/** A non-negative DER INTEGER, minimal as DER requires (OpenSSL refuses a redundant leading zero byte). */
|
|
63
|
+
const int = (raw) => {
|
|
64
|
+
let b = raw;
|
|
65
|
+
while (b.length > 1 && b[0] === 0)
|
|
66
|
+
b = b.subarray(1);
|
|
67
|
+
return tlv(0x02, (b[0] ?? 0) & 0x80 ? Buffer.concat([Buffer.from([0]), b]) : b);
|
|
68
|
+
};
|
|
69
|
+
const oid = (bytes) => tlv(0x06, Buffer.from(bytes));
|
|
70
|
+
const utf8 = (s) => tlv(0x0c, Buffer.from(s, "utf8"));
|
|
71
|
+
const bits = (b) => tlv(0x03, Buffer.concat([Buffer.from([0]), b]));
|
|
72
|
+
const ED25519_ALGORITHM = seq(oid([0x2b, 0x65, 0x70])); // 1.3.101.112, no parameters
|
|
73
|
+
const commonName = (cn) => seq(set(seq(oid([0x55, 0x04, 0x03]), utf8(cn))));
|
|
74
|
+
// From 2000 to 9999 (RFC 5280's "no well-defined expiry"): trust ends when the certificate leaves a trust list.
|
|
75
|
+
const VALIDITY = seq(tlv(0x17, Buffer.from("000101000000Z", "ascii")), tlv(0x18, Buffer.from("99991231235959Z", "ascii")));
|
|
76
|
+
const pemOf = (der) => `-----BEGIN CERTIFICATE-----\n${(der.toString("base64").match(/.{1,64}/g) ?? []).join("\n")}\n-----END CERTIFICATE-----\n`;
|
|
77
|
+
/** The self-signed certificate of `key`. The subject is the key's fingerprint, so no two members share one. */
|
|
78
|
+
export function certificateFor(key) {
|
|
79
|
+
const spki = createPublicKey(key).export({ type: "spki", format: "der" });
|
|
80
|
+
const digest = createHash("sha256").update(spki).digest();
|
|
81
|
+
const serial = Buffer.from(digest.subarray(0, 16));
|
|
82
|
+
serial[0] = (serial[0] ?? 0) & 0x7f;
|
|
83
|
+
const subject = commonName(`culture-agents member ${digest.toString("hex").slice(0, 32)}`);
|
|
84
|
+
const version = tlv(0xa0, int(Buffer.from([2])));
|
|
85
|
+
const tbs = seq(version, int(serial), ED25519_ALGORITHM, subject, VALIDITY, subject, spki);
|
|
86
|
+
const der = seq(tbs, ED25519_ALGORITHM, bits(sign(null, tbs, key)));
|
|
87
|
+
return { der, pem: pemOf(der), text: der.toString("base64") };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* A trust-list certificate from its one-line form. Refused unless it parses, carries an Ed25519
|
|
91
|
+
* public key and is signed by that key (a member certificate is self-signed).
|
|
92
|
+
*/
|
|
93
|
+
export function parseMemberCertificate(text) {
|
|
94
|
+
if (!/^[A-Za-z0-9+/]+={0,2}$/.test(text))
|
|
95
|
+
throw new FleetKeyError("a member certificate must be one base64 line");
|
|
96
|
+
const der = Buffer.from(text, "base64");
|
|
97
|
+
let cert;
|
|
98
|
+
try {
|
|
99
|
+
cert = new X509Certificate(der);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
throw new FleetKeyError("a member certificate does not parse as X.509");
|
|
103
|
+
}
|
|
104
|
+
if (cert.publicKey.asymmetricKeyType !== "ed25519")
|
|
105
|
+
throw new FleetKeyError("a member certificate must carry an Ed25519 key");
|
|
106
|
+
if (!cert.verify(cert.publicKey))
|
|
107
|
+
throw new FleetKeyError("a member certificate must be signed by its own key");
|
|
108
|
+
return { cert, pem: pemOf(der) };
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=cert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cert.js","sourceRoot":"","sources":["../../../src/fleet/cert.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,eAAe,EAAE,mBAAmB,EAAE,IAAI,EAAE,eAAe,EAAkB,MAAM,aAAa,CAAC;AAExI,MAAM,CAAC,MAAM,aAAa,GAAG,0BAA0B,CAAC;AACxD,MAAM,UAAU,GAAG,UAAU,CAAC;AAE9B,MAAM,OAAO,aAAc,SAAQ,KAAK;IACpB,IAAI,GAAG,eAAe,CAAC;CAC1C;AAED,uEAAuE;AACvE,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,MAAM,OAAO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