@agenthippo-ai/agenthippo 0.2.3-dataplane → 1.110.11

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.
Files changed (139) hide show
  1. package/out/agentpack/index.js +3 -1
  2. package/out/agentpack/paths.js +25 -2
  3. package/out/analytics/dashboard/localFleetAdapter.js +82 -2
  4. package/out/analytics/dashboard/provider.js +13 -2
  5. package/out/analytics/dashboard/webview/panel.js +3 -2
  6. package/out/analytics/identity.js +0 -0
  7. package/out/analytics/service.js +29 -25
  8. package/out/analytics/sessionEvents.js +100 -24
  9. package/out/auth/authBaseUrl.js +59 -0
  10. package/out/auth/bootstrapApply.js +9 -10
  11. package/out/auth/brokerClient.js +48 -14
  12. package/out/auth/provider.js +8 -21
  13. package/out/auth/sessionStore.js +3 -40
  14. package/out/auth/signInFlow.js +2 -1
  15. package/out/auth-broker/config.js +50 -5
  16. package/out/auth-broker/server.js +126 -26
  17. package/out/auth-broker/store.js +25 -24
  18. package/out/authority/warrant.js +206 -0
  19. package/out/branding.js +27 -1
  20. package/out/cli/commands/conformance.js +249 -0
  21. package/out/cli/commands/data-plane.js +151 -0
  22. package/out/cli/commands/deploy.js +1 -0
  23. package/out/cli/commands/gateway.js +4 -0
  24. package/out/cli/commands/pack.js +182 -3
  25. package/out/cli/commands/sandbox.js +351 -0
  26. package/out/cli/commands/serve.js +1145 -130
  27. package/out/cli/commands/store.js +12 -4
  28. package/out/cli/credential-context.js +17 -0
  29. package/out/cli/data-plane/gateway.js +28 -5
  30. package/out/cli/data-plane/index.js +18 -2
  31. package/out/cli/data-plane/registry.js +9 -0
  32. package/out/cli/data-plane/remote.js +106 -0
  33. package/out/cli/data-plane/sidecar.js +225 -0
  34. package/out/cli/deploy/layers/identity.js +88 -4
  35. package/out/cli/deploy-init.js +89 -24
  36. package/out/cli/deps.js +106 -2
  37. package/out/cli/idp-init.js +35 -0
  38. package/out/cli/index.js +171 -17
  39. package/out/cli/pack-install-ref.js +15 -0
  40. package/out/cli/pack-loader.js +8 -1
  41. package/out/cli/pack-runtime.js +61 -0
  42. package/out/cli/runtime.js +35 -1
  43. package/out/cli/serve-hardening.js +260 -14
  44. package/out/cli/utils.js +12 -1
  45. package/out/engines/base.js +32 -3
  46. package/out/engines/claude.js +33 -15
  47. package/out/engines/codex.js +111 -27
  48. package/out/engines/custom.js +15 -1
  49. package/out/evidence/sessionShip.js +643 -0
  50. package/out/extension.js +11 -2
  51. package/out/gateway/bridge.js +40 -2
  52. package/out/gateway/client.js +34 -1
  53. package/out/gateway/installSource.js +68 -0
  54. package/out/gateway/lifecycle.js +185 -51
  55. package/out/gateway/outboundPaths.js +4 -1
  56. package/out/gateway/secretsPreflight.js +90 -0
  57. package/out/gateway/service.js +7 -2
  58. package/out/headless/index.js +25 -2
  59. package/out/live-e2e/mcp-demo/server.mjs +32 -0
  60. package/out/mcp.js +30 -0
  61. package/out/pack/caps.js +271 -0
  62. package/out/pack/governor.js +326 -0
  63. package/out/pack/lease-schema.js +273 -0
  64. package/out/pack/lease.js +682 -0
  65. package/out/pack/reconcile.js +217 -0
  66. package/out/pack/signature.js +839 -0
  67. package/out/remote/handleRemoteChat.js +44 -3
  68. package/out/remote/remoteTrust.js +277 -0
  69. package/out/remote/serveClient.js +52 -5
  70. package/out/runner/host.js +141 -0
  71. package/out/runner/protocol.js +128 -0
  72. package/out/runner/remoteEngine.js +166 -0
  73. package/out/runtime/interfaces/edit-tracker.js +2 -0
  74. package/out/runtime/vscode/vscode-edit-tracker.js +2 -0
  75. package/out/sandbox/containerDriver.js +572 -0
  76. package/out/sandbox/processDriver.js +318 -0
  77. package/out/sandbox/sandboxRunner.js +303 -0
  78. package/out/sandbox/support.js +301 -0
  79. package/out/sandbox/types.js +55 -0
  80. package/out/scripts/agentide-litellm.sh +67 -5
  81. package/out/scripts/agentide_litellm_hooks_v1.py +266 -21
  82. package/out/scripts/analytics/agentide-litellm-otel.config.yaml +98 -132
  83. package/out/scripts/analytics/setup-analytics.ps1 +45 -14
  84. package/out/scripts/analytics/setup-analytics.sh +106 -15
  85. package/out/scripts/analytics/start-analytics.sh +86 -14
  86. package/out/scripts/gateway/setup-gateway.sh +72 -32
  87. package/out/shared/models.js +11 -110
  88. package/out/spotlight/install.js +7 -1
  89. package/out/store/index.js +41 -10
  90. package/out/sync.js +3 -1
  91. package/out/test/analytics.test.js +162 -23
  92. package/out/test/auth-baseurl.test.js +132 -0
  93. package/out/test/auth-bootstrapApply.test.js +27 -6
  94. package/out/test/auth-broker-hardening.test.js +227 -0
  95. package/out/test/auth-broker.test.js +59 -9
  96. package/out/test/branding.test.js +13 -0
  97. package/out/test/caps-governor.test.js +460 -0
  98. package/out/test/codex-new-file-survival.test.js +119 -0
  99. package/out/test/configuration-scopes.test.js +131 -0
  100. package/out/test/data-plane-engine-wiring.test.js +32 -0
  101. package/out/test/data-plane.test.js +380 -0
  102. package/out/test/deploy-init.test.js +47 -1
  103. package/out/test/gateway-client.test.js +28 -0
  104. package/out/test/gateway-install-source.test.js +111 -0
  105. package/out/test/gateway-lifecycle.test.js +1 -1
  106. package/out/test/gateway-outbound.test.js +7 -0
  107. package/out/test/gateway-secrets-preflight.test.js +127 -0
  108. package/out/test/gateway-session-routing.test.js +18 -0
  109. package/out/test/governor-hardening.test.js +222 -0
  110. package/out/test/headless-sync.test.js +22 -0
  111. package/out/test/lease-signature.test.js +357 -0
  112. package/out/test/lease-trust-root.test.js +273 -0
  113. package/out/test/lease-validation.test.js +224 -0
  114. package/out/test/lease.test.js +114 -0
  115. package/out/test/localFleetAdapter.test.js +91 -0
  116. package/out/test/mcp.test.js +27 -1
  117. package/out/test/pack-admission.test.js +216 -0
  118. package/out/test/pack-digest-parity.test.js +140 -0
  119. package/out/test/pack-reconcile.test.js +183 -0
  120. package/out/test/pack-signature-artifact.test.js +103 -0
  121. package/out/test/pack-signature.test.js +176 -0
  122. package/out/test/pack-trust-root.test.js +202 -0
  123. package/out/test/remote-trust.test.js +242 -0
  124. package/out/test/runner-protocol.test.js +249 -0
  125. package/out/test/sandbox-driver.test.js +553 -0
  126. package/out/test/sandbox-hardening.test.js +406 -0
  127. package/out/test/sandbox-runner.test.js +343 -0
  128. package/out/test/sandbox-scope.test.js +449 -0
  129. package/out/test/serve-cron-acceptance.test.js +370 -0
  130. package/out/test/serve-gateway-turn.test.js +122 -0
  131. package/out/test/serve-hardening.test.js +227 -15
  132. package/out/test/serveClient.test.js +6 -5
  133. package/out/test/sessionShip.test.js +618 -0
  134. package/out/test/spotlightPublish.test.js +28 -0
  135. package/out/test/store-install-safe.test.js +69 -0
  136. package/out/test/tls-bypass.test.js +90 -0
  137. package/out/test/warrant.test.js +138 -0
  138. package/out/utils.js +46 -9
  139. package/package.json +1 -1
