@agenthippo-ai/agenthippo 0.1.1 → 1.110.9
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/out/agentpack/index.js +2 -1
- package/out/agentpack/paths.js +23 -0
- package/out/analytics/dashboard/fleetDisplayUtils.js +3 -0
- package/out/analytics/dashboard/provider.js +13 -2
- package/out/analytics/dashboard/webview/panel.js +293 -82
- package/out/analytics/identity.js +0 -0
- package/out/analytics/service.js +23 -25
- package/out/analytics/sessionEvents.js +109 -22
- package/out/auth/authBaseUrl.js +59 -0
- package/out/auth/bootstrapApply.js +9 -10
- package/out/auth/brokerClient.js +49 -15
- package/out/auth/onboardingPrompt.js +112 -0
- package/out/auth/provider.js +9 -22
- package/out/auth/sessionStore.js +3 -40
- package/out/auth/signInFlow.js +2 -1
- package/out/auth-broker/config.js +54 -4
- package/out/auth-broker/server.js +152 -20
- package/out/auth-broker/store.js +25 -24
- package/out/authority/warrant.js +206 -0
- package/out/branding.js +27 -1
- package/out/cli/commands/ask.js +3 -0
- package/out/cli/commands/chat.js +3 -0
- package/out/cli/commands/conformance.js +249 -0
- package/out/cli/commands/data-plane.js +67 -0
- package/out/cli/commands/deploy.js +50 -10
- package/out/cli/commands/gateway.js +58 -0
- package/out/cli/commands/idp.js +85 -0
- package/out/cli/commands/pack.js +182 -3
- package/out/cli/commands/sandbox.js +332 -0
- package/out/cli/commands/serve.js +1165 -82
- package/out/cli/commands/store.js +12 -4
- package/out/cli/credential-context.js +42 -80
- package/out/cli/data-plane/broker.js +78 -0
- package/out/cli/data-plane/connector-host.js +121 -0
- package/out/cli/data-plane/egress.js +189 -0
- package/out/cli/data-plane/gateway.js +218 -0
- package/out/cli/data-plane/index.js +152 -0
- package/out/cli/data-plane/registry.js +89 -0
- package/out/cli/data-plane/remote.js +106 -0
- package/out/cli/data-plane/sidecar.js +161 -0
- package/out/cli/deploy/blueprints/registry.js +84 -0
- package/out/cli/deploy/layers/identity.js +172 -0
- package/out/cli/deploy-init.js +1182 -347
- package/out/cli/deps.js +106 -2
- package/out/cli/idp-init.js +338 -0
- package/out/cli/index.js +192 -23
- package/out/cli/pack-install-ref.js +15 -0
- package/out/cli/pack-loader.js +45 -3
- package/out/cli/pack-runtime.js +61 -0
- package/out/cli/runtime.js +44 -3
- package/out/cli/serve-hardening.js +139 -3
- package/out/cli/state-sync.js +16 -15
- package/out/cli/utils.js +12 -1
- package/out/engines/base.js +32 -3
- package/out/engines/claude.js +47 -8
- package/out/engines/codex.js +125 -22
- package/out/engines/custom.js +54 -12
- package/out/evidence/sessionShip.js +610 -0
- package/out/extension.js +13 -2
- package/out/gateway/bridge.js +40 -2
- package/out/gateway/client.js +34 -1
- package/out/gateway/installSource.js +68 -0
- package/out/gateway/lifecycle.js +185 -51
- package/out/gateway/outboundPaths.js +4 -1
- package/out/gateway/outboundSend.js +6 -6
- package/out/gateway/secretsPreflight.js +90 -0
- package/out/gateway/service.js +7 -2
- package/out/headless/index.js +40 -9
- package/out/live-e2e/mcp-demo/server.mjs +32 -0
- package/out/live-probe/connector.mjs +8 -0
- package/out/live-probe/env-report.mjs +8 -0
- package/out/mcp.js +115 -67
- package/out/pack/caps.js +271 -0
- package/out/pack/governor.js +309 -0
- package/out/pack/lease-schema.js +270 -0
- package/out/pack/lease.js +640 -0
- package/out/pack/reconcile.js +217 -0
- package/out/pack/signature.js +839 -0
- package/out/remote/handleRemoteChat.js +44 -3
- package/out/remote/remoteTrust.js +277 -0
- package/out/remote/serveClient.js +52 -5
- package/out/runner/host.js +131 -0
- package/out/runner/protocol.js +108 -0
- package/out/runner/remoteEngine.js +130 -0
- package/out/runtime/interfaces/edit-tracker.js +2 -0
- package/out/runtime/vscode/vscode-edit-tracker.js +2 -0
- package/out/sandbox/containerDriver.js +570 -0
- package/out/sandbox/processDriver.js +315 -0
- package/out/sandbox/sandboxRunner.js +191 -0
- package/out/sandbox/support.js +301 -0
- package/out/sandbox/types.js +55 -0
- package/out/scripts/agentide-litellm.sh +67 -5
- package/out/scripts/agentide_litellm_hooks_v1.py +182 -21
- package/out/scripts/analytics/agentide-litellm-otel.config.yaml +94 -118
- package/out/scripts/analytics/setup-analytics.ps1 +37 -13
- package/out/scripts/analytics/setup-analytics.sh +93 -13
- package/out/scripts/analytics/start-analytics.sh +86 -14
- package/out/scripts/gateway/setup-gateway.sh +72 -32
- package/out/shared/models.js +12 -111
- package/out/shared/providers.js +2 -2
- package/out/spotlight/install.js +7 -1
- package/out/store/index.js +41 -10
- package/out/sync.js +3 -1
- package/out/test/analytics.test.js +198 -34
- package/out/test/auth-baseurl.test.js +132 -0
- package/out/test/auth-bootstrapApply.test.js +27 -6
- package/out/test/auth-broker-hardening.test.js +227 -0
- package/out/test/auth-broker.test.js +112 -9
- package/out/test/blueprint-registry.test.js +105 -0
- package/out/test/branding.test.js +13 -0
- package/out/test/caps-governor.test.js +455 -0
- package/out/test/codex-new-file-survival.test.js +119 -0
- package/out/test/configuration-scopes.test.js +131 -0
- package/out/test/credential-context.test.js +23 -28
- package/out/test/custom-env-layering.test.js +151 -0
- package/out/test/data-plane-engine-wiring.test.js +250 -0
- package/out/test/data-plane.test.js +311 -0
- package/out/test/deploy-init.test.js +295 -4
- package/out/test/egress-broker.test.js +172 -0
- package/out/test/fleetDisplayUtils.test.js +4 -0
- package/out/test/gateway-client.test.js +28 -0
- package/out/test/gateway-install-source.test.js +111 -0
- package/out/test/gateway-lifecycle.test.js +1 -1
- package/out/test/gateway-outbound.test.js +7 -0
- package/out/test/gateway-secrets-preflight.test.js +127 -0
- package/out/test/gateway-session-routing.test.js +18 -0
- package/out/test/governor-hardening.test.js +217 -0
- package/out/test/headless-sync.test.js +22 -0
- package/out/test/idp-init.test.js +151 -0
- package/out/test/lease-signature.test.js +357 -0
- package/out/test/lease-trust-root.test.js +273 -0
- package/out/test/lease-validation.test.js +169 -0
- package/out/test/lease.test.js +114 -0
- package/out/test/mcp-obo.test.js +52 -27
- package/out/test/mcp.test.js +69 -3
- package/out/test/model-routing.test.js +133 -0
- package/out/test/pack-admission.test.js +216 -0
- package/out/test/pack-digest-parity.test.js +140 -0
- package/out/test/pack-reconcile.test.js +183 -0
- package/out/test/pack-signature-artifact.test.js +103 -0
- package/out/test/pack-signature.test.js +176 -0
- package/out/test/pack-trust-root.test.js +202 -0
- package/out/test/remote-trust.test.js +242 -0
- package/out/test/runner-protocol.test.js +249 -0
- package/out/test/sandbox-driver.test.js +553 -0
- package/out/test/sandbox-hardening.test.js +395 -0
- package/out/test/sandbox-runner.test.js +343 -0
- package/out/test/serve-gateway-turn.test.js +267 -0
- package/out/test/serve-hardening.test.js +125 -6
- package/out/test/serveClient.test.js +38 -5
- package/out/test/sessionShip.test.js +560 -0
- package/out/test/spotlightPublish.test.js +28 -0
- package/out/test/state-sync-peer.test.js +18 -5
- package/out/test/store-install-safe.test.js +69 -0
- package/out/test/tls-bypass.test.js +90 -0
- package/out/test/warrant.test.js +138 -0
- package/out/utils.js +73 -20
- package/package.json +1 -1
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* IdP Init Test Suite (PLAN/deploy.md — "customer 0")
|
|
4
|
+
*
|
|
5
|
+
* Verifies `agenthippo idp init` generates a self-contained stack: no repo dependency in the
|
|
6
|
+
* auth-broker image, identity routes reused verbatim from renderIdentityLayer (no drift risk),
|
|
7
|
+
* and valid YAML/bash throughout.
|
|
8
|
+
*--------------------------------------------------------------------------------------------*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
26
|
+
var ownKeys = function(o) {
|
|
27
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
28
|
+
var ar = [];
|
|
29
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
30
|
+
return ar;
|
|
31
|
+
};
|
|
32
|
+
return ownKeys(o);
|
|
33
|
+
};
|
|
34
|
+
return function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
})();
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
require("mocha");
|
|
44
|
+
const assert = __importStar(require("assert"));
|
|
45
|
+
const fs = __importStar(require("fs"));
|
|
46
|
+
const os = __importStar(require("os"));
|
|
47
|
+
const path = __importStar(require("path"));
|
|
48
|
+
const child_process_1 = require("child_process");
|
|
49
|
+
const yaml = __importStar(require("js-yaml"));
|
|
50
|
+
const idp_init_1 = require("../cli/idp-init");
|
|
51
|
+
const idp_1 = require("../cli/commands/idp");
|
|
52
|
+
suite('idp-init: renderIdpArtifacts', () => {
|
|
53
|
+
test('generates a self-contained stack — no monorepo build context', () => {
|
|
54
|
+
const files = (0, idp_init_1.renderIdpArtifacts)({ hostname: 'auth.corp.example' });
|
|
55
|
+
assert.ok(files['Dockerfile.auth-broker'].includes('FROM ghcr.io/agenthippoai/runtime'), 'auth-broker image must come from the published runtime image, not repo build artifacts');
|
|
56
|
+
assert.ok(!files['Dockerfile.auth-broker'].includes('extensions/agentide/dist'), 'must not reference this repo\'s local build output — a customer never has it');
|
|
57
|
+
assert.ok(files['docker-compose.yml'].includes('dockerfile: Dockerfile.auth-broker')
|
|
58
|
+
&& files['docker-compose.yml'].includes('context: .'), 'auth-broker builds from the generated dir itself, not a monorepo path');
|
|
59
|
+
});
|
|
60
|
+
test('docker-compose.yml is valid YAML with the expected services and networks', () => {
|
|
61
|
+
const files = (0, idp_init_1.renderIdpArtifacts)({ hostname: 'auth.corp.example' });
|
|
62
|
+
const compose = yaml.load(files['docker-compose.yml']);
|
|
63
|
+
assert.deepStrictEqual(Object.keys(compose.services), ['oauth2-proxy', 'auth-broker', 'caddy', 'cloudflared']);
|
|
64
|
+
assert.ok(!('agent' in compose.services), 'the IdP runs no agent');
|
|
65
|
+
assert.deepStrictEqual(Object.keys(compose.networks), ['default', 'colocate']);
|
|
66
|
+
assert.ok(files['docker-compose.yml'].includes('name: agenthippo-idp-colocate'));
|
|
67
|
+
});
|
|
68
|
+
test('Caddyfile reuses renderIdentityLayer verbatim — self-issued, no agent backend', () => {
|
|
69
|
+
const files = (0, idp_init_1.renderIdpArtifacts)({ hostname: 'auth.corp.example' });
|
|
70
|
+
const caddy = files['Caddyfile'];
|
|
71
|
+
assert.ok(caddy.includes('import agents/*.caddy'), 'colocated agents import in');
|
|
72
|
+
assert.ok(caddy.includes('handle /oauth/authorize {') && caddy.includes('handle /oauth/browser-login {'));
|
|
73
|
+
assert.ok(caddy.includes('forward_auth oauth2-proxy:4180'), 'self-issued: gates via oauth2-proxy');
|
|
74
|
+
assert.ok(caddy.includes('reverse_proxy auth-broker:9780'), 'health checks the broker, not an agent');
|
|
75
|
+
assert.ok(caddy.includes('respond "not_found" 404'), 'no /v1/* API here — Bearer requests 404, not silently passed through');
|
|
76
|
+
assert.ok(caddy.includes('respond "AgentHippo IdP" 200'), 'browser catch-all, past the SSO gate');
|
|
77
|
+
assert.ok(caddy.includes('http://{$AGENTHIPPO_PUBLIC_HOSTNAME} {') && !caddy.includes('https://{$AGENTHIPPO_PUBLIC_HOSTNAME}'), 'plain HTTP — auto_https is off, TLS terminates in front');
|
|
78
|
+
});
|
|
79
|
+
test('.env.auth.example carries the shared JWT secret + Google OAuth client, no fed vars', () => {
|
|
80
|
+
const files = (0, idp_init_1.renderIdpArtifacts)({ hostname: 'auth.corp.example' });
|
|
81
|
+
const auth = files['.env.auth.example'];
|
|
82
|
+
assert.ok(auth.includes('AGENTHIPPO_AUTH_JWT_SECRET') && auth.includes('OAUTH2_PROXY_CLIENT_ID'));
|
|
83
|
+
assert.ok(!auth.includes('AGENTHIPPO_AUTH_IDP_URL'), 'the IdP is not itself federated against anything');
|
|
84
|
+
});
|
|
85
|
+
test('cookie domain defaults to the hostname\'s own parent domain when not given explicitly', () => {
|
|
86
|
+
const files = (0, idp_init_1.renderIdpArtifacts)({ hostname: 'auth.corp.example' });
|
|
87
|
+
assert.ok(files['.env.auth.example'].includes('AGENTHIPPO_AUTH_COOKIE_DOMAIN=.corp.example'));
|
|
88
|
+
});
|
|
89
|
+
test('explicit cookieDomain overrides the derived default', () => {
|
|
90
|
+
const files = (0, idp_init_1.renderIdpArtifacts)({ hostname: 'auth.eu.corp.example', cookieDomain: '.corp.example' });
|
|
91
|
+
assert.ok(files['.env.auth.example'].includes('AGENTHIPPO_AUTH_COOKIE_DOMAIN=.corp.example'));
|
|
92
|
+
});
|
|
93
|
+
test('run.sh is valid bash and reflects the hostname', () => {
|
|
94
|
+
const files = (0, idp_init_1.renderIdpArtifacts)({ hostname: 'auth.corp.example' });
|
|
95
|
+
assert.doesNotThrow(() => (0, child_process_1.execFileSync)('bash', ['-n', '-c', files['run.sh']]));
|
|
96
|
+
assert.ok(files['run.sh'].includes('auth.corp.example'));
|
|
97
|
+
});
|
|
98
|
+
// Bare metal / BYO nginx or ALB (e.g. Hetzner): run.sh must not hard-require a Cloudflare
|
|
99
|
+
// Tunnel, and Caddy's host port must be reconfigurable when 80/443 are already taken by the
|
|
100
|
+
// operator's own reverse proxy.
|
|
101
|
+
test('run.sh branches on an explicit tunnel-credentials path argument, not a fixed file location', () => {
|
|
102
|
+
const sh = (0, idp_init_1.renderIdpArtifacts)({ hostname: 'auth.corp.example' })['run.sh'];
|
|
103
|
+
assert.ok(sh.includes('if [[ $# -ge 1 ]]; then'), 'branches on whether an argument was passed');
|
|
104
|
+
assert.ok(!sh.includes('-f "$HOME/.agent-hippo/tunnel-credentials.json"'), 'must not infer tunnel mode from a fixed default file path');
|
|
105
|
+
assert.ok(sh.includes('AGENTHIPPO_TUNNEL_CREDENTIALS="$1"'), 'the argument becomes the credentials path');
|
|
106
|
+
assert.ok(sh.includes('docker compose --profile edge --profile tunnel up -d --build'));
|
|
107
|
+
assert.ok(sh.includes('docker compose --profile edge up -d --build'), 'no-argument branch: --profile edge only, no --profile tunnel');
|
|
108
|
+
});
|
|
109
|
+
test('run.sh fails loudly if a given tunnel-credentials path doesn\'t exist', () => {
|
|
110
|
+
const sh = (0, idp_init_1.renderIdpArtifacts)({ hostname: 'auth.corp.example' })['run.sh'];
|
|
111
|
+
assert.ok(sh.includes('[[ -f "$AGENTHIPPO_TUNNEL_CREDENTIALS" ]] || {'));
|
|
112
|
+
assert.ok(sh.includes('exit 1'));
|
|
113
|
+
});
|
|
114
|
+
test('docker-compose.yml wires the cloudflared credentials mount to AGENTHIPPO_TUNNEL_CREDENTIALS', () => {
|
|
115
|
+
const compose = (0, idp_init_1.renderIdpArtifacts)({ hostname: 'auth.corp.example' })['docker-compose.yml'];
|
|
116
|
+
assert.ok(compose.includes('${AGENTHIPPO_TUNNEL_CREDENTIALS:-${HOME}/.agent-hippo/tunnel-credentials.json}'));
|
|
117
|
+
});
|
|
118
|
+
test('Caddy host ports are configurable via AGENTHIPPO_CADDY_HTTP_PORT/_HTTPS_PORT (Hetzner: 80/443 may already be taken)', () => {
|
|
119
|
+
const compose = (0, idp_init_1.renderIdpArtifacts)({ hostname: 'auth.corp.example' })['docker-compose.yml'];
|
|
120
|
+
assert.ok(compose.includes('${AGENTHIPPO_CADDY_HTTP_PORT:-80}:80'));
|
|
121
|
+
assert.ok(compose.includes('${AGENTHIPPO_CADDY_HTTPS_PORT:-443}:443'));
|
|
122
|
+
});
|
|
123
|
+
test('README documents both the Cloudflare Tunnel path and the bare-metal/BYO-nginx path', () => {
|
|
124
|
+
const readme = (0, idp_init_1.renderIdpArtifacts)({ hostname: 'auth.corp.example' })['README.md'];
|
|
125
|
+
assert.ok(readme.includes('Cloudflare Tunnel'));
|
|
126
|
+
assert.ok(readme.includes('Bare metal') || readme.includes('BYO nginx'));
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
suite('idp-init: idpCommand writes files to disk', () => {
|
|
130
|
+
let outDir;
|
|
131
|
+
setup(() => {
|
|
132
|
+
outDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ah-idp-'));
|
|
133
|
+
});
|
|
134
|
+
teardown(() => {
|
|
135
|
+
fs.rmSync(outDir, { recursive: true, force: true });
|
|
136
|
+
});
|
|
137
|
+
test('writes every generated file under --out', async () => {
|
|
138
|
+
await (0, idp_1.idpCommand)('init', { hostname: 'auth.corp.example', out: outDir });
|
|
139
|
+
for (const rel of ['docker-compose.yml', 'Dockerfile.auth-broker', 'Caddyfile', '.env.example', '.env.auth.example', 'run.sh', 'agents/README.md', 'README.md']) {
|
|
140
|
+
assert.ok(fs.existsSync(path.join(outDir, rel)), `${rel} should be written`);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
test('refuses to overwrite existing files without --force', async () => {
|
|
144
|
+
await (0, idp_1.idpCommand)('init', { hostname: 'auth.corp.example', out: outDir });
|
|
145
|
+
fs.writeFileSync(path.join(outDir, 'README.md'), 'hand-edited\n');
|
|
146
|
+
await (0, idp_1.idpCommand)('init', { hostname: 'auth.corp.example', out: outDir });
|
|
147
|
+
assert.strictEqual(fs.readFileSync(path.join(outDir, 'README.md'), 'utf8'), 'hand-edited\n');
|
|
148
|
+
await (0, idp_1.idpCommand)('init', { hostname: 'auth.corp.example', out: outDir, force: true });
|
|
149
|
+
assert.notStrictEqual(fs.readFileSync(path.join(outDir, 'README.md'), 'utf8'), 'hand-edited\n');
|
|
150
|
+
});
|
|
151
|
+
});
|
|
@@ -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
|
+
});
|