@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,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) AgentHippo.ai. All rights reserved.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.startDataPlaneSidecar = startDataPlaneSidecar;
|
|
40
|
+
/**
|
|
41
|
+
* Data-plane SIDECAR (secure-obo-design §7.6 / aperture-thin) — the connector's own trust
|
|
42
|
+
* domain, a SEPARATE container from the engine/agent.
|
|
43
|
+
*
|
|
44
|
+
* It runs the full data plane (TurnRegistry + gateway + connector) and holds the backend BASE
|
|
45
|
+
* credential (AWS keys, Postgres pool login, …). The agent container gets NONE of it: it only
|
|
46
|
+
* (a) registers verified turns via this authenticated control API and (b) points the engine at
|
|
47
|
+
* the gateway URL. Because the sidecar is a different container (different PID namespace), the
|
|
48
|
+
* engine cannot read the base credential from `/proc/<pid>/environ`, and because the sidecar
|
|
49
|
+
* resolves the nonce → userId server-side, the engine cannot forge another user's identity.
|
|
50
|
+
*
|
|
51
|
+
* Control API (loopback/pod-network, bearer-authenticated):
|
|
52
|
+
* POST /turns { userId, sessionKey, inboundToken?, egressStoreKey? } → { nonce }
|
|
53
|
+
* DELETE /turns/:nonce → 204
|
|
54
|
+
* GET /edge/turn (forward_auth from the trusted EDGE; X-Agent-User header)
|
|
55
|
+
* → 200 + `X-Agent-Turn-Nonce` response header
|
|
56
|
+
* The gateway (nonce-authenticated MCP) is a separate port the engine dials directly.
|
|
57
|
+
*
|
|
58
|
+
* EDGE-registration mode (P1 fix, obo-inprogress §2): the bearer secret is held by the IdP
|
|
59
|
+
* Caddy — NOT the agent container. Caddy registers each chat turn via `forward_auth` against
|
|
60
|
+
* `/edge/turn` (identity from the X-Agent-User header its auth-broker hop just verified) and
|
|
61
|
+
* copies the returned nonce header onto the request it proxies to serve. serve then has no
|
|
62
|
+
* registration authority at all: a compromised engine reading serve's `/proc/<pid>/environ`
|
|
63
|
+
* finds no token that can mint a nonce for an arbitrary userId. Release rides the gateway's
|
|
64
|
+
* nonce-authenticated `DELETE /turn`; the registry deadline is the backstop.
|
|
65
|
+
*/
|
|
66
|
+
const http = __importStar(require("http"));
|
|
67
|
+
const crypto_1 = require("crypto");
|
|
68
|
+
const index_1 = require("./index");
|
|
69
|
+
const serve_hardening_1 = require("../serve-hardening");
|
|
70
|
+
const gateway_1 = require("./gateway");
|
|
71
|
+
function bearer(header) {
|
|
72
|
+
return header?.match(/^Bearer\s+(\S+)$/i)?.[1];
|
|
73
|
+
}
|
|
74
|
+
function tokenEq(a, b) {
|
|
75
|
+
const x = Buffer.from(a);
|
|
76
|
+
const y = Buffer.from(b);
|
|
77
|
+
return x.length === y.length && (0, crypto_1.timingSafeEqual)(x, y);
|
|
78
|
+
}
|
|
79
|
+
async function startDataPlaneSidecar(opts) {
|
|
80
|
+
const host = opts.bindHost ?? '0.0.0.0';
|
|
81
|
+
// The gateway binds `host` on a fixed port so the engine can be told the URL at deploy time.
|
|
82
|
+
const plane = await index_1.DataPlane.start(opts.config, {
|
|
83
|
+
logger: opts.logger,
|
|
84
|
+
audit: opts.audit,
|
|
85
|
+
gateway: { host, port: opts.gatewayPort, advertiseHost: host === '0.0.0.0' ? undefined : host },
|
|
86
|
+
});
|
|
87
|
+
const releases = new Map();
|
|
88
|
+
const control = http.createServer(async (req, res) => {
|
|
89
|
+
const reject = (code, msg) => { res.writeHead(code, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ error: msg })); };
|
|
90
|
+
try {
|
|
91
|
+
const tok = bearer(req.headers.authorization);
|
|
92
|
+
if (!tok || !tokenEq(tok, opts.registerToken)) {
|
|
93
|
+
opts.audit?.('unauthorized', 'sidecar_register_reject', { reason: tok ? 'bad_token' : 'missing_token' });
|
|
94
|
+
return reject(401, 'unauthorized');
|
|
95
|
+
}
|
|
96
|
+
const path = req.url?.split('?')[0] ?? '';
|
|
97
|
+
// Edge registration (Caddy forward_auth sends GET, no body): identity comes from the
|
|
98
|
+
// X-Agent-User header the edge's preceding auth-broker hop verified and set. The nonce
|
|
99
|
+
// rides a response header so `copy_headers` can lift it onto the proxied request.
|
|
100
|
+
// sessionKey degrades to userId here — the edge never sees the body's session_id.
|
|
101
|
+
if ((req.method === 'GET' || req.method === 'POST') && path === '/edge/turn') {
|
|
102
|
+
const userId = (Array.isArray(req.headers['x-agent-user']) ? req.headers['x-agent-user'][0] : req.headers['x-agent-user'])?.trim();
|
|
103
|
+
if (!userId) {
|
|
104
|
+
opts.audit?.('unauthorized', 'sidecar_edge_reject', { reason: 'missing_user' });
|
|
105
|
+
return reject(400, 'X-Agent-User required');
|
|
106
|
+
}
|
|
107
|
+
const { nonce } = plane.registerTurnRaw({ userId, sessionKey: userId });
|
|
108
|
+
opts.audit?.(userId, 'sidecar_edge_register', { userId });
|
|
109
|
+
res.writeHead(200, { 'Content-Type': 'application/json', [gateway_1.TURN_NONCE_HEADER]: nonce });
|
|
110
|
+
return res.end(JSON.stringify({ ok: true }));
|
|
111
|
+
}
|
|
112
|
+
if (req.method === 'POST' && path === '/turns') {
|
|
113
|
+
let body;
|
|
114
|
+
try {
|
|
115
|
+
body = JSON.parse(await (0, serve_hardening_1.readBodyWithCap)(req));
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return reject(400, 'bad json');
|
|
119
|
+
}
|
|
120
|
+
const userId = (body.userId ?? '').trim();
|
|
121
|
+
if (!userId) {
|
|
122
|
+
return reject(400, 'userId required');
|
|
123
|
+
}
|
|
124
|
+
const { nonce, release } = plane.registerTurnRaw({
|
|
125
|
+
userId, sessionKey: (body.sessionKey ?? '').trim() || userId,
|
|
126
|
+
inboundToken: body.inboundToken, egressStoreKey: body.egressStoreKey,
|
|
127
|
+
});
|
|
128
|
+
releases.set(nonce, release);
|
|
129
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
130
|
+
return res.end(JSON.stringify({ nonce }));
|
|
131
|
+
}
|
|
132
|
+
if (req.method === 'DELETE' && path.startsWith('/turns/')) {
|
|
133
|
+
const nonce = decodeURIComponent(path.slice('/turns/'.length));
|
|
134
|
+
releases.get(nonce)?.();
|
|
135
|
+
releases.delete(nonce);
|
|
136
|
+
res.writeHead(204);
|
|
137
|
+
return res.end();
|
|
138
|
+
}
|
|
139
|
+
reject(404, 'not found');
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
opts.logger?.warn(`[Sidecar] control error: ${err instanceof Error ? err.message : String(err)}`);
|
|
143
|
+
if (!res.headersSent) {
|
|
144
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
145
|
+
}
|
|
146
|
+
res.end(JSON.stringify({ error: 'internal' }));
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
await new Promise((resolve, reject) => {
|
|
150
|
+
control.once('error', reject);
|
|
151
|
+
control.listen(opts.controlPort, host, () => resolve());
|
|
152
|
+
});
|
|
153
|
+
const controlAddress = control.address();
|
|
154
|
+
const controlPort = controlAddress && typeof controlAddress !== 'string' ? controlAddress.port : opts.controlPort;
|
|
155
|
+
opts.logger?.info(`[Sidecar] gateway ${plane.url} | control :${controlPort} (bound ${host})`);
|
|
156
|
+
return {
|
|
157
|
+
gatewayUrl: plane.url,
|
|
158
|
+
controlPort,
|
|
159
|
+
close: async () => { await new Promise((r) => control.close(() => r())); await plane.close(); },
|
|
160
|
+
};
|
|
161
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) AgentHippo.ai. All rights reserved.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BLUEPRINTS = exports.BLUEPRINT_IDS = void 0;
|
|
7
|
+
exports.isBlueprintId = isBlueprintId;
|
|
8
|
+
exports.resolveBlueprint = resolveBlueprint;
|
|
9
|
+
exports.BLUEPRINT_IDS = [
|
|
10
|
+
'sandbox',
|
|
11
|
+
'prospect-demo',
|
|
12
|
+
'team-pilot',
|
|
13
|
+
'regulated-air-gapped',
|
|
14
|
+
'enterprise-fleet',
|
|
15
|
+
];
|
|
16
|
+
function isBlueprintId(value) {
|
|
17
|
+
return exports.BLUEPRINT_IDS.includes(value);
|
|
18
|
+
}
|
|
19
|
+
exports.BLUEPRINTS = {
|
|
20
|
+
sandbox: {
|
|
21
|
+
id: 'sandbox',
|
|
22
|
+
description: 'Internal test, no external users — no edge, no SSO, no host port beyond localhost.',
|
|
23
|
+
targets: ['vm'],
|
|
24
|
+
},
|
|
25
|
+
'prospect-demo': {
|
|
26
|
+
id: 'prospect-demo',
|
|
27
|
+
description: 'Throwaway public demo for a prospect — Cloudflare Tunnel + a throwaway Google OAuth client.',
|
|
28
|
+
targets: ['vm', 'compose'],
|
|
29
|
+
},
|
|
30
|
+
'team-pilot': {
|
|
31
|
+
id: 'team-pilot',
|
|
32
|
+
description: 'Single-agent pilot. Rides the customer platform\'s own identity when one exists (GCP IAP, ' +
|
|
33
|
+
'Databricks workspace SSO, Snowflake network, Cloudflare Access); falls back to a self-issued edge ' +
|
|
34
|
+
'(own Caddy + oauth2-proxy + Google client) on vm/compose/aws-ecs/azure-container-apps, which have ' +
|
|
35
|
+
'no platform-native option yet.',
|
|
36
|
+
targets: ['cloudrun', 'databricks-app', 'spcs', 'cloudflare', 'vm', 'compose', 'aws-ecs', 'azure-container-apps'],
|
|
37
|
+
},
|
|
38
|
+
'regulated-air-gapped': {
|
|
39
|
+
id: 'regulated-air-gapped',
|
|
40
|
+
description: 'VPN/localhost only, no tunnel, no external telemetry — the highest-scrutiny buyer profile. ' +
|
|
41
|
+
'Currently generator-identical to sandbox (PLAN/deploy.md §2 gap); the distinction is buyer framing, ' +
|
|
42
|
+
'not yet enforced posture.',
|
|
43
|
+
targets: ['vm'],
|
|
44
|
+
},
|
|
45
|
+
'enterprise-fleet': {
|
|
46
|
+
id: 'enterprise-fleet',
|
|
47
|
+
description: 'Federated identity against a central IdP (enterprise-deploy/idp/) for a growing fleet of agents. ' +
|
|
48
|
+
'Same-host colocation (no edge of its own) is available for vm/compose via the raw ' +
|
|
49
|
+
'`--ingress edge-fed --colocate` flag — not yet encoded as a blueprint variant.',
|
|
50
|
+
targets: ['cloudrun', 'vm', 'compose', 'aws-ecs', 'azure-container-apps'],
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Resolve a blueprint (+ optional platform override) to the `--target`/`--ingress` pair
|
|
55
|
+
* `deploy-init.ts` already knows how to render. Throws on a platform not in the blueprint's
|
|
56
|
+
* supported set so a typo doesn't silently produce the wrong deployment shape.
|
|
57
|
+
*/
|
|
58
|
+
function resolveBlueprint(id, platform) {
|
|
59
|
+
const def = exports.BLUEPRINTS[id];
|
|
60
|
+
const target = platform ?? def.targets[0];
|
|
61
|
+
if (!def.targets.includes(target)) {
|
|
62
|
+
throw new Error(`Blueprint "${id}" does not support --platform ${target}. ` +
|
|
63
|
+
`Supported: ${def.targets.join(', ')}.`);
|
|
64
|
+
}
|
|
65
|
+
switch (id) {
|
|
66
|
+
case 'sandbox':
|
|
67
|
+
case 'regulated-air-gapped':
|
|
68
|
+
return { target };
|
|
69
|
+
case 'prospect-demo':
|
|
70
|
+
return { target, ingress: 'edge' };
|
|
71
|
+
case 'enterprise-fleet':
|
|
72
|
+
return { target, ingress: 'edge-fed' };
|
|
73
|
+
case 'team-pilot':
|
|
74
|
+
// Platform-native identity where the platform actually has one; vm/compose have
|
|
75
|
+
// none, so they fall back to the self-issued edge (own Caddy + oauth2-proxy).
|
|
76
|
+
if (target === 'cloudrun') {
|
|
77
|
+
return { target, ingress: 'iap' };
|
|
78
|
+
}
|
|
79
|
+
if (target === 'databricks-app' || target === 'spcs' || target === 'cloudflare') {
|
|
80
|
+
return { target };
|
|
81
|
+
}
|
|
82
|
+
return { target, ingress: 'edge' };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) AgentHippo.ai. All rights reserved.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.EDGE_AGENT_PORT = void 0;
|
|
7
|
+
exports.renderIdentityLayer = renderIdentityLayer;
|
|
8
|
+
exports.renderSidecarEdgeCaddyfile = renderSidecarEdgeCaddyfile;
|
|
9
|
+
exports.renderSidecarFedCaddyfile = renderSidecarFedCaddyfile;
|
|
10
|
+
/**
|
|
11
|
+
* Proof that `X-Auth-Request-Email` was set by THIS Caddy and not by a client.
|
|
12
|
+
*
|
|
13
|
+
* The broker now 401s an `X-Auth-Request-Email` that arrives without a matching
|
|
14
|
+
* `x-agenthippo-proxy-secret` (constant-time compared), because the header is otherwise a bearer
|
|
15
|
+
* assertion of identity that anything able to reach the broker's port could make. Only the routes
|
|
16
|
+
* that actually forward a verified email upstream carry it — adding it elsewhere would spread the
|
|
17
|
+
* secret across hops that have no use for it.
|
|
18
|
+
*
|
|
19
|
+
* `{env.…}` rather than `{$…}`: a runtime placeholder, so the secret is never baked into the
|
|
20
|
+
* rendered config on disk. Unset ⇒ empty ⇒ the broker refuses, which is the intended direction.
|
|
21
|
+
*/
|
|
22
|
+
const BROKER_PROXY_SECRET_LINES = [
|
|
23
|
+
' # Proves this hop is the trusted proxy — the broker 401s X-Auth-Request-Email without it.',
|
|
24
|
+
' header_up x-agenthippo-proxy-secret {env.AGENTHIPPO_AUTH_PROXY_SECRET}',
|
|
25
|
+
];
|
|
26
|
+
function renderIdentityLayer(opts) {
|
|
27
|
+
const { mode, authBrokerAddr, healthProxy, agentProxy } = opts;
|
|
28
|
+
const oauth2ProxyAddr = opts.oauth2ProxyAddr ?? '';
|
|
29
|
+
const catchallBody = opts.catchallBody ?? agentProxy;
|
|
30
|
+
const turn = opts.turnRegistration;
|
|
31
|
+
// The turn-registration hop, inserted AFTER the identity forward_auth (which sets
|
|
32
|
+
// X-Agent-User — the user the sidecar mints the nonce for). Only POST chat turns match.
|
|
33
|
+
const turnHop = turn
|
|
34
|
+
? [
|
|
35
|
+
' # Turn registration — after identity: X-Agent-User (set above) names the user the',
|
|
36
|
+
' # sidecar mints the nonce for. Only POST chat turns match; others pass through.',
|
|
37
|
+
` forward_auth @turnStart ${turn.connectorAddr} {`,
|
|
38
|
+
' uri /edge/turn',
|
|
39
|
+
' copy_headers X-Agent-Turn-Nonce',
|
|
40
|
+
` header_up Authorization "Bearer {$${turn.tokenEnvVar}}"`,
|
|
41
|
+
' }',
|
|
42
|
+
]
|
|
43
|
+
: [];
|
|
44
|
+
// NOTE: two forward_auth in one handle block do NOT run in source order — Caddy sorts by
|
|
45
|
+
// its directive table, so the turn-registration hop could fire before identity is
|
|
46
|
+
// established (the connector then gets no X-Agent-User → 400). Wrapping the sequence in
|
|
47
|
+
// `route {}` forces source order: identity first (unauth short-circuits), then turn
|
|
48
|
+
// registration, then proxy.
|
|
49
|
+
// Re-indent wrapped directives one level so the generated file stays readable — operators
|
|
50
|
+
// copy these snippets by hand onto the IdP host.
|
|
51
|
+
const indent = (lines) => lines.map((l) => (l.trim() ? ` ${l}` : l));
|
|
52
|
+
const gated = (identityGate, body) => turn
|
|
53
|
+
? [' route {', ...indent(identityGate), ...turnHop, ...indent(body), ' }']
|
|
54
|
+
: [...identityGate, ...body];
|
|
55
|
+
const lines = [];
|
|
56
|
+
if (turn) {
|
|
57
|
+
lines.push(' # Hygiene: never let a client-supplied nonce header through (copy_headers overwrites it', ' # on chat paths anyway, and a forged nonce fails closed at the gateway — belt-and-braces).', ' request_header -X-Agent-Turn-Nonce');
|
|
58
|
+
}
|
|
59
|
+
if (mode === 'self-issued') {
|
|
60
|
+
lines.push(' # IDE PKCE sign-in: broker requires X-Auth-Request-Email from oauth2-proxy. Must come', ' # before the generic /oauth/* handle so authorize is gated (not dumped straight to broker).', ' handle /oauth/authorize {', ` forward_auth ${oauth2ProxyAddr} {`, ' uri /oauth2/auth', ' copy_headers X-Auth-Request-Email', ' header_up X-Forwarded-Proto https', ' header_up X-Forwarded-Host {http.request.host}', ' @unauth status 401', ' handle_response @unauth {', ' redir * "/oauth2/sign_in?rd={http.request.uri}"', ' }', ' }', ` reverse_proxy ${authBrokerAddr} {`, ' header_up X-Forwarded-Proto https', ' header_up X-Forwarded-Host {http.request.host}', ...BROKER_PROXY_SECRET_LINES, ' }', ' }', ' # Federated SSO (A′): browsers from other subdomains land here to stamp the shared cookie.', ' # Same oauth2-proxy gate as authorize; must precede the generic /oauth/* handle.', ' handle /oauth/browser-login {', ` forward_auth ${oauth2ProxyAddr} {`, ' uri /oauth2/auth', ' copy_headers X-Auth-Request-Email', ' header_up X-Forwarded-Proto https', ' header_up X-Forwarded-Host {http.request.host}', ' @unauth status 401', ' handle_response @unauth {', ' redir * "/oauth2/sign_in?rd={http.request.uri}"', ' }', ' }', ` reverse_proxy ${authBrokerAddr} {`, ' header_up X-Forwarded-Proto https', ' header_up X-Forwarded-Host {http.request.host}', ...BROKER_PROXY_SECRET_LINES, ' }', ' }', ' # Auth-broker: token exchange + other /oauth/* routes that must stay ungated.', ' handle /oauth/* {', ` reverse_proxy ${authBrokerAddr} {`, ' header_up X-Forwarded-Proto https', ' header_up X-Forwarded-Host {http.request.host}', ' }', ' }');
|
|
61
|
+
}
|
|
62
|
+
lines.push(' handle /api/ide/* {', ` reverse_proxy ${authBrokerAddr} {`, ' header_up X-Forwarded-Proto https', ' header_up X-Forwarded-Host {http.request.host}', ' }', ' }');
|
|
63
|
+
if (mode === 'self-issued') {
|
|
64
|
+
lines.push(' # oauth2-proxy: Google SSO callback + sign-in.', ' handle /oauth2/* {', ` reverse_proxy ${oauth2ProxyAddr} {`, ' header_up X-Forwarded-Proto https', ' header_up X-Forwarded-Host {http.request.host}', ' }', ' }');
|
|
65
|
+
}
|
|
66
|
+
lines.push(' @health path /health /ready', ' handle @health {', ...healthProxy, ' }');
|
|
67
|
+
if (turn) {
|
|
68
|
+
lines.push(' # Chat-turn matcher for edge turn registration (P1 fix): only POST chat turns register.', ' @turnStart {', ' method POST', ' path /v1/chat /v1/chat/stream', ' }');
|
|
69
|
+
}
|
|
70
|
+
lines.push(' # API clients (IDE) with a Bearer token: validate via auth-broker, copy identity header.', ' @apiWithAuth {', ' path /v1/*', ' header Authorization *', ' }', ' handle @apiWithAuth {', ...gated([
|
|
71
|
+
` forward_auth ${authBrokerAddr} {`,
|
|
72
|
+
' uri /api/ide/me',
|
|
73
|
+
' copy_headers X-Agent-User',
|
|
74
|
+
' header_up X-Forwarded-Proto https',
|
|
75
|
+
' header_up X-Forwarded-Host {http.request.host}',
|
|
76
|
+
' @unauth status 401',
|
|
77
|
+
' handle_response @unauth {',
|
|
78
|
+
' respond "Unauthorized" 401',
|
|
79
|
+
' }',
|
|
80
|
+
' }',
|
|
81
|
+
], agentProxy), ' }');
|
|
82
|
+
if (mode === 'self-issued') {
|
|
83
|
+
lines.push(' # Browser clients: SSO via oauth2-proxy, identity injected as X-Agent-User.', ' handle {', ...gated([
|
|
84
|
+
` forward_auth ${oauth2ProxyAddr} {`,
|
|
85
|
+
' uri /oauth2/auth',
|
|
86
|
+
' copy_headers X-Auth-Request-Email>X-Agent-User',
|
|
87
|
+
' header_up X-Forwarded-Proto https',
|
|
88
|
+
' header_up X-Forwarded-Host {http.request.host}',
|
|
89
|
+
' @unauth status 401',
|
|
90
|
+
' handle_response @unauth {',
|
|
91
|
+
' redir * "/oauth2/sign_in?rd={http.request.uri}"',
|
|
92
|
+
' }',
|
|
93
|
+
' }',
|
|
94
|
+
], catchallBody), ' }');
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
const idp = opts.idpUrl?.trim() || '';
|
|
98
|
+
const loginRedirect = idp
|
|
99
|
+
? ` redir * "${idp}/oauth/browser-login?return_to=https://{http.request.host}{http.request.uri}" 302`
|
|
100
|
+
: ' respond "Unauthorized" 401';
|
|
101
|
+
lines.push(' # Browser clients: the shared .agenthippo.ai cookie is verified by auth-broker. No cookie', ' # → redirect to the central IdP to log in (it stamps the cookie), then return.', ' handle {', ...gated([
|
|
102
|
+
` forward_auth ${authBrokerAddr} {`,
|
|
103
|
+
' uri /api/ide/me',
|
|
104
|
+
' copy_headers X-Agent-User',
|
|
105
|
+
' header_up X-Forwarded-Proto https',
|
|
106
|
+
' header_up X-Forwarded-Host {http.request.host}',
|
|
107
|
+
' @unauth status 401',
|
|
108
|
+
' handle_response @unauth {',
|
|
109
|
+
loginRedirect,
|
|
110
|
+
' }',
|
|
111
|
+
' }',
|
|
112
|
+
], catchallBody), ' }');
|
|
113
|
+
}
|
|
114
|
+
return lines;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* "Sidecar" platforms — Cloud Run, ECS Fargate (`awsvpc` mode), Azure Container Apps (one
|
|
118
|
+
* replica) — all share one task's network namespace across containers and terminate TLS in
|
|
119
|
+
* front, so Caddy always listens on plain HTTP `:{$PORT}` and reaches every sidecar via
|
|
120
|
+
* `localhost:<port>` (never docker-DNS names). The agent isn't the ingress on these platforms,
|
|
121
|
+
* so it listens on a distinct internal port to avoid clashing with Caddy on `$PORT`.
|
|
122
|
+
*/
|
|
123
|
+
exports.EDGE_AGENT_PORT = 8090;
|
|
124
|
+
/** Caddyfile for a sidecar platform's self-issued edge (own oauth2-proxy + Google client). */
|
|
125
|
+
function renderSidecarEdgeCaddyfile() {
|
|
126
|
+
return [
|
|
127
|
+
'# Sidecar-platform edge ingress. TLS terminates in front; Caddy listens on HTTP :{$PORT}.',
|
|
128
|
+
'# Containers share one task/pod\'s localhost → upstreams are 127.0.0.1:<port> (not docker-DNS names).',
|
|
129
|
+
'{',
|
|
130
|
+
' auto_https off',
|
|
131
|
+
'}',
|
|
132
|
+
'',
|
|
133
|
+
':{$PORT} {',
|
|
134
|
+
...renderIdentityLayer({
|
|
135
|
+
mode: 'self-issued',
|
|
136
|
+
oauth2ProxyAddr: 'localhost:4180',
|
|
137
|
+
authBrokerAddr: 'localhost:9780',
|
|
138
|
+
healthProxy: [` reverse_proxy localhost:${exports.EDGE_AGENT_PORT}`],
|
|
139
|
+
agentProxy: [` reverse_proxy localhost:${exports.EDGE_AGENT_PORT}`],
|
|
140
|
+
}),
|
|
141
|
+
'}',
|
|
142
|
+
'',
|
|
143
|
+
].join('\n');
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* A′ — federated sidecar-platform edge. No oauth2-proxy: Google login happens once at the
|
|
147
|
+
* central IdP (`idpUrl`); this agent only verifies the shared AgentHippo JWT (Bearer for IDE,
|
|
148
|
+
* cookie for browser). On a browser 401, redirect to the IdP's `/oauth/browser-login` to stamp
|
|
149
|
+
* the shared cookie, then return.
|
|
150
|
+
*/
|
|
151
|
+
function renderSidecarFedCaddyfile(idpUrl) {
|
|
152
|
+
const idp = (idpUrl || '').trim().replace(/\/+$/, '');
|
|
153
|
+
return [
|
|
154
|
+
'# Sidecar-platform federated edge (A′). TLS terminates in front; Caddy listens on HTTP :{$PORT}.',
|
|
155
|
+
`# No oauth2-proxy — Google login happens once at the central IdP (${idp || '<IDP_URL>'});`,
|
|
156
|
+
'# this agent only verifies the shared AgentHippo JWT (Bearer for IDE, cookie for browser).',
|
|
157
|
+
'{',
|
|
158
|
+
' auto_https off',
|
|
159
|
+
'}',
|
|
160
|
+
'',
|
|
161
|
+
':{$PORT} {',
|
|
162
|
+
...renderIdentityLayer({
|
|
163
|
+
mode: 'federated',
|
|
164
|
+
authBrokerAddr: 'localhost:9780',
|
|
165
|
+
idpUrl: idp,
|
|
166
|
+
healthProxy: [` reverse_proxy localhost:${exports.EDGE_AGENT_PORT}`],
|
|
167
|
+
agentProxy: [` reverse_proxy localhost:${exports.EDGE_AGENT_PORT}`],
|
|
168
|
+
}),
|
|
169
|
+
'}',
|
|
170
|
+
'',
|
|
171
|
+
].join('\n');
|
|
172
|
+
}
|