lumoauth 1.2.0 → 1.3.1
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/README.md +67 -1
- package/dist/cli.js +330 -52
- package/dist/cli.js.map +1 -1
- package/dist/index.d.mts +51 -2
- package/dist/index.d.ts +51 -2
- package/dist/index.js +315 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +320 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -22,11 +22,13 @@ var src_exports = {};
|
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
StdioBridge: () => StdioBridge,
|
|
24
24
|
allowedToolNames: () => allowedToolNames,
|
|
25
|
+
createExtAuthzServer: () => createExtAuthzServer,
|
|
25
26
|
createSecureProxy: () => createSecureProxy,
|
|
26
27
|
filterJsonBody: () => filterJsonBody,
|
|
27
28
|
filterSseEvent: () => filterSseEvent,
|
|
28
29
|
inspect: () => inspect,
|
|
29
30
|
main: () => main,
|
|
31
|
+
refusedJitToolResult: () => refusedJitToolResult,
|
|
30
32
|
refusedToolResult: () => refusedToolResult,
|
|
31
33
|
startUpstream: () => startUpstream,
|
|
32
34
|
waitForUpstream: () => waitForUpstream
|
|
@@ -54,9 +56,13 @@ function inspect(body) {
|
|
|
54
56
|
result.isBatch = Array.isArray(parsed);
|
|
55
57
|
const messages = Array.isArray(parsed) ? parsed : [parsed];
|
|
56
58
|
for (const message of messages) {
|
|
57
|
-
if (typeof message !== "object" || message === null
|
|
59
|
+
if (typeof message !== "object" || message === null) continue;
|
|
60
|
+
const params = message.params;
|
|
61
|
+
if (!result.traceparent && typeof params?._meta?.traceparent === "string") {
|
|
62
|
+
result.traceparent = params._meta.traceparent;
|
|
63
|
+
}
|
|
64
|
+
if (message.id === void 0) continue;
|
|
58
65
|
if (message.method === "tools/call") {
|
|
59
|
-
const params = message.params;
|
|
60
66
|
result.toolCalls.push({ id: asId(message.id), name: typeof params?.name === "string" ? params.name : "" });
|
|
61
67
|
} else if (message.method === "tools/list") {
|
|
62
68
|
result.toolListIds.add(JSON.stringify(message.id));
|
|
@@ -67,6 +73,28 @@ function inspect(body) {
|
|
|
67
73
|
function refusedToolResult(id, message) {
|
|
68
74
|
return { jsonrpc: "2.0", id, result: { content: [{ type: "text", text: message }], isError: true } };
|
|
69
75
|
}
|
|
76
|
+
function refusedJitToolResult(id, tool, requiredDetails) {
|
|
77
|
+
const hintJson = JSON.stringify(requiredDetails);
|
|
78
|
+
const headerValue = Buffer.from(hintJson, "utf8").toString("base64");
|
|
79
|
+
const types = requiredDetails.map((d) => d.type).join(", ");
|
|
80
|
+
const message = `Tool '${tool}' requires JIT authorization_details (${types}); authorization_details_hint=${hintJson}`;
|
|
81
|
+
return {
|
|
82
|
+
headerValue,
|
|
83
|
+
body: {
|
|
84
|
+
jsonrpc: "2.0",
|
|
85
|
+
id,
|
|
86
|
+
result: {
|
|
87
|
+
content: [{ type: "text", text: message }],
|
|
88
|
+
isError: true,
|
|
89
|
+
_meta: {
|
|
90
|
+
error: "insufficient_authorization_details",
|
|
91
|
+
authorization_details_hint: requiredDetails,
|
|
92
|
+
"Insufficient-Authorization-Details": headerValue
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
70
98
|
async function filterMessage(message, ids, decide) {
|
|
71
99
|
if (typeof message !== "object" || message === null) return message;
|
|
72
100
|
const response = message;
|
|
@@ -220,6 +248,19 @@ function createSecureProxy(options) {
|
|
|
220
248
|
if (caller.actor) headers.set("x-lumoauth-actor", caller.actor);
|
|
221
249
|
if (caller.clientId) headers.set("x-lumoauth-client-id", caller.clientId);
|
|
222
250
|
headers.set("x-lumoauth-scopes", caller.scopes.join(" "));
|
|
251
|
+
if (caller.traceId) headers.set("x-lumoauth-trace-id", caller.traceId);
|
|
252
|
+
if (caller.isJit) headers.set("x-lumoauth-is-jit", "true");
|
|
253
|
+
}
|
|
254
|
+
if (caller?.traceparent && !headers.has("traceparent")) {
|
|
255
|
+
headers.set("traceparent", caller.traceparent);
|
|
256
|
+
}
|
|
257
|
+
if (caller && options.vaultConnections) {
|
|
258
|
+
for (const [slug, connectionId] of Object.entries(options.vaultConnections)) {
|
|
259
|
+
const cleanSlug = slug.trim().toLowerCase().replace(/[^a-z0-9-]/g, "-");
|
|
260
|
+
if (!cleanSlug || !connectionId) continue;
|
|
261
|
+
const vaultToken = await auth.vaultToken(connectionId, caller);
|
|
262
|
+
headers.set(`x-lumoauth-vault-${cleanSlug}-token`, vaultToken.accessToken);
|
|
263
|
+
}
|
|
223
264
|
}
|
|
224
265
|
const controller = new AbortController();
|
|
225
266
|
res.on("close", () => controller.abort());
|
|
@@ -309,21 +350,48 @@ function createSecureProxy(options) {
|
|
|
309
350
|
}
|
|
310
351
|
const body = method === "POST" ? await readBody(req, maxBody) : void 0;
|
|
311
352
|
let inspection;
|
|
312
|
-
if (body && options.toolPolicy) {
|
|
353
|
+
if (body && (options.toolPolicy || options.jit)) {
|
|
313
354
|
inspection = inspect(body.toString("utf8"));
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
if (
|
|
355
|
+
if (!caller.traceparent && inspection.traceparent) {
|
|
356
|
+
const parsedTp = (0, import_mcp.parseTraceparent)(inspection.traceparent);
|
|
357
|
+
if (parsedTp) {
|
|
358
|
+
caller.traceparent = parsedTp.traceparent;
|
|
359
|
+
caller.traceId ?? (caller.traceId = parsedTp.traceId);
|
|
360
|
+
}
|
|
317
361
|
}
|
|
318
|
-
if (
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
362
|
+
if (options.toolPolicy) {
|
|
363
|
+
const refused = [];
|
|
364
|
+
for (const call of inspection.toolCalls) {
|
|
365
|
+
if (!await auth.toolPolicy().isAllowed(caller, call.name)) refused.push(call);
|
|
366
|
+
}
|
|
367
|
+
if (refused.length > 0) {
|
|
368
|
+
const reason = (name) => `LumoAuth policy does not allow this caller to run '${name}'.`;
|
|
369
|
+
log2(`lumoauth: refused ${refused.map((c) => c.name).join(", ")} for ${caller.sub}`);
|
|
370
|
+
if (inspection.isBatch) {
|
|
371
|
+
writeJson(res, 200, inspection.toolCalls.map((c) => refusedToolResult(c.id, reason(refused[0].name))));
|
|
372
|
+
} else {
|
|
373
|
+
writeJson(res, 200, refusedToolResult(refused[0].id, reason(refused[0].name)));
|
|
374
|
+
}
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
if (options.jit) {
|
|
379
|
+
for (const call of inspection.toolCalls) {
|
|
380
|
+
const jitSpec = options.jit[call.name];
|
|
381
|
+
if (!jitSpec) continue;
|
|
382
|
+
const required = (0, import_mcp.normalizeAuthorizationDetails)(jitSpec);
|
|
383
|
+
const missing = (0, import_mcp.missingAuthorizationDetails)(required, caller.authorizationDetails);
|
|
384
|
+
if (missing.length > 0) {
|
|
385
|
+
const jitRefusal = refusedJitToolResult(call.id, call.name, missing);
|
|
386
|
+
res.setHeader("Insufficient-Authorization-Details", jitRefusal.headerValue);
|
|
387
|
+
writeJson(
|
|
388
|
+
res,
|
|
389
|
+
200,
|
|
390
|
+
inspection.isBatch ? inspection.toolCalls.map((c) => refusedJitToolResult(c.id, call.name, missing).body) : jitRefusal.body
|
|
391
|
+
);
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
325
394
|
}
|
|
326
|
-
return;
|
|
327
395
|
}
|
|
328
396
|
}
|
|
329
397
|
if (options.bridge) {
|
|
@@ -354,6 +422,138 @@ function createSecureProxy(options) {
|
|
|
354
422
|
});
|
|
355
423
|
}
|
|
356
424
|
|
|
425
|
+
// src/ext-authz.ts
|
|
426
|
+
var import_node_http2 = require("http");
|
|
427
|
+
var import_mcp2 = require("@lumoauth/mcp");
|
|
428
|
+
function headerOf2(req, name) {
|
|
429
|
+
const value = req.headers[name];
|
|
430
|
+
return Array.isArray(value) ? value[0] : value;
|
|
431
|
+
}
|
|
432
|
+
async function readBody2(req, limit) {
|
|
433
|
+
const chunks = [];
|
|
434
|
+
let size = 0;
|
|
435
|
+
for await (const chunk of req) {
|
|
436
|
+
size += chunk.length;
|
|
437
|
+
if (size > limit) break;
|
|
438
|
+
chunks.push(chunk);
|
|
439
|
+
}
|
|
440
|
+
return Buffer.concat(chunks);
|
|
441
|
+
}
|
|
442
|
+
function writeJson2(res, status, body, headers = {}) {
|
|
443
|
+
const text = JSON.stringify(body);
|
|
444
|
+
res.statusCode = status;
|
|
445
|
+
for (const [k, v] of Object.entries(headers)) res.setHeader(k, v);
|
|
446
|
+
res.setHeader("Content-Type", "application/json");
|
|
447
|
+
res.setHeader("Content-Length", Buffer.byteLength(text));
|
|
448
|
+
res.end(text);
|
|
449
|
+
}
|
|
450
|
+
function createExtAuthzServer(options) {
|
|
451
|
+
const { auth } = options;
|
|
452
|
+
const log2 = options.log ?? ((line) => console.error(line));
|
|
453
|
+
const identityHeaders = options.identityHeaders ?? true;
|
|
454
|
+
const publicPaths = options.publicPaths ?? ["/healthz", "/readyz"];
|
|
455
|
+
const maxBody = options.maxBodyBytes ?? 1024 * 1024;
|
|
456
|
+
async function handle(req, res) {
|
|
457
|
+
const method = headerOf2(req, "x-envoy-original-method") ?? req.method ?? "GET";
|
|
458
|
+
const rawPath = headerOf2(req, "x-envoy-original-path") ?? headerOf2(req, "x-forwarded-uri") ?? req.url ?? "/";
|
|
459
|
+
const url = new URL(rawPath, "http://ext-authz.invalid");
|
|
460
|
+
if (publicPaths.includes(url.pathname)) {
|
|
461
|
+
res.statusCode = 200;
|
|
462
|
+
res.end();
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
const discovery = await auth.discoveryResponse(method, url.pathname);
|
|
466
|
+
if (discovery) {
|
|
467
|
+
res.statusCode = discovery.status;
|
|
468
|
+
for (const [k, v] of Object.entries(discovery.headers)) res.setHeader(k, v);
|
|
469
|
+
res.end(discovery.body);
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
let info;
|
|
473
|
+
try {
|
|
474
|
+
info = await auth.authenticate({ method, url: rawPath, headers: req.headers });
|
|
475
|
+
} catch (error) {
|
|
476
|
+
if (error instanceof import_mcp2.LumoAuthChallenge) {
|
|
477
|
+
(0, import_mcp2.writeChallenge)(res, error);
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
throw error;
|
|
481
|
+
}
|
|
482
|
+
const caller = info.extra.caller;
|
|
483
|
+
const body = method === "POST" ? await readBody2(req, maxBody) : void 0;
|
|
484
|
+
if (body && body.length > 0 && (options.toolPolicy || options.jit)) {
|
|
485
|
+
const inspection = inspect(body.toString("utf8"));
|
|
486
|
+
if (!caller.traceparent && inspection.traceparent) {
|
|
487
|
+
const parsedTp = (0, import_mcp2.parseTraceparent)(inspection.traceparent);
|
|
488
|
+
if (parsedTp) {
|
|
489
|
+
caller.traceparent = parsedTp.traceparent;
|
|
490
|
+
caller.traceId ?? (caller.traceId = parsedTp.traceId);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
if (options.toolPolicy) {
|
|
494
|
+
for (const call of inspection.toolCalls) {
|
|
495
|
+
if (!await auth.toolPolicy().isAllowed(caller, call.name)) {
|
|
496
|
+
log2(`lumoauth ext-authz: refused tool '${call.name}' for ${caller.sub}`);
|
|
497
|
+
writeJson2(
|
|
498
|
+
res,
|
|
499
|
+
403,
|
|
500
|
+
refusedToolResult(call.id, `LumoAuth policy does not allow this caller to run '${call.name}'.`),
|
|
501
|
+
{ "X-LumoAuth-Denied-Tool": call.name }
|
|
502
|
+
);
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
if (options.jit) {
|
|
508
|
+
for (const call of inspection.toolCalls) {
|
|
509
|
+
const jitSpec = options.jit[call.name];
|
|
510
|
+
if (!jitSpec) continue;
|
|
511
|
+
const required = (0, import_mcp2.normalizeAuthorizationDetails)(jitSpec);
|
|
512
|
+
const missing = (0, import_mcp2.missingAuthorizationDetails)(required, caller.authorizationDetails);
|
|
513
|
+
if (missing.length > 0) {
|
|
514
|
+
const jitRefusal = refusedJitToolResult(call.id, call.name, missing);
|
|
515
|
+
writeJson2(res, 403, jitRefusal.body, {
|
|
516
|
+
"Insufficient-Authorization-Details": jitRefusal.headerValue,
|
|
517
|
+
"WWW-Authenticate": `Bearer error="insufficient_authorization_details", error_description="JIT step-up required for tool '${call.name}'"`
|
|
518
|
+
});
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
res.statusCode = 200;
|
|
525
|
+
if (identityHeaders) {
|
|
526
|
+
res.setHeader("x-lumoauth-subject", caller.sub);
|
|
527
|
+
res.setHeader("x-lumoauth-subject-type", caller.isAgent ? "agent" : "user");
|
|
528
|
+
if (caller.agentId) res.setHeader("x-lumoauth-agent-id", caller.agentId);
|
|
529
|
+
if (caller.actor) res.setHeader("x-lumoauth-actor", caller.actor);
|
|
530
|
+
if (caller.clientId) res.setHeader("x-lumoauth-client-id", caller.clientId);
|
|
531
|
+
res.setHeader("x-lumoauth-scopes", caller.scopes.join(" "));
|
|
532
|
+
if (caller.traceId) res.setHeader("x-lumoauth-trace-id", caller.traceId);
|
|
533
|
+
if (caller.isJit) res.setHeader("x-lumoauth-is-jit", "true");
|
|
534
|
+
}
|
|
535
|
+
if (caller.traceparent) {
|
|
536
|
+
res.setHeader("traceparent", caller.traceparent);
|
|
537
|
+
}
|
|
538
|
+
if (options.vaultConnections) {
|
|
539
|
+
for (const [slug, connectionId] of Object.entries(options.vaultConnections)) {
|
|
540
|
+
const cleanSlug = slug.trim().toLowerCase().replace(/[^a-z0-9-]/g, "-");
|
|
541
|
+
if (!cleanSlug || !connectionId) continue;
|
|
542
|
+
const vaultToken = await auth.vaultToken(connectionId, caller);
|
|
543
|
+
res.setHeader(`x-lumoauth-vault-${cleanSlug}-token`, vaultToken.accessToken);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
res.end();
|
|
547
|
+
}
|
|
548
|
+
return (0, import_node_http2.createServer)((req, res) => {
|
|
549
|
+
handle(req, res).catch((error) => {
|
|
550
|
+
log2(`lumoauth ext-authz: ${error.stack ?? error}`);
|
|
551
|
+
if (!res.headersSent) writeJson2(res, 500, { error: "server_error" });
|
|
552
|
+
else res.destroy();
|
|
553
|
+
});
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
|
|
357
557
|
// src/stdio.ts
|
|
358
558
|
var import_node_crypto = require("crypto");
|
|
359
559
|
var import_stdio = require("@modelcontextprotocol/sdk/client/stdio.js");
|
|
@@ -511,21 +711,25 @@ async function waitForUpstream(url, child, timeoutMs = 3e4) {
|
|
|
511
711
|
|
|
512
712
|
// src/cli.ts
|
|
513
713
|
var import_node_util = require("util");
|
|
514
|
-
var
|
|
515
|
-
var VERSION = "1.
|
|
714
|
+
var import_mcp3 = require("@lumoauth/mcp");
|
|
715
|
+
var VERSION = "1.3.1";
|
|
516
716
|
var HELP = `lumoauth: put LumoAuth in front of an MCP server
|
|
517
717
|
|
|
518
718
|
Usage:
|
|
519
719
|
npx lumoauth secure --upstream <url> [options] [-- <command that starts it>]
|
|
520
720
|
npx lumoauth secure --stdio [options] -- <stdio server command>
|
|
721
|
+
npx lumoauth ext-authz [options]
|
|
521
722
|
npx lumoauth check [options]
|
|
522
723
|
|
|
523
724
|
Commands:
|
|
524
|
-
secure
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
725
|
+
secure Serve the MCP server over HTTP behind LumoAuth: OAuth discovery,
|
|
726
|
+
token checks (Bearer and DPoP) and LumoAuth's per-tool policy.
|
|
727
|
+
The server's own code does not change.
|
|
728
|
+
ext-authz Run as an Envoy HTTP ext_authz check server for Kubernetes / service
|
|
729
|
+
mesh deployments, returning 200 OK with X-LumoAuth-* headers or
|
|
730
|
+
401/403 RFC 9728 challenges.
|
|
731
|
+
check Show what LumoAuth's registration says, the discovery document
|
|
732
|
+
and the 401 challenge, then exit.
|
|
529
733
|
|
|
530
734
|
Options:
|
|
531
735
|
--org <slug> Organization (LUMOAUTH_ORG_ID)
|
|
@@ -535,11 +739,14 @@ Options:
|
|
|
535
739
|
--issuer <url> Organization issuer, for a custom domain (LUMOAUTH_ISSUER)
|
|
536
740
|
--upstream <url> The MCP endpoint to protect, e.g. http://127.0.0.1:8000/mcp
|
|
537
741
|
--stdio The command after -- is a stdio MCP server
|
|
742
|
+
--ext-authz Run in Envoy HTTP ext_authz check mode
|
|
538
743
|
--port <n> Port to listen on (PORT, default 8080)
|
|
539
744
|
--host <address> Address to listen on (default 0.0.0.0)
|
|
540
745
|
--path <path> Public path of the MCP endpoint (default: the Resource URI's path, or /mcp)
|
|
541
746
|
--scope <scope> A scope every request needs; repeat for more
|
|
542
747
|
--public <path> Forward this path without a token (health checks); repeatable
|
|
748
|
+
--jit <tool=type[:a]> Require a JIT/RAR grant for a tool (e.g. refund=payment:refund); repeatable
|
|
749
|
+
--vault <slug=conn> Inject X-LumoAuth-Vault-<Slug>-Token from Token Vault; repeatable
|
|
543
750
|
--tool-policy Require LumoAuth's per-tool policy (LUMOAUTH_MCP_CLIENT_ID and _SECRET)
|
|
544
751
|
--no-tool-policy Do not ask LumoAuth about tools
|
|
545
752
|
--no-identity-headers Do not send X-LumoAuth-* identity headers upstream
|
|
@@ -557,7 +764,7 @@ var LUMOAUTH_OPTIONS = {
|
|
|
557
764
|
var UsageError = class extends Error {
|
|
558
765
|
};
|
|
559
766
|
function makeAuth(values) {
|
|
560
|
-
return (0,
|
|
767
|
+
return (0, import_mcp3.lumoAuth)({
|
|
561
768
|
orgId: values.org,
|
|
562
769
|
serverId: values.server,
|
|
563
770
|
resource: values.resource,
|
|
@@ -567,7 +774,39 @@ function makeAuth(values) {
|
|
|
567
774
|
});
|
|
568
775
|
}
|
|
569
776
|
var log = (line) => console.error(line);
|
|
570
|
-
|
|
777
|
+
function parseJitSpecs(specs) {
|
|
778
|
+
if (!specs || specs.length === 0) return void 0;
|
|
779
|
+
const out = {};
|
|
780
|
+
for (const raw of specs) {
|
|
781
|
+
const eq = raw.indexOf("=");
|
|
782
|
+
if (eq <= 0 || eq === raw.length - 1) {
|
|
783
|
+
throw new UsageError(`--jit must be <tool>=<type>[:action1,action2], got '${raw}'`);
|
|
784
|
+
}
|
|
785
|
+
const tool = raw.slice(0, eq).trim();
|
|
786
|
+
const rest = raw.slice(eq + 1).trim();
|
|
787
|
+
const [type, actionsRaw] = rest.split(":", 2);
|
|
788
|
+
if (!tool || !type) throw new UsageError(`--jit must be <tool>=<type>[:action1,action2], got '${raw}'`);
|
|
789
|
+
const actions = actionsRaw ? actionsRaw.split(",").map((a) => a.trim()).filter(Boolean) : void 0;
|
|
790
|
+
out[tool] = actions && actions.length > 0 ? { type, actions } : { type };
|
|
791
|
+
}
|
|
792
|
+
return out;
|
|
793
|
+
}
|
|
794
|
+
function parseVaultSpecs(specs) {
|
|
795
|
+
if (!specs || specs.length === 0) return void 0;
|
|
796
|
+
const out = {};
|
|
797
|
+
for (const raw of specs) {
|
|
798
|
+
const eq = raw.indexOf("=");
|
|
799
|
+
if (eq <= 0 || eq === raw.length - 1) {
|
|
800
|
+
throw new UsageError(`--vault must be <slug>=<connection_id>, got '${raw}'`);
|
|
801
|
+
}
|
|
802
|
+
const slug = raw.slice(0, eq).trim();
|
|
803
|
+
const conn = raw.slice(eq + 1).trim();
|
|
804
|
+
if (!slug || !conn) throw new UsageError(`--vault must be <slug>=<connection_id>, got '${raw}'`);
|
|
805
|
+
out[slug] = conn;
|
|
806
|
+
}
|
|
807
|
+
return out;
|
|
808
|
+
}
|
|
809
|
+
async function secure(args, command, forceExtAuthz = false) {
|
|
571
810
|
const { values } = (0, import_node_util.parseArgs)({
|
|
572
811
|
args,
|
|
573
812
|
strict: true,
|
|
@@ -575,25 +814,33 @@ async function secure(args, command) {
|
|
|
575
814
|
...LUMOAUTH_OPTIONS,
|
|
576
815
|
upstream: { type: "string" },
|
|
577
816
|
stdio: { type: "boolean" },
|
|
817
|
+
"ext-authz": { type: "boolean" },
|
|
578
818
|
port: { type: "string" },
|
|
579
819
|
host: { type: "string" },
|
|
580
820
|
path: { type: "string" },
|
|
581
821
|
public: { type: "string", multiple: true },
|
|
822
|
+
jit: { type: "string", multiple: true },
|
|
823
|
+
vault: { type: "string", multiple: true },
|
|
582
824
|
"tool-policy": { type: "boolean" },
|
|
583
825
|
"no-tool-policy": { type: "boolean" },
|
|
584
826
|
"no-identity-headers": { type: "boolean" }
|
|
585
827
|
}
|
|
586
828
|
});
|
|
587
|
-
|
|
588
|
-
if (
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
829
|
+
const isExtAuthz = forceExtAuthz || Boolean(values["ext-authz"]);
|
|
830
|
+
if (!isExtAuthz) {
|
|
831
|
+
if (values.stdio && values.upstream) throw new UsageError("use --upstream or --stdio, not both");
|
|
832
|
+
if (values.stdio && command.length === 0) {
|
|
833
|
+
throw new UsageError("--stdio needs the server command after --, for example: lumoauth secure --stdio -- node server.js");
|
|
834
|
+
}
|
|
835
|
+
if (!values.stdio && !values.upstream) {
|
|
836
|
+
throw new UsageError("say which server to protect: --upstream <url> for an HTTP server, or --stdio -- <command>");
|
|
837
|
+
}
|
|
838
|
+
if (values.upstream && !/^https?:\/\//.test(values.upstream)) {
|
|
839
|
+
throw new UsageError(`--upstream must be an http(s) URL, got '${values.upstream}'`);
|
|
840
|
+
}
|
|
596
841
|
}
|
|
842
|
+
const jit = parseJitSpecs(values.jit);
|
|
843
|
+
const vaultConnections = parseVaultSpecs(values.vault);
|
|
597
844
|
const auth = makeAuth(values);
|
|
598
845
|
const config = await auth.ready();
|
|
599
846
|
let toolPolicy = auth.hasToolPolicy && !values["no-tool-policy"];
|
|
@@ -610,6 +857,35 @@ async function secure(args, command) {
|
|
|
610
857
|
const port = Number(values.port ?? process.env.PORT ?? 8080);
|
|
611
858
|
const host = values.host ?? "0.0.0.0";
|
|
612
859
|
if (!Number.isInteger(port) || port < 0 || port > 65535) throw new UsageError(`--port must be a port number, got '${values.port}'`);
|
|
860
|
+
if (isExtAuthz) {
|
|
861
|
+
const extServer = createExtAuthzServer({
|
|
862
|
+
auth,
|
|
863
|
+
toolPolicy,
|
|
864
|
+
identityHeaders: !values["no-identity-headers"],
|
|
865
|
+
publicPaths: values.public ?? ["/healthz", "/readyz"],
|
|
866
|
+
jit,
|
|
867
|
+
vaultConnections,
|
|
868
|
+
log
|
|
869
|
+
});
|
|
870
|
+
await new Promise((resolve, reject) => {
|
|
871
|
+
extServer.once("error", reject);
|
|
872
|
+
extServer.listen(port, host, resolve);
|
|
873
|
+
});
|
|
874
|
+
const addr = extServer.address();
|
|
875
|
+
const listening2 = typeof addr === "object" && addr ? `${host}:${addr.port}` : `${host}:${port}`;
|
|
876
|
+
log(`lumoauth: Envoy ext_authz server listening on http://${listening2}`);
|
|
877
|
+
log(` resource ${config.resource}${config.requireDpop ? " (DPoP required)" : ""}`);
|
|
878
|
+
log(` issuer ${config.issuer}`);
|
|
879
|
+
log(` tool policy ${toolPolicy ? `on (server ${config.serverId})` : "off"}`);
|
|
880
|
+
const stopExt = () => {
|
|
881
|
+
log("lumoauth: stopping ext-authz");
|
|
882
|
+
extServer.close();
|
|
883
|
+
setTimeout(() => process.exit(0), 200).unref();
|
|
884
|
+
};
|
|
885
|
+
process.once("SIGINT", stopExt);
|
|
886
|
+
process.once("SIGTERM", stopExt);
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
613
889
|
let child;
|
|
614
890
|
if (values.upstream && command.length > 0) {
|
|
615
891
|
child = startUpstream(command);
|
|
@@ -632,6 +908,8 @@ async function secure(args, command) {
|
|
|
632
908
|
toolPolicy,
|
|
633
909
|
identityHeaders: !values["no-identity-headers"],
|
|
634
910
|
publicPaths: values.public ?? [],
|
|
911
|
+
jit,
|
|
912
|
+
vaultConnections,
|
|
635
913
|
log
|
|
636
914
|
});
|
|
637
915
|
await new Promise((resolve, reject) => {
|
|
@@ -710,7 +988,9 @@ async function main(argv) {
|
|
|
710
988
|
const [name, ...args] = own;
|
|
711
989
|
switch (name) {
|
|
712
990
|
case "secure":
|
|
713
|
-
return secure(args, command);
|
|
991
|
+
return secure(args, command, false);
|
|
992
|
+
case "ext-authz":
|
|
993
|
+
return secure(args, command, true);
|
|
714
994
|
case "check":
|
|
715
995
|
return check(args);
|
|
716
996
|
case "-v":
|
|
@@ -732,11 +1012,13 @@ async function main(argv) {
|
|
|
732
1012
|
0 && (module.exports = {
|
|
733
1013
|
StdioBridge,
|
|
734
1014
|
allowedToolNames,
|
|
1015
|
+
createExtAuthzServer,
|
|
735
1016
|
createSecureProxy,
|
|
736
1017
|
filterJsonBody,
|
|
737
1018
|
filterSseEvent,
|
|
738
1019
|
inspect,
|
|
739
1020
|
main,
|
|
1021
|
+
refusedJitToolResult,
|
|
740
1022
|
refusedToolResult,
|
|
741
1023
|
startUpstream,
|
|
742
1024
|
waitForUpstream
|