lumoauth 1.3.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -13
- package/dist/cli.js +134 -60
- package/dist/cli.js.map +1 -1
- package/dist/index.d.mts +14 -18
- package/dist/index.d.ts +14 -18
- package/dist/index.js +131 -55
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +116 -41
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -92,14 +92,24 @@ Calls without a token no longer reach your server. The `401` tells MCP clients w
|
|
|
92
92
|
|
|
93
93
|
### 4. Sign in from a client
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
Claude Code identifies itself with its [Client ID Metadata Document](https://docs.lumoauth.dev/mcp/client-id-metadata-documents), so you register nothing for it:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
claude mcp add --transport http invoices http://localhost:8080/mcp
|
|
99
|
+
|
|
100
|
+
claude mcp login invoices
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
LumoAuth reads Claude Code's metadata document when you sign in. This works while **Client ID metadata documents (CIMD)** is on for your organization, which is the default (**Security → Sign-in settings → Platform security**).
|
|
104
|
+
|
|
105
|
+
A client without a metadata document needs an application, and so does every client when your organization has CIMD off:
|
|
96
106
|
|
|
97
107
|
1. Open **Applications**, click **New application** and choose **Single-page or mobile app**.
|
|
98
108
|
2. Set **Application name** to `Local MCP client` and **Redirect URI** to `http://localhost:8765/callback`.
|
|
99
109
|
3. Click **Create application** and copy the **Client ID**.
|
|
100
110
|
4. On the **Configuration** tab, set **Scopes** to `openid profile email offline_access mcp:read`. Click **Save configuration**.
|
|
101
111
|
|
|
102
|
-
Then
|
|
112
|
+
Then give the client that client ID. For Claude Code:
|
|
103
113
|
|
|
104
114
|
```bash
|
|
105
115
|
claude mcp add --transport http \
|
|
@@ -116,7 +126,7 @@ Your browser opens on the LumoAuth sign-in page. After you sign in and approve,
|
|
|
116
126
|
invoices: http://localhost:8080/mcp (HTTP) - ✔ Connected
|
|
117
127
|
```
|
|
118
128
|
|
|
119
|
-
Other MCP clients connect the same way
|
|
129
|
+
Other MCP clients connect the same way: with a metadata document, or with a client ID and a callback port. [Troubleshooting](#troubleshooting) explains the errors that you may see.
|
|
120
130
|
|
|
121
131
|
### Before you go to production
|
|
122
132
|
|
|
@@ -182,14 +192,16 @@ npx lumoauth secure \
|
|
|
182
192
|
--jit delete_user=user_management:delete,purge
|
|
183
193
|
```
|
|
184
194
|
|
|
185
|
-
|
|
195
|
+
The client sends the approval in the `X-LumoAuth-Jit-Token` header, next to its normal token: the JIT token that LumoAuth issued for its approved request (`POST /jit/request/{id}/token`). `lumoauth` checks it as [`@lumoauth/mcp`](https://www.npmjs.com/package/@lumoauth/mcp#how-clients-send-a-jit-token) does (signature of your organization, `typ: JWT`, `aud` = the organization, not expired, issued to this caller) and never passes it to your server.
|
|
186
196
|
|
|
187
197
|
## Injecting third-party API tokens from Token Vault (`--vault`)
|
|
188
198
|
|
|
189
199
|
**Why it is useful:** If your upstream MCP server calls GitHub, Slack, Jira, or Google Workspace, you do not need to hardcode shared API keys or modify the server to integrate with LumoAuth's SDK. With `--vault <slug>=<connection_id>`, `lumoauth` fetches a short-lived access token from LumoAuth's Token Vault for the verified caller (automatically passing `user_id` when the caller is a person or an agent acting for a person) and injects it into the upstream request as `X-LumoAuth-Vault-<Slug>-Token`:
|
|
190
200
|
|
|
191
201
|
```bash
|
|
192
|
-
|
|
202
|
+
# The agent that lumoauth acts as: LumoAuth gives vault tokens to agents only.
|
|
203
|
+
export AGENT_CLIENT_ID=agt_0123456789abcdef
|
|
204
|
+
export AGENT_CLIENT_SECRET=...
|
|
193
205
|
|
|
194
206
|
npx lumoauth secure \
|
|
195
207
|
--upstream http://127.0.0.1:8000/mcp \
|
|
@@ -197,7 +209,9 @@ npx lumoauth secure \
|
|
|
197
209
|
--vault slack=conn_slack_workspace
|
|
198
210
|
```
|
|
199
211
|
|
|
200
|
-
|
|
212
|
+
`lumoauth` asks for the agent's token and renews it before it expires. `LUMOAUTH_AGENT_TOKEN` works too, for a fixed credential such as the agent's `agk_` API key. The server's own client (`LUMOAUTH_MCP_CLIENT_ID`) is for the per-tool policy and cannot fetch vault tokens. How to set up the agent: see [Token Vault in `@lumoauth/mcp`](https://www.npmjs.com/package/@lumoauth/mcp#fetching-a-token-with-authvaulttoken).
|
|
213
|
+
|
|
214
|
+
Your upstream server simply reads the `X-LumoAuth-Vault-Github-Token` and `X-LumoAuth-Vault-Slack-Token` headers. Any client-supplied `X-LumoAuth-*` headers are always stripped first. In `ext-authz` mode, Envoy strips them: see [Envoy `ext_authz` mode](#envoy-ext_authz-mode).
|
|
201
215
|
|
|
202
216
|
## Distributed tracing (`traceparent`)
|
|
203
217
|
|
|
@@ -223,14 +237,27 @@ For each incoming request forwarded by Envoy (`envoy.filters.http.ext_authz`):
|
|
|
223
237
|
- Inspects buffered JSON-RPC `tools/call` bodies (`with_request_body` in Envoy) to enforce LumoAuth's per-tool policy and `--jit` step-up requirements before the request reaches the upstream pod.
|
|
224
238
|
- Returns `200 OK` with `X-LumoAuth-*`, `X-LumoAuth-Vault-*-Token`, and `traceparent` headers for Envoy to inject into the upstream request.
|
|
225
239
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
-
|
|
229
|
-
-
|
|
240
|
+
**Only the check service sets `X-LumoAuth-*` headers.** Envoy replaces the headers that the answer sets, but it passes on every other header that the client sent. So each `200 OK` also lists, in `x-envoy-auth-headers-to-remove`, every `X-LumoAuth-*` header that it does not set: the identity headers that do not apply to the caller, `X-LumoAuth-Jit-Token`, and any other `X-LumoAuth-*` header of the request. Envoy removes them before the upstream. For this to work, your Envoy configuration must:
|
|
241
|
+
|
|
242
|
+
- pass the client's `x-lumoauth-*` headers to the check service (`allowed_headers` with the prefix `x-lumoauth-`);
|
|
243
|
+
- let the answer set them on the upstream request (`allowed_upstream_headers` with the same prefix).
|
|
244
|
+
|
|
245
|
+
The shipped configuration does both. It also removes the identity headers of the client before the check, with a `header_mutation` filter, and it never lets `ext_authz` fail open.
|
|
246
|
+
|
|
247
|
+
**DPoP behind Envoy.** Envoy's check request carries the client's method and path. A DPoP proof must name the URL that the client called (`htu`), and the check service builds that URL from the Resource URI's origin and the request path. This is right when clients reach Envoy at the Resource URI and nothing in front of Envoy changes the path. When a load balancer in front removes a prefix (clients call `https://gw.example.com/invoices/mcp`, Envoy sees `/mcp`), start the check service with `--public-url https://gw.example.com/invoices`. The load balancer must also send the metadata path, `/.well-known/oauth-protected-resource/invoices/mcp`, to Envoy unchanged. Do not set `path_prefix` on Envoy's `http_service`: the check service would see that prefix in the path. The check service reads the path from the check request only, never from headers such as `x-forwarded-uri` or `x-envoy-original-path`.
|
|
248
|
+
|
|
249
|
+
Deployment files are included in the repository:
|
|
250
|
+
- [`Dockerfile`](../../Dockerfile) — multi-stage non-root (`65532:65532`) container image with a `/healthz` health check. **There is no published image.** Build it from the repository and push it to your own registry: `docker build -t registry.example.com/lumoauth-mcp:1.4.0 .`. The image's command is `lumoauth`, so `docker run <image> ext-authz --port 9001` starts the check service.
|
|
251
|
+
- [`deploy/kubernetes-sidecar.yaml`](../../deploy/kubernetes-sidecar.yaml) — Kubernetes Deployment running `lumoauth` as a sidecar in front of a loopback MCP container. Set its `image:` to the image that you built, and its upstream image to your MCP server.
|
|
252
|
+
- [`deploy/envoy-ext-authz.yaml`](../../deploy/envoy-ext-authz.yaml) — Envoy configuration (tested with Envoy 1.34) with `with_request_body` JSON-RPC inspection, upstream identity headers, and the removal of client `x-lumoauth-*` headers.
|
|
253
|
+
|
|
254
|
+
Without an image of your own, the sidecar container can also be `node:22-alpine` running `npx --yes lumoauth@1.4.0 secure …`. It then downloads the package each time the pod starts, so it needs access to the npm registry and a writable `HOME`.
|
|
230
255
|
|
|
231
256
|
## Check the setup
|
|
232
257
|
|
|
233
|
-
`npx lumoauth check` prints what the registration says, the discovery document and the `401` challenge. It also prints what the authorization server
|
|
258
|
+
`npx lumoauth check` prints what the registration says, the discovery document and the `401` challenge. It also prints what the authorization server offers: PKCE, client metadata documents and dynamic registration.
|
|
259
|
+
|
|
260
|
+
LumoAuth names its registration endpoint in every discovery document, so the check asks the endpoint itself. It sends an empty request without a credential, which LumoAuth refuses before it creates anything. The line then says `yes` when any client may register, `no` when the organization has dynamic registration switched off or asks for an initial access token, and `unknown` for any other answer. The refused request can appear in the organization's audit log.
|
|
234
261
|
|
|
235
262
|
```console
|
|
236
263
|
$ npx lumoauth check
|
|
@@ -257,10 +284,11 @@ Run `npx lumoauth --help` for all of them. The common ones:
|
|
|
257
284
|
| `--ext-authz` | | Run as an Envoy HTTP `ext_authz` check server |
|
|
258
285
|
| `--port`, `--host` | `PORT` | Where to listen (default `0.0.0.0:8080`) |
|
|
259
286
|
| `--path` | | Public path of the MCP endpoint (default: the Resource URI's path) |
|
|
287
|
+
| `--public-url` | | Public URL of the service's root, for the DPoP check, when a proxy in front removes a path prefix (default: the Resource URI's origin) |
|
|
260
288
|
| `--scope` | | A scope that every request needs (repeatable) |
|
|
261
289
|
| `--public` | | A path that needs no token, such as `/health` (repeatable) |
|
|
262
290
|
| `--jit` | | Require a JIT/RAR grant for a tool, e.g. `refund=payment:refund` (repeatable) |
|
|
263
|
-
| `--vault` | `LUMOAUTH_AGENT_TOKEN` | Inject `X-LumoAuth-Vault-<Slug>-Token` from Token Vault, e.g. `github=conn_123` (repeatable) |
|
|
291
|
+
| `--vault` | `AGENT_CLIENT_ID` + `AGENT_CLIENT_SECRET`, or `LUMOAUTH_AGENT_TOKEN` | Inject `X-LumoAuth-Vault-<Slug>-Token` from Token Vault, e.g. `github=conn_123` (repeatable) |
|
|
264
292
|
|
|
265
293
|
## Troubleshooting
|
|
266
294
|
|
|
@@ -271,7 +299,7 @@ Run `npx lumoauth --help` for all of them. The common ones:
|
|
|
271
299
|
| `Protected resource … does not match expected …` | The client connects to a URL that differs from the Resource URI. `localhost` and `127.0.0.1` count as different. | Use the Resource URI exactly. |
|
|
272
300
|
| `invalid_dpop_proof` or `DPoP proof required` | **Require DPoP** is on and the client sends no proof. | Switch it off, then restart `lumoauth`. |
|
|
273
301
|
| `invalid_scope` … `not allowed for this client` | The application does not allow a scope that the client asks for. | Add the scope to the application's **Scopes**. Many clients add `offline_access` on their own. |
|
|
274
|
-
| `Invalid Redirect URL` on a LumoAuth page | The client's redirect URI is not registered.
|
|
302
|
+
| `Invalid Redirect URL` on a LumoAuth page | The client's redirect URI is not registered. A changing port is accepted on `127.0.0.1` and `[::1]`, and on `http://localhost` for a public application (**Single-page or mobile app**, or a metadata-document client such as Claude Code). The host and path must be the registered ones: `localhost` and `127.0.0.1` count as different. A confidential application needs the exact port on `localhost`. | Register the URI that the client uses (for example `http://localhost/callback`) on a public application, or give the client a fixed callback port. |
|
|
275
303
|
| `Dynamic client registration is not enabled` | The client tried to register itself, which is off by default. | Give the client a client ID, as in [step 4](#4-sign-in-from-a-client). |
|
|
276
304
|
| The list of tools is empty | The per-tool policy is on and the caller has no grant. | See [Per-tool policy](#per-tool-policy). |
|
|
277
305
|
| A registration change has no effect | `lumoauth` reads the registration at start-up. | Restart `lumoauth`. |
|
package/dist/cli.js
CHANGED
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
|
|
4
4
|
// src/cli.ts
|
|
5
5
|
var import_node_util = require("util");
|
|
6
|
-
var
|
|
6
|
+
var import_mcp4 = require("@lumoauth/mcp");
|
|
7
7
|
|
|
8
8
|
// src/ext-authz.ts
|
|
9
9
|
var import_node_http = require("http");
|
|
10
|
-
var
|
|
10
|
+
var import_mcp2 = require("@lumoauth/mcp");
|
|
11
11
|
|
|
12
12
|
// src/jsonrpc.ts
|
|
13
|
+
var import_mcp = require("@lumoauth/mcp");
|
|
13
14
|
function asId(value) {
|
|
14
15
|
return typeof value === "string" || typeof value === "number" ? value : null;
|
|
15
16
|
}
|
|
@@ -41,23 +42,20 @@ function inspect(body) {
|
|
|
41
42
|
function refusedToolResult(id, message) {
|
|
42
43
|
return { jsonrpc: "2.0", id, result: { content: [{ type: "text", text: message }], isError: true } };
|
|
43
44
|
}
|
|
44
|
-
function refusedJitToolResult(id, tool, requiredDetails) {
|
|
45
|
-
const
|
|
46
|
-
const headerValue = Buffer.from(hintJson, "utf8").toString("base64");
|
|
47
|
-
const types = requiredDetails.map((d) => d.type).join(", ");
|
|
48
|
-
const message = `Tool '${tool}' requires JIT authorization_details (${types}); authorization_details_hint=${hintJson}`;
|
|
45
|
+
function refusedJitToolResult(id, tool, requiredDetails, jitTokenError) {
|
|
46
|
+
const refusal = new import_mcp.InsufficientAuthorizationDetailsError(tool, requiredDetails, void 0, jitTokenError);
|
|
49
47
|
return {
|
|
50
|
-
headerValue,
|
|
48
|
+
headerValue: refusal.headerValue,
|
|
51
49
|
body: {
|
|
52
50
|
jsonrpc: "2.0",
|
|
53
51
|
id,
|
|
54
52
|
result: {
|
|
55
|
-
content: [{ type: "text", text: message }],
|
|
53
|
+
content: [{ type: "text", text: refusal.message }],
|
|
56
54
|
isError: true,
|
|
57
55
|
_meta: {
|
|
58
56
|
error: "insufficient_authorization_details",
|
|
59
|
-
authorization_details_hint:
|
|
60
|
-
"Insufficient-Authorization-Details": headerValue
|
|
57
|
+
authorization_details_hint: refusal.hint,
|
|
58
|
+
"Insufficient-Authorization-Details": refusal.headerValue
|
|
61
59
|
}
|
|
62
60
|
}
|
|
63
61
|
}
|
|
@@ -99,10 +97,19 @@ async function filterSseEvent(event, ids, decide) {
|
|
|
99
97
|
}
|
|
100
98
|
|
|
101
99
|
// src/ext-authz.ts
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
100
|
+
var IDENTITY_HEADERS = [
|
|
101
|
+
"x-lumoauth-subject",
|
|
102
|
+
"x-lumoauth-subject-type",
|
|
103
|
+
"x-lumoauth-agent-id",
|
|
104
|
+
"x-lumoauth-actor",
|
|
105
|
+
"x-lumoauth-client-id",
|
|
106
|
+
"x-lumoauth-scopes",
|
|
107
|
+
"x-lumoauth-trace-id",
|
|
108
|
+
"x-lumoauth-is-jit"
|
|
109
|
+
];
|
|
110
|
+
var IDENTITY_PREFIX = "x-lumoauth-";
|
|
111
|
+
var JIT_TOKEN_HEADER = "x-lumoauth-jit-token";
|
|
112
|
+
var ENVOY_HEADERS_TO_REMOVE = "x-envoy-auth-headers-to-remove";
|
|
106
113
|
async function readBody(req, limit) {
|
|
107
114
|
const chunks = [];
|
|
108
115
|
let size = 0;
|
|
@@ -121,23 +128,45 @@ function writeJson(res, status, body, headers = {}) {
|
|
|
121
128
|
res.setHeader("Content-Length", Buffer.byteLength(text));
|
|
122
129
|
res.end(text);
|
|
123
130
|
}
|
|
131
|
+
function vaultHeaderName(slug) {
|
|
132
|
+
const cleanSlug = slug.trim().toLowerCase().replace(/[^a-z0-9-]/g, "-");
|
|
133
|
+
return cleanSlug ? `x-lumoauth-vault-${cleanSlug}-token` : void 0;
|
|
134
|
+
}
|
|
124
135
|
function createExtAuthzServer(options) {
|
|
125
136
|
const { auth } = options;
|
|
126
137
|
const log2 = options.log ?? ((line) => console.error(line));
|
|
127
138
|
const identityHeaders = options.identityHeaders ?? true;
|
|
128
139
|
const publicPaths = options.publicPaths ?? ["/healthz", "/readyz"];
|
|
129
140
|
const maxBody = options.maxBodyBytes ?? 1024 * 1024;
|
|
141
|
+
const vaultHeaders = Object.keys(options.vaultConnections ?? {}).map(vaultHeaderName).filter((name) => Boolean(name));
|
|
142
|
+
function allow(req, res, headers, body) {
|
|
143
|
+
const remove = /* @__PURE__ */ new Set([...IDENTITY_HEADERS, JIT_TOKEN_HEADER, ...vaultHeaders]);
|
|
144
|
+
for (const name of Object.keys(req.headers)) {
|
|
145
|
+
const lower = name.toLowerCase();
|
|
146
|
+
if (lower.startsWith(IDENTITY_PREFIX)) remove.add(lower);
|
|
147
|
+
}
|
|
148
|
+
res.statusCode = 200;
|
|
149
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
150
|
+
res.setHeader(name, value);
|
|
151
|
+
remove.delete(name.toLowerCase());
|
|
152
|
+
}
|
|
153
|
+
res.setHeader(ENVOY_HEADERS_TO_REMOVE, [...remove].join(","));
|
|
154
|
+
res.end(body);
|
|
155
|
+
}
|
|
130
156
|
async function handle(req, res) {
|
|
131
|
-
const method =
|
|
132
|
-
const rawPath =
|
|
157
|
+
const method = req.method ?? "GET";
|
|
158
|
+
const rawPath = req.url ?? "/";
|
|
133
159
|
const url = new URL(rawPath, "http://ext-authz.invalid");
|
|
134
160
|
if (publicPaths.includes(url.pathname)) {
|
|
135
|
-
res
|
|
136
|
-
res.end();
|
|
161
|
+
allow(req, res, {});
|
|
137
162
|
return;
|
|
138
163
|
}
|
|
139
164
|
const discovery = await auth.discoveryResponse(method, url.pathname);
|
|
140
165
|
if (discovery) {
|
|
166
|
+
if (discovery.status === 200) {
|
|
167
|
+
allow(req, res, discovery.headers, discovery.body);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
141
170
|
res.statusCode = discovery.status;
|
|
142
171
|
for (const [k, v] of Object.entries(discovery.headers)) res.setHeader(k, v);
|
|
143
172
|
res.end(discovery.body);
|
|
@@ -147,8 +176,8 @@ function createExtAuthzServer(options) {
|
|
|
147
176
|
try {
|
|
148
177
|
info = await auth.authenticate({ method, url: rawPath, headers: req.headers });
|
|
149
178
|
} catch (error) {
|
|
150
|
-
if (error instanceof
|
|
151
|
-
(0,
|
|
179
|
+
if (error instanceof import_mcp2.LumoAuthChallenge) {
|
|
180
|
+
(0, import_mcp2.writeChallenge)(res, error);
|
|
152
181
|
return;
|
|
153
182
|
}
|
|
154
183
|
throw error;
|
|
@@ -158,7 +187,7 @@ function createExtAuthzServer(options) {
|
|
|
158
187
|
if (body && body.length > 0 && (options.toolPolicy || options.jit)) {
|
|
159
188
|
const inspection = inspect(body.toString("utf8"));
|
|
160
189
|
if (!caller.traceparent && inspection.traceparent) {
|
|
161
|
-
const parsedTp = (0,
|
|
190
|
+
const parsedTp = (0, import_mcp2.parseTraceparent)(inspection.traceparent);
|
|
162
191
|
if (parsedTp) {
|
|
163
192
|
caller.traceparent = parsedTp.traceparent;
|
|
164
193
|
caller.traceId ?? (caller.traceId = parsedTp.traceId);
|
|
@@ -182,10 +211,10 @@ function createExtAuthzServer(options) {
|
|
|
182
211
|
for (const call of inspection.toolCalls) {
|
|
183
212
|
const jitSpec = options.jit[call.name];
|
|
184
213
|
if (!jitSpec) continue;
|
|
185
|
-
const required = (0,
|
|
186
|
-
const missing = (0,
|
|
214
|
+
const required = (0, import_mcp2.normalizeAuthorizationDetails)(jitSpec);
|
|
215
|
+
const missing = (0, import_mcp2.missingAuthorizationDetails)(required, caller.authorizationDetails);
|
|
187
216
|
if (missing.length > 0) {
|
|
188
|
-
const jitRefusal = refusedJitToolResult(call.id, call.name, missing);
|
|
217
|
+
const jitRefusal = refusedJitToolResult(call.id, call.name, missing, caller.jitTokenError);
|
|
189
218
|
writeJson(res, 403, jitRefusal.body, {
|
|
190
219
|
"Insufficient-Authorization-Details": jitRefusal.headerValue,
|
|
191
220
|
"WWW-Authenticate": `Bearer error="insufficient_authorization_details", error_description="JIT step-up required for tool '${call.name}'"`
|
|
@@ -195,29 +224,29 @@ function createExtAuthzServer(options) {
|
|
|
195
224
|
}
|
|
196
225
|
}
|
|
197
226
|
}
|
|
198
|
-
|
|
227
|
+
const upstreamHeaders = {};
|
|
199
228
|
if (identityHeaders) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
if (caller.agentId)
|
|
203
|
-
if (caller.actor)
|
|
204
|
-
if (caller.clientId)
|
|
205
|
-
|
|
206
|
-
if (caller.traceId)
|
|
207
|
-
if (caller.isJit)
|
|
229
|
+
upstreamHeaders["x-lumoauth-subject"] = caller.sub;
|
|
230
|
+
upstreamHeaders["x-lumoauth-subject-type"] = caller.isAgent ? "agent" : "user";
|
|
231
|
+
if (caller.agentId) upstreamHeaders["x-lumoauth-agent-id"] = caller.agentId;
|
|
232
|
+
if (caller.actor) upstreamHeaders["x-lumoauth-actor"] = caller.actor;
|
|
233
|
+
if (caller.clientId) upstreamHeaders["x-lumoauth-client-id"] = caller.clientId;
|
|
234
|
+
upstreamHeaders["x-lumoauth-scopes"] = caller.scopes.join(" ");
|
|
235
|
+
if (caller.traceId) upstreamHeaders["x-lumoauth-trace-id"] = caller.traceId;
|
|
236
|
+
if (caller.isJit) upstreamHeaders["x-lumoauth-is-jit"] = "true";
|
|
208
237
|
}
|
|
209
238
|
if (caller.traceparent) {
|
|
210
|
-
|
|
239
|
+
upstreamHeaders.traceparent = caller.traceparent;
|
|
211
240
|
}
|
|
212
241
|
if (options.vaultConnections) {
|
|
213
242
|
for (const [slug, connectionId] of Object.entries(options.vaultConnections)) {
|
|
214
|
-
const
|
|
215
|
-
if (!
|
|
243
|
+
const name = vaultHeaderName(slug);
|
|
244
|
+
if (!name || !connectionId) continue;
|
|
216
245
|
const vaultToken = await auth.vaultToken(connectionId, caller);
|
|
217
|
-
|
|
246
|
+
upstreamHeaders[name] = vaultToken.accessToken;
|
|
218
247
|
}
|
|
219
248
|
}
|
|
220
|
-
res
|
|
249
|
+
allow(req, res, upstreamHeaders);
|
|
221
250
|
}
|
|
222
251
|
return (0, import_node_http.createServer)((req, res) => {
|
|
223
252
|
handle(req, res).catch((error) => {
|
|
@@ -232,11 +261,11 @@ function createExtAuthzServer(options) {
|
|
|
232
261
|
var import_node_http2 = require("http");
|
|
233
262
|
var import_node_stream = require("stream");
|
|
234
263
|
var import_promises = require("stream/promises");
|
|
235
|
-
var
|
|
264
|
+
var import_mcp3 = require("@lumoauth/mcp");
|
|
236
265
|
var HOP_BY_HOP = ["connection", "keep-alive", "proxy-authenticate", "proxy-authorization", "te", "trailer", "transfer-encoding", "upgrade"];
|
|
237
266
|
var REQUEST_DROP = /* @__PURE__ */ new Set([...HOP_BY_HOP, "host", "content-length", "authorization", "dpop", "accept-encoding"]);
|
|
238
267
|
var RESPONSE_DROP = /* @__PURE__ */ new Set([...HOP_BY_HOP, "content-length", "content-encoding", "set-cookie"]);
|
|
239
|
-
var
|
|
268
|
+
var IDENTITY_PREFIX2 = "x-lumoauth-";
|
|
240
269
|
var SessionOwners = class {
|
|
241
270
|
constructor() {
|
|
242
271
|
this.owners = /* @__PURE__ */ new Map();
|
|
@@ -264,7 +293,7 @@ var SessionOwners = class {
|
|
|
264
293
|
function principal(caller) {
|
|
265
294
|
return JSON.stringify([caller.issuer, caller.sub, caller.clientId ?? null]);
|
|
266
295
|
}
|
|
267
|
-
function
|
|
296
|
+
function headerOf(req, name) {
|
|
268
297
|
const value = req.headers[name];
|
|
269
298
|
return Array.isArray(value) ? value[0] : value;
|
|
270
299
|
}
|
|
@@ -336,13 +365,13 @@ function createSecureProxy(options) {
|
|
|
336
365
|
const headers = new Headers();
|
|
337
366
|
for (const [name, value] of Object.entries(req.headers)) {
|
|
338
367
|
const lower = name.toLowerCase();
|
|
339
|
-
if (value === void 0 || REQUEST_DROP.has(lower) || lower.startsWith(
|
|
368
|
+
if (value === void 0 || REQUEST_DROP.has(lower) || lower.startsWith(IDENTITY_PREFIX2)) continue;
|
|
340
369
|
for (const item of Array.isArray(value) ? value : [value]) headers.append(lower, item);
|
|
341
370
|
}
|
|
342
371
|
headers.set("accept-encoding", "identity");
|
|
343
372
|
if (req.headers.host) headers.set("x-forwarded-host", req.headers.host);
|
|
344
373
|
const remote = req.socket.remoteAddress;
|
|
345
|
-
if (remote) headers.set("x-forwarded-for", [
|
|
374
|
+
if (remote) headers.set("x-forwarded-for", [headerOf(req, "x-forwarded-for"), remote].filter(Boolean).join(", "));
|
|
346
375
|
if (caller && options.identityHeaders) {
|
|
347
376
|
headers.set("x-lumoauth-subject", caller.sub);
|
|
348
377
|
headers.set("x-lumoauth-subject-type", caller.isAgent ? "agent" : "user");
|
|
@@ -438,14 +467,14 @@ function createSecureProxy(options) {
|
|
|
438
467
|
try {
|
|
439
468
|
info = await auth.authenticate({ method, url: req.url ?? "/", headers: req.headers });
|
|
440
469
|
} catch (error) {
|
|
441
|
-
if (error instanceof
|
|
442
|
-
(0,
|
|
470
|
+
if (error instanceof import_mcp3.LumoAuthChallenge) {
|
|
471
|
+
(0, import_mcp3.writeChallenge)(res, error);
|
|
443
472
|
return;
|
|
444
473
|
}
|
|
445
474
|
throw error;
|
|
446
475
|
}
|
|
447
476
|
const caller = info.extra.caller;
|
|
448
|
-
const sessionId =
|
|
477
|
+
const sessionId = headerOf(req, "mcp-session-id");
|
|
449
478
|
if (!options.bridge && sessionId && !sessions.claim(sessionId, principal(caller))) {
|
|
450
479
|
writeJson2(res, 404, { jsonrpc: "2.0", id: null, error: { code: -32001, message: "Session not found" } });
|
|
451
480
|
return;
|
|
@@ -455,7 +484,7 @@ function createSecureProxy(options) {
|
|
|
455
484
|
if (body && (options.toolPolicy || options.jit)) {
|
|
456
485
|
inspection = inspect(body.toString("utf8"));
|
|
457
486
|
if (!caller.traceparent && inspection.traceparent) {
|
|
458
|
-
const parsedTp = (0,
|
|
487
|
+
const parsedTp = (0, import_mcp3.parseTraceparent)(inspection.traceparent);
|
|
459
488
|
if (parsedTp) {
|
|
460
489
|
caller.traceparent = parsedTp.traceparent;
|
|
461
490
|
caller.traceId ?? (caller.traceId = parsedTp.traceId);
|
|
@@ -481,15 +510,17 @@ function createSecureProxy(options) {
|
|
|
481
510
|
for (const call of inspection.toolCalls) {
|
|
482
511
|
const jitSpec = options.jit[call.name];
|
|
483
512
|
if (!jitSpec) continue;
|
|
484
|
-
const required = (0,
|
|
485
|
-
const missing = (0,
|
|
513
|
+
const required = (0, import_mcp3.normalizeAuthorizationDetails)(jitSpec);
|
|
514
|
+
const missing = (0, import_mcp3.missingAuthorizationDetails)(required, caller.authorizationDetails);
|
|
486
515
|
if (missing.length > 0) {
|
|
487
|
-
const jitRefusal = refusedJitToolResult(call.id, call.name, missing);
|
|
516
|
+
const jitRefusal = refusedJitToolResult(call.id, call.name, missing, caller.jitTokenError);
|
|
488
517
|
res.setHeader("Insufficient-Authorization-Details", jitRefusal.headerValue);
|
|
489
518
|
writeJson2(
|
|
490
519
|
res,
|
|
491
520
|
200,
|
|
492
|
-
inspection.isBatch ? inspection.toolCalls.map(
|
|
521
|
+
inspection.isBatch ? inspection.toolCalls.map(
|
|
522
|
+
(c) => refusedJitToolResult(c.id, call.name, missing, caller.jitTokenError).body
|
|
523
|
+
) : jitRefusal.body
|
|
493
524
|
);
|
|
494
525
|
return;
|
|
495
526
|
}
|
|
@@ -680,7 +711,7 @@ async function waitForUpstream(url, child, timeoutMs = 3e4) {
|
|
|
680
711
|
}
|
|
681
712
|
|
|
682
713
|
// src/cli.ts
|
|
683
|
-
var VERSION = "1.
|
|
714
|
+
var VERSION = "1.5.0";
|
|
684
715
|
var HELP = `lumoauth: put LumoAuth in front of an MCP server
|
|
685
716
|
|
|
686
717
|
Usage:
|
|
@@ -711,10 +742,16 @@ Options:
|
|
|
711
742
|
--port <n> Port to listen on (PORT, default 8080)
|
|
712
743
|
--host <address> Address to listen on (default 0.0.0.0)
|
|
713
744
|
--path <path> Public path of the MCP endpoint (default: the Resource URI's path, or /mcp)
|
|
745
|
+
--public-url <url> Public URL of this service's root, for the DPoP check: a proof
|
|
746
|
+
must name this URL plus the request path (default: the
|
|
747
|
+
Resource URI's origin). Set it when a proxy in front
|
|
748
|
+
removes a path prefix, e.g. https://gw.example.com/invoices
|
|
714
749
|
--scope <scope> A scope every request needs; repeat for more
|
|
715
750
|
--public <path> Forward this path without a token (health checks); repeatable
|
|
716
751
|
--jit <tool=type[:a]> Require a JIT/RAR grant for a tool (e.g. refund=payment:refund); repeatable
|
|
717
|
-
--vault <slug=conn> Inject X-LumoAuth-Vault-<Slug>-Token from Token Vault; repeatable
|
|
752
|
+
--vault <slug=conn> Inject X-LumoAuth-Vault-<Slug>-Token from Token Vault; repeatable.
|
|
753
|
+
Needs an agent: AGENT_CLIENT_ID and AGENT_CLIENT_SECRET,
|
|
754
|
+
or LUMOAUTH_AGENT_TOKEN
|
|
718
755
|
--tool-policy Require LumoAuth's per-tool policy (LUMOAUTH_MCP_CLIENT_ID and _SECRET)
|
|
719
756
|
--no-tool-policy Do not ask LumoAuth about tools
|
|
720
757
|
--no-identity-headers Do not send X-LumoAuth-* identity headers upstream
|
|
@@ -731,16 +768,33 @@ var LUMOAUTH_OPTIONS = {
|
|
|
731
768
|
};
|
|
732
769
|
var UsageError = class extends Error {
|
|
733
770
|
};
|
|
734
|
-
function makeAuth(values) {
|
|
735
|
-
return (0,
|
|
771
|
+
function makeAuth(values, publicUrl) {
|
|
772
|
+
return (0, import_mcp4.lumoAuth)({
|
|
736
773
|
orgId: values.org,
|
|
737
774
|
serverId: values.server,
|
|
738
775
|
resource: values.resource,
|
|
739
776
|
lumoauthUrl: values["lumoauth-url"],
|
|
740
777
|
issuer: values.issuer,
|
|
741
|
-
requiredScopes: values.scope
|
|
778
|
+
requiredScopes: values.scope,
|
|
779
|
+
requestUrl: publicUrl ? publicRequestUrl(publicUrl) : void 0
|
|
742
780
|
});
|
|
743
781
|
}
|
|
782
|
+
function publicRequestUrl(publicUrl) {
|
|
783
|
+
let base;
|
|
784
|
+
try {
|
|
785
|
+
base = new URL(publicUrl);
|
|
786
|
+
} catch {
|
|
787
|
+
throw new UsageError(`--public-url must be an absolute URL, got '${publicUrl}'`);
|
|
788
|
+
}
|
|
789
|
+
if (base.protocol !== "https:" && base.protocol !== "http:" || base.search || base.hash) {
|
|
790
|
+
throw new UsageError(`--public-url must be an http(s) URL without a query, got '${publicUrl}'`);
|
|
791
|
+
}
|
|
792
|
+
const root = `${base.origin}${base.pathname.replace(/\/+$/, "")}`;
|
|
793
|
+
return (request) => {
|
|
794
|
+
const path = /^https?:\/\//i.test(request.url) ? new URL(request.url).pathname : request.url.split("?")[0];
|
|
795
|
+
return `${root}${path.startsWith("/") ? path : `/${path}`}`;
|
|
796
|
+
};
|
|
797
|
+
}
|
|
744
798
|
var log = (line) => console.error(line);
|
|
745
799
|
function parseJitSpecs(specs) {
|
|
746
800
|
if (!specs || specs.length === 0) return void 0;
|
|
@@ -791,7 +845,8 @@ async function secure(args, command, forceExtAuthz = false) {
|
|
|
791
845
|
vault: { type: "string", multiple: true },
|
|
792
846
|
"tool-policy": { type: "boolean" },
|
|
793
847
|
"no-tool-policy": { type: "boolean" },
|
|
794
|
-
"no-identity-headers": { type: "boolean" }
|
|
848
|
+
"no-identity-headers": { type: "boolean" },
|
|
849
|
+
"public-url": { type: "string" }
|
|
795
850
|
}
|
|
796
851
|
});
|
|
797
852
|
const isExtAuthz = forceExtAuthz || Boolean(values["ext-authz"]);
|
|
@@ -809,7 +864,7 @@ async function secure(args, command, forceExtAuthz = false) {
|
|
|
809
864
|
}
|
|
810
865
|
const jit = parseJitSpecs(values.jit);
|
|
811
866
|
const vaultConnections = parseVaultSpecs(values.vault);
|
|
812
|
-
const auth = makeAuth(values);
|
|
867
|
+
const auth = makeAuth(values, values["public-url"]);
|
|
813
868
|
const config = await auth.ready();
|
|
814
869
|
let toolPolicy = auth.hasToolPolicy && !values["no-tool-policy"];
|
|
815
870
|
if (values["tool-policy"]) {
|
|
@@ -906,6 +961,25 @@ async function secure(args, command, forceExtAuthz = false) {
|
|
|
906
961
|
process.once("SIGINT", stop);
|
|
907
962
|
process.once("SIGTERM", stop);
|
|
908
963
|
}
|
|
964
|
+
async function dynamicRegistration(endpoint) {
|
|
965
|
+
if (typeof endpoint !== "string") return "no";
|
|
966
|
+
let status;
|
|
967
|
+
try {
|
|
968
|
+
const response = await fetch(endpoint, {
|
|
969
|
+
method: "POST",
|
|
970
|
+
headers: { "Content-Type": "application/json", Accept: "application/json" },
|
|
971
|
+
body: "{}"
|
|
972
|
+
});
|
|
973
|
+
status = response.status;
|
|
974
|
+
await response.body?.cancel();
|
|
975
|
+
} catch (error) {
|
|
976
|
+
return `unknown (${endpoint}: ${error.message})`;
|
|
977
|
+
}
|
|
978
|
+
if (status === 400) return "yes";
|
|
979
|
+
if (status === 401) return "no: registration needs an initial access token, so MCP clients cannot register by themselves";
|
|
980
|
+
if (status === 403) return "no: not enabled for this organization (clients need a client metadata document or a registered client ID)";
|
|
981
|
+
return `unknown (HTTP ${status} from ${endpoint})`;
|
|
982
|
+
}
|
|
909
983
|
async function check(args) {
|
|
910
984
|
const { values } = (0, import_node_util.parseArgs)({ args, strict: true, options: LUMOAUTH_OPTIONS });
|
|
911
985
|
const auth = makeAuth(values);
|
|
@@ -934,7 +1008,7 @@ async function check(args) {
|
|
|
934
1008
|
out(` issuer matches ${metadata.issuer === config.issuer ? "yes" : `NO (${String(metadata.issuer)})`}`);
|
|
935
1009
|
out(` PKCE S256 ${pkce ? "yes" : "NO: MCP clients refuse authorization servers without it"}`);
|
|
936
1010
|
out(` client metadata docs ${metadata.client_id_metadata_document_supported === true ? "yes" : "no"}`);
|
|
937
|
-
out(` dynamic registration ${
|
|
1011
|
+
out(` dynamic registration ${await dynamicRegistration(metadata.registration_endpoint)}`);
|
|
938
1012
|
} catch (error) {
|
|
939
1013
|
out(`Authorization server: cannot read ${discoveryUrl}: ${error.message}`);
|
|
940
1014
|
process.exitCode = 1;
|