Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
add local bootstrap
Thiago Araujo da Silva0f0bbbc6ef86
diff --git a/Makefile b/Makefileindex 5f78456512..25e11712ea 100644--- a/Makefile+++ b/Makefile@@ -74,7 +74,7 @@ seed-dev-ldap:docker compose -f docker-compose.dev.yml exec -T backend npx tsx ./src/db/seed-ldap.ts $(ORG_ID)seed-dev-oidc:- # Sets up the Infisical side for OIDC SSO testing: an [email protected] admin, a verified+ # Sets up the Infisical side for OIDC SSO testing: an [email protected] admin, a verified# domain, and an active OIDC config. With ORG_ID=<uuid> it configures that existing org;# otherwise it bootstraps a dedicated `oidc` org. Needs the stack up (`make up-dev-oidc`).docker compose -f docker-compose.dev.yml exec -T backend npx tsx ./src/db/seed-oidc.ts $(ORG_ID)diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.tsindex 284d600084..0950d9a0b9 100644--- a/backend/src/ee/services/audit-log/audit-log-types.ts+++ b/backend/src/ee/services/audit-log/audit-log-types.ts@@ -931,6 +931,7 @@ interface UserActorMetadata {username: string;permission?: Record<string, unknown>;authMethod?: string;+ oauthClientId?: string;}interface ServiceActorMetadata {diff --git a/backend/src/server/plugins/audit-log.ts b/backend/src/server/plugins/audit-log.tsindex 31ec61d82e..3dd63c28a5 100644--- a/backend/src/server/plugins/audit-log.ts+++ b/backend/src/server/plugins/audit-log.ts@@ -4,7 +4,7 @@ import fp from "fastify-plugin";import { UserAgentType } from "@app/ee/services/audit-log/audit-log-types";import { BadRequestError } from "@app/lib/errors";import { RequestContextKey } from "@app/lib/request-context/request-context-keys";-import { ActorType } from "@app/services/auth/auth-type";+import { ActorType, AuthMode } from "@app/services/auth/auth-type";export const getUserAgentType = (userAgent: string | undefined) => {if (userAgent === undefined) {@@ -57,6 +57,9 @@ export const injectAuditLogInfo = fp(async (server: FastifyZodProvider) => {type: ActorType.USER,metadata: {...(req.auth.authMethod ? { authMethod: req.auth.authMethod } : {}),+ ...(req.auth.authMode === AuthMode.OAUTH && req.auth.oauthClientId+ ? { oauthClientId: req.auth.oauthClientId }+ : {}),email: req.auth.user.email,username: req.auth.user.username,userId: req.permission.iddiff --git a/docker-compose.dev.yml b/docker-compose.dev.ymlindex d951284ac5..87ba93c1ea 100644--- a/docker-compose.dev.yml+++ b/docker-compose.dev.yml@@ -259,9 +259,9 @@ services:keycloak:# Admin console: http://localhost:8088 (admin / admin).- # On boot it imports the pre-seeded `infisical` realm (client `infisical-dev`,- # users jdoe/asmith) from the mounted realm file. The container has no volume,- # so the realm is re-imported fresh on every start. See sso.md.+ # On boot it imports the pre-seeded `infisical` realm from the mounted realm file: clients+ # `infisical-dev` (SSO login) and `infisical-mcp` (token exchange), users john/alice/admin.+ # The container has no volume, so the realm is re-imported fresh on every start. See sso.md.image: quay.io/keycloak/keycloak:26.1.0restart: alwaysenvironment:diff --git a/docker/keycloak/realm-infisical.json b/docker/keycloak/realm-infisical.jsonindex f8a686394a..2d3d87c578 100644--- a/docker/keycloak/realm-infisical.json+++ b/docker/keycloak/realm-infisical.json@@ -22,6 +22,18 @@"http://localhost:8080/*"],"webOrigins": ["http://localhost:8080"]+ },+ {+ "clientId": "infisical-mcp",+ "name": "Infisical MCP (dev middleware)",+ "description": "Stands in for trusted middleware in the OAuth token exchange flow. An ID token from this client carries aud=infisical-mcp, which is what an Infisical application's token exchange audience must match. See sso.md.",+ "enabled": true,+ "protocol": "openid-connect",+ "publicClient": false,+ "clientAuthenticatorType": "client-secret",+ "secret": "infisical-mcp-client-secret",+ "standardFlowEnabled": false,+ "directAccessGrantsEnabled": true}],"users": [diff --git a/frontend/src/hooks/api/auditLogs/types.tsx b/frontend/src/hooks/api/auditLogs/types.tsxindex 7ddeb69a99..22adf84d19 100644--- a/frontend/src/hooks/api/auditLogs/types.tsx+++ b/frontend/src/hooks/api/auditLogs/types.tsx@@ -29,6 +29,7 @@ export type TGetAuditLogsFilter = {interface UserActorMetadata {userId: string;email: string;+ oauthClientId?: string;}interface ServiceActorMetadata {diff --git a/frontend/src/pages/organization/AuditLogsPage/components/LogsTableRow.tsx b/frontend/src/pages/organization/AuditLogsPage/components/LogsTableRow.tsxindex bc4ebd0566..fa573b6e68 100644--- a/frontend/src/pages/organization/AuditLogsPage/components/LogsTableRow.tsx+++ b/frontend/src/pages/organization/AuditLogsPage/components/LogsTableRow.tsx@@ -69,6 +69,9 @@ export const LogsTableRow = ({ auditLog, rowNumber, timezone, onClick }: Props){auditLog.actor.type === ActorType.USER && (<Tag label="user_email" value={auditLog.actor.metadata.email} />)}+ {auditLog.actor.type === ActorType.USER && auditLog.actor.metadata.oauthClientId && (+ <Tag label="oauth_application" value={auditLog.actor.metadata.oauthClientId} />+ )}{auditLog.actor.type === ActorType.IDENTITY && (<Tag label="identity_name" value={auditLog.actor.metadata.name} />)}diff --git a/sso.md b/sso.mdindex 3d570f9660..09178ce6b1 100644--- a/sso.md+++ b/sso.md@@ -97,6 +97,11 @@ A one-shot `keycloak-config` sidecar runs alongside it and sets the built-in `ma| JWT signature algorithm | `RS256` || Redirect URI (registered) | `http://localhost:8080/api/v1/sso/oidc/callback` || Seeded users | `[email protected]`, `[email protected]`, `[email protected]` (password `password123!`) |+| Second client (token exchange only) | `infisical-mcp` / `infisical-mcp-client-secret` |++The realm defines a second client, `infisical-mcp`, purely for+[token exchange testing](#testing-oauth-token-exchange-rfc-8693). It stands in for trusted middleware:+direct access grants only, no browser redirect, and it is never used for SSO login.### Discovery URL (how the networking works)@@ -155,6 +160,98 @@ Then test the login two ways:4. Save, then enable OIDC.</details>+### Testing OAuth token exchange (RFC 8693)++Token exchange lets trusted middleware present a user's token from your IdP and receive that user's+Infisical token. Its trust anchor is the org's OIDC SSO config, so everything above has to be working+first. See [OAuth Token Exchange](docs/documentation/platform/oauth-token-exchange) for the product docs.++No license is needed. `plan.oidcSSO` is only checked when creating or updating an OIDC config through+the API, and `make seed-dev-oidc` writes the row directly.++**1. Seed, then confirm the trust anchor resolves.** This is what decides whether the `iss` check+passes, so check it rather than debugging a 401 later:++```bash+make seed-dev-oidc++docker compose -f docker-compose.dev.yml exec -T backend \+ sh -c 'curl -s http://keycloak:8080/realms/infisical/.well-known/openid-configuration' \+ | python3 -c 'import sys,json; d=json.load(sys.stdin); print(d["issuer"]); print(d["jwks_uri"])'+```++Expect the issuer `http://localhost:8088/realms/infisical` (pinned by `KC_HOSTNAME`, and what tokens+actually carry) and a `jwks_uri` on `keycloak:8080` that the backend can reach. The seeded config+stores no issuer of its own, so the backend falls back to the discovered one.++**2. Register the application.** Sign in at http://localhost:8080 as `[email protected]` /+`password123!`, then **Organization Settings > OAuth Applications > Add Application**. Choose flow+**Token exchange**, set **Audience** to `infisical-mcp`, and leave the identity-provider MFA+declaration off. Copy the client id and secret.++**3. Get a subject token and exchange it.**++```bash+CLIENT_ID="<paste>"; CLIENT_SECRET="<paste>"++SUBJECT_TOKEN=$(curl -s -X POST \+ http://localhost:8088/realms/infisical/protocol/openid-connect/token \+ -d grant_type=password -d scope=openid \+ -d client_id=infisical-mcp -d client_secret=infisical-mcp-client-secret \+ -d [email protected] -d password='password123!' \+ | python3 -c 'import sys,json; print(json.load(sys.stdin)["id_token"])')++curl -s -X POST http://localhost:8080/api/v1/oauth/token \+ -u "$CLIENT_ID:$CLIENT_SECRET" \+ -d grant_type=urn:ietf:params:oauth:grant-type:token-exchange \+ -d subject_token="$SUBJECT_TOKEN" \+ -d subject_token_type=urn:ietf:params:oauth:token-type:id_token | python3 -m json.tool+```++Use the **`id_token`**, not the access token. An ID token's `aud` is the requesting client by+specification, so it is already `infisical-mcp`. The realm defines no audience mapper, so Keycloak's+access token carries no `aud` at all (only `azp`) and is rejected.++The response has `access_token`, `issued_token_type`, `token_type`, `expires_in`, and deliberately no+`refresh_token` and no `scope`. Decode it and you should see `delegation: "full"`, no `scopes` claim,+and the seeded admin's `userId`.++**4. Check what the token can do.**++```bash+TOKEN="<paste access_token>"++# Introspection: 200 {"active":true} means it authenticated as AuthMode.OAUTH on a live session.+curl -s -o /dev/null -w '%{http_code}\n' http://localhost:8080/api/v1/oauth/validate \+ -H "Authorization: Bearer $TOKEN"++# Account routes stay unreachable for delegated tokens, so this must be 403.+curl -s -o /dev/null -w '%{http_code}\n' http://localhost:8080/api/v1/user/me/totp \+ -H "Authorization: Bearer $TOKEN"+```++Create a project and a secret in the `oidc` org, then read it with `GET /api/v3/secrets/raw` using the+token. A 200 proves full delegation carries the user's real permissions. The org's **Audit Logs** should+show the exchange attributed to `[email protected]` with the acting application in the metadata.++**5. Prove the alias requirement.** `[email protected]` has no seeded alias, so repeating step 3 with+`[email protected]` is rejected. Complete one SSO login as john via+`http://localhost:8080/api/v1/sso/oidc/login?orgSlug=oidc`, then retry: it now succeeds, because+Keycloak issues the same `sub` to both clients and the browser login wrote the alias the exchange+looks up.++**Cases worth checking:**++| Case | How | Expect |+| --- | --- | --- |+| Cross-application replay | subject token from `infisical-dev` | 401, audience does not match |+| Access token instead of ID token | send `access_token` | 401, audience does not match |+| Tampered signature | change a character in the third JWT segment | 401, could not be verified |+| `scope` supplied | add `-d scope=secrets:read` | 400, scope not supported |+| SSO disabled | `update oidc_configs set "isActive"=false;` | 400, naming the SSO settings |+| MFA required | enforce org MFA, leave the application flag off | 401, MFA required |+| Unregistered grant | use an authorization-code application's credentials | 401, not registered for the grant |+---## LDAP via OpenLDAP@@ -382,3 +479,6 @@ curl -sI "http://localhost:8080/api/v1/sso/redirect/saml2/organizations/saml" || SAML login fails with `assertion audience mismatch` | Authentik's SAML provider audience must equal `SITE_URL` (`http://localhost:8080`); the seed sets this. If you changed `SITE_URL`, re-run `make seed-dev-saml` so Authentik's audience and the SAML config agree. || Authentik unreachable or `Token invalid/expired` during the seed | Authentik takes ~40s after `make up-dev-saml` to finish bootstrapping (the worker applies blueprints and creates the API token). Wait for http://localhost:9100 to load, then re-run `make seed-dev-saml`. || Locked out after enforcing SSO | Recover via http://localhost:8080/login/admin. |+| Token exchange: `audience does not match` | You sent Keycloak's **access** token. The realm has no audience mapper, so its access tokens carry no `aud` claim. Use the `id_token` from the same response, whose `aud` is the client id. Also check the application's audience is `infisical-mcp` and not `infisical-dev`. |+| Token exchange: `has not signed in to Infisical through your organization's OIDC SSO yet` | That user has no `user_aliases` row. `make seed-dev-oidc` only seeds one for `[email protected]` (the realm pins its subject). For any other user, complete one browser SSO login first: `http://localhost:8080/api/v1/sso/oidc/login?orgSlug=oidc`. |+| Token exchange: `has no OIDC SSO configuration` / `OIDC SSO is disabled` | The org has no active `oidc_configs` row. Run `make seed-dev-oidc`, and note it targets the `oidc` org unless you pass `ORG_ID=<uuid>`. |