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
return the federated credential values with managed identity connections
DimitrisStaratzis872773030659
diff --git a/backend/AGENTS.md b/backend/AGENTS.mdindex c462e77090..0de43735dc 100644--- a/backend/AGENTS.md+++ b/backend/AGENTS.md@@ -1226,6 +1226,10 @@ The issuer URL and each consumer's `sub` format are one-way doors: customers copand 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`, whichcaches the provider's access token in the credentials like the secret-based methods do.+- **The API returns the values the customer copies.** Connection responses carry+ `credentials.federatedCredential` (issuer URL, subject, audience), built on every read by+ `addAppConnectionFederatedCredential` and never stored, so the UI and Terraform read them rather than rebuild them.+ The issuer is null when `SITE_URL` is unset, so reading a connection never fails on it.### Enterprise (EE) Featuresdiff --git a/backend/src/services/app-connection/app-connection-fns.ts b/backend/src/services/app-connection/app-connection-fns.tsindex 7c6c42abae..0e84a0af93 100644--- a/backend/src/services/app-connection/app-connection-fns.ts+++ b/backend/src/services/app-connection/app-connection-fns.ts@@ -85,8 +85,13 @@ import {getAzureEntraIdConnectionListItem,validateAzureEntraIdConnectionCredentials} from "./azure-entra-id";-import { AzureKeyVaultConnectionMethod, TAzureKeyVaultConnectionConfig } from "./azure-key-vault";import {+ AzureKeyVaultConnectionMethod,+ TAzureKeyVaultConnectionConfig,+ TAzureKeyVaultConnectionFederatedCredential+} from "./azure-key-vault";+import {+ getAzureKeyVaultConnectionFederatedCredential,getAzureKeyVaultConnectionListItem,validateAzureKeyVaultConnectionCredentials} from "./azure-key-vault/azure-key-vault-connection-fns";@@ -956,6 +961,35 @@ export const decryptAppConnection = async (} as TAppConnection;};+type TAzureKeyVaultManagedIdentityConnection = Extract<+ TAppConnection,+ { app: AppConnection.AzureKeyVault; method: AzureKeyVaultConnectionMethod.ManagedIdentity }+>;++// Only for connections returned to the user, who copies these values into Azure+export const addAppConnectionFederatedCredential = (+ appConnection: TAppConnection+):+ | Exclude<TAppConnection, TAzureKeyVaultManagedIdentityConnection>+ | (TAzureKeyVaultManagedIdentityConnection & {+ credentials: { federatedCredential: TAzureKeyVaultConnectionFederatedCredential };+ }) => {+ if (+ appConnection.app !== AppConnection.AzureKeyVault ||+ appConnection.method !== AzureKeyVaultConnectionMethod.ManagedIdentity+ ) {+ return appConnection;+ }++ return {+ ...appConnection,+ credentials: {+ ...appConnection.credentials,+ federatedCredential: getAzureKeyVaultConnectionFederatedCredential(appConnection)+ }+ };+};+const platformManagedCredentialsNotSupported: TAppConnectionTransitionCredentialsToPlatform = ({ app }) => {throw new BadRequestError({message: `${APP_CONNECTION_NAME_MAP[app]} Connections do not support platform managed credentials.`diff --git a/backend/src/services/app-connection/app-connection-service.ts b/backend/src/services/app-connection/app-connection-service.tsindex ad6885a97d..b276e0b21f 100644--- a/backend/src/services/app-connection/app-connection-service.ts+++ b/backend/src/services/app-connection/app-connection-service.ts@@ -29,6 +29,7 @@ import { BadRequestError, DatabaseError, NotFoundError } from "@app/lib/errors";import { getMissingGatewayMessage } from "@app/lib/gateway-v2/gateway-errors";import { DiscriminativePick, OrgServiceActor } from "@app/lib/types";import {+ addAppConnectionFederatedCredential,decryptAppConnection,decryptAppConnectionCredentials,encryptAppConnectionConfiguration,@@ -419,11 +420,13 @@ export const appConnectionServiceFactory = ({);}- return Promise.all(+ const decryptedAppConnections = await Promise.all(appConnections.sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase())).map((appConnection) => decryptAppConnection(appConnection, kmsService)));++ return decryptedAppConnections.map(addAppConnectionFederatedCredential);};const findAppConnectionById = async (@@ -471,7 +474,7 @@ export const appConnectionServiceFactory = ({if (appConnection.app !== app)throw new BadRequestError({ message: `App Connection with ID ${connectionId} is not for App "${app}"` });- return decryptAppConnection(appConnection, kmsService);+ return addAppConnectionFederatedCredential(await decryptAppConnection(appConnection, kmsService));};const findAppConnectionByName = async (@@ -522,7 +525,7 @@ export const appConnectionServiceFactory = ({if (appConnection.app !== app)throw new BadRequestError({ message: `App Connection with name ${connectionName} is not for App "${app}"` });- return decryptAppConnection(appConnection, kmsService);+ return addAppConnectionFederatedCredential(await decryptAppConnection(appConnection, kmsService));};// In project scope, an org-managed GitHub App can only be referenced by actors who can also@@ -755,12 +758,12 @@ export const appConnectionServiceFactory = ({connection = await createConnection(validatedCredentials);}- return {+ return addAppConnectionFederatedCredential({...connection,credentialsHash: crypto.nativeCrypto.createHash("sha256").update(connection.encryptedCredentials).digest("hex"),credentials: validatedCredentials,configuration- } as TAppConnection;+ } as TAppConnection);} catch (err) {if (err instanceof DatabaseError && (err.error as { code: string })?.code === DatabaseErrorCode.UniqueViolation) {throw new BadRequestError({ message: `An App Connection with the name "${params.name}" already exists` });@@ -1140,7 +1143,7 @@ export const appConnectionServiceFactory = ({return connection;});- return await decryptAppConnection(updatedConnection, kmsService);+ return addAppConnectionFederatedCredential(await decryptAppConnection(updatedConnection, kmsService));} catch (err) {if (err instanceof DatabaseError && (err.error as { code: string })?.code === DatabaseErrorCode.UniqueViolation) {throw new BadRequestError({ message: `An App Connection with the name "${params.name}" already exists` });@@ -1211,7 +1214,7 @@ export const appConnectionServiceFactory = ({try {const deletedAppConnection = await appConnectionDAL.deleteById(connectionId);- return await decryptAppConnection(deletedAppConnection, kmsService);+ return addAppConnectionFederatedCredential(await decryptAppConnection(deletedAppConnection, kmsService));} catch (err) {if (err instanceof DatabaseError &&diff --git a/backend/src/services/app-connection/azure-key-vault/azure-key-vault-connection-fns.test.ts b/backend/src/services/app-connection/azure-key-vault/azure-key-vault-connection-fns.test.tsnew file mode 100644index 0000000000..812b836996--- /dev/null+++ b/backend/src/services/app-connection/azure-key-vault/azure-key-vault-connection-fns.test.ts@@ -0,0 +1,26 @@+import { getAzureKeyVaultConnectionFederatedCredential } from "./azure-key-vault-connection-fns";++const config = vi.hoisted(() => ({ SITE_URL: "https://app.test" as string | undefined }));+vi.mock("@app/lib/config/env", () => ({ getConfig: () => config }));++const connection = { id: "11111111-1111-1111-1111-111111111111", orgId: "22222222-2222-2222-2222-222222222222" };++describe("getAzureKeyVaultConnectionFederatedCredential", () => {+ afterEach(() => {+ config.SITE_URL = "https://app.test";+ });++ test("returns the values to add to the federated credential", () => {+ expect(getAzureKeyVaultConnectionFederatedCredential(connection)).toEqual({+ issuerUrl: `https://app.test/api/v1/oidc-issuer/organizations/${connection.orgId}`,+ subjectIdentifier: `app-connection:${connection.id}`,+ audience: "api://AzureADTokenExchange"+ });+ });++ test("returns no issuer when SITE_URL is not set", () => {+ config.SITE_URL = undefined;++ expect(getAzureKeyVaultConnectionFederatedCredential(connection).issuerUrl).toBeNull();+ });+});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.tsindex ecf8ccdbe8..da08ace3a4 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,6 +21,7 @@ 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, getOidcIssuerUrl } 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";@@ -40,6 +41,18 @@ import {// Entra only accepts federated tokens with this audienceconst AZURE_FEDERATED_TOKEN_AUDIENCE = "api://AzureADTokenExchange";+// Not stored with the credentials, so the issuer follows SITE_URL if it changes. Without SITE_URL there is no issuer,+// but reading the connection must still work.+export const getAzureKeyVaultConnectionFederatedCredential = ({ id, orgId }: { id: string; orgId: string }) => {+ const { SITE_URL } = getConfig();++ return {+ issuerUrl: SITE_URL ? getOidcIssuerUrl(SITE_URL, orgId) : null,+ subjectIdentifier: getAppConnectionOidcSubject(id),+ audience: AZURE_FEDERATED_TOKEN_AUDIENCE+ };+};+const getManagedIdentityAccessToken = async ({appConnection,diff --git a/backend/src/services/app-connection/azure-key-vault/azure-key-vault-connection-schemas.ts b/backend/src/services/app-connection/azure-key-vault/azure-key-vault-connection-schemas.tsindex 532a6f5fba..0748b27149 100644--- a/backend/src/services/app-connection/azure-key-vault/azure-key-vault-connection-schemas.ts+++ b/backend/src/services/app-connection/azure-key-vault/azure-key-vault-connection-schemas.ts@@ -83,6 +83,12 @@ export const AzureKeyVaultConnectionManagedIdentityOutputCredentialsSchema = z.oexpiresAt: z.number().optional()});+export const AzureKeyVaultConnectionFederatedCredentialSchema = z.object({+ issuerUrl: z.string().nullable(),+ subjectIdentifier: z.string(),+ audience: z.string()+});+export const ValidateAzureKeyVaultConnectionCredentialsSchema = z.discriminatedUnion("method", [z.object({method: z@@ -204,6 +210,10 @@ export const SanitizedAzureKeyVaultConnectionSchema = z.discriminatedUnion("methcredentials: AzureKeyVaultConnectionManagedIdentityOutputCredentialsSchema.pick({clientId: true,tenantId: true+ }).extend({+ federatedCredential: AzureKeyVaultConnectionFederatedCredentialSchema.describe(+ "The values to add to a federated credential on the managed identity. The issuer is null when SITE_URL is not set."+ )})}).describe(JSON.stringify({ title: `${APP_CONNECTION_NAME_MAP[AppConnection.AzureKeyVault]} (Managed Identity)` }))]);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.tsindex 0f3e1d47e1..1b92b92d69 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@@ -6,6 +6,7 @@ import { AppConnection } from "../app-connection-enums";import {AzureKeyVaultConnectionCertificateOutputCredentialsSchema,AzureKeyVaultConnectionClientSecretOutputCredentialsSchema,+ AzureKeyVaultConnectionFederatedCredentialSchema,AzureKeyVaultConnectionManagedIdentityOutputCredentialsSchema,AzureKeyVaultConnectionOAuthOutputCredentialsSchema,AzureKeyVaultConnectionSchema,@@ -53,3 +54,7 @@ export type TAzureKeyVaultConnectionCertificateCredentials = z.infer<export type TAzureKeyVaultConnectionManagedIdentityCredentials = z.infer<typeof AzureKeyVaultConnectionManagedIdentityOutputCredentialsSchema>;++export type TAzureKeyVaultConnectionFederatedCredential = z.infer<+ typeof AzureKeyVaultConnectionFederatedCredentialSchema+>;diff --git a/backend/src/services/oidc-issuer/oidc-issuer-fns.ts b/backend/src/services/oidc-issuer/oidc-issuer-fns.tsindex 83ef8391d8..d9f70f7c1f 100644--- a/backend/src/services/oidc-issuer/oidc-issuer-fns.ts+++ b/backend/src/services/oidc-issuer/oidc-issuer-fns.ts@@ -14,6 +14,9 @@ type TIssuerKey = { id: string; createdAt: Date };// credential set up for a future use of the issuer.export const getAppConnectionOidcSubject = (connectionId: string) => `app-connection:${connectionId}`;+export const getOidcIssuerUrl = (siteUrl: string, orgId: string) =>+ `${siteUrl}/api/v1/oidc-issuer/organizations/${orgId}`;+// Keys are oldest first: previous, current, next. The next key is published a full signing period before it// takes over, so a provider that cached the JWKS already has it.export const getSigningKey = <T extends TIssuerKey>(keys: T[]): T | undefined => keys[keys.length - 2];diff --git a/backend/src/services/oidc-issuer/oidc-issuer-service.ts b/backend/src/services/oidc-issuer/oidc-issuer-service.tsindex cba41281c2..d32fc74922 100644--- a/backend/src/services/oidc-issuer/oidc-issuer-service.ts+++ b/backend/src/services/oidc-issuer/oidc-issuer-service.ts@@ -15,6 +15,7 @@ import { KmsKeyUsage } from "@app/services/kms/kms-types";import {getAppConnectionOidcSubject,getKeyRotationPlan,+ getOidcIssuerUrl,getSigningKey,OIDC_ISSUER_KEY_NAME_PREFIX,OIDC_ISSUER_SIGNING_ALG,@@ -52,7 +53,7 @@ export const oidcIssuerServiceFactory = ({});}- return `${SITE_URL}/api/v1/oidc-issuer/organizations/${orgId}`;+ return getOidcIssuerUrl(SITE_URL, orgId);};// Customers cannot create reserved keys, so the prefix only separates these from the org's other reserved keys