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
ldap credential rotation
Matheus Nogueira0d863b826197
diff --git a/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-enums.ts b/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-enums.tsindex bdbec0e302..77e45267d4 100644--- a/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-enums.ts+++ b/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-enums.ts@@ -1,5 +1,6 @@export enum AppConnectionCredentialRotationStrategy {- AzureClientSecret = "azure-client-secret"+ AzureClientSecret = "azure-client-secret",+ LdapPassword = "ldap-password"}export enum AppConnectionCredentialRotationStatus {diff --git a/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-service.ts b/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-service.tsindex e297667167..2a3a17919c 100644--- a/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-service.ts+++ b/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-service.ts@@ -17,6 +17,7 @@ import { TKmsServiceFactory } from "@app/services/kms/kms-service";import { TAppConnection, TAppConnectionRaw } from "../app-connection-types";import { AzureClientSecretsConnectionMethod } from "../azure-client-secrets";import { AzureKeyVaultConnectionMethod } from "../azure-key-vault";+import { LdapConnectionMethod } from "../ldap";import { TAppConnectionCredentialRotationDALFactory } from "./app-connection-credential-rotation-dal";import {AppConnectionCredentialRotationStatus,@@ -44,6 +45,7 @@ import {AzureClientSecretCredentialRotationCredentialsSchema,azureClientSecretRotationProviderFactory} from "./providers/azure-client-secret";+import { LdapCredentialRotationCredentialsSchema, ldapCredentialRotationProviderFactory } from "./providers/ldap";const MAX_GENERATED_CREDENTIALS_LENGTH = 2;@@ -63,6 +65,12 @@ const STRATEGY_MAP: Record<app: AppConnection.AzureClientSecrets,method: AzureClientSecretsConnectionMethod.ClientSecret}+ ],+ [AppConnectionCredentialRotationStrategy.LdapPassword]: [+ {+ app: AppConnection.LDAP,+ method: LdapConnectionMethod.SimpleBind+ }]};@@ -70,7 +78,8 @@ const CREDENTIAL_ROTATION_CREDENTIALS_SCHEMA_MAP: Record<AppConnectionCredentialRotationStrategy,z.ZodSchema<TAppConnectionCredentialCredentials>> = {- [AppConnectionCredentialRotationStrategy.AzureClientSecret]: AzureClientSecretCredentialRotationCredentialsSchema+ [AppConnectionCredentialRotationStrategy.AzureClientSecret]: AzureClientSecretCredentialRotationCredentialsSchema,+ [AppConnectionCredentialRotationStrategy.LdapPassword]: LdapCredentialRotationCredentialsSchema};const CREDENTIAL_ROTATION_PROVIDER_FACTORY_MAP: Record<@@ -78,7 +87,9 @@ const CREDENTIAL_ROTATION_PROVIDER_FACTORY_MAP: Record<TCredentialRotationProviderFactory> = {[AppConnectionCredentialRotationStrategy.AzureClientSecret]:- azureClientSecretRotationProviderFactory as TCredentialRotationProviderFactory+ azureClientSecretRotationProviderFactory as TCredentialRotationProviderFactory,+ [AppConnectionCredentialRotationStrategy.LdapPassword]:+ ldapCredentialRotationProviderFactory as TCredentialRotationProviderFactory};export type TAppConnectionCredentialRotationServiceFactoryDep = {diff --git a/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-types.ts b/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-types.tsindex b226bb2e7d..a75a6da195 100644--- a/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-types.ts+++ b/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-types.ts@@ -8,6 +8,11 @@ import {TAzureClientSecretGeneratedCredential,TAzureClientSecretStrategyConfig} from "./providers/azure-client-secret/azure-client-secret-credential-rotation-types";+import {+ TLdapCredentialRotationCredentials,+ TLdapGeneratedCredential,+ TLdapStrategyConfig+} from "./providers/ldap/ldap-credential-rotation-types";export type TAppConnectionCredentialRotationRaw = TAppConnectionCredentialRotations;@@ -21,13 +26,17 @@ export type TAppConnectionCredentialRotation = Omit<export type TCreateAppConnectionCredentialRotationSchema = z.infer<typeof CreateAppConnectionCredentialRotationSchema>;// Union of all strategy configs — expands as providers are added-export type TAppConnectionCredentialRotationStrategyConfig = TAzureClientSecretStrategyConfig;+export type TAppConnectionCredentialRotationStrategyConfig = TAzureClientSecretStrategyConfig | TLdapStrategyConfig;// Union of all individual generated credential types — expands as providers are added-export type TAppConnectionCredentialRotationGeneratedCredential = TAzureClientSecretGeneratedCredential;+export type TAppConnectionCredentialRotationGeneratedCredential =+ | TAzureClientSecretGeneratedCredential+ | TLdapGeneratedCredential;// Union of all individual credentials types — expands as providers are added-export type TAppConnectionCredentialCredentials = TAzureClientSecretCredentialRotationCredentials;+export type TAppConnectionCredentialCredentials =+ | TAzureClientSecretCredentialRotationCredentials+ | TLdapCredentialRotationCredentials;export type TAppConnectionCredentialRotationGeneratedCredentials =(TAppConnectionCredentialRotationGeneratedCredential | null)[];diff --git a/backend/src/services/app-connection/credential-rotation/providers/azure-client-secret/azure-client-secret-credential-rotation-fns.ts b/backend/src/services/app-connection/credential-rotation/providers/azure-client-secret/azure-client-secret-credential-rotation-fns.tsindex 07877d2f51..5a9a16e34e 100644--- a/backend/src/services/app-connection/credential-rotation/providers/azure-client-secret/azure-client-secret-credential-rotation-fns.ts+++ b/backend/src/services/app-connection/credential-rotation/providers/azure-client-secret/azure-client-secret-credential-rotation-fns.ts@@ -424,7 +424,8 @@ export const azureClientSecretRotationProviderFactory: TCredentialRotationProvidTAzureClientSecretStrategyConfig,TAzureClientSecretGeneratedCredential> = async (strategyConfig, credentials, rotationInterval, activeIndex) => {- const accessToken = await getGraphApiToken(credentials);+ const azureCredentials = credentials as TAzureClientSecretCredentialRotationCredentials;+ const accessToken = await getGraphApiToken(azureCredentials);return createAzureClientSecret({accessToken,@@ -448,9 +449,10 @@ export const azureClientSecretRotationProviderFactory: TCredentialRotationProvid> = async (inactiveCredential, strategyConfig, credentials) => {if (!inactiveCredential?.keyId) return;- const accessToken = await getGraphApiToken(credentials);+ const azureCredentials = credentials as TAzureClientSecretCredentialRotationCredentials;+ const accessToken = await getGraphApiToken(azureCredentials);- await revokeAzureClientSecret(inactiveCredential.keyId, strategyConfig, credentials, accessToken);+ await revokeAzureClientSecret(inactiveCredential.keyId, strategyConfig, azureCredentials, accessToken);};return {diff --git a/backend/src/services/app-connection/credential-rotation/providers/index.ts b/backend/src/services/app-connection/credential-rotation/providers/index.tsindex b52db11506..34810ff686 100644--- a/backend/src/services/app-connection/credential-rotation/providers/index.ts+++ b/backend/src/services/app-connection/credential-rotation/providers/index.ts@@ -1 +1,2 @@export * from "./azure-client-secret";+export * from "./ldap";diff --git a/backend/src/services/app-connection/credential-rotation/providers/ldap/index.ts b/backend/src/services/app-connection/credential-rotation/providers/ldap/index.tsnew file mode 100644index 0000000000..a720f03ebe--- /dev/null+++ b/backend/src/services/app-connection/credential-rotation/providers/ldap/index.ts@@ -0,0 +1,2 @@+export * from "./ldap-credential-rotation-fns";+export * from "./ldap-credential-rotation-types";diff --git a/backend/src/services/app-connection/credential-rotation/providers/ldap/ldap-credential-rotation-fns.ts b/backend/src/services/app-connection/credential-rotation/providers/ldap/ldap-credential-rotation-fns.tsnew file mode 100644index 0000000000..9d279fc599--- /dev/null+++ b/backend/src/services/app-connection/credential-rotation/providers/ldap/ldap-credential-rotation-fns.ts@@ -0,0 +1,222 @@+import ldap from "@infisical/ldapjs";++import { generatePassword } from "@app/ee/services/secret-rotation-v2/shared/utils";+import { BadRequestError } from "@app/lib/errors";+import { logger } from "@app/lib/logger";+import { DistinguishedNameRegex } from "@app/lib/regex";+import { getLdapConnectionClient } from "@app/services/app-connection/ldap";+import { LdapConnectionMethod, LdapProvider } from "@app/services/app-connection/ldap/ldap-connection-enums";++import {+ TCredentialRotationCreateCredential,+ TCredentialRotationIssueInitialCredentials,+ TCredentialRotationMergeCredentials,+ TCredentialRotationProviderFactory,+ TCredentialRotationRevokeCredential,+ TCredentialRotationValidateMethod+} from "../../app-connection-credential-rotation-types";+import {+ TLdapCredentialRotationCredentials,+ TLdapGeneratedCredential,+ TLdapStrategyConfig+} from "./ldap-credential-rotation-types";++const getEncodedPassword = (password: string) => Buffer.from(`"${password}"`, "utf16le");++const getDN = async (dn: string, client: ldap.Client): Promise<string> => {+ if (DistinguishedNameRegex.test(dn)) return dn;++ const opts: ldap.SearchOptions = {+ filter: `(userPrincipalName=${dn})`,+ scope: "sub",+ attributes: ["dn"]+ };++ const base = dn+ .split("@")[1]+ .split(".")+ .map((dc) => `dc=${dc}`)+ .join(",");++ return new Promise((resolve, reject) => {+ client.search(base, opts, (err, res) => {+ if (err) {+ reject(new Error(`Provider Resolve DN Error: ${err.message}`));+ return;+ }++ let userDn: string | null = null;++ res.on("searchEntry", (entry) => {+ userDn = entry.objectName;+ });++ res.on("error", (error) => {+ reject(new Error(`Provider Resolve DN Error: ${error.message}`));+ });++ res.on("end", () => {+ if (userDn) {+ resolve(userDn);+ } else {+ reject(new Error(`Unable to resolve DN for ${dn}.`));+ }+ });+ });+ });+};++const buildPasswordChanges = (provider: LdapProvider, currentPassword: string, newPassword: string): ldap.Change[] => {+ switch (provider) {+ case LdapProvider.ActiveDirectory: {+ const currentEncoded = getEncodedPassword(currentPassword);+ const newEncoded = getEncodedPassword(newPassword);++ return [+ new ldap.Change({+ operation: "delete",+ modification: {+ type: "unicodePwd",+ values: [currentEncoded]+ }+ }),+ new ldap.Change({+ operation: "add",+ modification: {+ type: "unicodePwd",+ values: [newEncoded]+ }+ })+ ];+ }+ default:+ throw new BadRequestError({ message: `Unsupported LDAP provider: ${provider as string}` });+ }+};++const modifyLdapPassword = async (+ credentials: TLdapCredentialRotationCredentials,+ newPassword: string+): Promise<void> => {+ if (!credentials.url.startsWith("ldaps")) {+ throw new BadRequestError({ message: "Credential rotation requires an LDAPS connection" });+ }++ const client = await getLdapConnectionClient(credentials);++ try {+ const userDn = await getDN(credentials.dn, client);++ const changes = buildPasswordChanges(credentials.provider, credentials.password, newPassword);++ await new Promise<void>((resolve, reject) => {+ client.modify(userDn, changes, (err) => {+ if (err) {+ reject(new Error(`Provider Modify Error: ${err.message}`));+ } else {+ resolve();+ }+ });+ });+ } finally {+ client.destroy();+ }+};++const verifyLdapCredentials = async (credentials: TLdapCredentialRotationCredentials): Promise<void> => {+ const client = await getLdapConnectionClient(credentials);+ client.destroy();+};++export const ldapCredentialRotationProviderFactory: TCredentialRotationProviderFactory<+ TLdapStrategyConfig,+ TLdapGeneratedCredential+> = (connection) => {+ const validateConnectionMethod: TCredentialRotationValidateMethod = (method) => {+ if (method !== LdapConnectionMethod.SimpleBind) {+ throw new BadRequestError({+ message: "Credential rotation is only supported for Simple Bind auth method"+ });+ }+ };++ const issueInitialCredentials: TCredentialRotationIssueInitialCredentials<+ TLdapStrategyConfig,+ TLdapGeneratedCredential+ > = async (credentials) => {+ const ldapCredentials = credentials as TLdapCredentialRotationCredentials;++ const strategyConfig: TLdapStrategyConfig = { provider: ldapCredentials.provider };++ const newPassword = generatePassword();++ await modifyLdapPassword(ldapCredentials, newPassword);++ const updatedCredentials = {+ ...ldapCredentials,+ password: newPassword+ };++ await verifyLdapCredentials(updatedCredentials);++ logger.info(`credentialRotation: LDAP initial credential rotation succeeded [connection=${connection.name}]`);++ const now = new Date().toISOString();+ const generatedCredential: TLdapGeneratedCredential = {+ dn: ldapCredentials.dn,+ password: newPassword,+ createdAt: now+ };++ return {+ strategyConfig,+ generatedCredentials: [generatedCredential, null],+ updatedCredentials+ };+ };++ const createCredential: TCredentialRotationCreateCredential<TLdapStrategyConfig, TLdapGeneratedCredential> = async (+ _strategyConfig,+ credentials+ ) => {+ const ldapCredentials = credentials as TLdapCredentialRotationCredentials;++ const newPassword = generatePassword();++ await modifyLdapPassword(ldapCredentials, newPassword);++ const updatedCredentials = { ...ldapCredentials, password: newPassword };+ await verifyLdapCredentials(updatedCredentials);++ logger.info(`credentialRotation: LDAP credential rotation succeeded [connection=${connection.name}]`);++ return {+ dn: ldapCredentials.dn,+ password: newPassword,+ createdAt: new Date().toISOString()+ };+ };++ const mergeCredentials: TCredentialRotationMergeCredentials<TLdapGeneratedCredential> = (+ currentCredentials,+ newCredential+ ) => {+ return { ...currentCredentials, password: newCredential.password };+ };++ const revokeCredential: TCredentialRotationRevokeCredential<+ TLdapStrategyConfig,+ TLdapGeneratedCredential+ > = async () => {+ // LDAP accounts have a single password. When a new password is set,+ // the old one is immediately invalid. No explicit revocation needed.+ };++ return {+ validateConnectionMethod,+ issueInitialCredentials,+ createCredential,+ mergeCredentials,+ revokeCredential+ };+};diff --git a/backend/src/services/app-connection/credential-rotation/providers/ldap/ldap-credential-rotation-types.ts b/backend/src/services/app-connection/credential-rotation/providers/ldap/ldap-credential-rotation-types.tsnew file mode 100644index 0000000000..ebc7e09dfa--- /dev/null+++ b/backend/src/services/app-connection/credential-rotation/providers/ldap/ldap-credential-rotation-types.ts@@ -0,0 +1,18 @@+import { z } from "zod";++import { LdapProvider } from "@app/services/app-connection/ldap/ldap-connection-enums";+import { LdapConnectionSimpleBindCredentialsSchema } from "@app/services/app-connection/ldap/ldap-connection-schemas";++export type TLdapStrategyConfig = {+ provider: LdapProvider;+};++export type TLdapGeneratedCredential = {+ dn: string;+ password: string;+ createdAt: string;+};++export const LdapCredentialRotationCredentialsSchema = LdapConnectionSimpleBindCredentialsSchema;++export type TLdapCredentialRotationCredentials = z.infer<typeof LdapCredentialRotationCredentialsSchema>;diff --git a/backend/src/services/app-connection/ldap/ldap-connection-schemas.ts b/backend/src/services/app-connection/ldap/ldap-connection-schemas.tsindex 54a6335f49..dab2eb0c45 100644--- a/backend/src/services/app-connection/ldap/ldap-connection-schemas.ts+++ b/backend/src/services/app-connection/ldap/ldap-connection-schemas.ts@@ -76,7 +76,8 @@ export const ValidateLdapConnectionCredentialsSchema = z.discriminatedUnion("metexport const CreateLdapConnectionSchema = ValidateLdapConnectionCredentialsSchema.and(GenericCreateAppConnectionFieldsSchema(AppConnection.LDAP, {- supportsGateways: true+ supportsGateways: true,+ supportsCredentialRotation: true}));@@ -88,7 +89,8 @@ export const UpdateLdapConnectionSchema = z}).and(GenericUpdateAppConnectionFieldsSchema(AppConnection.LDAP, {- supportsGateways: true+ supportsGateways: true,+ supportsCredentialRotation: true}));diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/LdapConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/LdapConnectionForm.tsxindex 1f0c0264bd..e823055b33 100644--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/LdapConnectionForm.tsx+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/LdapConnectionForm.tsx@@ -42,6 +42,7 @@ import {} from "@app/hooks/api/appConnections";import { AppConnection } from "@app/hooks/api/appConnections/enums";+import { CredentialRotationForm } from "./shared/CredentialRotationForm";import { AppConnectionFormFooter } from "./AppConnectionFormFooter";import {genericAppConnectionFieldsSchema,@@ -97,20 +98,34 @@ export const LdapConnectionForm = ({ appConnection, onSubmit }: Props) => {const form = useForm<FormData>({resolver: zodResolver(formSchema),- defaultValues: appConnection ?? {- app: AppConnection.LDAP,- method: LdapConnectionMethod.SimpleBind,- gatewayId: null,- gatewayPoolId: null,- credentials: {- provider: LdapConnectionProvider.ActiveDirectory,- url: "",- dn: "",- password: "",- sslRejectUnauthorized: true,- sslCertificate: undefined- }- }+ defaultValues: appConnection+ ? {+ ...appConnection,+ isAutoRotationEnabled: appConnection.isAutoRotationEnabled ?? false,+ rotation: appConnection.rotation ?? {+ rotationInterval: 30,+ rotateAtUtc: { hours: 0, minutes: 0 }+ }+ }+ : {+ app: AppConnection.LDAP,+ method: LdapConnectionMethod.SimpleBind,+ gatewayId: null,+ gatewayPoolId: null,+ isAutoRotationEnabled: false,+ rotation: {+ rotationInterval: 30,+ rotateAtUtc: { hours: 0, minutes: 0 }+ },+ credentials: {+ provider: LdapConnectionProvider.ActiveDirectory,+ url: "",+ dn: "",+ password: "",+ sslRejectUnauthorized: true,+ sslCertificate: undefined+ }+ }});const { handleSubmit, control, setValue, watch } = form;@@ -337,6 +352,7 @@ export const LdapConnectionForm = ({ appConnection, onSubmit }: Props) => {/></TabsContent></Tabs>+ <CredentialRotationForm /><AppConnectionFormFootersubmitLabel={isUpdate