@@ -0,0 +1,357 @@
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Signed leases, lease validation, and the staleness ceiling.
4
+ *
5
+ * The whole governance story — kill switch, deny rules, caps, version pin, pack signing — was
6
+ * rooted in an UNSIGNED document fetched over an unauthenticated channel and `JSON.parse`d
7
+ * straight into policy. Anyone who could answer AGENTHIPPO_LEASE_URL could lift the kill switch;
8
+ * anyone who could drop packets to it could keep a revoked fleet running indefinitely.
9
+ *--------------------------------------------------------------------------------------------*/
10
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ var desc = Object.getOwnPropertyDescriptor(m, k);
13
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
14
+ desc = { enumerable: true, get: function() { return m[k]; } };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }) : (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ o[k2] = m[k];
20
+ }));
21
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
22
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
23
+ }) : function(o, v) {
24
+ o["default"] = v;
25
+ });
26
+ var __importStar = (this && this.__importStar) || (function () {
27
+ var ownKeys = function(o) {
28
+ ownKeys = Object.getOwnPropertyNames || function (o) {
29
+ var ar = [];
30
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
31
+ return ar;
32
+ };
33
+ return ownKeys(o);
34
+ };
35
+ return function (mod) {
36
+ if (mod && mod.__esModule) return mod;
37
+ var result = {};
38
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
39
+ __setModuleDefault(result, mod);
40
+ return result;
41
+ };
42
+ })();
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ require("mocha");
45
+ const assert = __importStar(require("assert"));
46
+ const warrant_1 = require("../authority/warrant");
47
+ const lease_1 = require("../pack/lease");
48
+ const key = (0, warrant_1.generateWarrantKeypair)('lease-k1');
49
+ const keys = { 'lease-k1': key.publicKeyPem };
50
+ const NOW = 1_800_000_000;
51
+ const lease = { pack: 'analyst', expiresAt: NOW + 3600, enabled: true };
52
+ const bodyResponse = (text) => ({
53
+ ok: true,
54
+ status: 200,
55
+ text: async () => text,
56
+ json: async () => JSON.parse(text),
57
+ });
58
+ const collectLogs = () => {
59
+ const lines = [];
60
+ return { lines, logger: { info: (m) => lines.push(m), warn: (m) => lines.push(m) } };
61
+ };
62
+ suite('signed lease — envelope verification', () => {
63
+ test('a lease signed by a trusted key verifies, and the policy survives intact', () => {
64
+ const token = (0, lease_1.signLease)(lease, key, { instanceId: 'inst-1', nowSeconds: NOW });
65
+ const res = (0, lease_1.verifySignedLease)(token, keys, { instanceId: 'inst-1', nowSeconds: NOW });
66
+ assert.ok(res.ok, res.ok ? '' : res.reason);
67
+ assert.deepStrictEqual(res.lease, lease);
68
+ });
69
+ test('an empty keyring never verifies — the same rule packs get', () => {
70
+ const token = (0, lease_1.signLease)(lease, key, { nowSeconds: NOW });
71
+ const res = (0, lease_1.verifySignedLease)(token, {}, { nowSeconds: NOW });
72
+ assert.strictEqual(res.ok, false);
73
+ });
74
+ test('a key we do not trust is refused, never trusted-on-first-use', () => {
75
+ const stranger = (0, warrant_1.generateWarrantKeypair)('evil');
76
+ const token = (0, lease_1.signLease)({ ...lease, enabled: true }, stranger, { nowSeconds: NOW });
77
+ const res = (0, lease_1.verifySignedLease)(token, keys, { nowSeconds: NOW });
78
+ assert.strictEqual(res.ok, false);
79
+ assert.match(res.reason, /unknown kid/);
80
+ });
81
+ test('a tampered payload breaks the signature', () => {
82
+ const token = (0, lease_1.signLease)({ ...lease, enabled: false }, key, { nowSeconds: NOW });
83
+ const [h, , s] = token.split('.');
84
+ const forged = Buffer.from(JSON.stringify({
85
+ lease: { ...lease, enabled: true }, aud: '*', sub: 'analyst', iat: NOW, exp: NOW + 300,
86
+ })).toString('base64url');
87
+ const res = (0, lease_1.verifySignedLease)(`${h}.${forged}.${s}`, keys, { nowSeconds: NOW });
88
+ assert.strictEqual(res.ok, false);
89
+ assert.match(res.reason, /bad signature/);
90
+ });
91
+ test('a lease for another instance does not verify here (audience binding)', () => {
92
+ const token = (0, lease_1.signLease)(lease, key, { instanceId: 'inst-other', nowSeconds: NOW });
93
+ const res = (0, lease_1.verifySignedLease)(token, keys, { instanceId: 'inst-1', nowSeconds: NOW });
94
+ assert.strictEqual(res.ok, false);
95
+ assert.match(res.reason, /for instance inst-other/);
96
+ });
97
+ test('a fleet-wide (*) lease is accepted by any instance', () => {
98
+ const token = (0, lease_1.signLease)(lease, key, { nowSeconds: NOW });
99
+ assert.ok((0, lease_1.verifySignedLease)(token, keys, { instanceId: 'inst-1', nowSeconds: NOW }).ok);
100
+ });
101
+ test('an expired envelope is refused even though the LEASE has not expired', () => {
102
+ const token = (0, lease_1.signLease)(lease, key, { nowSeconds: NOW, ttlSeconds: 60 });
103
+ const res = (0, lease_1.verifySignedLease)(token, keys, { nowSeconds: NOW + 3600 });
104
+ assert.strictEqual(res.ok, false);
105
+ assert.match(res.reason, /envelope expired/);
106
+ });
107
+ test('envelope TTL is capped — a lease refresh must not become a credential', () => {
108
+ const token = (0, lease_1.signLease)(lease, key, { nowSeconds: NOW, ttlSeconds: 99_999 });
109
+ // The cap is applied at signing; verification also refuses anything longer.
110
+ const res = (0, lease_1.verifySignedLease)(token, keys, { nowSeconds: NOW + lease_1.MAX_LEASE_ENVELOPE_TTL_SECONDS - 1 });
111
+ assert.ok(res.ok, 'inside the capped lifetime it is still valid');
112
+ assert.strictEqual((0, lease_1.verifySignedLease)(token, keys, { nowSeconds: NOW + lease_1.MAX_LEASE_ENVELOPE_TTL_SECONDS + 120 }).ok, false);
113
+ });
114
+ /**
115
+ * The binding that matters most. `governor.checkLease` treats a restored lease as "lease
116
+ * restored — accepting turns again", so replaying an older `enabled: true` envelope does not
117
+ * merely delay a kill: it LIFTS one that has already latched.
118
+ */
119
+ test('an older envelope is refused as a rollback replay', () => {
120
+ const older = (0, lease_1.signLease)(lease, key, { nowSeconds: NOW });
121
+ const newer = (0, lease_1.signLease)({ ...lease, enabled: false }, key, { nowSeconds: NOW + 100 });
122
+ assert.ok((0, lease_1.verifySignedLease)(newer, keys, { nowSeconds: NOW + 100 }).ok);
123
+ const replay = (0, lease_1.verifySignedLease)(older, keys, { nowSeconds: NOW + 120, minIat: NOW + 100 });
124
+ assert.strictEqual(replay.ok, false);
125
+ assert.match(replay.reason, /replay\/rollback/);
126
+ });
127
+ test('a pack signature cannot be replayed as a lease under the same key (typ binding)', () => {
128
+ // A JWT-typed token signed by the same key must not pass as a lease envelope.
129
+ const notALease = require('../authority/warrant').signCompactJws({ typ: 'JWT', kid: 'lease-k1' }, { lease, aud: '*', sub: 'analyst', iat: NOW, exp: NOW + 300 }, key.privateKeyPem);
130
+ const res = (0, lease_1.verifySignedLease)(notALease, keys, { nowSeconds: NOW });
131
+ assert.strictEqual(res.ok, false);
132
+ assert.match(res.reason, /unexpected token type/);
133
+ });
134
+ test('a signed lease carrying a malformed policy is refused, not half-adopted', () => {
135
+ const token = (0, lease_1.signLease)({ ...lease, caps: { maxTurnsPerSession: 'lots' } }, key, { nowSeconds: NOW });
136
+ const res = (0, lease_1.verifySignedLease)(token, keys, { nowSeconds: NOW });
137
+ assert.strictEqual(res.ok, false);
138
+ assert.match(res.reason, /malformed/);
139
+ });
140
+ });
141
+ suite('requireSignedLease is tighten-only', () => {
142
+ test('either side may demand it; neither may waive the other', () => {
143
+ assert.strictEqual((0, lease_1.requireSignedLease)(undefined, undefined), false);
144
+ assert.strictEqual((0, lease_1.requireSignedLease)(true, undefined), true);
145
+ assert.strictEqual((0, lease_1.requireSignedLease)(undefined, true), true);
146
+ assert.strictEqual((0, lease_1.requireSignedLease)(false, true), true);
147
+ });
148
+ });
149
+ suite('lease source — signature enforcement', () => {
150
+ test('a signed lease is accepted and reported as signed', async () => {
151
+ const token = (0, lease_1.signLease)(lease, key, { instanceId: 'inst-1', nowSeconds: NOW });
152
+ const src = (0, lease_1.createLeaseSource)({
153
+ url: 'https://plane.example/lease',
154
+ cacheSeconds: 0,
155
+ instanceId: 'inst-1',
156
+ signingKeys: () => keys,
157
+ fetchImpl: (async () => bodyResponse(JSON.stringify({ lease: token }))),
158
+ });
159
+ assert.deepStrictEqual(await src.get(NOW), lease);
160
+ assert.strictEqual(src.status(NOW).signed, true);
161
+ });
162
+ test('a bare compact-JWS body works too', async () => {
163
+ const token = (0, lease_1.signLease)(lease, key, { nowSeconds: NOW });
164
+ const src = (0, lease_1.createLeaseSource)({
165
+ url: 'https://plane.example/lease',
166
+ cacheSeconds: 0,
167
+ signingKeys: () => keys,
168
+ fetchImpl: (async () => bodyResponse(token)),
169
+ });
170
+ assert.deepStrictEqual(await src.get(NOW), lease);
171
+ });
172
+ test('an unsigned lease still works, and says so LOUDLY, when signing is not required', async () => {
173
+ const { lines, logger } = collectLogs();
174
+ const src = (0, lease_1.createLeaseSource)({
175
+ url: 'https://plane.example/lease',
176
+ cacheSeconds: 0,
177
+ logger,
178
+ fetchImpl: (async () => bodyResponse(JSON.stringify(lease))),
179
+ });
180
+ assert.deepStrictEqual(await src.get(NOW), lease);
181
+ assert.ok(lines.some((l) => /UNSIGNED lease/.test(l)), 'back-compat must not be silent');
182
+ });
183
+ test('an unsigned lease is REFUSED when signing is required — and the last good lease stands', async () => {
184
+ const token = (0, lease_1.signLease)(lease, key, { nowSeconds: NOW });
185
+ let signed = true;
186
+ const src = (0, lease_1.createLeaseSource)({
187
+ url: 'https://plane.example/lease',
188
+ cacheSeconds: 0,
189
+ requireSignedLease: true,
190
+ signingKeys: () => keys,
191
+ fetchImpl: (async () => bodyResponse(signed ? token : JSON.stringify({ ...lease, enabled: true }))),
192
+ });
193
+ assert.deepStrictEqual(await src.get(NOW), lease);
194
+ signed = false;
195
+ // A downgrade to unsigned must not install new policy.
196
+ const after = await src.get(NOW + 1);
197
+ assert.deepStrictEqual(after, lease, 'the verified lease is kept; the unsigned one is rejected');
198
+ });
199
+ test('lease.requireSignedLease LATCHES — a later unsigned response cannot undo it', async () => {
200
+ const demanding = (0, lease_1.signLease)({ ...lease, requireSignedLease: true }, key, { nowSeconds: NOW });
201
+ let phase = 'signed';
202
+ const { lines, logger } = collectLogs();
203
+ const src = (0, lease_1.createLeaseSource)({
204
+ url: 'https://plane.example/lease',
205
+ cacheSeconds: 0,
206
+ logger,
207
+ signingKeys: () => keys,
208
+ fetchImpl: (async () => bodyResponse(phase === 'signed' ? demanding : JSON.stringify({ ...lease, enabled: true, version: '9.9.9' }))),
209
+ });
210
+ const first = await src.get(NOW);
211
+ assert.strictEqual(first?.requireSignedLease, true);
212
+ phase = 'unsigned';
213
+ const second = await src.get(NOW + 1);
214
+ assert.strictEqual(second?.version, undefined, 'the unsigned downgrade must not take effect');
215
+ assert.ok(lines.some((l) => /signed lease is required/.test(l)));
216
+ });
217
+ });
218
+ /**
219
+ * The insecure-channel warning, which for one shape did not exist.
220
+ *
221
+ * `createLeaseSource` carried a `leaseUrlRefused` flag, declared and read but never assigned — its
222
+ * comment promised "we never poll it at all", a refusal the file elsewhere argues explicitly
223
+ * against (refusing to poll a plaintext lease URL disables the kill switch, which fails OPEN).
224
+ * Worse, the warning next to it was guarded by `else if (!signingRequired())`, so the one operator
225
+ * who most needed to hear it — one who has demanded signed leases and therefore believes the
226
+ * channel is accounted for — was the only one who heard nothing at all.
227
+ */
228
+ suite('lease source — a plaintext lease URL warns, always, and never stops the poll', () => {
229
+ // An explicit empty env: the ambient ALLOW_INSECURE_TRUST_ROOT escape hatch must not decide
230
+ // what these tests observe.
231
+ const noEnv = {};
232
+ test('http + signing NOT required — warns, and keeps polling', async () => {
233
+ const { lines, logger } = collectLogs();
234
+ const src = (0, lease_1.createLeaseSource)({
235
+ url: 'http://plane.example/lease',
236
+ cacheSeconds: 0,
237
+ env: noEnv,
238
+ logger,
239
+ fetchImpl: (async () => bodyResponse(JSON.stringify(lease))),
240
+ });
241
+ assert.deepStrictEqual(await src.get(NOW), lease, 'refusing to poll would disable the kill switch');
242
+ assert.ok(lines.some((l) => /INSECURE LEASE CHANNEL/.test(l)));
243
+ });
244
+ test('http + signing REQUIRED — still warns; this was the silent case', async () => {
245
+ const token = (0, lease_1.signLease)(lease, key, { nowSeconds: NOW });
246
+ const { lines, logger } = collectLogs();
247
+ const src = (0, lease_1.createLeaseSource)({
248
+ url: 'http://plane.example/lease',
249
+ cacheSeconds: 0,
250
+ env: noEnv,
251
+ logger,
252
+ requireSignedLease: true,
253
+ signingKeys: () => keys,
254
+ fetchImpl: (async () => bodyResponse(token)),
255
+ });
256
+ assert.deepStrictEqual(await src.get(NOW), lease, 'a signed lease over http is still polled');
257
+ const warning = lines.find((l) => /INSECURE LEASE CHANNEL/.test(l));
258
+ assert.ok(warning, 'signing-required over plaintext must not be the quiet case');
259
+ // And it must say what signing does NOT buy, rather than repeating "set requireSignedLease"
260
+ // at an operator who already did.
261
+ assert.match(warning, /not a substitute for https/i);
262
+ });
263
+ test('https warns about nothing', async () => {
264
+ const { lines, logger } = collectLogs();
265
+ const src = (0, lease_1.createLeaseSource)({
266
+ url: 'https://plane.example/lease',
267
+ cacheSeconds: 0,
268
+ env: noEnv,
269
+ logger,
270
+ fetchImpl: (async () => bodyResponse(JSON.stringify(lease))),
271
+ });
272
+ assert.deepStrictEqual(await src.get(NOW), lease);
273
+ assert.ok(!lines.some((l) => /INSECURE LEASE CHANNEL/.test(l)));
274
+ });
275
+ });
276
+ suite('lease source — a garbled document is not policy', () => {
277
+ const badBodies = [
278
+ ['non-numeric cap', JSON.stringify({ ...lease, caps: { maxTurnsPerSession: 'lots' } })],
279
+ ['negative cap', JSON.stringify({ ...lease, caps: { maxSessionSeconds: -5 } })],
280
+ ['string enabled', JSON.stringify({ ...lease, enabled: 'false' })],
281
+ ['unknown deny scope', JSON.stringify({ ...lease, deny: [{ scope: 'tenant', match: 'x', mode: 'kill' }] })],
282
+ ['not an object', '"hello"'],
283
+ ['not JSON at all', '<html>502</html>'],
284
+ ];
285
+ for (const [name, body] of badBodies) {
286
+ test(`${name} is rejected and the previous lease is kept`, async () => {
287
+ let good = true;
288
+ const { lines, logger } = collectLogs();
289
+ const src = (0, lease_1.createLeaseSource)({
290
+ url: 'https://plane.example/lease',
291
+ cacheSeconds: 0,
292
+ logger,
293
+ fetchImpl: (async () => bodyResponse(good ? JSON.stringify(lease) : body)),
294
+ });
295
+ assert.deepStrictEqual(await src.get(NOW), lease);
296
+ good = false;
297
+ assert.deepStrictEqual(await src.get(NOW + 1), lease, 'junk must never replace a validated lease');
298
+ assert.ok(lines.some((l) => /fetch failed/.test(l)), 'and the rejection must be logged');
299
+ });
300
+ }
301
+ test('a NaN cap cannot reach the meter — where every comparison would be false', async () => {
302
+ const src = (0, lease_1.createLeaseSource)({
303
+ url: 'https://plane.example/lease',
304
+ cacheSeconds: 0,
305
+ fetchImpl: (async () => bodyResponse(JSON.stringify({ ...lease, caps: { maxTurnsPerSession: null } }))),
306
+ });
307
+ const got = await src.get(NOW);
308
+ assert.strictEqual(got?.caps?.maxTurnsPerSession, undefined, 'null is dropped, never carried through as a cap');
309
+ });
310
+ });
311
+ suite('lease source — staleness ceiling (kill switch under network denial)', () => {
312
+ test('past the ceiling, the instance fails CLOSED with an actionable reason', async () => {
313
+ let alive = true;
314
+ const { lines, logger } = collectLogs();
315
+ const src = (0, lease_1.createLeaseSource)({
316
+ url: 'https://plane.example/lease',
317
+ cacheSeconds: 0,
318
+ maxStalenessSeconds: 100,
319
+ logger,
320
+ fetchImpl: (async () => {
321
+ if (!alive) {
322
+ throw new Error('control plane unreachable');
323
+ }
324
+ return bodyResponse(JSON.stringify(lease));
325
+ }),
326
+ });
327
+ assert.deepStrictEqual(await src.get(NOW), lease);
328
+ alive = false;
329
+ assert.strictEqual((await src.get(NOW + 50))?.enabled, true, 'inside the ceiling we still fail OPEN on transport');
330
+ const stale = await src.get(NOW + 200);
331
+ assert.strictEqual(stale?.enabled, false, 'past the ceiling the kill switch can no longer be starved out');
332
+ assert.match(stale?.reason ?? '', /staleness ceiling/);
333
+ assert.ok(lines.some((l) => /STALENESS CEILING PASSED/.test(l)));
334
+ assert.strictEqual(src.status(NOW + 200).failClosed, true);
335
+ });
336
+ test('0 disables the ceiling — an operator can explicitly accept unbounded staleness', async () => {
337
+ let alive = true;
338
+ const src = (0, lease_1.createLeaseSource)({
339
+ url: 'https://plane.example/lease',
340
+ cacheSeconds: 0,
341
+ maxStalenessSeconds: 0,
342
+ fetchImpl: (async () => {
343
+ if (!alive) {
344
+ throw new Error('down');
345
+ }
346
+ return bodyResponse(JSON.stringify(lease));
347
+ }),
348
+ });
349
+ await src.get(NOW);
350
+ alive = false;
351
+ assert.strictEqual((await src.get(NOW + 10_000_000))?.enabled, true);
352
+ });
353
+ test('an unmanaged deployment (no lease URL) is untouched by any of this', async () => {
354
+ const src = (0, lease_1.createLeaseSource)({ maxStalenessSeconds: 1 });
355
+ assert.strictEqual(await src.get(NOW + 1_000_000), undefined);
356
+ });
357
+ });
@@ -0,0 +1,273 @@
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * The LEASE trust root — the keyring that decides which policy this instance obeys.
4
+ *
5
+ * Signed leases were unreachable end to end. serve verified lease envelopes with
6
+ * `signingKeys: () => packTrust.keys` — the PACK trust root — while the control plane publishes
7
+ * the lease public key under purpose `lease-signing` and refuses to register one kid under two
8
+ * purposes. So a correctly-configured plane and a correctly-configured serve could not name the
9
+ * same key, and `requireSignedLease` (sticky, with no plane-side undo) would latch an instance
10
+ * into refusing turns with no way back from the console.
11
+ *--------------------------------------------------------------------------------------------*/
12
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ var desc = Object.getOwnPropertyDescriptor(m, k);
15
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
16
+ desc = { enumerable: true, get: function() { return m[k]; } };
17
+ }
18
+ Object.defineProperty(o, k2, desc);
19
+ }) : (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ o[k2] = m[k];
22
+ }));
23
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
24
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
25
+ }) : function(o, v) {
26
+ o["default"] = v;
27
+ });
28
+ var __importStar = (this && this.__importStar) || (function () {
29
+ var ownKeys = function(o) {
30
+ ownKeys = Object.getOwnPropertyNames || function (o) {
31
+ var ar = [];
32
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
33
+ return ar;
34
+ };
35
+ return ownKeys(o);
36
+ };
37
+ return function (mod) {
38
+ if (mod && mod.__esModule) return mod;
39
+ var result = {};
40
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
41
+ __setModuleDefault(result, mod);
42
+ return result;
43
+ };
44
+ })();
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ require("mocha");
47
+ const assert = __importStar(require("assert"));
48
+ const warrant_1 = require("../authority/warrant");
49
+ const lease_1 = require("../pack/lease");
50
+ const signature_1 = require("../pack/signature");
51
+ const leaseKey = (0, warrant_1.generateWarrantKeypair)('lease-2026');
52
+ const packKey = (0, warrant_1.generateWarrantKeypair)('pack-2026');
53
+ const NOW = 1_800_000_000;
54
+ const lease = { pack: 'analyst', expiresAt: NOW + 3600, enabled: true };
55
+ const okResponse = (body) => ({
56
+ ok: true,
57
+ status: 200,
58
+ json: async () => body,
59
+ });
60
+ const fetchReturning = (body) => (async () => okResponse(body));
61
+ const bodyResponse = (text) => ({
62
+ ok: true,
63
+ status: 200,
64
+ text: async () => text,
65
+ json: async () => JSON.parse(text),
66
+ });
67
+ const collectLogs = () => {
68
+ const lines = [];
69
+ return { lines, logger: { info: (m) => lines.push(m), warn: (m) => lines.push(m) } };
70
+ };
71
+ /** A trust root shaped like one nobody configured. */
72
+ const unconfigured = { status: 'unconfigured', keys: {}, warnings: [] };
73
+ suite('lease trust root — sources and precedence', () => {
74
+ test('an explicit lease JWKS URL is used, and is marked as named outright', async () => {
75
+ let asked = '';
76
+ const root = await (0, signature_1.loadLeaseTrustRoot)({
77
+ env: { [signature_1.LEASE_JWKS_URL_ENV]: 'https://plane.example/.well-known/lease-jwks.json' },
78
+ leaseUrl: 'https://elsewhere.example/lease',
79
+ fetchImpl: (async (u) => { asked = u; return okResponse({ pemsByKid: { 'lease-2026': leaseKey.publicKeyPem } }); }),
80
+ });
81
+ assert.strictEqual(asked, 'https://plane.example/.well-known/lease-jwks.json');
82
+ assert.strictEqual(root.status, 'configured');
83
+ assert.strictEqual(root.explicitlyConfigured, true);
84
+ assert.deepStrictEqual(Object.keys(root.keys), ['lease-2026']);
85
+ });
86
+ test('inline keys need no network at all (air-gapped), same as the pack root', async () => {
87
+ const root = await (0, signature_1.loadLeaseTrustRoot)({
88
+ env: { [signature_1.LEASE_SIGNING_KEYS_ENV]: JSON.stringify({ 'lease-2026': leaseKey.publicKeyPem }) },
89
+ fetchImpl: (async () => { throw new Error('must not be called'); }),
90
+ });
91
+ assert.strictEqual(root.status, 'configured');
92
+ assert.strictEqual(root.explicitlyConfigured, true);
93
+ });
94
+ test('the derived URL asks for the lease-signing purpose, not the plane\'s default document', async () => {
95
+ let asked = '';
96
+ const root = await (0, signature_1.loadLeaseTrustRoot)({
97
+ env: {},
98
+ leaseUrl: 'https://plane.example/lease',
99
+ fetchImpl: (async (u) => { asked = u; return okResponse({ pemsByKid: { 'lease-2026': leaseKey.publicKeyPem } }); }),
100
+ });
101
+ // The bare path serves PACK-signing keys on a plane that splits by purpose. Deriving without
102
+ // the query string would hand the lease verifier a keyring that can never verify a lease —
103
+ // and, worse, one that can authorise code execution.
104
+ assert.strictEqual(asked, 'https://plane.example/.well-known/jwks.json?purpose=lease-signing');
105
+ assert.strictEqual(root.status, 'configured');
106
+ assert.strictEqual(root.derivedFromLease, true);
107
+ assert.strictEqual(root.explicitlyConfigured, false, 'derived is not "named outright"');
108
+ });
109
+ test('nothing configured at all is UNCONFIGURED, not an error', async () => {
110
+ const root = await (0, signature_1.loadLeaseTrustRoot)({ env: {} });
111
+ assert.strictEqual(root.status, 'unconfigured');
112
+ assert.deepStrictEqual(root.keys, {});
113
+ });
114
+ });
115
+ suite('lease trust root — the pack root\'s properties, unchanged', () => {
116
+ test('http is refused unless the documented escape hatch is set, and the hatch is LOUD', async () => {
117
+ const env = { [signature_1.LEASE_JWKS_URL_ENV]: 'http://plane.example/lease-jwks.json' };
118
+ const refused = await (0, signature_1.loadLeaseTrustRoot)({ env, fetchImpl: fetchReturning({ pemsByKid: { 'lease-2026': leaseKey.publicKeyPem } }) });
119
+ assert.strictEqual(refused.status, 'unavailable');
120
+ assert.match(refused.reason ?? '', /must be https/);
121
+ const allowed = await (0, signature_1.loadLeaseTrustRoot)({
122
+ env: { ...env, [signature_1.ALLOW_INSECURE_TRUST_ROOT_ENV]: '1' },
123
+ fetchImpl: fetchReturning({ pemsByKid: { 'lease-2026': leaseKey.publicKeyPem } }),
124
+ });
125
+ assert.strictEqual(allowed.status, 'configured');
126
+ assert.ok(allowed.warnings.some((w) => /INSECURE/.test(w)));
127
+ });
128
+ test('a fetch failure is UNAVAILABLE, never an empty keyring (finding A4)', async () => {
129
+ const root = await (0, signature_1.loadLeaseTrustRoot)({
130
+ env: { [signature_1.LEASE_JWKS_URL_ENV]: 'https://plane.example/j' },
131
+ fetchImpl: (async () => { throw new Error('ECONNREFUSED'); }),
132
+ });
133
+ assert.strictEqual(root.status, 'unavailable');
134
+ assert.match(root.reason ?? '', /ECONNREFUSED/);
135
+ // Still "named outright", so serve must NOT quietly fall back to the pack keyring here.
136
+ assert.strictEqual(root.explicitlyConfigured, true);
137
+ });
138
+ test('a garbled inline keyring names the variable an operator has to fix', async () => {
139
+ const root = await (0, signature_1.loadLeaseTrustRoot)({ env: { [signature_1.LEASE_SIGNING_KEYS_ENV]: '{not json' } });
140
+ assert.strictEqual(root.status, 'unavailable');
141
+ assert.match(root.reason ?? '', new RegExp(`${signature_1.LEASE_SIGNING_KEYS_ENV} is set but is not valid JSON`));
142
+ });
143
+ test('thumbprint pins refuse a key the plane did not previously publish', async () => {
144
+ const tp = (0, signature_1.publicKeyThumbprints)(leaseKey.publicKeyPem);
145
+ const root = await (0, signature_1.loadLeaseTrustRoot)({
146
+ env: { [signature_1.LEASE_JWKS_URL_ENV]: 'https://plane.example/j', [signature_1.LEASE_JWKS_PINS_ENV]: tp.spki },
147
+ fetchImpl: fetchReturning({ pemsByKid: { 'lease-2026': leaseKey.publicKeyPem, 'stranger': packKey.publicKeyPem } }),
148
+ });
149
+ assert.strictEqual(root.status, 'configured');
150
+ assert.deepStrictEqual(Object.keys(root.keys), ['lease-2026']);
151
+ assert.ok(root.warnings.some((w) => /lease trust root: key stranger does not match any pin/.test(w)));
152
+ });
153
+ test('a standard JWKS document (what the plane publishes) is accepted', async () => {
154
+ const root = await (0, signature_1.loadLeaseTrustRoot)({
155
+ env: { [signature_1.LEASE_JWKS_URL_ENV]: 'https://plane.example/j' },
156
+ fetchImpl: fetchReturning((0, warrant_1.jwks)([leaseKey])),
157
+ });
158
+ assert.strictEqual(root.status, 'configured');
159
+ assert.deepStrictEqual(Object.keys(root.keys), ['lease-2026']);
160
+ });
161
+ });
162
+ suite('lease trust root — which keyring verifies a lease', () => {
163
+ test('a lease root named outright is the WHOLE answer: the pack keyring is not consulted', async () => {
164
+ const leaseTrust = await (0, signature_1.loadLeaseTrustRoot)({
165
+ env: { [signature_1.LEASE_SIGNING_KEYS_ENV]: JSON.stringify({ 'lease-2026': leaseKey.publicKeyPem }) },
166
+ });
167
+ const packTrust = await (0, signature_1.loadPackTrustRoot)({
168
+ env: { [signature_1.PACK_JWKS_URL_ENV]: 'https://plane.example/j' },
169
+ fetchImpl: fetchReturning({ pemsByKid: { 'pack-2026': packKey.publicKeyPem } }),
170
+ });
171
+ const selected = (0, signature_1.selectLeaseSigningKeys)(leaseTrust, packTrust);
172
+ assert.deepStrictEqual(Object.keys(selected.keys), ['lease-2026']);
173
+ assert.strictEqual(selected.packFallback, false);
174
+ // A key that can vouch for a lease must not thereby be able to vouch for CODE, and the
175
+ // converse matters just as much: the pack key must stop being a lease key.
176
+ assert.ok(!('pack-2026' in selected.keys));
177
+ });
178
+ test('with no lease root named, the pack keyring stays in play and the caller is told to warn', async () => {
179
+ const packTrust = await (0, signature_1.loadPackTrustRoot)({
180
+ env: { [signature_1.PACK_JWKS_URL_ENV]: 'https://plane.example/j' },
181
+ fetchImpl: fetchReturning({ pemsByKid: { 'pack-2026': packKey.publicKeyPem } }),
182
+ });
183
+ const selected = (0, signature_1.selectLeaseSigningKeys)(unconfigured, packTrust);
184
+ assert.strictEqual(selected.packFallback, true, 'the caller must warn, naming the new variable');
185
+ assert.deepStrictEqual(Object.keys(selected.keys), ['pack-2026']);
186
+ });
187
+ test('during a rollover both halves are live, and the lease key wins a kid collision', async () => {
188
+ const derived = { status: 'configured', keys: { shared: leaseKey.publicKeyPem }, warnings: [], derivedFromLease: true, explicitlyConfigured: false };
189
+ const packTrust = { status: 'configured', keys: { shared: packKey.publicKeyPem, 'pack-2026': packKey.publicKeyPem }, warnings: [] };
190
+ const selected = (0, signature_1.selectLeaseSigningKeys)(derived, packTrust);
191
+ assert.deepStrictEqual(Object.keys(selected.keys).sort(), ['pack-2026', 'shared']);
192
+ assert.strictEqual(selected.keys.shared, leaseKey.publicKeyPem);
193
+ });
194
+ });
195
+ suite('signed leases end to end through the lease trust root', () => {
196
+ /** Exactly what serve wires: the lease source reads its keys through the selection above. */
197
+ const sourceOver = (leaseTrust, packTrust, body, logger) => (0, lease_1.createLeaseSource)({
198
+ url: 'https://plane.example/lease',
199
+ cacheSeconds: 0,
200
+ env: {},
201
+ instanceId: 'inst-1',
202
+ ...(logger ? { logger } : {}),
203
+ signingKeys: () => (0, signature_1.selectLeaseSigningKeys)(leaseTrust, packTrust).keys,
204
+ fetchImpl: (async () => bodyResponse(body)),
205
+ });
206
+ test('a lease signed with the plane\'s lease-signing key verifies', async () => {
207
+ const leaseTrust = await (0, signature_1.loadLeaseTrustRoot)({
208
+ env: { [signature_1.LEASE_JWKS_URL_ENV]: 'https://plane.example/.well-known/lease-jwks.json' },
209
+ fetchImpl: fetchReturning((0, warrant_1.jwks)([leaseKey])),
210
+ });
211
+ const packTrust = await (0, signature_1.loadPackTrustRoot)({
212
+ env: { [signature_1.PACK_JWKS_URL_ENV]: 'https://plane.example/j' },
213
+ fetchImpl: fetchReturning({ pemsByKid: { 'pack-2026': packKey.publicKeyPem } }),
214
+ });
215
+ const token = (0, lease_1.signLease)(lease, leaseKey, { instanceId: 'inst-1', nowSeconds: NOW });
216
+ const src = sourceOver(leaseTrust, packTrust, JSON.stringify({ lease: token }));
217
+ assert.deepStrictEqual(await src.get(NOW), lease);
218
+ assert.strictEqual(src.status(NOW).signed, true);
219
+ });
220
+ test('the back-compat path still verifies: a lease signed with the PACK key, no lease root named', async () => {
221
+ const packTrust = await (0, signature_1.loadPackTrustRoot)({
222
+ env: { [signature_1.PACK_JWKS_URL_ENV]: 'https://plane.example/j' },
223
+ fetchImpl: fetchReturning({ pemsByKid: { 'pack-2026': packKey.publicKeyPem } }),
224
+ });
225
+ const token = (0, lease_1.signLease)(lease, packKey, { instanceId: 'inst-1', nowSeconds: NOW });
226
+ const selected = (0, signature_1.selectLeaseSigningKeys)(unconfigured, packTrust);
227
+ assert.strictEqual(selected.packFallback, true, 'and the operator is told, once');
228
+ const src = sourceOver(unconfigured, packTrust, JSON.stringify({ lease: token }));
229
+ assert.deepStrictEqual(await src.get(NOW), lease, 'a deployment that works today must keep working');
230
+ });
231
+ test('a lease signed by a kid nobody trusts is refused', async () => {
232
+ const leaseTrust = await (0, signature_1.loadLeaseTrustRoot)({
233
+ env: { [signature_1.LEASE_SIGNING_KEYS_ENV]: JSON.stringify({ 'lease-2026': leaseKey.publicKeyPem }) },
234
+ });
235
+ const stranger = (0, warrant_1.generateWarrantKeypair)('stranger');
236
+ const { lines, logger } = collectLogs();
237
+ const src = sourceOver(leaseTrust, unconfigured, JSON.stringify({ lease: (0, lease_1.signLease)(lease, stranger, { nowSeconds: NOW }) }), logger);
238
+ assert.strictEqual(await src.get(NOW), undefined, 'nothing unverifiable is installed as policy');
239
+ assert.ok(lines.some((l) => /unknown kid/.test(l)));
240
+ });
241
+ test('a pack-key-signed lease is refused once a lease root IS named — silently trusting it would undo the split', async () => {
242
+ const leaseTrust = await (0, signature_1.loadLeaseTrustRoot)({
243
+ env: { [signature_1.LEASE_SIGNING_KEYS_ENV]: JSON.stringify({ 'lease-2026': leaseKey.publicKeyPem }) },
244
+ });
245
+ const packTrust = { status: 'configured', keys: { 'pack-2026': packKey.publicKeyPem }, warnings: [] };
246
+ const src = sourceOver(leaseTrust, packTrust, JSON.stringify({ lease: (0, lease_1.signLease)(lease, packKey, { nowSeconds: NOW }) }));
247
+ assert.strictEqual(await src.get(NOW), undefined);
248
+ });
249
+ test('fail-open on a SIGNATURE failure survives: the last good lease stands', async () => {
250
+ const leaseTrust = await (0, signature_1.loadLeaseTrustRoot)({
251
+ env: { [signature_1.LEASE_SIGNING_KEYS_ENV]: JSON.stringify({ 'lease-2026': leaseKey.publicKeyPem }) },
252
+ });
253
+ const good = (0, lease_1.signLease)(lease, leaseKey, { instanceId: 'inst-1', nowSeconds: NOW });
254
+ const forged = (0, lease_1.signLease)({ ...lease, enabled: false, version: '9.9.9' }, (0, warrant_1.generateWarrantKeypair)('stranger'), { nowSeconds: NOW + 1 });
255
+ let phase = 'good';
256
+ const { lines, logger } = collectLogs();
257
+ const src = (0, lease_1.createLeaseSource)({
258
+ url: 'https://plane.example/lease',
259
+ cacheSeconds: 0,
260
+ env: {},
261
+ instanceId: 'inst-1',
262
+ logger,
263
+ signingKeys: () => (0, signature_1.selectLeaseSigningKeys)(leaseTrust, unconfigured).keys,
264
+ fetchImpl: (async () => bodyResponse(JSON.stringify({ lease: phase === 'good' ? good : forged }))),
265
+ });
266
+ assert.deepStrictEqual(await src.get(NOW), lease);
267
+ phase = 'forged';
268
+ // An unverifiable document is treated exactly like a transport failure — never installed as
269
+ // policy, and never allowed to take a fleet down by being publishable junk.
270
+ assert.deepStrictEqual(await src.get(NOW + 1), lease);
271
+ assert.ok(lines.some((l) => /fetch failed/.test(l)));
272
+ });
273
+ });