@app-vitals/agent-admin 1.120.1 → 1.122.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/openapi.platform.json +20 -0
- package/package.json +2 -2
- package/src/account-repo-lookup-api.integration.test.ts +1 -1
- package/src/admin-boot-config.ts +2 -2
- package/src/admin-boot-config.unit.test.ts +1 -1
- package/src/admin-boot.ts +1 -1
- package/src/admin-ui-account.ts +2 -2
- package/src/admin-ui-agent-template.smoke.test.ts +1 -1
- package/src/admin-ui-github-identity-pages.ts +2 -2
- package/src/admin-ui-push-test.smoke.test.ts +7 -5
- package/src/admin-ui-styles.unit.test.ts +3 -1
- package/src/admin-ui-templates-pages.ts +5 -5
- package/src/agent-cron-run-stats.integration.test.ts +11 -2
- package/src/agent-deletion-checklist.unit.test.ts +1 -1
- package/src/agent-manifest.unit.test.ts +3 -3
- package/src/agent-marketplaces-api.integration.test.ts +9 -7
- package/src/agent-members.integration.test.ts +1 -1
- package/src/agent-pod-labels.unit.test.ts +2 -2
- package/src/agent-provisioner.unit.test.ts +4 -4
- package/src/agent-setup.unit.test.ts +14 -3
- package/src/agent-template-items.ts +1 -1
- package/src/agent-templates.ts +1 -1
- package/src/agent-tools-token.integration.test.ts +3 -3
- package/src/api-auth.ts +10 -4
- package/src/brand-tokens.json +23 -4
- package/src/brand-tokens.unit.test.ts +11 -4
- package/src/chat-credential-config.unit.test.ts +6 -2
- package/src/chat-markers.unit.test.ts +5 -2
- package/src/cron-run-now.smoke.test.ts +1 -1
- package/src/cron-run-now.ts +1 -1
- package/src/errors.unit.test.ts +7 -4
- package/src/fixtures/github-agent-installation-cassette.json +35 -5
- package/src/github-access-backfill.ts +1 -1
- package/src/github-access-backfill.unit.test.ts +1 -1
- package/src/github-agent-installation-crawler.integration.test.ts +29 -12
- package/src/github-agent-installation-crawler.ts +2 -2
- package/src/github-agent-installation-crawler.unit.test.ts +28 -7
- package/src/github-app-api.ts +1 -1
- package/src/github-app-jwt.unit.test.ts +2 -1
- package/src/github-cache-roundtrip.integration.test.ts +4 -4
- package/src/github-enterprise-api.integration.test.ts +4 -4
- package/src/github-enterprise-api.ts +6 -6
- package/src/github-enterprise-client-page.unit.test.ts +18 -6
- package/src/github-enterprise-client.integration.test.ts +97 -32
- package/src/github-enterprise-client.ts +81 -22
- package/src/github-enterprise-client.unit.test.ts +1 -1
- package/src/github-enterprise-warnings.unit.test.ts +19 -6
- package/src/github-installation-selection.integration.test.ts +4 -1
- package/src/github-installation-wiring.unit.test.ts +1 -1
- package/src/github-repo-refresh-discovery.unit.test.ts +1 -1
- package/src/github-repo-refresher.unit.test.ts +11 -5
- package/src/github-sync-cache.integration.test.ts +1 -1
- package/src/github-sync-cached-access.ts +1 -1
- package/src/github-sync-reverify.unit.test.ts +1 -1
- package/src/github-sync-snapshot-refresh.integration.test.ts +1 -1
- package/src/github-sync.unit.test.ts +6 -6
- package/src/installation-ports-fixture.integration.test.ts +2 -2
- package/src/installation-repos-service.ts +5 -5
- package/src/kubernetes-client.integration.test.ts +1 -2
- package/src/openapi-schemas.ts +9 -0
- package/src/platform-routes.ts +1 -1
- package/src/principal-lookup.ts +26 -4
- package/src/principal-lookup.unit.test.ts +61 -4
- package/src/principals-api.integration.test.ts +9 -1
- package/src/principals-api.smoke.test.ts +96 -0
- package/src/push-content.unit.test.ts +2 -2
- package/src/push-sender.unit.test.ts +1 -1
- package/src/push-service.integration.test.ts +1 -1
- package/src/pwa-icons.unit.test.ts +1 -1
- package/src/slack-config-token-resolve.unit.test.ts +25 -7
- package/src/slack-provisioning-client.integration.test.ts +10 -8
- package/src/slack-provisioning-client.ts +2 -6
- package/src/tools-token-policy.integration.test.ts +48 -6
- package/src/tools-token-policy.smoke.test.ts +11 -5
- package/src/tools-token-policy.ts +85 -8
- package/src/tools-token-policy.unit.test.ts +111 -4
- package/src/trial-expiry-sweeper.unit.test.ts +1 -1
- package/src/user-prefs.integration.test.ts +1 -1
- package/src/user-repo-access-resolver.unit.test.ts +1 -1
|
@@ -19,9 +19,11 @@
|
|
|
19
19
|
* env is blanked (blankEnvForToolsToken) and a cron preCheck must be a
|
|
20
20
|
* `plugin:script` reference (assertToolsTokenPreCheck).
|
|
21
21
|
*
|
|
22
|
-
* Runtime-kind tokens
|
|
23
|
-
*
|
|
24
|
-
*
|
|
22
|
+
* Runtime-kind tokens are restricted by a smaller denylist
|
|
23
|
+
* (RUNTIME_TOKEN_DENYLIST, see below) with an admin kill switch. Admin keys,
|
|
24
|
+
* platform keys and session callers are never touched. Routes with no
|
|
25
|
+
* declaration, including extension routes that do not declare a policy,
|
|
26
|
+
* default to allowed.
|
|
25
27
|
*
|
|
26
28
|
* Known limit: an extension route mounted outside /agents/* is not covered
|
|
27
29
|
* (tools tokens are per-agent and every agent route lives under /agents).
|
|
@@ -393,6 +395,76 @@ export const TOOLS_TOKEN_POLICY: readonly ToolsTokenPolicyRule[] = [
|
|
|
393
395
|
},
|
|
394
396
|
];
|
|
395
397
|
|
|
398
|
+
// ─── Runtime-kind denylist ────────────────────────────────────────────────────
|
|
399
|
+
|
|
400
|
+
const RD = (
|
|
401
|
+
method: string,
|
|
402
|
+
path: string,
|
|
403
|
+
note: string,
|
|
404
|
+
subpaths = false,
|
|
405
|
+
): ToolsTokenPolicyRule => ({
|
|
406
|
+
method,
|
|
407
|
+
path,
|
|
408
|
+
decision: D,
|
|
409
|
+
note,
|
|
410
|
+
...(subpaths ? { subpaths } : {}),
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Routes a runtime-kind token may not call. Deny-only: every other route,
|
|
415
|
+
* including extension routes, stays allowed (the runtime uses config, crons
|
|
416
|
+
* list, crons/template reconcile, cron run POST/PATCH/GET, github-installations,
|
|
417
|
+
* baked-marketplaces, chat-tokens/daily and POST /work-queue). Exact matching
|
|
418
|
+
* (no `subpaths` on the cron rules) keeps `/crons/reconcile`,
|
|
419
|
+
* `/crons/{id}/runs` and `/crons/{id}/runs/{runId}` allowed.
|
|
420
|
+
*/
|
|
421
|
+
export const RUNTIME_TOKEN_DENYLIST: readonly ToolsTokenPolicyRule[] = [
|
|
422
|
+
RD("POST", "/agents/{id}/tokens", "token minting", true),
|
|
423
|
+
RD("GET", "/agents/{id}/tokens", "token listing", true),
|
|
424
|
+
RD("DELETE", "/agents/{id}/tokens/{tokenId}", "token revocation", true),
|
|
425
|
+
RD("POST", "/agents/{id}/envs", "env write", true),
|
|
426
|
+
RD("PATCH", "/agents/{id}/envs", "env write", true),
|
|
427
|
+
RD("DELETE", "/agents/{id}/envs/{key}", "env write", true),
|
|
428
|
+
RD("POST", "/agents/{id}/tools", "allowed-tools write", true),
|
|
429
|
+
RD("PATCH", "/agents/{id}/tools/{toolId}", "allowed-tools write", true),
|
|
430
|
+
RD("DELETE", "/agents/{id}/tools/{toolId}", "allowed-tools write", true),
|
|
431
|
+
RD("POST", "/agents/{id}/plugins", "plugin write", true),
|
|
432
|
+
RD("PATCH", "/agents/{id}/plugins", "plugin write", true),
|
|
433
|
+
RD("DELETE", "/agents/{id}/plugins", "plugin write", true),
|
|
434
|
+
RD("POST", "/agents/{id}/marketplaces", "marketplace write", true),
|
|
435
|
+
RD(
|
|
436
|
+
"DELETE",
|
|
437
|
+
"/agents/{id}/marketplaces/{marketplaceId}",
|
|
438
|
+
"marketplace write",
|
|
439
|
+
true,
|
|
440
|
+
),
|
|
441
|
+
RD("POST", "/agents/{id}/crons", "cron create"),
|
|
442
|
+
RD("PATCH", "/agents/{id}/crons/{cronId}", "cron update"),
|
|
443
|
+
RD("DELETE", "/agents/{id}/crons/{cronId}", "cron delete"),
|
|
444
|
+
];
|
|
445
|
+
|
|
446
|
+
/** Pure decision for a runtime-kind caller . */
|
|
447
|
+
export function runtimeTokenDecision(
|
|
448
|
+
method: string,
|
|
449
|
+
path: string,
|
|
450
|
+
): ToolsTokenDecision {
|
|
451
|
+
return RUNTIME_TOKEN_DENYLIST.some((r) => ruleMatches(r, method, path))
|
|
452
|
+
? D
|
|
453
|
+
: A;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Enforcement helper: true (and one log line) when a runtime-kind token must
|
|
458
|
+
* be denied on method+path. The log line is read by the observation gate.
|
|
459
|
+
*/
|
|
460
|
+
export function runtimeTokenDenied(method: string, path: string): boolean {
|
|
461
|
+
if (runtimeTokenDecision(method, path) !== D) return false;
|
|
462
|
+
console.warn(
|
|
463
|
+
`[token-policy] runtime token denied ${method.toUpperCase()} ${JSON.stringify(path)}`,
|
|
464
|
+
);
|
|
465
|
+
return true;
|
|
466
|
+
}
|
|
467
|
+
|
|
396
468
|
// ─── Matching ─────────────────────────────────────────────────────────────────
|
|
397
469
|
|
|
398
470
|
/** Decode, collapse repeated slashes and drop a trailing slash. */
|
|
@@ -485,8 +557,8 @@ export function blankEnvForToolsToken(
|
|
|
485
557
|
|
|
486
558
|
/**
|
|
487
559
|
* Guard for routes that authenticate on their own (extension API routes). It
|
|
488
|
-
* resolves a bearer's kind itself and applies the policy to tools-kind tokens;
|
|
489
|
-
* everything else (no bearer, env keys,
|
|
560
|
+
* resolves a bearer's kind itself and applies the tools policy to tools-kind tokens and the runtime denylist to runtime-kind tokens;
|
|
561
|
+
* everything else (no bearer, env keys, invalid tokens) passes
|
|
490
562
|
* through for the route's own auth to decide.
|
|
491
563
|
*/
|
|
492
564
|
export function createToolsTokenGuard(deps: {
|
|
@@ -503,9 +575,14 @@ export function createToolsTokenGuard(deps: {
|
|
|
503
575
|
if (!deps.adminApiKeys?.has(raw)) {
|
|
504
576
|
const result = await deps.agentTokenService.validate(raw);
|
|
505
577
|
if (
|
|
506
|
-
result?.kind === "tools" &&
|
|
507
|
-
|
|
508
|
-
|
|
578
|
+
(result?.kind === "tools" &&
|
|
579
|
+
toolsTokenDecision(
|
|
580
|
+
c.req.method,
|
|
581
|
+
c.req.path,
|
|
582
|
+
deps.extensionRules,
|
|
583
|
+
) === D) ||
|
|
584
|
+
(result?.kind === "runtime" &&
|
|
585
|
+
runtimeTokenDenied(c.req.method, c.req.path))
|
|
509
586
|
) {
|
|
510
587
|
return c.json({ error: "Forbidden" }, 403);
|
|
511
588
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, expect, it } from "bun:test";
|
|
1
|
+
import { afterEach, describe, expect, it, spyOn } from "bun:test";
|
|
2
2
|
import { Hono } from "hono";
|
|
3
3
|
import {
|
|
4
4
|
type AdminExtension,
|
|
@@ -12,7 +12,10 @@ import {
|
|
|
12
12
|
blankEnvForToolsToken,
|
|
13
13
|
createToolsTokenGuard,
|
|
14
14
|
isPluginScriptPreCheck,
|
|
15
|
+
RUNTIME_TOKEN_DENYLIST,
|
|
15
16
|
ruleMatches,
|
|
17
|
+
runtimeTokenDecision,
|
|
18
|
+
runtimeTokenDenied,
|
|
16
19
|
TOOLS_TOKEN_POLICY,
|
|
17
20
|
type ToolsTokenPolicyRule,
|
|
18
21
|
toolsTokenDecision,
|
|
@@ -242,9 +245,6 @@ describe("createAdminAuthMiddleware tools-token policy", () => {
|
|
|
242
245
|
expect(
|
|
243
246
|
(await call(app, TOOLS_KEY, "PUT", `/agents/${ID}/gadgets/g`)).status,
|
|
244
247
|
).toBe(200);
|
|
245
|
-
expect(
|
|
246
|
-
(await call(app, RUNTIME_KEY, "POST", `/agents/${ID}/tokens`)).status,
|
|
247
|
-
).toBe(200);
|
|
248
248
|
expect(
|
|
249
249
|
(await call(app, RUNTIME_KEY, "PUT", `/agents/${ID}/widgets/w`)).status,
|
|
250
250
|
).toBe(200);
|
|
@@ -277,3 +277,110 @@ describe("createToolsTokenGuard (extension routes)", () => {
|
|
|
277
277
|
).toBe(200);
|
|
278
278
|
});
|
|
279
279
|
});
|
|
280
|
+
|
|
281
|
+
describe("runtime-kind denylist", () => {
|
|
282
|
+
const denied: Array<[string, string]> = [
|
|
283
|
+
["POST", `/agents/${ID}/tokens`],
|
|
284
|
+
["GET", `/agents/${ID}/tokens`],
|
|
285
|
+
["DELETE", `/agents/${ID}/tokens/t1`],
|
|
286
|
+
["POST", `/agents/${ID}/envs`],
|
|
287
|
+
["PATCH", `/agents/${ID}/envs`],
|
|
288
|
+
["DELETE", `/agents/${ID}/envs/FOO`],
|
|
289
|
+
["POST", `/agents/${ID}/tools`],
|
|
290
|
+
["PATCH", `/agents/${ID}/tools/t1`],
|
|
291
|
+
["DELETE", `/agents/${ID}/tools/t1`],
|
|
292
|
+
["POST", `/agents/${ID}/plugins`],
|
|
293
|
+
["PATCH", `/agents/${ID}/plugins`],
|
|
294
|
+
["DELETE", `/agents/${ID}/plugins`],
|
|
295
|
+
["POST", `/agents/${ID}/marketplaces`],
|
|
296
|
+
["DELETE", `/agents/${ID}/marketplaces/m1`],
|
|
297
|
+
["POST", `/agents/${ID}/crons`],
|
|
298
|
+
["PATCH", `/agents/${ID}/crons/c1`],
|
|
299
|
+
["DELETE", `/agents/${ID}/crons/c1`],
|
|
300
|
+
];
|
|
301
|
+
const allowed: Array<[string, string]> = [
|
|
302
|
+
["GET", `/agents/${ID}/config`],
|
|
303
|
+
["GET", `/agents/${ID}/crons`],
|
|
304
|
+
["POST", `/agents/${ID}/crons/reconcile`],
|
|
305
|
+
["POST", `/agents/${ID}/template/reconcile`],
|
|
306
|
+
["POST", `/agents/${ID}/crons/c1/runs`],
|
|
307
|
+
["PATCH", `/agents/${ID}/crons/c1/runs/r1`],
|
|
308
|
+
["GET", `/agents/${ID}/crons/c1/runs`],
|
|
309
|
+
["PUT", `/agents/${ID}/github-installations`],
|
|
310
|
+
["GET", `/agents/${ID}/github-installations`],
|
|
311
|
+
["PUT", `/agents/${ID}/baked-marketplaces`],
|
|
312
|
+
["POST", `/agents/${ID}/chat-tokens/daily`],
|
|
313
|
+
["GET", `/agents/${ID}/chat-tokens/daily/stats`],
|
|
314
|
+
["POST", `/agents/${ID}/work-queue`],
|
|
315
|
+
["PUT", `/agents/${ID}/phase-methodology`],
|
|
316
|
+
["GET", `/agents/${ID}/envs`],
|
|
317
|
+
];
|
|
318
|
+
for (const [m, p] of denied)
|
|
319
|
+
it(`denies ${m} ${p}`, () =>
|
|
320
|
+
expect(runtimeTokenDecision(m, p)).toBe("deny"));
|
|
321
|
+
for (const [m, p] of allowed)
|
|
322
|
+
it(`allows ${m} ${p}`, () =>
|
|
323
|
+
expect(runtimeTokenDecision(m, p)).toBe("allow"));
|
|
324
|
+
|
|
325
|
+
it("has unique method+path entries, all deny", () => {
|
|
326
|
+
const keys = RUNTIME_TOKEN_DENYLIST.map((r) => `${r.method} ${r.path}`);
|
|
327
|
+
expect(new Set(keys).size).toBe(keys.length);
|
|
328
|
+
for (const r of RUNTIME_TOKEN_DENYLIST) expect(r.decision).toBe("deny");
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
describe("denial logging", () => {
|
|
332
|
+
afterEach(() => spyOn(console, "warn").mockRestore());
|
|
333
|
+
it("logs one line per denial and nothing when allowed", () => {
|
|
334
|
+
const warn = spyOn(console, "warn").mockImplementation(() => {});
|
|
335
|
+
expect(runtimeTokenDenied("post", `/agents/${ID}/envs`)).toBe(true);
|
|
336
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
337
|
+
expect(warn.mock.calls[0]?.[0]).toBe(
|
|
338
|
+
`[token-policy] runtime token denied POST "/agents/${ID}/envs"`,
|
|
339
|
+
);
|
|
340
|
+
expect(runtimeTokenDenied("GET", `/agents/${ID}/config`)).toBe(false);
|
|
341
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
342
|
+
});
|
|
343
|
+
it("escapes control characters in the logged path (no log forging)", () => {
|
|
344
|
+
const warn = spyOn(console, "warn").mockImplementation(() => {});
|
|
345
|
+
const path = `/agents/${ID}/envs/x\n[token-policy] runtime token denied POST /forged`;
|
|
346
|
+
expect(runtimeTokenDenied("DELETE", path)).toBe(true);
|
|
347
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
348
|
+
const msg = String(warn.mock.calls[0]?.[0]);
|
|
349
|
+
expect(msg).not.toContain("\n");
|
|
350
|
+
expect(msg).toContain("\\n[token-policy]");
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
describe("runtime-kind enforcement points", () => {
|
|
356
|
+
afterEach(() => {
|
|
357
|
+
spyOn(console, "warn").mockRestore();
|
|
358
|
+
});
|
|
359
|
+
const mk = (guard: boolean) => {
|
|
360
|
+
const app = new Hono();
|
|
361
|
+
app.use(
|
|
362
|
+
"/agents/*",
|
|
363
|
+
guard
|
|
364
|
+
? createToolsTokenGuard({ agentTokenService: tokenService })
|
|
365
|
+
: createAdminAuthMiddleware({
|
|
366
|
+
sessionSecret: "s".repeat(32),
|
|
367
|
+
agentTokenService: tokenService,
|
|
368
|
+
}),
|
|
369
|
+
);
|
|
370
|
+
app.all("/agents/*", (c) => c.json({ ok: true }));
|
|
371
|
+
return app;
|
|
372
|
+
};
|
|
373
|
+
for (const guard of [false, true]) {
|
|
374
|
+
it(`${guard ? "guard" : "auth middleware"}: 403 on denied, 200 on allowed on allowed`, async () => {
|
|
375
|
+
spyOn(console, "warn").mockImplementation(() => {});
|
|
376
|
+
const app = mk(guard);
|
|
377
|
+
expect(
|
|
378
|
+
(await call(app, RUNTIME_KEY, "POST", `/agents/${ID}/tokens`)).status,
|
|
379
|
+
).toBe(403);
|
|
380
|
+
expect(
|
|
381
|
+
(await call(app, RUNTIME_KEY, "POST", `/agents/${ID}/crons/reconcile`))
|
|
382
|
+
.status,
|
|
383
|
+
).toBe(200);
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
});
|
|
@@ -16,9 +16,9 @@ import { describe, expect, it } from "bun:test";
|
|
|
16
16
|
import { FixedClock } from "./clock.ts";
|
|
17
17
|
import {
|
|
18
18
|
DEFAULT_TRIAL_EXPIRY_SWEEP_INTERVAL_MS,
|
|
19
|
+
resolveTrialExpirySweepIntervalMs,
|
|
19
20
|
type TrialExpiryCronJobServiceLike,
|
|
20
21
|
TrialExpirySweeper,
|
|
21
|
-
resolveTrialExpirySweepIntervalMs,
|
|
22
22
|
} from "./trial-expiry-sweeper.ts";
|
|
23
23
|
|
|
24
24
|
const NOW = new Date("2026-06-15T00:00:00.000Z");
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
import { afterEach, beforeEach, describe, expect, it } from "bun:test";
|
|
10
10
|
import type { PrismaClient } from "../prisma/client/client.ts";
|
|
11
|
-
import { resetMemberIdFixture } from "./test-support/member-id-test-support.ts";
|
|
12
11
|
import { createAdminPrismaClient } from "./prisma-client.ts";
|
|
12
|
+
import { resetMemberIdFixture } from "./test-support/member-id-test-support.ts";
|
|
13
13
|
import { InvalidTimezoneError, UserPrefsService } from "./user-prefs.ts";
|
|
14
14
|
|
|
15
15
|
const TEST_DB = process.env.DATABASE_URL_ADMIN_TEST;
|
|
@@ -8,8 +8,8 @@ import { GithubEnterpriseError } from "./github-enterprise-client.ts";
|
|
|
8
8
|
import type { RepoRole } from "./github-lookup-client.ts";
|
|
9
9
|
import {
|
|
10
10
|
canPushForRole,
|
|
11
|
-
UserRepoAccessResolver,
|
|
12
11
|
type LookupPort,
|
|
12
|
+
UserRepoAccessResolver,
|
|
13
13
|
} from "./user-repo-access-resolver.ts";
|
|
14
14
|
|
|
15
15
|
const NOW = new Date("2026-11-09T12:00:00Z");
|