Skip to content

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

feat: add certificate authentication method for Azure Key Vault connections

Victor Hugo dos Santos9648365bde58
diff --git a/backend/src/services/app-connection/azure-client-secrets/azure-client-secrets-connection-fns.ts b/backend/src/services/app-connection/azure-client-secrets/azure-client-secrets-connection-fns.ts
index 6ca8bd703f..4ac4251196 100644
--- a/backend/src/services/app-connection/azure-client-secrets/azure-client-secrets-connection-fns.ts
+++ b/backend/src/services/app-connection/azure-client-secrets/azure-client-secrets-connection-fns.ts
@@ -1,12 +1,8 @@
/* eslint-disable no-case-declarations */
import { AxiosError, AxiosResponse } from "axios";
-import type { KeyObject } from "crypto";
-import RE2 from "re2";
-import { v4 as uuidv4 } from "uuid";
import { getConfig } from "@app/lib/config/env";
import { request } from "@app/lib/config/request";
-import { crypto } from "@app/lib/crypto";
import { BadRequestError, InternalServerError, NotFoundError } from "@app/lib/errors";
import { logger } from "@app/lib/logger";
import {
@@ -19,6 +15,7 @@ import { TKmsServiceFactory } from "@app/services/kms/kms-service";
import { TAppConnectionDALFactory } from "../app-connection-dal";
import { AppConnection } from "../app-connection-enums";
+import { generateClientAssertion } from "../shared/azure/generate-client-assertion";
import { AzureClientSecretsConnectionMethod } from "./azure-client-secrets-connection-enums";
import {
ExchangeCodeAzureResponse,
@@ -28,76 +25,6 @@ import {
TAzureClientSecretsConnectionCredentials
} from "./azure-client-secrets-connection-types";
-const generateClientAssertion = (
- clientId: string,
- tenantId: string,
- privateKey: string,
- certificate: string
-): string => {
- const tokenEndpoint = `https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/token`;
-
- const certBuffer = Buffer.from(
- certificate
- .replace(new RE2("-----BEGIN CERTIFICATE-----"), "")
- .replace(new RE2("-----END CERTIFICATE-----"), "")
- .replace(new RE2("\\s", "g"), ""),
- "base64"
- );
-
- // thumbprint of the certificate is used for the jwt header
- const thumbprint = crypto.nativeCrypto.createHash("sha1").update(certBuffer).digest("hex");
- const x5t = Buffer.from(thumbprint, "hex").toString("base64url");
-
- // JWT Header
- const header = {
- alg: "RS256",
- typ: "JWT",
- x5t
- };
-
- const now = Math.floor(Date.now() / 1000);
- const payload = {
- aud: tokenEndpoint,
- exp: now + 600, // expire the assertion in 10 minutes (not the access access token TTL, but rather the assertion TTL itself)
- iss: clientId,
- jti: uuidv4(), // random ID for the JWT
- nbf: now, // not before the jwt is valid
- sub: clientId
- };
-
- // encode header and payload
- const encodedHeader = Buffer.from(JSON.stringify(header)).toString("base64url");
- const encodedPayload = Buffer.from(JSON.stringify(payload)).toString("base64url");
- const signatureInput = `${encodedHeader}.${encodedPayload}`;
-
- let keyObject: KeyObject;
-
- try {
- if (privateKey.includes("BEGIN PRIVATE KEY")) {
- keyObject = crypto.nativeCrypto.createPrivateKey(privateKey);
- } else {
- // if user forgot to wrap in begin/end private key, decode and use as der format
- keyObject = crypto.nativeCrypto.createPrivateKey({
- key: Buffer.from(privateKey, "base64"),
- format: "der",
- type: "pkcs8"
- });
- }
- } catch (error) {
- throw new BadRequestError({
- message: "Invalid private key format provided. Expected PEM format private key."
- });
- }
-
- // sign with private key
- const signer = crypto.nativeCrypto.createSign("RSA-SHA256");
- signer.update(signatureInput);
- signer.end();
- const signature = signer.sign(keyObject, "base64url");
-
- return `${signatureInput}.${signature}`;
-};
-
export const getAzureClientSecretsConnectionListItem = () => {
const { INF_APP_CONNECTION_AZURE_CLIENT_SECRETS_CLIENT_ID } = getConfig();
diff --git a/backend/src/services/app-connection/azure-key-vault/azure-key-vault-connection-enums.ts b/backend/src/services/app-connection/azure-key-vault/azure-key-vault-connection-enums.ts
index aa70ccb68b..529d7f4842 100644
--- a/backend/src/services/app-connection/azure-key-vault/azure-key-vault-connection-enums.ts
+++ b/backend/src/services/app-connection/azure-key-vault/azure-key-vault-connection-enums.ts
@@ -1,4 +1,5 @@
export enum AzureKeyVaultConnectionMethod {
OAuth = "oauth",
- ClientSecret = "client-secret"
+ ClientSecret = "client-secret",
+ Certificate = "certificate"
}
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 9227c1a331..c135e61164 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
@@ -4,6 +4,7 @@ import { AxiosError, AxiosResponse } from "axios";
import { getConfig } from "@app/lib/config/env";
import { request } from "@app/lib/config/request";
import { BadRequestError, InternalServerError, NotFoundError } from "@app/lib/errors";
+import { logger } from "@app/lib/logger";
import {
decryptAppConnectionCredentials,
encryptAppConnectionCredentials,
@@ -14,9 +15,11 @@ import { TKmsServiceFactory } from "@app/services/kms/kms-service";
import { TAppConnectionDALFactory } from "../app-connection-dal";
import { AppConnection } from "../app-connection-enums";
+import { generateClientAssertion } from "../shared/azure/generate-client-assertion";
import { AzureKeyVaultConnectionMethod } from "./azure-key-vault-connection-enums";
import {
ExchangeCodeAzureResponse,
+ TAzureKeyVaultConnectionCertificateCredentials,
TAzureKeyVaultConnectionClientSecretCredentials,
TAzureKeyVaultConnectionConfig,
TAzureKeyVaultConnectionCredentials
@@ -135,6 +138,65 @@ export const getAzureConnectionAccessToken = async (
return { accessToken: clientData.access_token };
+ case AzureKeyVaultConnectionMethod.Certificate:
+ const certificateCredentials = (await decryptAppConnectionCredentials({
+ orgId: appConnection.orgId,
+ kmsService,
+ encryptedCredentials: appConnection.encryptedCredentials,
+ projectId: appConnection.projectId
+ })) as TAzureKeyVaultConnectionCertificateCredentials;
+
+ const {
+ accessToken: certAccessToken,
+ expiresAt: certExpiresAt,
+ clientId: certClientId,
+ tenantId: certTenantId,
+ certificateBody,
+ privateKey
+ } = certificateCredentials;
+
+ // Check if token is still valid (with 5 minute buffer)
+ if (certAccessToken && certExpiresAt && certExpiresAt > currentTime + 300000) {
+ return { accessToken: certAccessToken };
+ }
+
+ const certificateClientAssertion = generateClientAssertion(
+ certClientId,
+ certTenantId,
+ privateKey,
+ certificateBody
+ );
+
+ const { data: certificateData } = await request.post<ExchangeCodeAzureResponse>(
+ IntegrationUrls.AZURE_TOKEN_URL.replace("common", certTenantId || "common"),
+ new URLSearchParams({
+ grant_type: "client_credentials",
+ scope: `https://vault.azure.net/.default`,
+ client_id: certClientId,
+ client_assertion_type: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
+ client_assertion: certificateClientAssertion
+ })
+ );
+
+ const updatedCertificateCredentials = {
+ ...certificateCredentials,
+ accessToken: certificateData.access_token,
+ expiresAt: currentTime + certificateData.expires_in * 1000
+ };
+
+ const encryptedCertificateCredentials = await encryptAppConnectionCredentials({
+ credentials: updatedCertificateCredentials,
+ orgId: appConnection.orgId,
+ kmsService,
+ projectId: appConnection.projectId
+ });
+
+ await appConnectionDAL.updateById(appConnection.id, {
+ encryptedCredentials: encryptedCertificateCredentials
+ });
+
+ return { accessToken: certificateData.access_token };
+
default:
throw new InternalServerError({
message: `Unhandled Azure Key Vault connection method: ${appConnection.method as AzureKeyVaultConnectionMethod}`
@@ -150,7 +212,8 @@ export const getAzureKeyVaultConnectionListItem = () => {
app: AppConnection.AzureKeyVault as const,
methods: Object.values(AzureKeyVaultConnectionMethod) as [
AzureKeyVaultConnectionMethod.OAuth,
- AzureKeyVaultConnectionMethod.ClientSecret
+ AzureKeyVaultConnectionMethod.ClientSecret,
+ AzureKeyVaultConnectionMethod.Certificate
],
oauthClientId: INF_APP_CONNECTION_AZURE_KEY_VAULT_CLIENT_ID
};
@@ -263,6 +326,61 @@ export const validateAzureKeyVaultConnectionCredentials = async (config: TAzureK
}
}
+ case AzureKeyVaultConnectionMethod.Certificate:
+ const {
+ tenantId: certTenantId,
+ certificateBody,
+ privateKey,
+ clientId: certClientId
+ } = inputCredentials as {
+ tenantId: string;
+ certificateBody: string;
+ privateKey: string;
+ clientId: string;
+ };
+
+ try {
+ const clientAssertion = generateClientAssertion(certClientId, certTenantId, privateKey, certificateBody);
+
+ const { data: certificateData } = await request.post<ExchangeCodeAzureResponse>(
+ IntegrationUrls.AZURE_TOKEN_URL.replace("common", certTenantId || "common"),
+ new URLSearchParams({
+ grant_type: "client_credentials",
+ scope: `https://vault.azure.net/.default`,
+ client_id: certClientId,
+ client_assertion_type: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
+ client_assertion: clientAssertion
+ })
+ );
+
+ return {
+ tenantId: certTenantId,
+ clientId: certClientId,
+ certificateBody,
+ privateKey,
+ accessToken: certificateData.access_token,
+ expiresAt: Date.now() + certificateData.expires_in * 1000
+ };
+ } catch (e: unknown) {
+ if (e instanceof AxiosError) {
+ throw new BadRequestError({
+ message: `Failed to get access token: ${
+ (e?.response?.data as { error_description?: string })?.error_description || "Unknown error"
+ }`
+ });
+ } else if (e instanceof BadRequestError) {
+ throw e;
+ } else {
+ logger.error(
+ e,
+ "validateAzureKeyVaultConnectionCredentials: Failed to get access token using certificate authentication"
+ );
+ throw new InternalServerError({
+ message: "Failed to get access token"
+ });
+ }
+ }
+
default:
throw new InternalServerError({
message: `Unhandled Azure Key Vault connection method: ${method as AzureKeyVaultConnectionMethod}`
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.ts
index 8d6ef9dd0b..9e8c61ad2c 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
@@ -55,6 +55,22 @@ export const AzureKeyVaultConnectionClientSecretOutputCredentialsSchema = z.obje
expiresAt: z.number()
});
+export const AzureKeyVaultConnectionCertificateInputCredentialsSchema = z.object({
+ tenantId: z.string().uuid().trim().min(1, "Tenant ID required"),
+ clientId: z.string().uuid().trim().min(1, "Client ID required"),
+ certificateBody: z.string().trim().min(1, "Certificate body required"),
+ privateKey: z.string().trim().min(1, "Private Key required")
+});
+
+export const AzureKeyVaultConnectionCertificateOutputCredentialsSchema = z.object({
+ clientId: z.string(),
+ tenantId: z.string(),
+ certificateBody: z.string(),
+ privateKey: z.string(),
+ accessToken: z.string(),
+ expiresAt: z.number()
+});
+
export const ValidateAzureKeyVaultConnectionCredentialsSchema = z.discriminatedUnion("method", [
z.object({
method: z
@@ -71,6 +87,14 @@ export const ValidateAzureKeyVaultConnectionCredentialsSchema = z.discriminatedU
credentials: AzureKeyVaultConnectionClientSecretInputCredentialsSchema.describe(
AppConnections.CREATE(AppConnection.AzureKeyVault).credentials
)
+ }),
+ z.object({
+ method: z
+ .literal(AzureKeyVaultConnectionMethod.Certificate)
+ .describe(AppConnections.CREATE(AppConnection.AzureKeyVault).method),
+ credentials: AzureKeyVaultConnectionCertificateInputCredentialsSchema.describe(
+ AppConnections.CREATE(AppConnection.AzureKeyVault).credentials
+ )
})
]);
@@ -83,7 +107,8 @@ export const UpdateAzureKeyVaultConnectionSchema = z
credentials: z
.union([
AzureKeyVaultConnectionOAuthInputCredentialsSchema,
- AzureKeyVaultConnectionClientSecretInputCredentialsSchema
+ AzureKeyVaultConnectionClientSecretInputCredentialsSchema,
+ AzureKeyVaultConnectionCertificateInputCredentialsSchema
])
.optional()
.describe(AppConnections.UPDATE(AppConnection.AzureKeyVault).credentials)
@@ -104,6 +129,10 @@ export const AzureKeyVaultConnectionSchema = z.intersection(
z.object({
method: z.literal(AzureKeyVaultConnectionMethod.ClientSecret),
credentials: AzureKeyVaultConnectionClientSecretOutputCredentialsSchema
+ }),
+ z.object({
+ method: z.literal(AzureKeyVaultConnectionMethod.Certificate),
+ credentials: AzureKeyVaultConnectionCertificateOutputCredentialsSchema
})
])
);
@@ -121,7 +150,14 @@ export const SanitizedAzureKeyVaultConnectionSchema = z.discriminatedUnion("meth
clientId: true,
tenantId: true
})
- }).describe(JSON.stringify({ title: `${APP_CONNECTION_NAME_MAP[AppConnection.AzureKeyVault]} (Client Secret)` }))
+ }).describe(JSON.stringify({ title: `${APP_CONNECTION_NAME_MAP[AppConnection.AzureKeyVault]} (Client Secret)` })),
+ BaseAzureKeyVaultConnectionSchema.extend({
+ method: z.literal(AzureKeyVaultConnectionMethod.Certificate),
+ credentials: AzureKeyVaultConnectionCertificateOutputCredentialsSchema.pick({
+ clientId: true,
+ tenantId: true
+ })
+ }).describe(JSON.stringify({ title: `${APP_CONNECTION_NAME_MAP[AppConnection.AzureKeyVault]} (Certificate)` }))
]);
export const AzureKeyVaultConnectionListItemSchema = z
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 5c5c89b957..6e93dee126 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
@@ -4,6 +4,7 @@ import { DiscriminativePick } from "@app/lib/types";
import { AppConnection } from "../app-connection-enums";
import {
+ AzureKeyVaultConnectionCertificateOutputCredentialsSchema,
AzureKeyVaultConnectionClientSecretOutputCredentialsSchema,
AzureKeyVaultConnectionOAuthOutputCredentialsSchema,
AzureKeyVaultConnectionSchema,
@@ -41,3 +42,7 @@ export type TAzureKeyVaultConnectionCredentials = z.infer<typeof AzureKeyVaultCo
export type TAzureKeyVaultConnectionClientSecretCredentials = z.infer<
typeof AzureKeyVaultConnectionClientSecretOutputCredentialsSchema
>;
+
+export type TAzureKeyVaultConnectionCertificateCredentials = z.infer<
+ typeof AzureKeyVaultConnectionCertificateOutputCredentialsSchema
+>;
diff --git a/backend/src/services/app-connection/shared/azure/generate-client-assertion.ts b/backend/src/services/app-connection/shared/azure/generate-client-assertion.ts
new file mode 100644
index 0000000000..a1f1828f89
--- /dev/null
+++ b/backend/src/services/app-connection/shared/azure/generate-client-assertion.ts
@@ -0,0 +1,76 @@
+import type { KeyObject } from "crypto";
+import RE2 from "re2";
+import { v4 as uuidv4 } from "uuid";
+
+import { crypto } from "@app/lib/crypto";
+import { BadRequestError } from "@app/lib/errors";
+
+export const generateClientAssertion = (
+ clientId: string,
+ tenantId: string,
+ privateKey: string,
+ certificate: string
+): string => {
+ const tokenEndpoint = `https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/token`;
+
+ const certBuffer = Buffer.from(
+ certificate
+ .replace(new RE2("-----BEGIN CERTIFICATE-----"), "")
+ .replace(new RE2("-----END CERTIFICATE-----"), "")
+ .replace(new RE2("\\s", "g"), ""),
+ "base64"
+ );
+
+ // thumbprint of the certificate is used for the jwt header
+ const thumbprint = crypto.nativeCrypto.createHash("sha1").update(certBuffer).digest("hex");
+ const x5t = Buffer.from(thumbprint, "hex").toString("base64url");
+
+ // JWT Header
+ const header = {
+ alg: "RS256",
+ typ: "JWT",
+ x5t
+ };
+
+ const now = Math.floor(Date.now() / 1000);
+ const payload = {
+ aud: tokenEndpoint,
+ exp: now + 600, // expire the assertion in 10 minutes (not the access access token TTL, but rather the assertion TTL itself)
+ iss: clientId,
+ jti: uuidv4(), // random ID for the JWT
+ nbf: now, // not before the jwt is valid
+ sub: clientId
+ };
+
+ // encode header and payload
+ const encodedHeader = Buffer.from(JSON.stringify(header)).toString("base64url");
+ const encodedPayload = Buffer.from(JSON.stringify(payload)).toString("base64url");
+ const signatureInput = `${encodedHeader}.${encodedPayload}`;
+
+ let keyObject: KeyObject;
+
+ try {
+ if (privateKey.includes("BEGIN PRIVATE KEY")) {
+ keyObject = crypto.nativeCrypto.createPrivateKey(privateKey);
+ } else {
+ // if user forgot to wrap in begin/end private key, decode and use as der format
+ keyObject = crypto.nativeCrypto.createPrivateKey({
+ key: Buffer.from(privateKey, "base64"),
+ format: "der",
+ type: "pkcs8"
+ });
+ }
+ } catch (error) {
+ throw new BadRequestError({
+ message: "Invalid private key format provided. Expected PEM format private key."
+ });
+ }
+
+ // sign with private key
+ const signer = crypto.nativeCrypto.createSign("RSA-SHA256");
+ signer.update(signatureInput);
+ signer.end();
+ const signature = signer.sign(keyObject, "base64url");
+
+ return `${signatureInput}.${signature}`;
+};
diff --git a/docs/images/app-connections/azure/key-vault/create-certificate-method.png b/docs/images/app-connections/azure/key-vault/create-certificate-method.png
new file mode 100644
index 0000000000..0e8c3a0515
Binary files /dev/null and b/docs/images/app-connections/azure/key-vault/create-certificate-method.png differ
diff --git a/docs/integrations/app-connections/azure-key-vault.mdx b/docs/integrations/app-connections/azure-key-vault.mdx
index f4a58223d9..c6751416a8 100644
--- a/docs/integrations/app-connections/azure-key-vault.mdx
+++ b/docs/integrations/app-connections/azure-key-vault.mdx
@@ -3,7 +3,7 @@ title: "Azure Key Vault Connection"
description: "Learn how to configure a Azure Key Vault Connection for Infisical."
---
-Infisical currently only supports two methods for connecting to Azure, which are OAuth and Client Secrets.
+Infisical supports three methods for connecting to Azure Key Vault: OAuth, Client Secret, and Certificate (SPN with certificate).
<Accordion title="Self-Hosted Instance">
Using the Azure Key Vault connection on a self-hosted instance of Infisical requires configuring an application in Azure
@@ -79,6 +79,24 @@ Infisical currently only supports two methods for connecting to Azure, which are
</Steps>
</Accordion>
+<Accordion title="Certificate Authentication">
+ To use certificate authentication, ensure your Azure Service Principal has access to the Azure Key Vault instances you want to use. You'll need a certificate uploaded to the App Registration and the matching private key kept locally.
+
+ **Prerequisites:**
+ - Set up Azure and have an existing Key Vault instance.
+ - The service principal must be granted access to your target Azure Key Vault instance(s) via Access Policies or RBAC (e.g. the **Key Vault Secrets Officer** role).
+ - A certificate (PEM) uploaded to your App Registration and the matching PEM private key.
+
+ <Steps>
+ <Step title="Upload your certificate to your Azure App Registration">
+
+ In the Azure Portal, navigate to your App Registration and open the **Certificates & secrets** section. Choose the **Certificates** tab and press the **Upload certificate** button. Select and upload your public certificate (PEM/CER/CRT).
+
+ You will need both the **certificate body** and the matching **private key** (in PEM format) to configure the connection in Infisical.
+ </Step>
+ </Steps>
+</Accordion>
+
## Setup Azure Connection in Infisical
<Steps>
@@ -123,6 +141,28 @@ Infisical currently only supports two methods for connecting to Azure, which are
</Step>
</Steps>
</Tab>
+ <Tab title="Certificate">
+ <Steps>
+ <Step title="Create Connection">
+ Select the **Certificate** method and fill in the following fields:
+
+ - **Tenant ID** — the Directory (Tenant) ID of your Azure App Registration.
+ - **Client ID** — the Application (Client) ID of your Azure App Registration.
+ - **Certificate** — the PEM-encoded public certificate that was uploaded to the App Registration.
+ - **Private Key** — the PEM-encoded private key matching the certificate above.
+
+ ![Connect via Certificate](/images/app-connections/azure/key-vault/create-certificate-method.png)
+
+ <Note>
+ The private key is never transmitted to Azure; it is only used locally by Infisical to sign the client assertion used to authenticate with Azure.
+ </Note>
+
+ <Note>
+ Automatic Credential Rotation is not available for the Certificate authentication method.
+ </Note>
+ </Step>
+ </Steps>
+ </Tab>
</Tabs>
</Step>
<Step title="Connection Created">
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/AzureKeyVaultSyncOptionsFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/AzureKeyVaultSyncOptionsFields.tsx
index b823fb002c..8e46bcd799 100644
--- a/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/AzureKeyVaultSyncOptionsFields.tsx
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/AzureKeyVaultSyncOptionsFields.tsx
@@ -23,7 +23,7 @@ export const AzureKeyVaultSyncOptionsFields = () => {
onCheckedChange={onChange}
isChecked={value}
>
- <p className="w-64">
+ <p className="w-52">
Disable Certificate Import{" "}
<Tooltip
className="max-w-md"
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/SecretSyncOptionsFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/SecretSyncOptionsFields.tsx
index 7e49b649f1..a246ee9bd5 100644
--- a/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/SecretSyncOptionsFields.tsx
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/SecretSyncOptionsFields.tsx
@@ -307,7 +307,7 @@ export const SecretSyncOptionsFields = ({ hideInitialSync }: Props) => {
onCheckedChange={onChange}
isChecked={value}
>
- <p className="w-44">
+ <p className="w-52">
Disable Secret Deletion{" "}
<Tooltip
className="max-w-md"
diff --git a/frontend/src/helpers/appConnections.ts b/frontend/src/helpers/appConnections.ts
index 189e2f944c..43a9683368 100644
--- a/frontend/src/helpers/appConnections.ts
+++ b/frontend/src/helpers/appConnections.ts
@@ -275,6 +275,7 @@ export const getAppConnectionMethodDetails = (method: TAppConnection["method"])
case AzureDevOpsConnectionMethod.ClientSecret:
return { name: "Client Secret", icon: faKey };
case AzureClientSecretsConnectionMethod.Certificate:
+ case AzureKeyVaultConnectionMethod.Certificate:
return { name: "Certificate", icon: faCertificate };
case DNSMadeEasyConnectionMethod.APIKeySecret:
return { name: "API Key & Secret", icon: faKey };
diff --git a/frontend/src/hooks/api/appConnections/types/azure-key-vault-connection.ts b/frontend/src/hooks/api/appConnections/types/azure-key-vault-connection.ts
index 5cea148fa6..ce69ee66f3 100644
--- a/frontend/src/hooks/api/appConnections/types/azure-key-vault-connection.ts
+++ b/frontend/src/hooks/api/appConnections/types/azure-key-vault-connection.ts
@@ -3,7 +3,8 @@ import { TRootAppConnection } from "@app/hooks/api/appConnections/types/root-con
export enum AzureKeyVaultConnectionMethod {
OAuth = "oauth",
- ClientSecret = "client-secret"
+ ClientSecret = "client-secret",
+ Certificate = "certificate"
}
export type TAzureKeyVaultConnection = TRootAppConnection & { app: AppConnection.AzureKeyVault } & (
@@ -22,4 +23,13 @@ export type TAzureKeyVaultConnection = TRootAppConnection & { app: AppConnection
tenantId: string;
};
}
+ | {
+ method: AzureKeyVaultConnectionMethod.Certificate;
+ credentials: {
+ clientId: string;
+ tenantId: string;
+ certificateBody: string;
+ privateKey: string;
+ };
+ }
);
diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AzureKeyVaultConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AzureKeyVaultConnectionForm.tsx
index a44340f3f3..76b4ba8240 100644
--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AzureKeyVaultConnectionForm.tsx
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AzureKeyVaultConnectionForm.tsx
@@ -5,7 +5,15 @@ import { Controller, FormProvider, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from "zod";
-import { Button, FormControl, Input, ModalClose, Select, SelectItem } from "@app/components/v2";
+import {
+ Button,
+ FormControl,
+ Input,
+ ModalClose,
+ Select,
+ SelectItem,
+ TextArea
+} from "@app/components/v2";
import {
APP_CONNECTION_MAP,
getAppConnectionMethodDetails,
@@ -27,10 +35,13 @@ import {
} from "./GenericAppConnectionFields";
type ClientSecretForm = z.infer<typeof clientSecretSchema>;
+type CertificateForm = z.infer<typeof certificateSchema>;
+
+type TInputFormData = ClientSecretForm | CertificateForm;
type Props = {
appConnection?: TAzureKeyVaultConnection;
- onSubmit: (formData: ClientSecretForm) => Promise<void>;
+ onSubmit: (formData: TInputFormData) => Promise<void>;
projectId: string | undefined | null;
};
@@ -54,7 +65,21 @@ const clientSecretSchema = baseSchema.extend({
})
});
-const formSchema = z.discriminatedUnion("method", [oauthSchema, clientSecretSchema]);
+const certificateSchema = baseSchema.extend({
+ method: z.literal(AzureKeyVaultConnectionMethod.Certificate),
+ credentials: z.object({
+ clientId: z.string().trim().min(1, "Client ID is required"),
+ certificateBody: z.string().trim().min(1, "Certificate is required"),
+ privateKey: z.string().trim().min(1, "Private Key is required"),
+ tenantId: z.string().trim().min(1, "Tenant ID is required")
+ })
+});
+
+const formSchema = z.discriminatedUnion("method", [
+ oauthSchema,
+ clientSecretSchema,
+ certificateSchema
+]);
type FormData = z.infer<typeof formSchema>;
@@ -109,6 +134,20 @@ const getDefaultValues = (appConnection?: TAzureKeyVaultConnection): Partial<For
};
}
break;
+ case AzureKeyVaultConnectionMethod.Certificate:
+ if ("clientId" in credentials && "tenantId" in credentials) {
+ return {
+ ...base,
+ method: AzureKeyVaultConnectionMethod.Certificate,
+ credentials: {
+ clientId: credentials.clientId,
+ tenantId: credentials.tenantId,
+ certificateBody: "",
+ privateKey: ""
+ }
+ };
+ }
+ break;
default:
return base;
}
@@ -164,6 +203,9 @@ export const AzureKeyVaultConnectionForm = ({ appConnection, onSubmit, projectId
case AzureKeyVaultConnectionMethod.ClientSecret:
await onSubmit(formData);
break;
+ case AzureKeyVaultConnectionMethod.Certificate:
+ await onSubmit(formData);
+ break;
default:
throw new Error(`Unhandled Azure Connection method: ${(formData as FormData).method}`);
}
@@ -178,6 +220,9 @@ export const AzureKeyVaultConnectionForm = ({ appConnection, onSubmit, projectId
case AzureKeyVaultConnectionMethod.ClientSecret:
isMissingConfig = false;
break;
+ case AzureKeyVaultConnectionMethod.Certificate:
+ isMissingConfig = false;
+ break;
default:
throw new Error(`Unhandled Azure Connection method: ${selectedMethod}`);
}
@@ -312,6 +357,75 @@ export const AzureKeyVaultConnectionForm = ({ appConnection, onSubmit, projectId
</>
)}
+ {/* Certificate-specific fields */}
+ {selectedMethod === AzureKeyVaultConnectionMethod.Certificate && (
+ <>
+ <Controller
+ name="credentials.tenantId"
+ control={control}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ tooltipText="The Azure Active Directory (Entra ID) Tenant ID."
+ isError={Boolean(error?.message)}
+ label="Tenant ID"
+ errorText={error?.message}
+ >
+ <Input {...field} placeholder="00000000-0000-0000-0000-000000000000" />
+ </FormControl>
+ )}
+ />
+ <Controller
+ name="credentials.clientId"
+ control={control}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ isError={Boolean(error?.message)}
+ label="Client ID"
+ errorText={error?.message}
+ >
+ <Input {...field} placeholder="00000000-0000-0000-0000-000000000000" />
+ </FormControl>
+ )}
+ />
+ <Controller
+ name="credentials.certificateBody"
+ control={control}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ isError={Boolean(error?.message)}
+ label="Certificate"
+ errorText={error?.message}
+ tooltipText="The PEM-encoded public certificate uploaded to your Azure App Registration."
+ >
+ <TextArea
+ {...field}
+ className="h-[6rem] resize-none!"
+ placeholder={"-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----"}
+ />
+ </FormControl>
+ )}
+ />
+ <Controller
+ name="credentials.privateKey"
+ control={control}
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ isError={Boolean(error?.message)}
+ label="Private Key"
+ errorText={error?.message}
+ tooltipText="The PEM-encoded private key matching the certificate. The private key is never transmitted to Azure; it is only used locally to sign the client assertion."
+ >
+ <TextArea
+ {...field}
+ className="h-[6rem] resize-none!"
+ placeholder={"-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----"}
+ />
+ </FormControl>
+ )}
+ />
+ </>
+ )}
+
<div className="mt-8 flex items-center">
<Button
className="mr-4"