Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9486518832 | ||
|
|
b35a465303 | ||
|
|
54c29d182d | ||
|
|
1728752ce1 |
@@ -335,6 +335,13 @@ reliable pattern:
|
|||||||
> curl -s https://auth.example.com/application/o/shared-memory-mcp/.well-known/openid-configuration | jq .issuer
|
> curl -s https://auth.example.com/application/o/shared-memory-mcp/.well-known/openid-configuration | jq .issuer
|
||||||
> ```
|
> ```
|
||||||
>
|
>
|
||||||
|
> **Identity note:** the app verifies MCP tokens against `OIDC_ISSUER_MCP` but
|
||||||
|
> keys the user record on `OIDC_ISSUER`. Authentik's `sub` is `user.uid`, which
|
||||||
|
> is stable across providers, so the same person resolves to the same row
|
||||||
|
> whether they arrive via the Web UI or the MCP endpoint. Without that
|
||||||
|
> normalization the MCP path silently creates a second, empty account instead
|
||||||
|
> of failing visibly.
|
||||||
|
>
|
||||||
> Note also that Claude Code sends an RFC 8707 `resource` parameter on the
|
> Note also that Claude Code sends an RFC 8707 `resource` parameter on the
|
||||||
> authorize request; Authentik 2026.5 ignores it, so it cannot be relied on
|
> authorize request; Authentik 2026.5 ignores it, so it cannot be relied on
|
||||||
> for audience binding. The scope mapping is what sets `aud`.
|
> for audience binding. The scope mapping is what sets `aud`.
|
||||||
|
|||||||
@@ -135,7 +135,24 @@ export async function authenticateBearer(authHeader: string | null): Promise<Aut
|
|||||||
buildWwwAuthenticate("invalid_token", "missing sub"),
|
buildWwwAuthenticate("invalid_token", "missing sub"),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return { ...payload, groups: extractGroupsClaim(payload) } as AuthenticatedClaims;
|
// Normalize the issuer for identity purposes.
|
||||||
|
//
|
||||||
|
// The token was just verified against mcpIssuer() — that check is done.
|
||||||
|
// But identity is keyed on (oidc_iss, oidc_sub), and the Web UI signs
|
||||||
|
// people in through a DIFFERENT application whose tokens carry
|
||||||
|
// OIDC_ISSUER. Authentik's `sub` is stable across providers (it is
|
||||||
|
// `user.uid`, a user-level value), so the only thing that differs is the
|
||||||
|
// issuer.
|
||||||
|
//
|
||||||
|
// Leave it un-normalized and userContextFromClaims — which UPSERTS rather
|
||||||
|
// than failing — quietly creates a SECOND user row for the same human:
|
||||||
|
// MCP writes would land in an account with none of their memories, and
|
||||||
|
// nothing would look broken. Pin identity to the canonical issuer.
|
||||||
|
return {
|
||||||
|
...payload,
|
||||||
|
iss: env().OIDC_ISSUER,
|
||||||
|
groups: extractGroupsClaim(payload),
|
||||||
|
} as AuthenticatedClaims;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof UnauthorizedError) throw err;
|
if (err instanceof UnauthorizedError) throw err;
|
||||||
const desc =
|
const desc =
|
||||||
|
|||||||
+12
-2
@@ -4,6 +4,16 @@ const Bool = z
|
|||||||
.union([z.boolean(), z.enum(["true", "false", "1", "0"])])
|
.union([z.boolean(), z.enum(["true", "false", "1", "0"])])
|
||||||
.transform((v) => v === true || v === "true" || v === "1");
|
.transform((v) => v === true || v === "true" || v === "1");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Treat an empty string as "not set".
|
||||||
|
*
|
||||||
|
* docker-compose renders `${VAR:-}` as an empty string rather than omitting
|
||||||
|
* the key, so an unset optional var arrives as "" and would otherwise fail
|
||||||
|
* `.url()` / `.min(1)` validation and take the whole app down at boot.
|
||||||
|
*/
|
||||||
|
const optional = <T extends z.ZodTypeAny>(schema: T) =>
|
||||||
|
z.preprocess((v) => (v === "" ? undefined : v), schema.optional());
|
||||||
|
|
||||||
const envSchema = z.object({
|
const envSchema = z.object({
|
||||||
NODE_ENV: z.enum(["development", "test", "production"]).default("development"),
|
NODE_ENV: z.enum(["development", "test", "production"]).default("development"),
|
||||||
LOG_LEVEL: z.enum(["debug", "info", "warn", "error"]).default("info"),
|
LOG_LEVEL: z.enum(["debug", "info", "warn", "error"]).default("info"),
|
||||||
@@ -25,7 +35,7 @@ const envSchema = z.object({
|
|||||||
//
|
//
|
||||||
// Set this to the MCP application's issuer. Defaults to OIDC_ISSUER for
|
// Set this to the MCP application's issuer. Defaults to OIDC_ISSUER for
|
||||||
// single-application setups.
|
// single-application setups.
|
||||||
OIDC_ISSUER_MCP: z.string().url().optional(),
|
OIDC_ISSUER_MCP: optional(z.string().url()),
|
||||||
OIDC_CLIENT_ID_WEB: z.string().min(1),
|
OIDC_CLIENT_ID_WEB: z.string().min(1),
|
||||||
OIDC_CLIENT_SECRET_WEB: z.string().min(1),
|
OIDC_CLIENT_SECRET_WEB: z.string().min(1),
|
||||||
OIDC_CLIENT_ID_MCP: z.string().min(1),
|
OIDC_CLIENT_ID_MCP: z.string().min(1),
|
||||||
@@ -40,7 +50,7 @@ const envSchema = z.object({
|
|||||||
// every token arrives without an `aud` claim (-> 401 "claim invalid: aud").
|
// every token arrives without an `aud` claim (-> 401 "claim invalid: aud").
|
||||||
//
|
//
|
||||||
// Defaults to the `aud-<audience>` convention used in the README setup.
|
// Defaults to the `aud-<audience>` convention used in the README setup.
|
||||||
OIDC_AUDIENCE_SCOPE: z.string().min(1).optional(),
|
OIDC_AUDIENCE_SCOPE: optional(z.string().min(1)),
|
||||||
|
|
||||||
// Database
|
// Database
|
||||||
DATABASE_URL: z.string().url(),
|
DATABASE_URL: z.string().url(),
|
||||||
|
|||||||
@@ -113,6 +113,10 @@ services:
|
|||||||
OIDC_CLIENT_SECRET_WEB: ${OIDC_CLIENT_SECRET_WEB:?required}
|
OIDC_CLIENT_SECRET_WEB: ${OIDC_CLIENT_SECRET_WEB:?required}
|
||||||
OIDC_CLIENT_ID_MCP: ${OIDC_CLIENT_ID_MCP:?required}
|
OIDC_CLIENT_ID_MCP: ${OIDC_CLIENT_ID_MCP:?required}
|
||||||
OIDC_AUDIENCE: ${OIDC_AUDIENCE:?required}
|
OIDC_AUDIENCE: ${OIDC_AUDIENCE:?required}
|
||||||
|
# Optional. This block is an explicit allow-list, not env_file — a var
|
||||||
|
# added to .env but not listed here never reaches the container.
|
||||||
|
OIDC_ISSUER_MCP: ${OIDC_ISSUER_MCP:-}
|
||||||
|
OIDC_AUDIENCE_SCOPE: ${OIDC_AUDIENCE_SCOPE:-}
|
||||||
|
|
||||||
DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}
|
DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user