@mycadet/credential-executor 0.13.0-dev.202610290143.526d7ca → 0.13.0-dev.202610291822.708cf19
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/Dockerfile +0 -1
- package/package.json +1 -2
- package/src/__tests__/credential-record-store.test.ts +0 -14
- package/src/__tests__/local-standalone.test.ts +15 -1
- package/src/__tests__/managed-integration.test.ts +0 -5
- package/src/__tests__/managed-reconnect.test.ts +0 -1
- package/src/__tests__/transport.test.ts +3 -7
- package/src/index.ts +1 -4
- package/src/main.ts +48 -65
- package/src/paths.ts +7 -25
package/Dockerfile
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mycadet/credential-executor",
|
|
3
|
-
"version": "0.13.0-dev.
|
|
3
|
+
"version": "0.13.0-dev.202610291822.708cf19",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/vargasjr-dev/mycadet-temp.git"
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
18
|
"dev": "bun run src/main.ts",
|
|
19
|
-
"dev:managed": "CES_MODE=managed bun run src/main.ts",
|
|
20
19
|
"lint": "eslint",
|
|
21
20
|
"lint:unused": "knip --include files,dependencies,unlisted",
|
|
22
21
|
"typecheck": "bunx tsc --noEmit",
|
|
@@ -116,10 +116,8 @@ describe("003-import-workspace-metadata", () => {
|
|
|
116
116
|
);
|
|
117
117
|
|
|
118
118
|
const prevWorkspace = process.env.CADET_WORKSPACE_DIR;
|
|
119
|
-
const prevMode = process.env.CES_MODE;
|
|
120
119
|
const prevData = process.env.CES_DATA_DIR;
|
|
121
120
|
process.env.CADET_WORKSPACE_DIR = workspace;
|
|
122
|
-
process.env.CES_MODE = "managed";
|
|
123
121
|
process.env.CES_DATA_DIR = cesData;
|
|
124
122
|
|
|
125
123
|
const unusedBackend: SecureKeyBackend = {
|
|
@@ -142,11 +140,6 @@ describe("003-import-workspace-metadata", () => {
|
|
|
142
140
|
} else {
|
|
143
141
|
process.env.CADET_WORKSPACE_DIR = prevWorkspace;
|
|
144
142
|
}
|
|
145
|
-
if (prevMode === undefined) {
|
|
146
|
-
delete process.env.CES_MODE;
|
|
147
|
-
} else {
|
|
148
|
-
process.env.CES_MODE = prevMode;
|
|
149
|
-
}
|
|
150
143
|
if (prevData === undefined) {
|
|
151
144
|
delete process.env.CES_DATA_DIR;
|
|
152
145
|
} else {
|
|
@@ -184,10 +177,8 @@ describe("003-import-workspace-metadata", () => {
|
|
|
184
177
|
);
|
|
185
178
|
|
|
186
179
|
const prevWorkspace = process.env.CADET_WORKSPACE_DIR;
|
|
187
|
-
const prevMode = process.env.CES_MODE;
|
|
188
180
|
const prevData = process.env.CES_DATA_DIR;
|
|
189
181
|
process.env.CADET_WORKSPACE_DIR = workspace;
|
|
190
|
-
process.env.CES_MODE = "managed";
|
|
191
182
|
process.env.CES_DATA_DIR = cesData;
|
|
192
183
|
|
|
193
184
|
const unusedBackend: SecureKeyBackend = {
|
|
@@ -209,11 +200,6 @@ describe("003-import-workspace-metadata", () => {
|
|
|
209
200
|
} else {
|
|
210
201
|
process.env.CADET_WORKSPACE_DIR = prevWorkspace;
|
|
211
202
|
}
|
|
212
|
-
if (prevMode === undefined) {
|
|
213
|
-
delete process.env.CES_MODE;
|
|
214
|
-
} else {
|
|
215
|
-
process.env.CES_MODE = prevMode;
|
|
216
|
-
}
|
|
217
203
|
if (prevData === undefined) {
|
|
218
204
|
delete process.env.CES_DATA_DIR;
|
|
219
205
|
} else {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { afterEach, describe, expect, test } from "bun:test";
|
|
16
|
-
import { createConnection, type Socket } from "node:net";
|
|
16
|
+
import { createConnection, createServer, type Socket } from "node:net";
|
|
17
17
|
import { existsSync, mkdirSync, mkdtempSync, rmSync } from "node:fs";
|
|
18
18
|
import { tmpdir } from "node:os";
|
|
19
19
|
import { join, resolve } from "node:path";
|
|
@@ -30,6 +30,18 @@ import {
|
|
|
30
30
|
|
|
31
31
|
import type { Subprocess } from "bun";
|
|
32
32
|
|
|
33
|
+
function pickFreePort(): Promise<number> {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
const srv = createServer();
|
|
36
|
+
srv.listen(0, () => {
|
|
37
|
+
const address = srv.address();
|
|
38
|
+
const port = typeof address === "object" && address ? address.port : 0;
|
|
39
|
+
srv.close(() => (port ? resolve(port) : reject(new Error("no port"))));
|
|
40
|
+
});
|
|
41
|
+
srv.on("error", reject);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
33
45
|
function delay(ms: number): Promise<void> {
|
|
34
46
|
return new Promise((r) => setTimeout(r, ms));
|
|
35
47
|
}
|
|
@@ -149,11 +161,13 @@ describe("local CES standalone sibling (real entrypoint)", () => {
|
|
|
149
161
|
}).path;
|
|
150
162
|
|
|
151
163
|
const localMain = resolve(__dirname, "..", "main.ts");
|
|
164
|
+
const healthPort = await pickFreePort();
|
|
152
165
|
const env: Record<string, string | undefined> = {
|
|
153
166
|
...process.env,
|
|
154
167
|
CREDENTIAL_SECURITY_DIR: securityDir,
|
|
155
168
|
CADET_WORKSPACE_DIR: workspaceDir,
|
|
156
169
|
CES_BOOTSTRAP_SOCKET_DIR: bootstrapDir,
|
|
170
|
+
CES_HEALTH_PORT: String(healthPort),
|
|
157
171
|
};
|
|
158
172
|
|
|
159
173
|
// stdin closed is how the CLI launches the sibling — CES serves over a
|
|
@@ -55,7 +55,6 @@ const SAVED_ENV_KEYS = [
|
|
|
55
55
|
"CES_DATA_DIR",
|
|
56
56
|
"CES_BOOTSTRAP_SOCKET_DIR",
|
|
57
57
|
"CES_HEALTH_PORT",
|
|
58
|
-
"CES_MODE",
|
|
59
58
|
"CREDENTIAL_SECURITY_DIR",
|
|
60
59
|
] as const;
|
|
61
60
|
|
|
@@ -350,7 +349,6 @@ describe("managed CES integration (real Unix socket)", () => {
|
|
|
350
349
|
mkdirSync(socketDir, { recursive: true });
|
|
351
350
|
|
|
352
351
|
process.env["CES_DATA_DIR"] = dataDir;
|
|
353
|
-
process.env["CES_MODE"] = "managed";
|
|
354
352
|
|
|
355
353
|
// -- Pick a free port for health server ------------------------------------
|
|
356
354
|
// Use port 0 trick: bind, read the port, close, then use it.
|
|
@@ -553,7 +551,6 @@ describe("managed CES integration (real Unix socket)", () => {
|
|
|
553
551
|
mkdirSync(socketDir, { recursive: true });
|
|
554
552
|
|
|
555
553
|
process.env["CES_DATA_DIR"] = dataDir;
|
|
556
|
-
process.env["CES_MODE"] = "managed";
|
|
557
554
|
|
|
558
555
|
controller = new AbortController();
|
|
559
556
|
|
|
@@ -605,7 +602,6 @@ describe("managed CES integration (real Unix socket)", () => {
|
|
|
605
602
|
mkdirSync(socketDir, { recursive: true });
|
|
606
603
|
|
|
607
604
|
process.env["CES_DATA_DIR"] = dataDir;
|
|
608
|
-
process.env["CES_MODE"] = "managed";
|
|
609
605
|
|
|
610
606
|
controller = new AbortController();
|
|
611
607
|
|
|
@@ -712,7 +708,6 @@ describe("credential CRUD RPC", () => {
|
|
|
712
708
|
mkdirSync(socketDir, { recursive: true });
|
|
713
709
|
|
|
714
710
|
process.env["CES_DATA_DIR"] = dataDir;
|
|
715
|
-
process.env["CES_MODE"] = "managed";
|
|
716
711
|
process.env["CREDENTIAL_SECURITY_DIR"] = securityDir;
|
|
717
712
|
|
|
718
713
|
controller = new AbortController();
|
|
@@ -189,7 +189,6 @@ describe("managed CES reconnection (real entrypoint)", () => {
|
|
|
189
189
|
cmd: [process.execPath, managedMain],
|
|
190
190
|
env: {
|
|
191
191
|
...process.env,
|
|
192
|
-
CES_MODE: "managed",
|
|
193
192
|
CES_DATA_DIR: dataDir,
|
|
194
193
|
CES_BOOTSTRAP_SOCKET_DIR: socketDir,
|
|
195
194
|
CES_HEALTH_PORT: String(healthPort),
|
|
@@ -355,12 +355,11 @@ describe("CesRpcServer", () => {
|
|
|
355
355
|
// ---------------------------------------------------------------------------
|
|
356
356
|
|
|
357
357
|
describe("CES data paths", () => {
|
|
358
|
-
test("data root resolves CES_DATA_DIR
|
|
358
|
+
test("data root resolves CES_DATA_DIR when set", () => {
|
|
359
359
|
const savedDir = process.env["CES_DATA_DIR"];
|
|
360
360
|
process.env["CES_DATA_DIR"] = "/custom/ces-data";
|
|
361
361
|
try {
|
|
362
|
-
expect(getCesDataRoot(
|
|
363
|
-
expect(getCesDataRoot("managed")).toBe("/custom/ces-data");
|
|
362
|
+
expect(getCesDataRoot()).toBe("/custom/ces-data");
|
|
364
363
|
} finally {
|
|
365
364
|
if (savedDir !== undefined) {
|
|
366
365
|
process.env["CES_DATA_DIR"] = savedDir;
|
|
@@ -374,10 +373,7 @@ describe("CES data paths", () => {
|
|
|
374
373
|
const savedDir = process.env["CES_DATA_DIR"];
|
|
375
374
|
delete process.env["CES_DATA_DIR"];
|
|
376
375
|
try {
|
|
377
|
-
expect(getCesDataRoot(
|
|
378
|
-
join(process.cwd(), "ces-data"),
|
|
379
|
-
);
|
|
380
|
-
expect(getCesDataRoot("local")).toBe(join(process.cwd(), "ces-data"));
|
|
376
|
+
expect(getCesDataRoot()).toBe(join(process.cwd(), "ces-data"));
|
|
381
377
|
} finally {
|
|
382
378
|
if (savedDir !== undefined) process.env["CES_DATA_DIR"] = savedDir;
|
|
383
379
|
}
|
package/src/index.ts
CHANGED
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
* delete, list, bulk-set) plus the cloud-credential update handshake.
|
|
9
9
|
*
|
|
10
10
|
* This module re-exports the public API surface. For the entrypoint see
|
|
11
|
-
* `main.ts
|
|
12
|
-
* (Kubernetes sidecar) modes, selected by `getCesMode()`.
|
|
11
|
+
* `main.ts`.
|
|
13
12
|
*/
|
|
14
13
|
|
|
15
14
|
export { CesRpcServer, createCesServer } from "./server.js";
|
|
@@ -22,8 +21,6 @@ export type {
|
|
|
22
21
|
|
|
23
22
|
export {
|
|
24
23
|
getCesDataRoot,
|
|
25
|
-
getCesMode,
|
|
26
24
|
getBootstrapSocketPath,
|
|
27
25
|
getHealthPort,
|
|
28
26
|
} from "./paths.js";
|
|
29
|
-
export type { CesMode } from "./paths.js";
|
package/src/main.ts
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
/**
|
|
3
|
-
* CES (Credential Execution Service) entrypoint
|
|
4
|
-
* local (bare-metal sibling) and managed (Kubernetes sidecar) modes.
|
|
3
|
+
* CES (Credential Execution Service) entrypoint.
|
|
5
4
|
*
|
|
6
|
-
*
|
|
7
|
-
* - `CES_MODE=managed` (set in the Dockerfile / K8s statefulset) → managed mode
|
|
8
|
-
* - absent or any other value → local mode (bare-metal sibling)
|
|
9
|
-
*
|
|
10
|
-
* Both modes serve credential CRUD RPC over a Unix socket using a concurrent
|
|
5
|
+
* Serves credential CRUD RPC over a Unix socket using a concurrent
|
|
11
6
|
* multi-connection server (`serveStandaloneSocket`). Each connection gets its
|
|
12
7
|
* own `CesRpcServer` over a shared, process-scoped handler registry. The server
|
|
13
8
|
* stays listening across connections, so an assistant that disconnects (crash,
|
|
14
9
|
* restart) can reconnect without CES re-binding.
|
|
15
10
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
11
|
+
* Also starts a health HTTP server (`/healthz`, `/readyz`, optional credential
|
|
12
|
+
* CRUD routes) for liveness/readiness probes.
|
|
18
13
|
*/
|
|
19
14
|
|
|
20
15
|
import { mkdirSync } from "node:fs";
|
|
@@ -39,10 +34,8 @@ import {
|
|
|
39
34
|
getBootstrapSocketPath,
|
|
40
35
|
getCesDataRoot,
|
|
41
36
|
getCesLogDir,
|
|
42
|
-
getCesMode,
|
|
43
37
|
getHealthPort,
|
|
44
38
|
getSecurityDir,
|
|
45
|
-
type CesMode,
|
|
46
39
|
} from "./paths.js";
|
|
47
40
|
import { CesRpcServer, type RpcHandlerRegistry } from "./server.js";
|
|
48
41
|
import {
|
|
@@ -68,8 +61,8 @@ const log = getLogger("main");
|
|
|
68
61
|
// Data directory bootstrap
|
|
69
62
|
// ---------------------------------------------------------------------------
|
|
70
63
|
|
|
71
|
-
function ensureDataDirs(
|
|
72
|
-
mkdirSync(getCesDataRoot(
|
|
64
|
+
function ensureDataDirs(): void {
|
|
65
|
+
mkdirSync(getCesDataRoot(), { recursive: true });
|
|
73
66
|
}
|
|
74
67
|
|
|
75
68
|
// ---------------------------------------------------------------------------
|
|
@@ -80,9 +73,7 @@ function ensureDataDirs(mode: CesMode): void {
|
|
|
80
73
|
* Build the RPC handler registry. CES serves credential CRUD (get / set /
|
|
81
74
|
* delete / list / bulk-set) backed by the secure key store. The
|
|
82
75
|
* `update_managed_credential` handler is registered separately by the RPC
|
|
83
|
-
* server when an `onApiKeyUpdate` callback is supplied.
|
|
84
|
-
* share the same registry — they differ only in where the secure key backend
|
|
85
|
-
* reads from and whether the health server is started.
|
|
76
|
+
* server when an `onApiKeyUpdate` callback is supplied.
|
|
86
77
|
*/
|
|
87
78
|
export function buildCrudHandlers(
|
|
88
79
|
secureKeyBackend: SecureKeyBackend,
|
|
@@ -237,7 +228,7 @@ function serveStandaloneSocket(opts: {
|
|
|
237
228
|
}
|
|
238
229
|
|
|
239
230
|
// ---------------------------------------------------------------------------
|
|
240
|
-
// Health server
|
|
231
|
+
// Health server
|
|
241
232
|
// ---------------------------------------------------------------------------
|
|
242
233
|
|
|
243
234
|
let connectionCount = 0;
|
|
@@ -305,7 +296,7 @@ function startHealthServer(
|
|
|
305
296
|
// Log export route
|
|
306
297
|
const logExportResponse = await handleLogExportRoute(
|
|
307
298
|
req,
|
|
308
|
-
getCesLogDir(
|
|
299
|
+
getCesLogDir(),
|
|
309
300
|
);
|
|
310
301
|
if (logExportResponse) return logExportResponse;
|
|
311
302
|
|
|
@@ -332,14 +323,11 @@ function startHealthServer(
|
|
|
332
323
|
// ---------------------------------------------------------------------------
|
|
333
324
|
|
|
334
325
|
async function main(): Promise<void> {
|
|
335
|
-
|
|
336
|
-
ensureDataDirs(mode);
|
|
326
|
+
ensureDataDirs();
|
|
337
327
|
|
|
338
|
-
initLogger({ dir: getCesLogDir(
|
|
328
|
+
initLogger({ dir: getCesLogDir(), retentionDays: 30 });
|
|
339
329
|
|
|
340
|
-
log.info(
|
|
341
|
-
`Starting CES v${CES_PROTOCOL_VERSION} (${mode} mode, socket transport)`,
|
|
342
|
-
);
|
|
330
|
+
log.info(`Starting CES v${CES_PROTOCOL_VERSION} (socket transport)`);
|
|
343
331
|
|
|
344
332
|
const controller = new AbortController();
|
|
345
333
|
|
|
@@ -357,13 +345,13 @@ async function main(): Promise<void> {
|
|
|
357
345
|
const secureKeyBackend = createLocalSecureKeyBackend(getSecurityDir());
|
|
358
346
|
|
|
359
347
|
await runCesMigrations(
|
|
360
|
-
getCesDataRoot(
|
|
348
|
+
getCesDataRoot(),
|
|
361
349
|
secureKeyBackend,
|
|
362
350
|
CES_MIGRATIONS,
|
|
363
351
|
);
|
|
364
|
-
log.info(
|
|
352
|
+
log.info("CES startup: migrations complete");
|
|
365
353
|
|
|
366
|
-
initMetadataStore(getCesDataRoot(
|
|
354
|
+
initMetadataStore(getCesDataRoot());
|
|
367
355
|
|
|
368
356
|
// -- Build handlers --------------------------------------------------------
|
|
369
357
|
// The per-connection session ID lives in each CesRpcServer's SessionContext;
|
|
@@ -374,26 +362,24 @@ async function main(): Promise<void> {
|
|
|
374
362
|
...buildRecordHandlers(),
|
|
375
363
|
};
|
|
376
364
|
|
|
377
|
-
// -- Health server
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
"CES_SERVICE_TOKEN
|
|
388
|
-
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
const healthPort = getHealthPort();
|
|
393
|
-
startHealthServer(healthPort, controller.signal, credentialDeps);
|
|
394
|
-
log.info(`Health server listening on port ${healthPort}`);
|
|
365
|
+
// -- Health server ----------------------------------------------------------
|
|
366
|
+
const serviceToken = process.env["CES_SERVICE_TOKEN"] ?? "";
|
|
367
|
+
let credentialDeps: CredentialRouteDeps | null = null;
|
|
368
|
+
|
|
369
|
+
if (serviceToken) {
|
|
370
|
+
credentialDeps = { backend: secureKeyBackend, serviceToken };
|
|
371
|
+
log.info("Credential CRUD routes enabled (CES_SERVICE_TOKEN configured)");
|
|
372
|
+
} else {
|
|
373
|
+
log.warn(
|
|
374
|
+
"CES_SERVICE_TOKEN not set — credential CRUD HTTP routes are disabled. " +
|
|
375
|
+
"Set CES_SERVICE_TOKEN to enable credential management over HTTP.",
|
|
376
|
+
);
|
|
395
377
|
}
|
|
396
378
|
|
|
379
|
+
const healthPort = getHealthPort();
|
|
380
|
+
startHealthServer(healthPort, controller.signal, credentialDeps);
|
|
381
|
+
log.info(`Health server listening on port ${healthPort}`);
|
|
382
|
+
|
|
397
383
|
// -- Socket server ---------------------------------------------------------
|
|
398
384
|
const socketPath = getBootstrapSocketPath();
|
|
399
385
|
|
|
@@ -404,8 +390,8 @@ async function main(): Promise<void> {
|
|
|
404
390
|
error: (msg: string, ...args: unknown[]) => rpcLog.error({ args }, msg),
|
|
405
391
|
};
|
|
406
392
|
|
|
407
|
-
//
|
|
408
|
-
//
|
|
393
|
+
// The `update_managed_credential` handler (via the `onApiKeyUpdate` hook)
|
|
394
|
+
// lets the assistant push its API key/ID after hatch.
|
|
409
395
|
// The push is acknowledged and logged; CES stores credentials via the CRUD
|
|
410
396
|
// handlers and no longer materializes platform tokens itself.
|
|
411
397
|
serveStandaloneSocket({
|
|
@@ -414,23 +400,20 @@ async function main(): Promise<void> {
|
|
|
414
400
|
signal: controller.signal,
|
|
415
401
|
logger: rpcLogger,
|
|
416
402
|
log,
|
|
417
|
-
onApiKeyUpdate:
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
);
|
|
432
|
-
}
|
|
433
|
-
: undefined,
|
|
403
|
+
onApiKeyUpdate: (newKey: string, newAssistantId?: string) => {
|
|
404
|
+
// Ack-only. CES reads the durable assistant API key from the shared
|
|
405
|
+
// credential store via the CRUD handlers; this RPC just acknowledges
|
|
406
|
+
// the assistant's notification that the key rotated. The pushed
|
|
407
|
+
// value is intentionally not persisted here (length logged, never
|
|
408
|
+
// the value).
|
|
409
|
+
log.info(
|
|
410
|
+
{
|
|
411
|
+
keyBytes: newKey.length,
|
|
412
|
+
assistantIdUpdated: Boolean(newAssistantId),
|
|
413
|
+
},
|
|
414
|
+
"Acknowledged assistant API key update notification (ack only; value not stored by CES)",
|
|
415
|
+
);
|
|
416
|
+
},
|
|
434
417
|
});
|
|
435
418
|
|
|
436
419
|
await new Promise<void>((resolve) => {
|
|
@@ -450,7 +433,7 @@ if (import.meta.main) {
|
|
|
450
433
|
try {
|
|
451
434
|
getLogger("main").fatal({ err }, "Fatal error");
|
|
452
435
|
} catch {
|
|
453
|
-
process.stderr.write(`[ces
|
|
436
|
+
process.stderr.write(`[ces] Fatal: ${err}\n`);
|
|
454
437
|
}
|
|
455
438
|
process.exit(1);
|
|
456
439
|
});
|
package/src/paths.ts
CHANGED
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
* - `CES_DATA_DIR` → `./ces-data`
|
|
16
16
|
*
|
|
17
17
|
* Managed containers set both explicitly (the cloud template provisions
|
|
18
|
-
* `/ces-security` and `/ces-data` volumes);
|
|
19
|
-
*
|
|
18
|
+
* `/ces-security` and `/ces-data` volumes); bare-metal runs fall back to
|
|
19
|
+
* the cwd convention. The assistant-visible data root (where
|
|
20
20
|
* workspace, embeddings, etc. live) is a separate path and must never be
|
|
21
21
|
* used for CES-private writes.
|
|
22
22
|
*/
|
|
@@ -25,22 +25,6 @@ import { join } from "node:path";
|
|
|
25
25
|
|
|
26
26
|
import { resolveIpcEndpoint } from "@mycadet/ipc-server-utils";
|
|
27
27
|
|
|
28
|
-
// ---------------------------------------------------------------------------
|
|
29
|
-
// Mode detection
|
|
30
|
-
// ---------------------------------------------------------------------------
|
|
31
|
-
|
|
32
|
-
export type CesMode = "local" | "managed";
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Determine the CES operating mode from the environment.
|
|
36
|
-
*
|
|
37
|
-
* `CES_MODE=managed` is set explicitly in managed container entrypoints.
|
|
38
|
-
* Everything else defaults to local.
|
|
39
|
-
*/
|
|
40
|
-
export function getCesMode(): CesMode {
|
|
41
|
-
return process.env["CES_MODE"] === "managed" ? "managed" : "local";
|
|
42
|
-
}
|
|
43
|
-
|
|
44
28
|
// ---------------------------------------------------------------------------
|
|
45
29
|
// Root directory helpers
|
|
46
30
|
// ---------------------------------------------------------------------------
|
|
@@ -50,8 +34,7 @@ export function getCesMode(): CesMode {
|
|
|
50
34
|
*
|
|
51
35
|
* Priority:
|
|
52
36
|
* 1. `CREDENTIAL_SECURITY_DIR` env var (set by the cloud template for the
|
|
53
|
-
* CES container — `/ces-security`
|
|
54
|
-
* `<instanceDir>/ces-security` in local mode)
|
|
37
|
+
* CES container — `/ces-security`)
|
|
55
38
|
* 2. Default: `./ces-security` (cwd fallback convention)
|
|
56
39
|
*/
|
|
57
40
|
export function getSecurityDir(): string {
|
|
@@ -65,11 +48,10 @@ export function getSecurityDir(): string {
|
|
|
65
48
|
* Return the CES-private data root (grants, audit logs, tool store).
|
|
66
49
|
*
|
|
67
50
|
* Priority:
|
|
68
|
-
* 1. `CES_DATA_DIR` env var (set by the cloud template — `/ces-data`
|
|
69
|
-
* managed mode; per-instance `<instanceDir>/ces-data` in local mode)
|
|
51
|
+
* 1. `CES_DATA_DIR` env var (set by the cloud template — `/ces-data`)
|
|
70
52
|
* 2. Default: `./ces-data` (cwd fallback convention)
|
|
71
53
|
*/
|
|
72
|
-
export function getCesDataRoot(
|
|
54
|
+
export function getCesDataRoot(): string {
|
|
73
55
|
return process.env["CES_DATA_DIR"]?.trim() || join(process.cwd(), "ces-data");
|
|
74
56
|
}
|
|
75
57
|
|
|
@@ -78,8 +60,8 @@ export function getCesDataRoot(_mode?: CesMode): string {
|
|
|
78
60
|
// ---------------------------------------------------------------------------
|
|
79
61
|
|
|
80
62
|
/** Directory for CES log files. */
|
|
81
|
-
export function getCesLogDir(
|
|
82
|
-
return join(getCesDataRoot(
|
|
63
|
+
export function getCesLogDir(): string {
|
|
64
|
+
return join(getCesDataRoot(), "logs");
|
|
83
65
|
}
|
|
84
66
|
|
|
85
67
|
// ---------------------------------------------------------------------------
|