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
consider key schema
Matheus Nogueiraf2a82baa5b73
diff --git a/backend/src/server/routes/v1/secret-sync-routers/secret-sync-endpoints.ts b/backend/src/server/routes/v1/secret-sync-routers/secret-sync-endpoints.tsindex f2661d3f62..ab34f23e19 100644--- a/backend/src/server/routes/v1/secret-sync-routers/secret-sync-endpoints.ts+++ b/backend/src/server/routes/v1/secret-sync-routers/secret-sync-endpoints.ts@@ -493,6 +493,7 @@ export const registerSyncSecretsEndpoints = <T extends TSecretSync, I extends TSbody: z.object({destinationConfig: z.unknown(),connectionId: z.string().uuid().optional(),+ syncOptions: z.record(z.unknown()).optional(),excludeSyncId: z.string().uuid().optional(),projectId: z.string().uuid()}),@@ -505,13 +506,14 @@ export const registerSyncSecretsEndpoints = <T extends TSecretSync, I extends TS},onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),handler: async (req) => {- const { destinationConfig, connectionId, excludeSyncId, projectId } = req.body;+ const { destinationConfig, connectionId, syncOptions, excludeSyncId, projectId } = req.body;const result = await server.services.secretSync.checkDuplicateDestination({destinationConfig: destinationConfig as Record<string, unknown>,destination,connectionId,+ syncOptions,excludeSyncId,projectId},diff --git a/backend/src/services/app-connection/aws/aws-connection-fns.ts b/backend/src/services/app-connection/aws/aws-connection-fns.tsindex 695785c074..bf41c638c8 100644--- a/backend/src/services/app-connection/aws/aws-connection-fns.ts+++ b/backend/src/services/app-connection/aws/aws-connection-fns.ts@@ -228,63 +228,24 @@ export const validateAwsConnectionCredentials = async (appConnection: TAwsConnecreturn appConnection.credentials;};-const extractAccountIdFromArn = (roleArn: string): string | null => {- const match = roleArn.match(/^arn:aws[^:]*:iam::(\d{12}):/);- return match ? match[1] : null;-};--// eslint-disable-next-line no-bitwise-const extractAccountIdFromAccessKey = (accessKeyId: string): string | null => {- if (accessKeyId.length < 16) return null;-- const trimmed = accessKeyId.slice(4);- const base32Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";-- const bits: number[] = [];- for (const char of trimmed) {- const val = base32Chars.indexOf(char.toUpperCase());- if (val === -1) return null;- for (let i = 4; i >= 0; i -= 1) {- // eslint-disable-next-line no-bitwise- bits.push((val >> i) & 1);- }- }-- const bytes: number[] = [];- for (let i = 0; i < 6 * 8 && i < bits.length; i += 8) {- let byte = 0;- for (let j = 0; j < 8 && i + j < bits.length; j += 1) {- // eslint-disable-next-line no-bitwise- byte = (byte << 1) | bits[i + j];- }- bytes.push(byte);- }-- if (bytes.length < 6) return null;-- let num = 0n;- for (const byte of bytes) {- // eslint-disable-next-line no-bitwise- num = (num << 8n) | BigInt(byte);- }- const mask = 0x7fffffffff80n;- // eslint-disable-next-line no-bitwise- const accountId = ((num & mask) >> 7n).toString();+export const getAwsAccountId = async (appConnection: TAwsConnectionConfig): Promise<string | null> => {+ try {+ const awsConfig = await getAwsConnectionConfig(appConnection);- return accountId.padStart(12, "0");-};+ const stsEndpoint =+ appConnection.method === AwsConnectionMethod.AssumeRole ? appConnection.credentials.stsEndpoint : undefined;+ const stsRegion = getStsSigningRegion(stsEndpoint);-export const extractAwsAccountId = (connection: {- method: string;- credentials: { roleArn?: string; accessKeyId?: string };-}): string | null => {- if (connection.method === AwsConnectionMethod.AssumeRole && connection.credentials.roleArn) {- return extractAccountIdFromArn(connection.credentials.roleArn);- }+ const sts = new STSClient({+ region: stsRegion.region ?? awsConfig.region,+ credentials: awsConfig.credentials,+ ...(stsEndpoint && stsRegion.isValidEndpoint ? { endpoint: stsEndpoint } : {})+ });- if (connection.method === AwsConnectionMethod.AccessKey && connection.credentials.accessKeyId) {- return extractAccountIdFromAccessKey(connection.credentials.accessKeyId);+ const response = await sts.send(new GetCallerIdentityCommand({}));+ return response.Account ?? null;+ } catch (error) {+ logger.error(error, "Failed to retrieve AWS account ID via STS");+ return null;}-- return null;};diff --git a/backend/src/services/secret-sync/secret-sync-maps.ts b/backend/src/services/secret-sync/secret-sync-maps.tsindex a530a7321b..ff8a528b0d 100644--- a/backend/src/services/secret-sync/secret-sync-maps.ts+++ b/backend/src/services/secret-sync/secret-sync-maps.ts@@ -1,5 +1,5 @@import { AppConnection } from "@app/services/app-connection/app-connection-enums";-import { extractAwsAccountId } from "@app/services/app-connection/aws/aws-connection-fns";+import { buildAwsConnectionConfig, getAwsAccountId } from "@app/services/app-connection/aws/aws-connection-fns";import { TAwsConnection } from "@app/services/app-connection/aws/aws-connection-types";import { SecretSync, SecretSyncPlanType } from "@app/services/secret-sync/secret-sync-enums";import { DestinationDuplicateCheckFn } from "@app/services/secret-sync/secret-sync-types";@@ -214,26 +214,34 @@ export const SECRET_SYNC_SKIP_FIELDS_MAP: Record<SecretSync, string[]> = {};const defaultDuplicateCheck: DestinationDuplicateCheckFn = async () => true;-const awsDuplicateCheck: DestinationDuplicateCheckFn = async ({- existingConnectionId,- newConnectionId,- decryptConnection-}) => {- if (!newConnectionId) return true;- if (existingConnectionId === newConnectionId) return true;- if (!existingConnectionId) return false;+const awsDuplicateCheck: DestinationDuplicateCheckFn = async ({ existingSync, newSync, decryptConnection }) => {+ if (!newSync.connectionId) return true;++ const existingKeySchema = (existingSync.syncOptions?.keySchema as string) ?? "";+ const newKeySchema = (newSync.syncOptions?.keySchema as string) ?? "";++ if (existingSync.connectionId === newSync.connectionId) {+ return existingKeySchema === newKeySchema;+ }++ if (!existingSync.connectionId) return false;const [existingConn, newConn] = await Promise.all([- decryptConnection(existingConnectionId),- decryptConnection(newConnectionId)+ decryptConnection(existingSync.connectionId),+ decryptConnection(newSync.connectionId)]);- const existingAccountId = extractAwsAccountId(existingConn as TAwsConnection);- const newAccountId = extractAwsAccountId(newConn as TAwsConnection);+ const existingAwsConn = existingConn as TAwsConnection;+ const newAwsConn = newConn as TAwsConnection;++ const [existingAccountId, newAccountId] = await Promise.all([+ getAwsAccountId(buildAwsConnectionConfig(existingAwsConn, existingAwsConn.credentials)),+ getAwsAccountId(buildAwsConnectionConfig(newAwsConn, newAwsConn.credentials))+ ]);if (!existingAccountId || !newAccountId) return false;- return existingAccountId === newAccountId;+ return existingAccountId === newAccountId && existingKeySchema === newKeySchema;};export const DESTINATION_DUPLICATE_CHECK_MAP: Record<SecretSync, DestinationDuplicateCheckFn> = {@@ -258,7 +266,10 @@ export const DESTINATION_DUPLICATE_CHECK_MAP: Record<SecretSync, DestinationDupl[SecretSync.Render]: defaultDuplicateCheck,[SecretSync.Flyio]: defaultDuplicateCheck,[SecretSync.TriggerDev]: defaultDuplicateCheck,- [SecretSync.GitLab]: async ({ existingConfig, newConfig }) => {+ [SecretSync.GitLab]: async ({ existingSync, newSync }) => {+ const existingConfig = existingSync.destinationConfig;+ const newConfig = newSync.destinationConfig;+const existingTargetEnv = existingConfig.targetEnvironment as string | undefined;const newTargetEnv = newConfig.targetEnvironment as string | undefined;diff --git a/backend/src/services/secret-sync/secret-sync-service.ts b/backend/src/services/secret-sync/secret-sync-service.tsindex 5645dfb2f6..26b894768a 100644--- a/backend/src/services/secret-sync/secret-sync-service.ts+++ b/backend/src/services/secret-sync/secret-sync-service.ts@@ -257,7 +257,14 @@ export const secretSyncServiceFactory = ({};const checkDuplicateDestination = async (- { destination, destinationConfig, connectionId, excludeSyncId, projectId }: TCheckDuplicateDestinationDTO,+ {+ destination,+ destinationConfig,+ connectionId,+ syncOptions,+ excludeSyncId,+ projectId+ }: TCheckDuplicateDestinationDTO,actor: OrgServiceActor) => {const skipFields = SECRET_SYNC_SKIP_FIELDS_MAP[destination];@@ -282,18 +289,27 @@ export const secretSyncServiceFactory = ({try {const existingSyncs = await secretSyncDAL.findByDestinationAndOrgId(destination, actor.orgId);- const decryptConnection = async (connId: string): Promise<TAppConnection> => {- const conn = await appConnectionDAL.findById(connId);- if (!conn || conn.orgId !== actor.orgId) {- throw new NotFoundError({ message: `App connection with ID "${connId}" not found` });- }- const credentials = await decryptAppConnectionCredentials({- orgId: conn.orgId,- encryptedCredentials: conn.encryptedCredentials,- kmsService,- projectId: conn.projectId- });- return { ...conn, credentials } as TAppConnection;+ const connectionCache = new Map<string, Promise<TAppConnection>>();+ const decryptConnection = (connId: string): Promise<TAppConnection> => {+ const cached = connectionCache.get(connId);+ if (cached) return cached;++ const promise = (async () => {+ const conn = await appConnectionDAL.findById(connId);+ if (!conn || conn.orgId !== actor.orgId) {+ throw new NotFoundError({ message: `App connection with ID "${connId}" not found` });+ }+ const credentials = await decryptAppConnectionCredentials({+ orgId: conn.orgId,+ encryptedCredentials: conn.encryptedCredentials,+ kmsService,+ projectId: conn.projectId+ });+ return { ...conn, credentials } as TAppConnection;+ })();++ connectionCache.set(connId, promise);+ return promise;};const candidates = existingSyncs.filter((sync) => {@@ -305,10 +321,16 @@ export const secretSyncServiceFactory = ({candidates.map(async (sync) => {try {const isDuplicate = await DESTINATION_DUPLICATE_CHECK_MAP[destination]({- existingConfig: sync.destinationConfig as Record<string, unknown>,- newConfig: destinationConfig,- existingConnectionId: sync.connectionId,- newConnectionId: connectionId ?? null,+ existingSync: {+ connectionId: sync.connectionId,+ syncOptions: (sync.syncOptions as Record<string, unknown>) ?? null,+ destinationConfig: sync.destinationConfig as Record<string, unknown>+ },+ newSync: {+ connectionId: connectionId ?? null,+ syncOptions: syncOptions ?? null,+ destinationConfig+ },decryptConnection});return isDuplicate ? sync : null;@@ -391,6 +413,7 @@ export const secretSyncServiceFactory = ({destination: params.destination,destinationConfig: params.destinationConfig,connectionId: params.connectionId,+ syncOptions: params.syncOptions as Record<string, unknown> | undefined,projectId},actor@@ -526,6 +549,9 @@ export const secretSyncServiceFactory = ({destination,destinationConfig: params.destinationConfig ?? (secretSync.destinationConfig as Record<string, unknown>),connectionId: params.connectionId ?? connectionId,+ syncOptions:+ (params.syncOptions as Record<string, unknown> | undefined) ??+ (secretSync.syncOptions as Record<string, unknown> | null),projectId: secretSync.projectId,excludeSyncId: secretSync.id},diff --git a/backend/src/services/secret-sync/secret-sync-types.ts b/backend/src/services/secret-sync/secret-sync-types.tsindex 2c913f07c1..c4555633b8 100644--- a/backend/src/services/secret-sync/secret-sync-types.ts+++ b/backend/src/services/secret-sync/secret-sync-types.ts@@ -475,6 +475,7 @@ export type TCheckDuplicateDestinationDTO = {destination: SecretSync;destinationConfig: Record<string, unknown>;connectionId?: string | null;+ syncOptions?: Record<string, unknown> | null;excludeSyncId?: string;projectId: string;};@@ -571,11 +572,15 @@ export type TSecretMap = Record<}>;+export type DuplicateCheckSyncFields = {+ connectionId: string | null;+ syncOptions: Record<string, unknown> | null;+ destinationConfig: Record<string, unknown>;+};+export type DestinationDuplicateCheckFn = (opts: {- existingConfig: Record<string, unknown>;- newConfig: Record<string, unknown>;- existingConnectionId: string | null;- newConnectionId: string | null;+ existingSync: DuplicateCheckSyncFields;+ newSync: DuplicateCheckSyncFields;decryptConnection: (connectionId: string) => Promise<TAppConnection>;}) => Promise<boolean>;diff --git a/frontend/src/components/secret-syncs/forms/CreateSecretSyncForm.tsx b/frontend/src/components/secret-syncs/forms/CreateSecretSyncForm.tsxindex 16f9467ebe..f9dbfb0c89 100644--- a/frontend/src/components/secret-syncs/forms/CreateSecretSyncForm.tsx+++ b/frontend/src/components/secret-syncs/forms/CreateSecretSyncForm.tsx@@ -215,6 +215,7 @@ export const CreateSecretSyncForm = ({destination,projectId: currentProject?.id || "",connectionId: watch("connection")?.id,+ syncOptions: watch("syncOptions"),enabled: true,destinationConfig: watch("destinationConfig")});diff --git a/frontend/src/components/secret-syncs/forms/EditSecretSyncForm.tsx b/frontend/src/components/secret-syncs/forms/EditSecretSyncForm.tsxindex c7867c4ecf..f37219e643 100644--- a/frontend/src/components/secret-syncs/forms/EditSecretSyncForm.tsx+++ b/frontend/src/components/secret-syncs/forms/EditSecretSyncForm.tsx@@ -156,6 +156,7 @@ export const EditSecretSyncForm = ({ secretSync, onComplete, onDirtyChange, onCasecretSync.projectId,secretSync.id,formMethods.watch("connection")?.id,+ formMethods.watch("syncOptions"),{ enabled: checkDuplicateEnabled && Boolean(destinationConfigToCheck) });diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/SecretSyncReviewFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/SecretSyncReviewFields.tsxindex d4d242478b..4310240bf9 100644--- a/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/SecretSyncReviewFields.tsx+++ b/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/SecretSyncReviewFields.tsx@@ -100,6 +100,7 @@ export const SecretSyncReviewFields = () => {destination,projectId: currentProject?.id || "",connectionId: connection?.id,+ syncOptions: watch("syncOptions"),enabled: true,destinationConfig: watch("destinationConfig")});diff --git a/frontend/src/hooks/api/secretSyncs/queries.tsx b/frontend/src/hooks/api/secretSyncs/queries.tsxindex 2019902a69..f02265e741 100644--- a/frontend/src/hooks/api/secretSyncs/queries.tsx+++ b/frontend/src/hooks/api/secretSyncs/queries.tsx@@ -19,6 +19,7 @@ export const secretSyncKeys = {destination: SecretSync,destinationConfig: unknown,connectionId?: string,+ syncOptions?: unknown,excludeSyncId?: string) =>[@@ -27,6 +28,7 @@ export const secretSyncKeys = {"duplicate-check",destinationConfig,connectionId,+ syncOptions,excludeSyncId] as const};@@ -109,6 +111,7 @@ export const useCheckDuplicateDestination = (projectId: string,excludeSyncId?: string,connectionId?: string,+ syncOptions?: unknown,options?: Omit<UseQueryOptions<{ hasDuplicate: boolean; duplicateProjectId?: string },@@ -124,6 +127,7 @@ export const useCheckDuplicateDestination = (destination,destinationConfig,connectionId,+ syncOptions,excludeSyncId),queryFn: async () => {@@ -133,6 +137,7 @@ export const useCheckDuplicateDestination = (}>(`/api/v1/secret-syncs/${destination}/check-destination`, {destinationConfig,connectionId,+ syncOptions,excludeSyncId,projectId});diff --git a/frontend/src/hooks/api/secretSyncs/useDuplicateDestinationCheck.ts b/frontend/src/hooks/api/secretSyncs/useDuplicateDestinationCheck.tsindex 3615fa1a1d..7d3c782c1f 100644--- a/frontend/src/hooks/api/secretSyncs/useDuplicateDestinationCheck.ts+++ b/frontend/src/hooks/api/secretSyncs/useDuplicateDestinationCheck.ts@@ -7,6 +7,7 @@ type UseDuplicateDestinationCheckProps = {projectId: string;excludeSyncId?: string;connectionId?: string;+ syncOptions?: unknown;enabled?: boolean;destinationConfig?: unknown;};@@ -16,6 +17,7 @@ export const useDuplicateDestinationCheck = ({projectId,excludeSyncId,connectionId,+ syncOptions,enabled = true,destinationConfig}: UseDuplicateDestinationCheckProps) => {@@ -42,6 +44,7 @@ export const useDuplicateDestinationCheck = ({projectId,excludeSyncId,connectionId,+ syncOptions,{enabled: shouldCheck,staleTime: 0,