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
checkpoint
Daniel Hougaard574d84eecb27
diff --git a/backend/src/ee/services/secret-rotation-v2/auth0-client-secret/auth0-client-secret-rotation-fns.ts b/backend/src/ee/services/secret-rotation-v2/auth0-client-secret/auth0-client-secret-rotation-fns.tsindex 6debd2402a..3a4c26211a 100644--- a/backend/src/ee/services/secret-rotation-v2/auth0-client-secret/auth0-client-secret-rotation-fns.ts+++ b/backend/src/ee/services/secret-rotation-v2/auth0-client-secret/auth0-client-secret-rotation-fns.ts@@ -11,7 +11,7 @@ import {} from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-types";import { request } from "@app/lib/config/request";import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";-import { getAuth0ConnectionAccessToken } from "@app/services/app-connection/auth0";+import { getAuth0ConnectionAccessToken } from "@app/services/app-connection/auth0/auth0-connection-fns";import { generatePassword } from "../shared/utils";diff --git a/backend/src/ee/services/secret-rotation-v2/azure-client-secret/azure-client-secret-rotation-fns.ts b/backend/src/ee/services/secret-rotation-v2/azure-client-secret/azure-client-secret-rotation-fns.tsindex 84fcfdd90d..183258fc83 100644--- a/backend/src/ee/services/secret-rotation-v2/azure-client-secret/azure-client-secret-rotation-fns.ts+++ b/backend/src/ee/services/secret-rotation-v2/azure-client-secret/azure-client-secret-rotation-fns.ts@@ -15,7 +15,7 @@ import {} from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-types";import { request } from "@app/lib/config/request";import { BadRequestError } from "@app/lib/errors";-import { getAzureConnectionAccessToken } from "@app/services/app-connection/azure-client-secrets";+import { getAzureConnectionAccessToken } from "@app/services/app-connection/azure-client-secrets/azure-client-secrets-connection-fns";const GRAPH_API_BASE = "https://graph.microsoft.com/v1.0";diff --git a/backend/src/ee/services/secret-scanning-v2/gitlab/gitlab-secret-scanning-factory.ts b/backend/src/ee/services/secret-scanning-v2/gitlab/gitlab-secret-scanning-factory.tsindex 6ea294c1fc..a18359073b 100644--- a/backend/src/ee/services/secret-scanning-v2/gitlab/gitlab-secret-scanning-factory.ts+++ b/backend/src/ee/services/secret-scanning-v2/gitlab/gitlab-secret-scanning-factory.ts@@ -28,11 +28,11 @@ import { BadRequestError } from "@app/lib/errors";import { titleCaseToCamelCase } from "@app/lib/fn";import { alphaNumericNanoId } from "@app/lib/nanoid";import { GitLabProjectRegex } from "@app/lib/regex";+import { TGitLabConnection } from "@app/services/app-connection/gitlab";import {getGitLabConnectionClient,- getGitLabInstanceUrl,- TGitLabConnection-} from "@app/services/app-connection/gitlab";+ getGitLabInstanceUrl+} from "@app/services/app-connection/gitlab/gitlab-connection-fns";import { GitLabDataSourceScope } from "./gitlab-secret-scanning-enums";import {diff --git a/backend/src/services/app-connection/app-connection-dal.ts b/backend/src/services/app-connection/app-connection-dal.tsindex 10b6a62742..0f375e531e 100644--- a/backend/src/services/app-connection/app-connection-dal.ts+++ b/backend/src/services/app-connection/app-connection-dal.ts@@ -5,6 +5,9 @@ import { TableName, TAppConnections } from "@app/db/schemas";import { buildFindFilter, ormify, prependTableNameToFindFilter, selectAllTableCols } from "@app/lib/knex";import { transformUsageToProjects } from "@app/services/app-connection/app-connection-fns";+import { TAppConnection } from "./app-connection-types";+import { AppConnectionCredentialRotationRotateAtUtcSchema } from "./credential-rotation/app-connection-credential-rotation-schemas";+export type TAppConnectionDALFactory = ReturnType<typeof appConnectionDALFactory>;type AppConnectionFindFilter = Parameters<typeof buildFindFilter<TAppConnections>>[0];@@ -15,7 +18,16 @@ export const appConnectionDALFactory = (db: TDbClient) => {const findWithProjectDetails = async (filter: AppConnectionFindFilter, tx?: Knex) => {const query = (tx || db.replicaNode())(TableName.AppConnection).leftJoin(TableName.Project, `${TableName.AppConnection}.projectId`, `${TableName.Project}.id`)+ .leftJoin(+ TableName.AppConnectionCredentialRotation,+ `${TableName.AppConnection}.id`,+ `${TableName.AppConnectionCredentialRotation}.connectionId`+ ).select(selectAllTableCols(TableName.AppConnection))+ .select(+ db.ref("rotationInterval").withSchema(TableName.AppConnectionCredentialRotation).as("rotationInterval"),+ db.ref("rotateAtUtc").withSchema(TableName.AppConnectionCredentialRotation).as("rotateAtUtc")+ ).select(// projectdb.ref("name").withSchema(TableName.Project).as("projectName"),@@ -30,18 +42,34 @@ export const appConnectionDALFactory = (db: TDbClient) => {const connections = await query;- return connections.map(({ projectName, projectSlug, projectType, projectId, ...connection }) => ({- ...connection,- projectId,- project: projectId- ? {- name: projectName,- type: projectType,- slug: projectSlug,- id: projectId- }- : null- }));+ return connections.map(({ projectName, projectSlug, projectType, projectId, ...connection }) => {+ let rotation: TAppConnection["rotation"] | undefined;++ if (connection.isAutoRotationEnabled && connection.rotateAtUtc) {+ const parsedRotationAtUtc = AppConnectionCredentialRotationRotateAtUtcSchema.safeParse(connection.rotateAtUtc);++ if (parsedRotationAtUtc.success) {+ rotation = {+ rotationInterval: connection.rotationInterval,+ rotateAtUtc: parsedRotationAtUtc.data+ };+ }+ }++ return {+ ...connection,+ rotation,+ projectId,+ project: projectId+ ? {+ name: projectName,+ type: projectType,+ slug: projectSlug,+ id: projectId+ }+ : null+ };+ });};const findAppConnectionUsageById = async (connectionId: string, tx?: Knex) => {diff --git a/backend/src/services/app-connection/app-connection-fns.ts b/backend/src/services/app-connection/app-connection-fns.tsindex 86c23acdba..45a71de67e 100644--- a/backend/src/services/app-connection/app-connection-fns.ts+++ b/backend/src/services/app-connection/app-connection-fns.ts@@ -1,5 +1,4 @@-import { ProjectType } from "@app/db/schemas";-import { TAppConnections } from "@app/db/schemas/app-connections";+import { ProjectType, TAppConnections } from "@app/db/schemas";import {ChefConnectionMethod,getChefConnectionListItem,@@ -39,7 +38,8 @@ import {TAppConnectionCredentialsValidator,TAppConnectionTransitionCredentialsToPlatform} from "./app-connection-types";-import { Auth0ConnectionMethod, getAuth0ConnectionListItem, validateAuth0ConnectionCredentials } from "./auth0";+import { Auth0ConnectionMethod } from "./auth0";+import { getAuth0ConnectionListItem, validateAuth0ConnectionCredentials } from "./auth0/auth0-connection-fns";import { AwsConnectionMethod, getAwsConnectionListItem, validateAwsConnectionCredentials } from "./aws";import { AzureADCSConnectionMethod } from "./azure-adcs";import {@@ -51,27 +51,28 @@ import {getAzureAppConfigurationConnectionListItem,validateAzureAppConfigurationConnectionCredentials} from "./azure-app-configuration";+import { AzureClientSecretsConnectionMethod } from "./azure-client-secrets";import {- AzureClientSecretsConnectionMethod,getAzureClientSecretsConnectionListItem,validateAzureClientSecretsConnectionCredentials-} from "./azure-client-secrets";+} from "./azure-client-secrets/azure-client-secrets-connection-fns";import { AzureDevOpsConnectionMethod } from "./azure-devops/azure-devops-enums";import {getAzureDevopsConnectionListItem,validateAzureDevOpsConnectionCredentials} from "./azure-devops/azure-devops-fns";+import { AzureKeyVaultConnectionMethod } from "./azure-key-vault";import {- AzureKeyVaultConnectionMethod,getAzureKeyVaultConnectionListItem,validateAzureKeyVaultConnectionCredentials-} from "./azure-key-vault";+} from "./azure-key-vault/azure-key-vault-connection-fns";import {BitbucketConnectionMethod,getBitbucketConnectionListItem,validateBitbucketConnectionCredentials} from "./bitbucket";-import { CamundaConnectionMethod, getCamundaConnectionListItem, validateCamundaConnectionCredentials } from "./camunda";+import { CamundaConnectionMethod } from "./camunda";+import { getCamundaConnectionListItem, validateCamundaConnectionCredentials } from "./camunda/camunda-connection-fns";import { ChecklyConnectionMethod, getChecklyConnectionListItem, validateChecklyConnectionCredentials } from "./checkly";import {CircleCIConnectionMethod,@@ -83,11 +84,11 @@ import {getCloudflareConnectionListItem,validateCloudflareConnectionCredentials} from "./cloudflare/cloudflare-connection-fns";+import { DatabricksConnectionMethod } from "./databricks";import {- DatabricksConnectionMethod,getDatabricksConnectionListItem,validateDatabricksConnectionCredentials-} from "./databricks";+} from "./databricks/databricks-connection-fns";import { DbtConnectionMethod, getDbtConnectionListItem, validateDbtConnectionCredentials } from "./dbt";import {DigitalOceanConnectionMethod,@@ -107,13 +108,15 @@ import {GitHubRadarConnectionMethod,validateGitHubRadarConnectionCredentials} from "./github-radar";-import { getGitLabConnectionListItem, GitLabConnectionMethod, validateGitLabConnectionCredentials } from "./gitlab";+import { GitLabConnectionMethod } from "./gitlab";+import { getGitLabConnectionListItem, validateGitLabConnectionCredentials } from "./gitlab/gitlab-connection-fns";import {getHCVaultConnectionListItem,HCVaultConnectionMethod,validateHCVaultConnectionCredentials} from "./hc-vault";-import { getHerokuConnectionListItem, HerokuConnectionMethod, validateHerokuConnectionCredentials } from "./heroku";+import { HerokuConnectionMethod } from "./heroku";+import { getHerokuConnectionListItem, validateHerokuConnectionCredentials } from "./heroku/heroku-connection-fns";import {getHumanitecConnectionListItem,HumanitecConnectionMethod,@@ -482,11 +485,20 @@ export const getAppConnectionMethodName = (method: TAppConnection["method"]) =>};export const decryptAppConnection = async (- appConnection: TAppConnections,+ appConnection: TAppConnections & {+ rotation?: { rotationInterval: number; rotateAtUtc: { hours: number; minutes: number } };+ project?: { name: string; id: string; type: string; slug: string } | null;+ },kmsService: TAppConnectionServiceFactoryDep["kmsService"]) => {return {...appConnection,+ rotation: appConnection.rotation+ ? {+ rotationInterval: appConnection.rotation.rotationInterval,+ rotateAtUtc: appConnection.rotation.rotateAtUtc+ }+ : undefined,credentials: await decryptAppConnectionCredentials({encryptedCredentials: appConnection.encryptedCredentials,orgId: appConnection.orgId,diff --git a/backend/src/services/app-connection/app-connection-schemas.ts b/backend/src/services/app-connection/app-connection-schemas.tsindex 3053ae9d34..3b1dd78172 100644--- a/backend/src/services/app-connection/app-connection-schemas.ts+++ b/backend/src/services/app-connection/app-connection-schemas.ts@@ -14,6 +14,16 @@ export const BaseAppConnectionSchema = AppConnectionsSchema.omit({app: true,method: true}).extend({+ rotation: z+ .object({+ rotationInterval: z.number(),+ rotateAtUtc: z.object({+ hours: z.number(),+ minutes: z.number()+ })+ })+ .optional(),+credentialsHash: z.string().optional(),project: z.object({diff --git a/backend/src/services/app-connection/app-connection-types.ts b/backend/src/services/app-connection/app-connection-types.tsindex d43823b26b..46bb4b2ee6 100644--- a/backend/src/services/app-connection/app-connection-types.ts+++ b/backend/src/services/app-connection/app-connection-types.ts@@ -349,6 +349,10 @@ export type TAppConnection = { id: string } & (export type TAppConnectionRaw = NonNullable<Awaited<ReturnType<TAppConnectionDALFactory["findById"]>>>;+export type TAppConnectionRawWithMetadata = Awaited<+ ReturnType<TAppConnectionDALFactory["findWithProjectDetails"]>+>[number];+export type TSqlConnection = TPostgresConnection | TMsSqlConnection | TMySqlConnection | TOracleDBConnection;export type TAppConnectionInput = { id: string } & (diff --git a/backend/src/services/app-connection/auth0/index.ts b/backend/src/services/app-connection/auth0/index.tsindex 310ae3ea89..6a4fbcfcfa 100644--- a/backend/src/services/app-connection/auth0/index.ts+++ b/backend/src/services/app-connection/auth0/index.ts@@ -1,4 +1,3 @@export * from "./auth0-connection-enums";-export * from "./auth0-connection-fns";export * from "./auth0-connection-schemas";export * from "./auth0-connection-types";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.tsindex 00515c49ad..7916ac92db 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@@ -113,38 +113,6 @@ export const getAzureClientSecretsConnectionListItem = () => {};};-const getAzureConnectionApplicationObjectId = async (- connectionId: string,- appConnectionDAL: Pick<TAppConnectionDALFactory, "findById">,- kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">-) => {- const appConnection = await appConnectionDAL.findById(connectionId);- if (!appConnection) {- throw new NotFoundError({ message: `Connection with ID '${connectionId}' not found` });- }-- if (appConnection.method !== AzureClientSecretsConnectionMethod.ClientSecret) {- return null;- }-- const credentials = (await decryptAppConnectionCredentials({- orgId: appConnection.orgId,- kmsService,- projectId: appConnection.projectId,- encryptedCredentials: appConnection.encryptedCredentials- })) as TAzureClientSecretsConnectionClientSecretCredentials;-- if (!credentials.applicationObjectId) {- // then we need to make an api call to get it- const { data } = await request.get<{ value: { appId: string }[] }>(- `https://graph.microsoft.com/v1.0/applications?$filter=appId eq '${credentials.clientId}'`- );- return data.value[0].appId;- }-- return credentials.applicationObjectId;-};-export const getAzureConnectionAccessToken = async (connectionId: string,appConnectionDAL: Pick<TAppConnectionDALFactory, "findById" | "updateById">,diff --git a/backend/src/services/app-connection/azure-client-secrets/index.ts b/backend/src/services/app-connection/azure-client-secrets/index.tsindex 60177973eb..e991414ccf 100644--- a/backend/src/services/app-connection/azure-client-secrets/index.ts+++ b/backend/src/services/app-connection/azure-client-secrets/index.ts@@ -1,4 +1,3 @@export * from "./azure-client-secrets-connection-enums";-export * from "./azure-client-secrets-connection-fns";export * from "./azure-client-secrets-connection-schemas";export * from "./azure-client-secrets-connection-types";diff --git a/backend/src/services/app-connection/azure-key-vault/index.ts b/backend/src/services/app-connection/azure-key-vault/index.tsindex b80b07c17a..33bc16d5c2 100644--- a/backend/src/services/app-connection/azure-key-vault/index.ts+++ b/backend/src/services/app-connection/azure-key-vault/index.ts@@ -1,4 +1,3 @@export * from "./azure-key-vault-connection-enums";-export * from "./azure-key-vault-connection-fns";export * from "./azure-key-vault-connection-schemas";export * from "./azure-key-vault-connection-types";diff --git a/backend/src/services/app-connection/camunda/index.ts b/backend/src/services/app-connection/camunda/index.tsindex 4458717248..ece911489e 100644--- a/backend/src/services/app-connection/camunda/index.ts+++ b/backend/src/services/app-connection/camunda/index.ts@@ -1,4 +1,3 @@export * from "./camunda-connection-enums";-export * from "./camunda-connection-fns";export * from "./camunda-connection-schema";export * from "./camunda-connection-types";diff --git a/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-schemas.ts b/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-schemas.tsindex 800b5e2e17..8f0c6f2886 100644--- a/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-schemas.ts+++ b/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-schemas.ts@@ -1,13 +1,13 @@import { z } from "zod";-import { AppConnectionCredentialRotationStatus } from "./app-connection-credential-rotation-enums";+export const AppConnectionCredentialRotationRotateAtUtcSchema = z.object({+ hours: z.number().int().min(0).max(23),+ minutes: z.number().int().min(0).max(59)+});export const CreateAppConnectionCredentialRotationSchema = z.object({rotationInterval: z.number().int().min(1).max(365),- rotateAtUtc: z.object({- hours: z.number().int().min(0).max(23),- minutes: z.number().int().min(0).max(59)- })+ rotateAtUtc: AppConnectionCredentialRotationRotateAtUtcSchema});export const UpdateAppConnectionCredentialRotationSchema = z.object({@@ -20,23 +20,3 @@ export const UpdateAppConnectionCredentialRotationSchema = z.object({.optional(),isAutoRotationEnabled: z.boolean().optional()});--export const SanitizedAppConnectionCredentialRotationSchema = z.object({- id: z.string().uuid(),- connectionId: z.string().uuid(),- strategy: z.string(),- rotationInterval: z.number(),- rotateAtUtc: z.object({- hours: z.number(),- minutes: z.number()- }),- rotationStatus: z.nativeEnum(AppConnectionCredentialRotationStatus),- lastRotationAttemptedAt: z.date().nullable(),- lastRotatedAt: z.date().nullable(),- lastRotationMessage: z.string().nullable(),- lastRotationJobId: z.string().nullable(),- nextRotationAt: z.date().nullable(),- activeIndex: z.number(),- createdAt: z.date(),- updatedAt: z.date()-});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 7137b2d789..ca15d3acea 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@@ -1,4 +1,5 @@import { Knex } from "knex";+import { z } from "zod";import { TKeyStoreFactory } from "@app/keystore/keystore";import { BadRequestError, NotFoundError } from "@app/lib/errors";@@ -14,6 +15,7 @@ import {import { TKmsServiceFactory } from "@app/services/kms/kms-service";import { TAppConnection } from "../app-connection-types";+import { AzureKeyVaultConnectionMethod } from "../azure-key-vault";import { TAppConnectionCredentialRotationDALFactory } from "./app-connection-credential-rotation-dal";import {AppConnectionCredentialRotationStatus,@@ -30,22 +32,46 @@ import {parseRotationErrorMessage} from "./app-connection-credential-rotation-fns";import {+ TAppConnectionCredentialCredentials,TAppConnectionCredentialRotationStrategyConfig,TCreateAppConnectionCredentialRotationDTO,- TCredentialRotationProvider,+ TCredentialRotationProviderFactory,TTriggerAppConnectionCredentialRotationDTO,TUpdateAppConnectionCredentialRotationDTO} from "./app-connection-credential-rotation-types";-import { azureClientSecretRotationProvider } from "./providers/azure-client-secret-credential-rotation";+import {+ AzureClientSecretCredentialRotationCredentialsSchema,+ azureClientSecretRotationProviderFactory+} from "./providers/azure-client-secret";const MAX_GENERATED_CREDENTIALS_LENGTH = 2;-const STRATEGY_MAP: Record<string, AppConnectionCredentialRotationStrategy> = {- [AppConnection.AzureKeyVault]: AppConnectionCredentialRotationStrategy.AzureClientSecret+const STRATEGY_MAP: Record<+ AppConnectionCredentialRotationStrategy,+ {+ app: TAppConnection["app"]; // azure-key-vault+ method: TAppConnection["method"]; // client-secret+ }+> = {+ [AppConnectionCredentialRotationStrategy.AzureClientSecret]: {+ app: AppConnection.AzureKeyVault,+ method: AzureKeyVaultConnectionMethod.ClientSecret+ }+};++const CREDENTIAL_ROTATION_CREDENTIALS_SCHEMA_MAP: Record<+ AppConnectionCredentialRotationStrategy,+ z.ZodSchema<TAppConnectionCredentialCredentials>+> = {+ [AppConnectionCredentialRotationStrategy.AzureClientSecret]: AzureClientSecretCredentialRotationCredentialsSchema};-const CREDENTIAL_ROTATION_PROVIDER_MAP: Record<AppConnectionCredentialRotationStrategy, TCredentialRotationProvider> = {- [AppConnectionCredentialRotationStrategy.AzureClientSecret]: azureClientSecretRotationProvider+const CREDENTIAL_ROTATION_PROVIDER_FACTORY_MAP: Record<+ AppConnectionCredentialRotationStrategy,+ TCredentialRotationProviderFactory+> = {+ [AppConnectionCredentialRotationStrategy.AzureClientSecret]:+ azureClientSecretRotationProviderFactory as TCredentialRotationProviderFactory};export type TAppConnectionCredentialRotationServiceFactoryDep = {@@ -114,22 +140,25 @@ export const appConnectionCredentialRotationServiceFactory = ({const connection = await appConnectionDAL.findById(connectionId, tx);if (!connection) throw new NotFoundError({ message: `Connection ${connectionId} not found` });- // Auto-infer strategy from connection type- const strategy = STRATEGY_MAP[connection.app];+ const strategy = Object.values(AppConnectionCredentialRotationStrategy).find(+ (s) => STRATEGY_MAP[s].app === connection.app && STRATEGY_MAP[s].method === connection.method+ );+if (!strategy) {- throw new BadRequestError({ message: `Credential rotation is not supported for ${connection.app} connections` });+ throw new BadRequestError({+ message: `Credential rotation is not supported for ${connection.app} connections with ${connection.method} method`+ });}- const provider = CREDENTIAL_ROTATION_PROVIDER_MAP[strategy];+ const provider = CREDENTIAL_ROTATION_PROVIDER_FACTORY_MAP[strategy](connection);+provider.validateConnectionMethod(connection.method);- // Check if rotation config already existsconst existingRotation = await appConnectionCredentialRotationDAL.findByConnectionId(connectionId, tx);if (existingRotation) {throw new BadRequestError({ message: "Credential rotation is already configured for this connection" });}- // Get the connection's own credentials for self-rotationconst credentials = await getConnectionClientCredentials(connection);const { strategyConfig, generatedCredentials, updatedCredentials } = await provider.issueInitialCredentials(@@ -305,8 +334,8 @@ export const appConnectionCredentialRotationServiceFactory = ({};/**- * Core rotation logic — called by the queue worker.- * Uses two-credential self-rotation pattern.+ * Core rotation logic. called by the queue worker+ * twoo credential self-rotation pattern*/const rotateCredentials = async (rotationId: string,@@ -360,15 +389,31 @@ export const appConnectionCredentialRotationServiceFactory = ({kmsService});- const provider = CREDENTIAL_ROTATION_PROVIDER_MAP[strategy as AppConnectionCredentialRotationStrategy];+ const provider =+ CREDENTIAL_ROTATION_PROVIDER_FACTORY_MAP[strategy as AppConnectionCredentialRotationStrategy](connection);// Two-credential rotation: create-first, revoke-after.// This ordering ensures that if create fails, we still have 2 valid secrets.const inactiveIndex = (activeIndex + 1) % MAX_GENERATED_CREDENTIALS_LENGTH;const inactiveCredential = generatedCredentials[inactiveIndex];+ const credentialsSchema =+ CREDENTIAL_ROTATION_CREDENTIALS_SCHEMA_MAP[strategy as AppConnectionCredentialRotationStrategy];++ const parsedCredentials = credentialsSchema.safeParse(credentials);+ if (!parsedCredentials.success) {+ throw new BadRequestError({+ message: `Failed to parse credentials for ${strategy} connection`+ });+ }+// Step 1: Create new credential first (safe — worst case we have 3 secrets temporarily)- const newCredential = await provider.createCredential(config, credentials, rotationInterval, inactiveIndex);+ const newCredential = await provider.createCredential(+ config,+ parsedCredentials.data,+ rotationInterval,+ inactiveIndex+ );// Step 2: Update connection credentials with new secretconst updatedCredentials = provider.mergeCredentials(@@ -384,7 +429,7 @@ export const appConnectionCredentialRotationServiceFactory = ({logger.info(`credentialRotation: Revoking old credential keyId=${inactiveCredential.keyId} at index=${inactiveIndex} [rotationId=${rotationId}]`);- await provider.revokeCredential(inactiveCredential, config, credentials);+ await provider.revokeCredential(inactiveCredential, config, parsedCredentials.data);} catch (revokeError) {logger.warn(revokeError,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 2570b06d6e..0951487e46 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@@ -1,8 +1,13 @@import { z } from "zod";import { TAppConnectionCredentialRotations } from "../../../db/schemas/app-connection-credential-rotations";+import { TAppConnectionRaw } from "../app-connection-types";import { CreateAppConnectionCredentialRotationSchema } from "./app-connection-credential-rotation-schemas";-import { TAzureClientSecretGeneratedCredential, TAzureClientSecretStrategyConfig } from "./providers";+import {+ TAzureClientSecretCredentialRotationCredentials,+ TAzureClientSecretGeneratedCredential,+ TAzureClientSecretStrategyConfig+} from "./providers/azure-client-secret/azure-client-secret-credential-rotation-types";export type TAppConnectionCredentialRotationRaw = TAppConnectionCredentialRotations;@@ -15,52 +20,66 @@ export type TAppConnectionCredentialRotation = Omit<export type TCreateAppConnectionCredentialRotationSchema = z.infer<typeof CreateAppConnectionCredentialRotationSchema>;+// Union of all strategy configs — expands as providers are addedexport type TAppConnectionCredentialRotationStrategyConfig = TAzureClientSecretStrategyConfig;-export type TAppConnectionCredentialRotationGeneratedCredentials = (TAzureClientSecretGeneratedCredential | null)[];--export type TCredentialRotationProvider = {- // Validates the connection's auth method is supported — throws BadRequestError if not- validateConnectionMethod(method: string): void;-- // Called during createRotation:- // - Auto-detects strategy config (e.g. applicationObjectId) from credentials- // - Validates accessibility (e.g. Graph API call)- // - Lists existing credentials (to track original for first revocation cycle)- // - Creates the initial credential- issueInitialCredentials(- credentials: Record<string, unknown>,- rotationInterval: number- ): Promise<{- strategyConfig: TAppConnectionCredentialRotationStrategyConfig;- generatedCredentials: TAppConnectionCredentialRotationGeneratedCredentials;- updatedCredentials: Record<string, unknown>;- }>;-- // Called during rotateCredentials (queue worker):- // Creates a new credential at the given index- createCredential(- strategyConfig: TAppConnectionCredentialRotationStrategyConfig,- credentials: Record<string, unknown>,- rotationInterval: number,- inactiveIndex: number- ): Promise<TAzureClientSecretGeneratedCredential>;-- // Merges newly created credential back into the connection's credentials object- mergeCredentials(- currentCredentials: Record<string, unknown>,- newCredential: TAzureClientSecretGeneratedCredential- ): Record<string, unknown>;-- // Revokes the inactive/old credential (best-effort, non-fatal)- revokeCredential(- inactiveCredential: TAzureClientSecretGeneratedCredential,- strategyConfig: TAppConnectionCredentialRotationStrategyConfig,- credentials: Record<string, unknown>- ): Promise<void>;+// Union of all individual generated credential types — expands as providers are added+export type TAppConnectionCredentialRotationGeneratedCredential = TAzureClientSecretGeneratedCredential;++// Union of all individual credentials types — expands as providers are added+export type TAppConnectionCredentialCredentials = TAzureClientSecretCredentialRotationCredentials;++export type TAppConnectionCredentialRotationGeneratedCredentials =+ (TAppConnectionCredentialRotationGeneratedCredential | null)[];++// We might need to update this in the future to do more in-depth validation if need be+export type TCredentialRotationValidateMethod = (method: string) => void;++export type TCredentialRotationIssueInitialCredentials<+ S extends TAppConnectionCredentialRotationStrategyConfig,+ C extends TAppConnectionCredentialRotationGeneratedCredential+> = (+ credentials: Record<string, unknown>,+ rotationInterval: number+) => Promise<{+ strategyConfig: S;+ generatedCredentials: (C | null)[];+ updatedCredentials: Record<string, unknown>;+}>;++export type TCredentialRotationCreateCredential<+ S extends TAppConnectionCredentialRotationStrategyConfig,+ C extends TAppConnectionCredentialRotationGeneratedCredential+> = (+ strategyConfig: S,+ credentials: TAppConnectionCredentialCredentials,+ rotationInterval: number,+ activeIndex: number+) => Promise<C>;++export type TCredentialRotationMergeCredentials<C extends TAppConnectionCredentialRotationGeneratedCredential> = (+ currentCredentials: Record<string, unknown>,+ newCredential: C+) => Record<string, unknown>;++export type TCredentialRotationRevokeCredential<+ S extends TAppConnectionCredentialRotationStrategyConfig,+ C extends TAppConnectionCredentialRotationGeneratedCredential+> = (inactiveCredential: C, strategyConfig: S, credentials: TAppConnectionCredentialCredentials) => Promise<void>;++// Factory type — takes connection context, returns typed operations.+// Mirrors TRotationFactory in secret-rotation-v2.+export type TCredentialRotationProviderFactory<+ S extends TAppConnectionCredentialRotationStrategyConfig = TAppConnectionCredentialRotationStrategyConfig,+ C extends TAppConnectionCredentialRotationGeneratedCredential = TAppConnectionCredentialRotationGeneratedCredential+> = (connection: TAppConnectionRaw) => {+ validateConnectionMethod: TCredentialRotationValidateMethod;+ issueInitialCredentials: TCredentialRotationIssueInitialCredentials<S, C>;+ createCredential: TCredentialRotationCreateCredential<S, C>;+ mergeCredentials: TCredentialRotationMergeCredentials<C>;+ revokeCredential: TCredentialRotationRevokeCredential<S, C>;};-// DTOsexport type TCreateAppConnectionCredentialRotationDTO = {connectionId: string;rotationInterval: number;@@ -78,7 +97,6 @@ export type TTriggerAppConnectionCredentialRotationDTO = {connectionId: string;};-// Queue payloadsexport type TAppConnectionCredentialRotationRotateJobPayload = {rotationId: string;connectionId: string;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 aff4613b1d..34152cefd5 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@@ -7,43 +7,42 @@ import { logger } from "@app/lib/logger";import { AzureKeyVaultConnectionMethod } from "@app/services/app-connection/azure-key-vault/azure-key-vault-connection-enums";import {- TAppConnectionCredentialRotationGeneratedCredentials,+ TCredentialRotationCreateCredential,+ TCredentialRotationIssueInitialCredentials,+ TCredentialRotationMergeCredentials,+ TCredentialRotationProviderFactory,+ TCredentialRotationRevokeCredential,+ TCredentialRotationValidateMethod+} from "../../app-connection-credential-rotation-types";+import {+ AzureAddPasswordResponse,+ AzureErrorResponse,+ TAzureClientSecretCredentialRotationCredentials,TAzureClientSecretGeneratedCredential,TAzureClientSecretStrategyConfig,- TCredentialRotationProvider-} from "../app-connection-credential-rotation-types";--const GRAPH_API_BASE = "https://graph.microsoft.com/v1.0";-const EXPIRY_PADDING_IN_DAYS = 3;--type AzureAddPasswordResponse = {- keyId: string;- secretText: string;- displayName: string;- endDateTime: string;-};+ TCreateAzureClientSecretDTO+} from "./azure-client-secret-credential-rotation-types";-type AzureErrorResponse = { error: { message: string } };--const sleep = (ms: number) =>- new Promise((resolve) => {+const sleep = async (ms: number) => {+ return new Promise<void>((resolve) => {setTimeout(resolve, ms);});+};-/**- * Gets a Graph API access token using the connection's own credentials (client credentials grant).- * This token is ephemeral and NOT stored in the connection's accessToken field.- */+const GRAPH_API_BASE = "https://graph.microsoft.com/v1.0";+const EXPIRY_PADDING_IN_DAYS = 3;const GRAPH_TOKEN_MAX_RETRIES = 3;-const GRAPH_TOKEN_RETRY_DELAY_MS = 2000;+const GRAPH_TOKEN_BASE_RETRY_DELAY_MS = 2000;+// might be thrown if its a newly created client secret and it hasn't propagated yet.+// we need to retry in this case to give it some timeconst isInvalidClientSecretError = (error: unknown): boolean => {if (!(error instanceof AxiosError)) return false;const desc = (error.response?.data as { error_description?: string })?.error_description || "";return desc.includes("AADSTS7000215");};-export const getGraphApiToken = async (+const getGraphApiToken = async (credentials: {clientId: string;clientSecret: string;@@ -76,7 +75,7 @@ export const getGraphApiToken = async (// Retry on AADSTS7000215 (invalid client secret) — this can happen when a newly created// secret hasn't propagated in Azure AD yet.if (isInvalidClientSecretError(error) && attempt < GRAPH_TOKEN_MAX_RETRIES) {- const delay = GRAPH_TOKEN_RETRY_DELAY_MS * 2 ** attempt;+ const delay = GRAPH_TOKEN_BASE_RETRY_DELAY_MS * 2 ** attempt;logger.info(`credentialRotation: Graph API token auth failed (secret not propagated?), retrying in ${delay}ms (attempt ${attempt + 1}/${GRAPH_TOKEN_MAX_RETRIES})`);@@ -120,14 +119,12 @@ const parseAzureError = (error: unknown, context: string): never => {};/**- * Looks up the Azure AD Application Object ID from a client ID (appId) using the Graph API.+ * Looks up the Azure AD application object ID from a client ID*/-export const getApplicationObjectId = async (credentials: {- clientId: string;- clientSecret: string;- tenantId: string;-}): Promise<string> => {- const accessToken = await getGraphApiToken(credentials);+const getApplicationObjectId = async (+ credentials: Pick<TAzureClientSecretCredentialRotationCredentials, "clientId">,+ accessToken: string+): Promise<string> => {const endpoint = `${GRAPH_API_BASE}/applications?$filter=appId eq '${credentials.clientId}'&$select=id`;try {@@ -153,14 +150,12 @@ export const getApplicationObjectId = async (credentials: {}};-/**- * Validates the strategy config by checking the app's objectId is accessible via Graph API.- */-export const validateAzureClientSecretRotationConfig = async (+// Validates the strategy config by checking the app's objectId is accessible via Graph API.+const validateAzureClientSecretRotationConfig = async (config: TAzureClientSecretStrategyConfig,- credentials: { clientId: string; clientSecret: string; tenantId: string }+ credentials: { clientId: string; clientSecret: string; tenantId: string },+ accessToken: string) => {- const accessToken = await getGraphApiToken(credentials);const endpoint = `${GRAPH_API_BASE}/applications/${config.objectId}`;try {@@ -189,13 +184,11 @@ const isAzureConcurrentRequestError = (error: unknown): boolean => {* Retries on Azure's transient "concurrent requests" error with exponential backoff.*/export const createAzureClientSecret = async (- config: TAzureClientSecretStrategyConfig,- credentials: { clientId: string; clientSecret: string; tenantId: string },- rotationInterval: number,- index?: number,- attempt = 0+ dto: TCreateAzureClientSecretDTO): Promise<TAzureClientSecretGeneratedCredential> => {- const accessToken = await getGraphApiToken(credentials);+ const { connectionName, config, accessToken, rotationInterval, activeIndex } = dto;+ const attempt = dto.attempt ?? 0;+const endpoint = `${GRAPH_API_BASE}/applications/${config.objectId}/addPassword`;const now = new Date();@@ -212,7 +205,7 @@ export const createAzureClientSecret = async (endpoint,{passwordCredential: {- displayName: `Infisical Managed Credential (${formattedDate}) (idx-${index})`,+ displayName: `Infisical Managed Credential (${formattedDate}) [${activeIndex + 1}] - ${connectionName}`,endDateTime: endDateTime.toISOString()}},@@ -225,7 +218,9 @@ export const createAzureClientSecret = async ();if (!data?.secretText || !data?.keyId) {- throw new Error("Invalid response from Azure: missing secretText or keyId.");+ throw new BadRequestError({+ message: "Invalid response from Azure: missing secretText or keyId."+ });}return {@@ -240,7 +235,7 @@ export const createAzureClientSecret = async (`credentialRotation: Azure concurrent request error, retrying in ${delay}ms (attempt ${attempt + 1}/${AZURE_CONCURRENT_REQUEST_MAX_RETRIES})`);await sleep(delay);- return createAzureClientSecret(config, credentials, rotationInterval, index, attempt + 1);+ return createAzureClientSecret({ ...dto, attempt: attempt + 1 });}if (error instanceof BadRequestError) throw error;@@ -257,9 +252,9 @@ export const createAzureClientSecret = async (*/export const listAzurePasswordCredentials = async (config: TAzureClientSecretStrategyConfig,- credentials: { clientId: string; clientSecret: string; tenantId: string }+ credentials: { clientId: string; clientSecret: string; tenantId: string },+ accessToken: string): Promise<Array<{ keyId: string; displayName: string }>> => {- const accessToken = await getGraphApiToken(credentials);const endpoint = `${GRAPH_API_BASE}/applications/${config.objectId}?$select=passwordCredentials`;try {@@ -286,9 +281,10 @@ export const listAzurePasswordCredentials = async (export const azureCredentialExists = async (keyId: string,config: TAzureClientSecretStrategyConfig,- credentials: { clientId: string; clientSecret: string; tenantId: string }+ credentials: TAzureClientSecretCredentialRotationCredentials,+ accessToken: string): Promise<boolean> => {- const passwordCredentials = await listAzurePasswordCredentials(config, credentials);+ const passwordCredentials = await listAzurePasswordCredentials(config, credentials, accessToken);return passwordCredentials.some((credential) => credential.keyId === keyId);};@@ -300,15 +296,15 @@ export const revokeAzureClientSecret = async (keyId: string,config: TAzureClientSecretStrategyConfig,credentials: { clientId: string; clientSecret: string; tenantId: string },+ accessToken: string,attempt = 0): Promise<void> => {- const exists = await azureCredentialExists(keyId, config, credentials);+ const exists = await azureCredentialExists(keyId, config, credentials, accessToken);if (!exists) {logger.info(`Credential keyId=${keyId} does not exist on app ${config.objectId}, skipping revocation`);return;}- const accessToken = await getGraphApiToken(credentials);const endpoint = `${GRAPH_API_BASE}/applications/${config.objectId}/removePassword`;try {@@ -329,7 +325,7 @@ export const revokeAzureClientSecret = async (`credentialRotation: Azure concurrent request error on revoke, retrying in ${delay}ms (attempt ${attempt + 1}/${AZURE_CONCURRENT_REQUEST_MAX_RETRIES})`);await sleep(delay);- await revokeAzureClientSecret(keyId, config, credentials, attempt + 1);+ await revokeAzureClientSecret(keyId, config, credentials, accessToken, attempt + 1);return;}@@ -337,63 +333,99 @@ export const revokeAzureClientSecret = async (}};-export const azureClientSecretRotationProvider: TCredentialRotationProvider = {- validateConnectionMethod(method: string) {+export const azureClientSecretRotationProviderFactory: TCredentialRotationProviderFactory<+ TAzureClientSecretStrategyConfig,+ TAzureClientSecretGeneratedCredential+> = (connection) => {+ const validateConnectionMethod: TCredentialRotationValidateMethod = (method) => {if (method !== AzureKeyVaultConnectionMethod.ClientSecret) {throw new BadRequestError({message: "Credential rotation is only supported for Client Secret auth method"});}- },+ };- async issueInitialCredentials(credentials, rotationInterval) {+ const issueInitialCredentials: TCredentialRotationIssueInitialCredentials<+ TAzureClientSecretStrategyConfig,+ TAzureClientSecretGeneratedCredential+ > = async (credentials, rotationInterval) => {const azureCredentials = credentials as {clientId: string;clientSecret: string;tenantId: string;applicationObjectId?: string;};++ const accessToken = await getGraphApiToken(azureCredentials);+let { applicationObjectId } = azureCredentials;if (!applicationObjectId) {- applicationObjectId = await getApplicationObjectId(azureCredentials);+ applicationObjectId = await getApplicationObjectId(azureCredentials, accessToken);}+const strategyConfig: TAzureClientSecretStrategyConfig = { objectId: applicationObjectId };- await validateAzureClientSecretRotationConfig(strategyConfig, azureCredentials);- const existingCreds = await listAzurePasswordCredentials(strategyConfig, azureCredentials);- const newCredential = await createAzureClientSecret(strategyConfig, azureCredentials, rotationInterval, 0);- const originalCredential = existingCreds.find((c) => c.keyId !== newCredential.keyId);- const generatedCredentials: TAppConnectionCredentialRotationGeneratedCredentials = [- newCredential,- originalCredential- ? { keyId: originalCredential.keyId, clientSecret: azureCredentials.clientSecret, createdAt: "" }- : null- ];+ await validateAzureClientSecretRotationConfig(strategyConfig, azureCredentials, accessToken);++ // Create one Infisical-managed credential. The second slot starts empty (null) and will+ // be filled on the first rotation cycle. The original user-provided secret becomes unused+ // but can't be revoked because Azure doesn't expose which keyId maps to a given secret value.+ // It will expire naturally based on its configured expiry in Azure AD.+ const newCredential = await createAzureClientSecret({+ accessToken,+ connectionName: connection.name,+ config: strategyConfig,+ rotationInterval,+ activeIndex: 0,+ attempt: 0+ });++ const generatedCredentials: (TAzureClientSecretGeneratedCredential | null)[] = [newCredential, null];+return {strategyConfig,generatedCredentials,updatedCredentials: { ...azureCredentials, clientSecret: newCredential.clientSecret, applicationObjectId }};- },-- async createCredential(strategyConfig, credentials, rotationInterval, inactiveIndex) {- return createAzureClientSecret(- strategyConfig,- credentials as { clientId: string; clientSecret: string; tenantId: string; applicationObjectId?: string },- rotationInterval,- inactiveIndex- );- },+ };++ const createCredential: TCredentialRotationCreateCredential<+ TAzureClientSecretStrategyConfig,+ TAzureClientSecretGeneratedCredential+ > = async (strategyConfig, credentials, rotationInterval, activeIndex) => {+ const accessToken = await getGraphApiToken(credentials);++ return createAzureClientSecret({+ accessToken,+ activeIndex,+ config: strategyConfig,+ connectionName: connection.name,+ rotationInterval+ });+ };- mergeCredentials(currentCredentials, newCredential) {+ const mergeCredentials: TCredentialRotationMergeCredentials<TAzureClientSecretGeneratedCredential> = (+ currentCredentials,+ newCredential+ ) => {return { ...currentCredentials, clientSecret: newCredential.clientSecret };- },+ };- async revokeCredential(inactiveCredential, strategyConfig, credentials) {+ const revokeCredential: TCredentialRotationRevokeCredential<+ TAzureClientSecretStrategyConfig,+ TAzureClientSecretGeneratedCredential+ > = async (inactiveCredential, strategyConfig, credentials) => {if (!inactiveCredential?.keyId) return;- await revokeAzureClientSecret(- inactiveCredential.keyId,- strategyConfig,- credentials as { clientId: string; clientSecret: string; tenantId: string }- );- }++ const accessToken = await getGraphApiToken(credentials);++ await revokeAzureClientSecret(inactiveCredential.keyId, strategyConfig, credentials, accessToken);+ };++ return {+ validateConnectionMethod,+ issueInitialCredentials,+ createCredential,+ mergeCredentials,+ revokeCredential+ };};diff --git a/backend/src/services/app-connection/credential-rotation/providers/azure-client-secret/azure-client-secret-credential-rotation-types.ts b/backend/src/services/app-connection/credential-rotation/providers/azure-client-secret/azure-client-secret-credential-rotation-types.tsindex 6a8a8b4824..d04c35d451 100644--- a/backend/src/services/app-connection/credential-rotation/providers/azure-client-secret/azure-client-secret-credential-rotation-types.ts+++ b/backend/src/services/app-connection/credential-rotation/providers/azure-client-secret/azure-client-secret-credential-rotation-types.ts@@ -1,3 +1,7 @@+import { z } from "zod";++import { AzureKeyVaultConnectionClientSecretInputCredentialsSchema } from "@app/services/app-connection/azure-key-vault";+// Strategy config typesexport type TAzureClientSecretStrategyConfig = {objectId: string;@@ -9,3 +13,28 @@ export type TAzureClientSecretGeneratedCredential = {clientSecret: string;createdAt: string;};++export type AzureErrorResponse = { error: { message: string } };++export type AzureAddPasswordResponse = {+ keyId: string;+ secretText: string;+ displayName: string;+ endDateTime: string;+};++export type TCreateAzureClientSecretDTO = {+ accessToken: string;+ connectionName: string;+ config: TAzureClientSecretStrategyConfig;+ rotationInterval: number;+ activeIndex: number;+ attempt?: number;+};+// exact same schema as AzureKeyVaultConnectionClientSecretInputCredentialsSchema+export const AzureClientSecretCredentialRotationCredentialsSchema =+ AzureKeyVaultConnectionClientSecretInputCredentialsSchema;++export type TAzureClientSecretCredentialRotationCredentials = z.infer<+ typeof AzureClientSecretCredentialRotationCredentialsSchema+>;diff --git a/backend/src/services/app-connection/databricks/index.ts b/backend/src/services/app-connection/databricks/index.tsindex 844000af4f..7c5aefff04 100644--- a/backend/src/services/app-connection/databricks/index.ts+++ b/backend/src/services/app-connection/databricks/index.ts@@ -1,4 +1,3 @@export * from "./databricks-connection-enums";-export * from "./databricks-connection-fns";export * from "./databricks-connection-schemas";export * from "./databricks-connection-types";diff --git a/backend/src/services/app-connection/gitlab/index.ts b/backend/src/services/app-connection/gitlab/index.tsindex 9c6463d8c8..2c2e5d2700 100644--- a/backend/src/services/app-connection/gitlab/index.ts+++ b/backend/src/services/app-connection/gitlab/index.ts@@ -1,4 +1,3 @@export * from "./gitlab-connection-enums";-export * from "./gitlab-connection-fns";export * from "./gitlab-connection-schemas";export * from "./gitlab-connection-types";diff --git a/backend/src/services/app-connection/heroku/index.ts b/backend/src/services/app-connection/heroku/index.tsindex c23bc60c63..ccb1945363 100644--- a/backend/src/services/app-connection/heroku/index.ts+++ b/backend/src/services/app-connection/heroku/index.ts@@ -1,4 +1,3 @@export * from "./heroku-connection-enums";-export * from "./heroku-connection-fns";export * from "./heroku-connection-schemas";export * from "./heroku-connection-types";diff --git a/backend/src/services/pki-sync/azure-key-vault/azure-key-vault-pki-sync-fns.ts b/backend/src/services/pki-sync/azure-key-vault/azure-key-vault-pki-sync-fns.tsindex 765d0b8ba6..390a08098c 100644--- a/backend/src/services/pki-sync/azure-key-vault/azure-key-vault-pki-sync-fns.ts+++ b/backend/src/services/pki-sync/azure-key-vault/azure-key-vault-pki-sync-fns.ts@@ -6,7 +6,7 @@ import { TCertificateSyncs } from "@app/db/schemas";import { request } from "@app/lib/config/request";import { logger } from "@app/lib/logger";import { TAppConnectionDALFactory } from "@app/services/app-connection/app-connection-dal";-import { getAzureConnectionAccessToken } from "@app/services/app-connection/azure-key-vault";+import { getAzureConnectionAccessToken } from "@app/services/app-connection/azure-key-vault/azure-key-vault-connection-fns";import { TCertificateDALFactory } from "@app/services/certificate/certificate-dal";import { TCertificateSyncDALFactory } from "@app/services/certificate-sync/certificate-sync-dal";import { CertificateSyncStatus } from "@app/services/certificate-sync/certificate-sync-enums";diff --git a/backend/src/services/secret-sync/azure-app-configuration/azure-app-configuration-sync-fns.ts b/backend/src/services/secret-sync/azure-app-configuration/azure-app-configuration-sync-fns.tsindex 51669067a1..f054d04b84 100644--- a/backend/src/services/secret-sync/azure-app-configuration/azure-app-configuration-sync-fns.ts+++ b/backend/src/services/secret-sync/azure-app-configuration/azure-app-configuration-sync-fns.ts@@ -4,7 +4,7 @@ import https from "https";import { request } from "@app/lib/config/request";import { BadRequestError } from "@app/lib/errors";import { TAppConnectionDALFactory } from "@app/services/app-connection/app-connection-dal";-import { getAzureConnectionAccessToken } from "@app/services/app-connection/azure-key-vault";+import { getAzureConnectionAccessToken } from "@app/services/app-connection/azure-key-vault/azure-key-vault-connection-fns";import { isAzureKeyVaultReference } from "@app/services/integration-auth/integration-sync-secret-fns";import { TKmsServiceFactory } from "@app/services/kms/kms-service";import { matchesSchema } from "@app/services/secret-sync/secret-sync-fns";diff --git a/backend/src/services/secret-sync/azure-key-vault/azure-key-vault-sync-fns.ts b/backend/src/services/secret-sync/azure-key-vault/azure-key-vault-sync-fns.tsindex a4cf59909f..d16abac28a 100644--- a/backend/src/services/secret-sync/azure-key-vault/azure-key-vault-sync-fns.ts+++ b/backend/src/services/secret-sync/azure-key-vault/azure-key-vault-sync-fns.ts@@ -3,7 +3,7 @@ import { AxiosError } from "axios";import { request } from "@app/lib/config/request";import { TAppConnectionDALFactory } from "@app/services/app-connection/app-connection-dal";-import { getAzureConnectionAccessToken } from "@app/services/app-connection/azure-key-vault";+import { getAzureConnectionAccessToken } from "@app/services/app-connection/azure-key-vault/azure-key-vault-connection-fns";import { TKmsServiceFactory } from "@app/services/kms/kms-service";import { matchesSchema } from "@app/services/secret-sync/secret-sync-fns";import { TSecretMap } from "@app/services/secret-sync/secret-sync-types";diff --git a/backend/src/services/secret-sync/camunda/camunda-sync-fns.ts b/backend/src/services/secret-sync/camunda/camunda-sync-fns.tsindex 516efae109..b0d9f08a6a 100644--- a/backend/src/services/secret-sync/camunda/camunda-sync-fns.ts+++ b/backend/src/services/secret-sync/camunda/camunda-sync-fns.ts@@ -1,6 +1,6 @@import { request } from "@app/lib/config/request";import { TAppConnectionDALFactory } from "@app/services/app-connection/app-connection-dal";-import { getCamundaConnectionAccessToken } from "@app/services/app-connection/camunda";+import { getCamundaConnectionAccessToken } from "@app/services/app-connection/camunda/camunda-connection-fns";import { IntegrationUrls } from "@app/services/integration-auth/integration-list";import { TKmsServiceFactory } from "@app/services/kms/kms-service";import {diff --git a/backend/src/services/secret-sync/databricks/databricks-sync-fns.ts b/backend/src/services/secret-sync/databricks/databricks-sync-fns.tsindex 1759013236..7d5273a4ea 100644--- a/backend/src/services/secret-sync/databricks/databricks-sync-fns.ts+++ b/backend/src/services/secret-sync/databricks/databricks-sync-fns.ts@@ -1,7 +1,7 @@import { request } from "@app/lib/config/request";import { removeTrailingSlash } from "@app/lib/fn";import { TAppConnectionDALFactory } from "@app/services/app-connection/app-connection-dal";-import { getDatabricksConnectionAccessToken } from "@app/services/app-connection/databricks";+import { getDatabricksConnectionAccessToken } from "@app/services/app-connection/databricks/databricks-connection-fns";import { TKmsServiceFactory } from "@app/services/kms/kms-service";import {TDatabricksDeleteSecret,diff --git a/backend/src/services/secret-sync/gitlab/gitlab-sync-fns.ts b/backend/src/services/secret-sync/gitlab/gitlab-sync-fns.tsindex 7bf45d47ce..3aa9ed9a93 100644--- a/backend/src/services/secret-sync/gitlab/gitlab-sync-fns.ts+++ b/backend/src/services/secret-sync/gitlab/gitlab-sync-fns.ts@@ -2,12 +2,8 @@import { GitbeakerRequestError } from "@gitbeaker/rest";import { TAppConnectionDALFactory } from "@app/services/app-connection/app-connection-dal";-import {- getGitLabClient,- GitLabConnectionMethod,- refreshGitLabToken,- TGitLabConnection-} from "@app/services/app-connection/gitlab";+import { GitLabConnectionMethod, TGitLabConnection } from "@app/services/app-connection/gitlab";+import { getGitLabClient, refreshGitLabToken } from "@app/services/app-connection/gitlab/gitlab-connection-fns";import { TKmsServiceFactory } from "@app/services/kms/kms-service";import { TGitLabSyncWithCredentials, TGitLabVariable } from "@app/services/secret-sync/gitlab/gitlab-sync-types";import { SecretSyncError } from "@app/services/secret-sync/secret-sync-errors";diff --git a/backend/src/services/secret-sync/heroku/heroku-sync-fns.ts b/backend/src/services/secret-sync/heroku/heroku-sync-fns.tsindex 5f23759793..678c8c5cd5 100644--- a/backend/src/services/secret-sync/heroku/heroku-sync-fns.ts+++ b/backend/src/services/secret-sync/heroku/heroku-sync-fns.ts@@ -1,6 +1,7 @@import { request } from "@app/lib/config/request";import { TAppConnectionDALFactory } from "@app/services/app-connection/app-connection-dal";-import { HerokuConnectionMethod, refreshHerokuToken, THerokuConnection } from "@app/services/app-connection/heroku";+import { HerokuConnectionMethod, THerokuConnection } from "@app/services/app-connection/heroku";+import { refreshHerokuToken } from "@app/services/app-connection/heroku/heroku-connection-fns";import { IntegrationUrls } from "@app/services/integration-auth/integration-list";import { TKmsServiceFactory } from "@app/services/kms/kms-service";import {diff --git a/frontend/src/hooks/api/appConnections/types/root-connection.ts b/frontend/src/hooks/api/appConnections/types/root-connection.tsindex 96198265e1..d186aee216 100644--- a/frontend/src/hooks/api/appConnections/types/root-connection.ts+++ b/frontend/src/hooks/api/appConnections/types/root-connection.ts@@ -9,6 +9,14 @@ export type TRootAppConnection = {createdAt: string;updatedAt: string;isPlatformManagedCredentials?: boolean;+ isAutoRotationEnabled?: boolean;+ rotation?: {+ rotationInterval: number;+ rotateAtUtc: {+ hours: number;+ minutes: number;+ };+ };gatewayId?: string | null;projectId?: string | null;project?: {diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionForm.tsxindex ba3201bcdc..8e55e6fd8a 100644--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionForm.tsx+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionForm.tsx@@ -79,7 +79,13 @@ const CreateForm = ({ app, onComplete, projectId }: CreateFormProps) => {const onSubmit = async (formData: DiscriminativePick<TAppConnection,- "method" | "name" | "app" | "credentials" | "isPlatformManagedCredentials"+ | "method"+ | "name"+ | "app"+ | "credentials"+ | "isPlatformManagedCredentials"+ | "isAutoRotationEnabled"+ | "rotation">) => {const connection = await createAppConnection.mutateAsync({diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AzureKeyVaultConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AzureKeyVaultConnectionForm.tsxindex 8c0f00acfa..2b1b520f56 100644--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AzureKeyVaultConnectionForm.tsx+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AzureKeyVaultConnectionForm.tsx@@ -20,6 +20,7 @@ import {} from "@app/hooks/api/appConnections/types/azure-key-vault-connection";import { AzureKeyVaultFormData } from "../../../OauthCallbackPage/OauthCallbackPage.types";+import { CredentialRotationForm } from "./shared/CredentialRotationForm";import {genericAppConnectionFieldsSchema,GenericAppConnectionsFields@@ -60,7 +61,15 @@ const getDefaultValues = (appConnection?: TAzureKeyVaultConnection): Partial<Forif (!appConnection) {return {app: AppConnection.AzureKeyVault,- method: AzureKeyVaultConnectionMethod.OAuth+ method: AzureKeyVaultConnectionMethod.OAuth,+ isAutoRotationEnabled: false,+ rotation: {+ rotationInterval: 30,+ rotateAtUtc: {+ hours: 0,+ minutes: 0+ }+ }};}@@ -68,7 +77,9 @@ const getDefaultValues = (appConnection?: TAzureKeyVaultConnection): Partial<Forname: appConnection.name,description: appConnection.description,app: appConnection.app,- method: appConnection.method+ method: appConnection.method,+ isAutoRotationEnabled: appConnection.isAutoRotationEnabled,+ rotation: appConnection.rotation};const { credentials } = appConnection;@@ -272,6 +283,8 @@ export const AzureKeyVaultConnectionForm = ({ appConnection, onSubmit, projectId</FormControl>)}/>++ <CredentialRotationForm /></>)}diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GenericAppConnectionFields.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GenericAppConnectionFields.tsxindex 7867c3f25b..91304c257e 100644--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GenericAppConnectionFields.tsx+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GenericAppConnectionFields.tsx@@ -4,13 +4,26 @@ import { z } from "zod";import { FormControl, Input, TextArea } from "@app/components/v2";import { slugSchema } from "@app/lib/schemas";+export const rotationSchema = z.object({+ rotationInterval: z+ .number()+ .min(1)+ .max(365 * 2.5),+ rotateAtUtc: z.object({+ hours: z.number().min(0).max(23),+ minutes: z.number().min(0).max(59)+ })+});+export const genericAppConnectionFieldsSchema = z.object({name: slugSchema({ min: 1, max: 64, field: "Name" }),description: z.string().trim().max(256, "Description cannot exceed 256 characters").nullish(),gatewayId: z.string().nullish()- .transform((v) => (v === "" ? null : v))+ .transform((v) => (v === "" ? null : v)),+ isAutoRotationEnabled: z.boolean().optional(),+ rotation: rotationSchema.optional()});export const GenericAppConnectionsFields = () => {diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/shared/CredentialRotationForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/shared/CredentialRotationForm.tsxnew file mode 100644index 0000000000..19fb80b0df--- /dev/null+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/shared/CredentialRotationForm.tsx@@ -0,0 +1,101 @@+import { Controller, useFormContext } from "react-hook-form";+import { format, setHours, setMinutes } from "date-fns";+import { twMerge } from "tailwind-merge";++import { FormControl, Input, Switch } from "@app/components/v2";+import { getRotateAtLocal } from "@app/helpers/secretRotationsV2";++export const CredentialRotationForm = () => {+ const { control, watch } = useFormContext();++ const isAutoRotationEnabled = watch("isAutoRotationEnabled");+ return (+ <div>+ <div className={twMerge(isAutoRotationEnabled && "mb-4", "mt-5")}>+ <Controller+ name="isAutoRotationEnabled"+ control={control}+ render={({ field: { value, onChange }, fieldState: { error } }) => (+ <FormControl+ helperText={+ value+ ? "App connection credentials will automatically be rotated when the rotation interval specified above as elapsed."+ : "App connection credentials will not be rotated automatically."+ }+ isError={Boolean(error?.message)}+ errorText={error?.message}+ >+ <Switch+ className="bg-mineshaft-400/50 shadow-inner data-[state=checked]:bg-green/80"+ id="platform-managed"+ thumbClassName="bg-mineshaft-800"+ isChecked={value}+ onCheckedChange={onChange}+ >+ <p className="w-[13.6rem]">Automatic Credential Rotation</p>+ </Switch>+ </FormControl>+ )}+ />+ </div>++ {isAutoRotationEnabled && (+ <div className="flex w-full items-center gap-2">+ <Controller+ render={({ field: { value, onChange }, fieldState: { error } }) => (+ <FormControl+ className="flex-1"+ tooltipText="How often Infisical will rotate the credentials of this connection."+ isError={Boolean(error)}+ errorText={error?.message}+ label="Rotation Interval (In Days)"+ >+ <Input+ value={value}+ type="number"+ onChange={onChange}+ min={1}+ placeholder="my-secret-rotation"+ />+ </FormControl>+ )}+ control={control}+ name="rotation.rotationInterval"+ />+ <Controller+ render={({ field: { value, onChange }, fieldState: { error } }) => {+ return (+ <FormControl+ className="flex-1"+ tooltipText="The time of day at which Infisical will rotate the credentials of this connection."+ label="Rotate At (Local Time)"+ isError={Boolean(error)}+ errorText={error?.message}+ >+ <Input+ type="time"+ value={format(getRotateAtLocal(value), "HH:mm")}+ onChange={(e) => {+ const time = e.target.value;+ if (time) {+ const [hours, minutes] = time.split(":").map((str) => parseInt(str, 10));+ const newSelectedDate = setHours(setMinutes(new Date(), minutes), hours);+ onChange({+ hours: newSelectedDate.getUTCHours(),+ minutes: newSelectedDate.getUTCMinutes()+ });+ }+ }}+ className="bg-mineshaft-700 text-white scheme-dark"+ />+ </FormControl>+ );+ }}+ control={control}+ name="rotation.rotateAtUtc"+ />+ </div>+ )}+ </div>+ );+};diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionRow.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionRow.tsxindex b8caa86787..1cd3a6e2ca 100644--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionRow.tsx+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionRow.tsx@@ -13,7 +13,7 @@ import {} from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { Link } from "@tanstack/react-router";-import { ServerIcon } from "lucide-react";+import { ClockIcon, ServerIcon } from "lucide-react";import { twMerge } from "tailwind-merge";import { createNotification } from "@app/components/notifications";@@ -53,8 +53,16 @@ export const AppConnectionRow = ({isProjectView}: Props) => {const { currentOrg } = useOrganization();- const { id, name, method, app, description, isPlatformManagedCredentials, project } =- appConnection;+ const {+ id,+ name,+ method,+ app,+ description,+ isPlatformManagedCredentials,+ project,+ isAutoRotationEnabled+ } = appConnection;const [isIdCopied, setIsIdCopied] = useToggle(false);@@ -166,6 +174,21 @@ export const AppConnectionRow = ({</div></Tooltip>)}++ {isAutoRotationEnabled && (+ <Tooltip+ side="left"+ content="This connection's credentials are automatically rotated by Infisical."+ >+ <div>+ <Badge variant="org">+ <ClockIcon />+ Automatic Credential Rotation+ </Badge>+ </div>+ </Tooltip>+ )}+<Tooltip className="max-w-sm text-center" content="Options"><DropdownMenu><DropdownMenuTrigger asChild>