Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

log the connection name when the oidc issuer signs a token

DimitrisStaratzisf8e2e816a097
diff --git a/backend/AGENTS.md b/backend/AGENTS.md
index 53dbe7e84a..061a808d6a 100644
--- a/backend/AGENTS.md
+++ b/backend/AGENTS.md
@@ -1216,11 +1216,11 @@ The issuer URL and each consumer's `sub` format are one-way doors: customers cop
route. The 24h lead makes a stale set safe. Empty sets are never cached, in Redis or over HTTP.
- **Fresh keys are read on the primary.** Signing and the JWKS a rotation caches pass a `tx` to
`getPublicKey` and `signWithKmsKey`, because a read replica may not have a key created moments earlier.
-- **Every signed token is audit logged** (`issue-oidc-token`) inside `signToken`, so a new consumer gets it
- for free and never logs on its own.
-- **Connections sign for their own ID only.** The subject is `getAppConnectionOidcSubject(connection.id)`,
- built server-side from the connection row, and the token is only ever sent to the provider's token
- endpoint, never returned to a caller. Never let a caller choose the ID: a deleted connection's ID would
+- **Every signed token is audit logged** (`issue-oidc-token`, with the connection's ID and name) inside
+ `signToken`, so a new consumer gets it for free and never logs on its own.
+- **Connections sign for their own ID only.** `signToken` takes the connection, not a subject, and builds
+ `app-connection:<id>` itself, and the token is only ever sent to the provider's token endpoint, never
+ returned to a caller. Never let a caller choose the ID: a deleted connection's ID would
regain whatever the provider still trusts. So the connection is created first, without a token exchange,
and reconnecting verifies it once the customer has added the federated credential. The Azure Key Vault
`managed-identity` method is the reference consumer: copy its `getManagedIdentityAccessToken`, which
diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.ts
index a62a958ffc..99d6beefbd 100644
--- a/backend/src/ee/services/audit-log/audit-log-types.ts
+++ b/backend/src/ee/services/audit-log/audit-log-types.ts
@@ -7870,9 +7870,9 @@ interface OauthClientTokenExchangeEvent {
interface IssueOidcTokenEvent {
type: EventType.ISSUE_OIDC_TOKEN;
metadata: {
- subject: string;
+ connectionId: string;
+ connectionName: string;
audience: string;
- tokenId: string;
};
}
diff --git a/backend/src/services/app-connection/app-connection-service.ts b/backend/src/services/app-connection/app-connection-service.ts
index 64b8278dbc..ad6885a97d 100644
--- a/backend/src/services/app-connection/app-connection-service.ts
+++ b/backend/src/services/app-connection/app-connection-service.ts
@@ -949,7 +949,7 @@ export const appConnectionServiceFactory = ({
app,
orgId: actor.orgId,
projectId: appConnection.projectId,
- connectionId: appConnection.id,
+ connection: { id: appConnection.id, name: appConnection.name },
version: appConnection.version,
credentials: credentialsToValidate,
method,
diff --git a/backend/src/services/app-connection/azure-key-vault/azure-key-vault-connection-fns.ts b/backend/src/services/app-connection/azure-key-vault/azure-key-vault-connection-fns.ts
index 0707bd9b32..ecf8ccdbe8 100644
--- a/backend/src/services/app-connection/azure-key-vault/azure-key-vault-connection-fns.ts
+++ b/backend/src/services/app-connection/azure-key-vault/azure-key-vault-connection-fns.ts
@@ -21,8 +21,8 @@ import {
} from "@app/services/app-connection/app-connection-fns";
import { IntegrationUrls } from "@app/services/integration-auth/integration-list";
import { TKmsServiceFactory } from "@app/services/kms/kms-service";
-import { getAppConnectionOidcSubject } from "@app/services/oidc-issuer/oidc-issuer-fns";
import { TOidcIssuerServiceFactory } from "@app/services/oidc-issuer/oidc-issuer-service";
+import { TSignOidcIssuerTokenDTO } from "@app/services/oidc-issuer/oidc-issuer-types";
import { TAppConnectionDALFactory } from "../app-connection-dal";
import { AppConnection } from "../app-connection-enums";
@@ -42,18 +42,14 @@ const AZURE_FEDERATED_TOKEN_AUDIENCE = "api://AzureADTokenExchange";
const getManagedIdentityAccessToken = async (
{
- orgId,
- projectId,
- connectionId,
+ appConnection,
tenantId,
clientId
- }: { orgId: string; projectId?: string | null; connectionId: string; tenantId: string; clientId: string },
+ }: { appConnection: TSignOidcIssuerTokenDTO["appConnection"]; tenantId: string; clientId: string },
oidcIssuerService: Pick<TOidcIssuerServiceFactory, "signToken">
) => {
const clientAssertion = await oidcIssuerService.signToken({
- orgId,
- projectId,
- subject: getAppConnectionOidcSubject(connectionId),
+ appConnection,
audience: AZURE_FEDERATED_TOKEN_AUDIENCE
});
@@ -357,9 +353,7 @@ export const getAzureConnectionAccessToken = async (
const managedIdentityToken = await getManagedIdentityAccessToken(
{
- orgId: appConnection.orgId,
- projectId: appConnection.projectId,
- connectionId: appConnection.id,
+ appConnection,
tenantId: managedIdentityCredentials.tenantId,
clientId: managedIdentityCredentials.clientId
},
@@ -406,7 +400,7 @@ export const validateAzureKeyVaultConnectionCredentials = async (
config: TAzureKeyVaultConnectionConfig,
oidcIssuerService: Pick<TOidcIssuerServiceFactory, "signToken">
) => {
- const { credentials: inputCredentials, method, orgId, projectId, connectionId } = config;
+ const { credentials: inputCredentials, method, orgId, projectId, connection } = config;
const { INF_APP_CONNECTION_AZURE_KEY_VAULT_CLIENT_ID, INF_APP_CONNECTION_AZURE_KEY_VAULT_CLIENT_SECRET, SITE_URL } =
getConfig();
@@ -569,16 +563,14 @@ export const validateAzureKeyVaultConnectionCredentials = async (
clientId: string;
};
- // A new connection has no ID yet, so Azure cannot trust its subject. Reconnecting verifies it once the
- // customer has added the federated credential.
- if (!connectionId) return { tenantId: managedIdentityTenantId, clientId: managedIdentityClientId };
+ // A new connection has no ID yet, so Azure cannot trust its subject. Verifying it after create runs the
+ // exchange once the customer has added the federated credential.
+ if (!connection) return { tenantId: managedIdentityTenantId, clientId: managedIdentityClientId };
try {
const managedIdentityToken = await getManagedIdentityAccessToken(
{
- orgId,
- projectId,
- connectionId,
+ appConnection: { ...connection, orgId, projectId },
tenantId: managedIdentityTenantId,
clientId: managedIdentityClientId
},
diff --git a/backend/src/services/app-connection/azure-key-vault/azure-key-vault-connection-types.ts b/backend/src/services/app-connection/azure-key-vault/azure-key-vault-connection-types.ts
index b9a7b4343c..0f3e1d47e1 100644
--- a/backend/src/services/app-connection/azure-key-vault/azure-key-vault-connection-types.ts
+++ b/backend/src/services/app-connection/azure-key-vault/azure-key-vault-connection-types.ts
@@ -27,7 +27,7 @@ export type TAzureKeyVaultConnectionConfig = DiscriminativePick<
> & {
orgId: string;
projectId?: string | null;
- connectionId?: string;
+ connection?: { id: string; name: string };
};
export type ExchangeCodeAzureResponse = {
diff --git a/backend/src/services/oidc-issuer/oidc-issuer-service.ts b/backend/src/services/oidc-issuer/oidc-issuer-service.ts
index 3434109a20..cba41281c2 100644
--- a/backend/src/services/oidc-issuer/oidc-issuer-service.ts
+++ b/backend/src/services/oidc-issuer/oidc-issuer-service.ts
@@ -13,6 +13,7 @@ import { TKmsServiceFactory } from "@app/services/kms/kms-service";
import { KmsKeyUsage } from "@app/services/kms/kms-types";
import {
+ getAppConnectionOidcSubject,
getKeyRotationPlan,
getSigningKey,
OIDC_ISSUER_KEY_NAME_PREFIX,
@@ -168,7 +169,9 @@ export const oidcIssuerServiceFactory = ({
return signingKey;
};
- const signToken = async ({ orgId, projectId, subject, audience }: TSignOidcIssuerTokenDTO) => {
+ // Takes the connection rather than a subject, so a caller can only ever sign for a real connection
+ const signToken = async ({ appConnection, audience }: TSignOidcIssuerTokenDTO) => {
+ const { orgId } = appConnection;
const issuer = $getIssuerUrl(orgId);
const { id: kmsId } = await $getSigningKey(orgId);
@@ -181,18 +184,17 @@ export const oidcIssuerServiceFactory = ({
);
const iat = Math.floor(Date.now() / 1000);
- const jti = crypto.nativeCrypto.randomUUID();
const token = await signJwt({
kid,
claims: {
iss: issuer,
- sub: subject,
+ sub: getAppConnectionOidcSubject(appConnection.id),
aud: audience,
iat,
nbf: iat,
exp: iat + TOKEN_TTL_SECONDS,
- jti
+ jti: crypto.nativeCrypto.randomUUID()
},
sign: async (data) =>
(await sign({ data, signingAlgorithm: SigningAlgorithm.RSASSA_PKCS1_V1_5_SHA_256, isDigest: false })).signature
@@ -200,9 +202,12 @@ export const oidcIssuerServiceFactory = ({
await auditLogService.createAuditLog({
orgId,
- projectId: projectId ?? undefined,
+ projectId: appConnection.projectId ?? undefined,
actor: { type: ActorType.PLATFORM, metadata: {} },
- event: { type: EventType.ISSUE_OIDC_TOKEN, metadata: { subject, audience, tokenId: jti } }
+ event: {
+ type: EventType.ISSUE_OIDC_TOKEN,
+ metadata: { connectionId: appConnection.id, connectionName: appConnection.name, audience }
+ }
});
return token;
diff --git a/backend/src/services/oidc-issuer/oidc-issuer-types.ts b/backend/src/services/oidc-issuer/oidc-issuer-types.ts
index bf695a7267..ef8f58d13c 100644
--- a/backend/src/services/oidc-issuer/oidc-issuer-types.ts
+++ b/backend/src/services/oidc-issuer/oidc-issuer-types.ts
@@ -1,6 +1,4 @@
export type TSignOidcIssuerTokenDTO = {
- orgId: string;
- projectId?: string | null;
- subject: string;
+ appConnection: { id: string; name: string; orgId: string; projectId?: string | null };
audience: string;
};