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
feat(app-connection): add External Infisical connection type
Igor Correa5633eb67f006
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.tsindex 08b626e3cc..6a966b3cf9 100644--- a/backend/src/lib/api-docs/constants.ts+++ b/backend/src/lib/api-docs/constants.ts@@ -3038,6 +3038,11 @@ export const SecretSyncs = {orgName: "The CircleCI organization name to sync secrets to.",projectId: "The CircleCI project ID to sync secrets to.",projectName: "The CircleCI project name to sync secrets to."+ },+ EXTERNAL_INFISICAL: {+ projectId: "The ID of the project on the external Infisical instance to sync secrets to.",+ environment: "The environment slug on the external Infisical instance to sync secrets to.",+ secretPath: "The secret path on the external Infisical instance to sync secrets to."}}};diff --git a/backend/src/services/app-connection/app-connection-enums.ts b/backend/src/services/app-connection/app-connection-enums.tsindex 67124d390d..cfa38d52e5 100644--- a/backend/src/services/app-connection/app-connection-enums.ts+++ b/backend/src/services/app-connection/app-connection-enums.ts@@ -51,7 +51,8 @@ export enum AppConnection {OpenRouter = "open-router",CircleCI = "circleci",AzureEntraId = "azure-entra-id",- Venafi = "venafi"+ Venafi = "venafi",+ ExternalInfisical = "external-infisical"}export enum AWSRegion {diff --git a/backend/src/services/app-connection/app-connection-fns.ts b/backend/src/services/app-connection/app-connection-fns.tsindex d0d296521c..9335f85c87 100644--- a/backend/src/services/app-connection/app-connection-fns.ts+++ b/backend/src/services/app-connection/app-connection-fns.ts@@ -22,6 +22,7 @@ import {transferSqlConnectionCredentialsToPlatform,validateSqlConnectionCredentials} from "@app/services/app-connection/shared/sql";+import { TIdentityUaDALFactory } from "@app/services/identity-ua/identity-ua-dal";import { KmsDataKey } from "@app/services/kms/kms-types";import { SECRET_SYNC_CONNECTION_MAP } from "@app/services/secret-sync/secret-sync-maps";@@ -112,6 +113,12 @@ import {getDNSMadeEasyConnectionListItem,validateDNSMadeEasyConnectionCredentials} from "./dns-made-easy/dns-made-easy-connection-fns";+import {+ ExternalInfisicalConnectionMethod,+ getExternalInfisicalConnectionListItem,+ TExternalInfisicalConnectionConfig,+ validateExternalInfisicalConnectionCredentials+} from "./external-infisical";import { FlyioConnectionMethod, getFlyioConnectionListItem, validateFlyioConnectionCredentials } from "./flyio";import { GcpConnectionMethod, getGcpConnectionListItem, validateGcpConnectionCredentials } from "./gcp";import { getGitHubConnectionListItem, GitHubConnectionMethod, validateGitHubConnectionCredentials } from "./github";@@ -271,7 +278,8 @@ export const listAppConnectionOptions = (projectType?: ProjectType) => {getOpenRouterConnectionListItem(),getCircleCIConnectionListItem(),getAzureEntraIdConnectionListItem(),- getVenafiConnectionListItem()+ getVenafiConnectionListItem(),+ getExternalInfisicalConnectionListItem()].filter((option) => {switch (projectType) {@@ -357,7 +365,8 @@ export const decryptAppConnectionCredentials = async ({export const validateAppConnectionCredentials = async (appConnection: TAppConnectionConfig,gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,- gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">,+ deps?: { identityUaDAL?: Pick<TIdentityUaDALFactory, "findOne"> }): Promise<TAppConnection["credentials"]> => {const VALIDATE_APP_CONNECTION_CREDENTIALS_MAP: Record<AppConnection, TAppConnectionCredentialsValidator> = {[AppConnection.AWS]: validateAwsConnectionCredentials as TAppConnectionCredentialsValidator,@@ -414,7 +423,12 @@ export const validateAppConnectionCredentials = async ([AppConnection.OpenRouter]: validateOpenRouterConnectionCredentials as TAppConnectionCredentialsValidator,[AppConnection.CircleCI]: validateCircleCIConnectionCredentials as TAppConnectionCredentialsValidator,[AppConnection.AzureEntraId]: validateAzureEntraIdConnectionCredentials as TAppConnectionCredentialsValidator,- [AppConnection.Venafi]: validateVenafiConnectionCredentials as TAppConnectionCredentialsValidator+ [AppConnection.Venafi]: validateVenafiConnectionCredentials as TAppConnectionCredentialsValidator,+ [AppConnection.ExternalInfisical]: ((config: TAppConnectionConfig) =>+ validateExternalInfisicalConnectionCredentials(+ config as TExternalInfisicalConnectionConfig,+ deps!.identityUaDAL!+ )) as TAppConnectionCredentialsValidator};return VALIDATE_APP_CONNECTION_CREDENTIALS_MAP[appConnection.app](appConnection, gatewayService, gatewayV2Service);@@ -504,6 +518,8 @@ export const getAppConnectionMethodName = (method: TAppConnection["method"]) =>return "User Key";case SupabaseConnectionMethod.AccessToken:return "Access Token";+ case ExternalInfisicalConnectionMethod.MachineIdentity:+ return "Machine Identity";default:// eslint-disable-next-line @typescript-eslint/restrict-template-expressionsthrow new Error(`Unhandled App Connection Method: ${method}`);@@ -610,7 +626,8 @@ export const TRANSITION_CONNECTION_CREDENTIALS_TO_PLATFORM: Record<[AppConnection.OpenRouter]: platformManagedCredentialsNotSupported,[AppConnection.CircleCI]: platformManagedCredentialsNotSupported,[AppConnection.AzureEntraId]: platformManagedCredentialsNotSupported,- [AppConnection.Venafi]: platformManagedCredentialsNotSupported+ [AppConnection.Venafi]: platformManagedCredentialsNotSupported,+ [AppConnection.ExternalInfisical]: platformManagedCredentialsNotSupported};export const enterpriseAppCheck = async (diff --git a/backend/src/services/app-connection/app-connection-maps.ts b/backend/src/services/app-connection/app-connection-maps.tsindex ea1da6b11a..e5e9587471 100644--- a/backend/src/services/app-connection/app-connection-maps.ts+++ b/backend/src/services/app-connection/app-connection-maps.ts@@ -53,7 +53,8 @@ export const APP_CONNECTION_NAME_MAP: Record<AppConnection, string> = {[AppConnection.OpenRouter]: "OpenRouter",[AppConnection.CircleCI]: "CircleCI",[AppConnection.AzureEntraId]: "Azure Entra ID",- [AppConnection.Venafi]: "Venafi TLS Protect Cloud"+ [AppConnection.Venafi]: "Venafi TLS Protect Cloud",+ [AppConnection.ExternalInfisical]: "Infisical"};export const APP_CONNECTION_PLAN_MAP: Record<AppConnection, AppConnectionPlanType> = {@@ -109,5 +110,6 @@ export const APP_CONNECTION_PLAN_MAP: Record<AppConnection, AppConnectionPlanTyp[AppConnection.OpenRouter]: AppConnectionPlanType.Regular,[AppConnection.CircleCI]: AppConnectionPlanType.Regular,[AppConnection.AzureEntraId]: AppConnectionPlanType.Regular,- [AppConnection.Venafi]: AppConnectionPlanType.Regular+ [AppConnection.Venafi]: AppConnectionPlanType.Regular,+ [AppConnection.ExternalInfisical]: AppConnectionPlanType.Regular};diff --git a/backend/src/services/app-connection/app-connection-types.ts b/backend/src/services/app-connection/app-connection-types.tsindex 83798025ae..b9e028020e 100644--- a/backend/src/services/app-connection/app-connection-types.ts+++ b/backend/src/services/app-connection/app-connection-types.ts@@ -136,6 +136,12 @@ import {TDNSMadeEasyConnectionInput,TValidateDNSMadeEasyConnectionCredentialsSchema} from "./dns-made-easy/dns-made-easy-connection-types";+import {+ TExternalInfisicalConnection,+ TExternalInfisicalConnectionConfig,+ TExternalInfisicalConnectionInput,+ TValidateExternalInfisicalConnectionCredentialsSchema+} from "./external-infisical";import {TFlyioConnection,TFlyioConnectionConfig,@@ -366,6 +372,7 @@ export type TAppConnection = { id: string } & (| TCircleCIConnection| TAzureEntraIdConnection| TVenafiConnection+ | TExternalInfisicalConnection);export type TAppConnectionRaw = NonNullable<Awaited<ReturnType<TAppConnectionDALFactory["findById"]>>>;@@ -430,6 +437,7 @@ export type TAppConnectionInput = { id: string } & (| TCircleCIConnectionInput| TAzureEntraIdConnectionInput| TVenafiConnectionInput+ | TExternalInfisicalConnectionInput);export type TSqlConnectionInput =@@ -522,7 +530,8 @@ export type TAppConnectionConfig =| TOpenRouterConnectionConfig| TCircleCIConnectionConfig| TAzureEntraIdConnectionConfig- | TVenafiConnectionConfig;+ | TVenafiConnectionConfig+ | TExternalInfisicalConnectionConfig;export type TValidateAppConnectionCredentialsSchema =| TValidateAwsConnectionCredentialsSchema@@ -577,7 +586,8 @@ export type TValidateAppConnectionCredentialsSchema =| TValidateOpenRouterConnectionCredentialsSchema| TValidateCircleCIConnectionCredentialsSchema| TValidateAzureEntraIdConnectionCredentialsSchema- | TValidateVenafiConnectionCredentialsSchema;+ | TValidateVenafiConnectionCredentialsSchema+ | TValidateExternalInfisicalConnectionCredentialsSchema;export type TListAwsConnectionKmsKeys = {connectionId: string;diff --git a/backend/src/services/app-connection/external-infisical/external-infisical-connection-enums.ts b/backend/src/services/app-connection/external-infisical/external-infisical-connection-enums.tsnew file mode 100644index 0000000000..1996ef559c--- /dev/null+++ b/backend/src/services/app-connection/external-infisical/external-infisical-connection-enums.ts@@ -0,0 +1,3 @@+export enum ExternalInfisicalConnectionMethod {+ MachineIdentity = "machine-identity"+}diff --git a/backend/src/services/app-connection/external-infisical/external-infisical-connection-fns.ts b/backend/src/services/app-connection/external-infisical/external-infisical-connection-fns.tsnew file mode 100644index 0000000000..566276412a--- /dev/null+++ b/backend/src/services/app-connection/external-infisical/external-infisical-connection-fns.ts@@ -0,0 +1,146 @@+import { AxiosError } from "axios";++import { request } from "@app/lib/config/request";+import { BadRequestError } from "@app/lib/errors";+import { TIdentityUaDALFactory } from "@app/services/identity-ua/identity-ua-dal";++import { AppConnection } from "../app-connection-enums";+import { ExternalInfisicalConnectionMethod } from "./external-infisical-connection-enums";+import {+ TExternalInfisicalConnection,+ TExternalInfisicalConnectionConfig+} from "./external-infisical-connection-types";++export type TRemoteProject = {+ id: string;+ name: string;+ slug: string;+ environments: Array<{ id: string; name: string; slug: string }>;+};++export type TRemoteEnvironmentFolderTree = Record<+ string,+ { id: string; name: string; slug: string; folders: Array<{ id: string; name: string; path: string }> }+>;++export const getExternalInfisicalConnectionListItem = () => {+ return {+ name: "Infisical" as const,+ app: AppConnection.ExternalInfisical as const,+ methods: Object.values(ExternalInfisicalConnectionMethod) as [ExternalInfisicalConnectionMethod.MachineIdentity]+ };+};++export const getExternalInfisicalAccessToken = async (credentials: {+ instanceUrl: string;+ machineIdentityClientId: string;+ machineIdentityClientSecret: string;+}): Promise<string> => {+ const { instanceUrl, machineIdentityClientId, machineIdentityClientSecret } = credentials;++ const { data } = await request.post<{ accessToken: string; expiresIn: number; tokenType: string }>(+ `${instanceUrl}/api/v1/auth/universal-auth/login`,+ {+ clientId: machineIdentityClientId,+ clientSecret: machineIdentityClientSecret+ }+ );++ return data.accessToken;+};++export const validateExternalInfisicalConnectionCredentials = async (+ config: TExternalInfisicalConnectionConfig,+ identityUaDAL: Pick<TIdentityUaDALFactory, "findOne">+) => {+ const { credentials: inputCredentials } = config;++ const localIdentity = await identityUaDAL.findOne({+ clientId: inputCredentials.machineIdentityClientId+ });++ if (localIdentity) {+ throw new BadRequestError({+ message:+ "Cannot create an Infisical connection targeting the same instance. Use a machine identity from a different Infisical instance."+ });+ }++ try {+ await getExternalInfisicalAccessToken(inputCredentials);+ } catch (error: unknown) {+ if (error instanceof AxiosError) {+ throw new BadRequestError({+ message: `Failed to validate credentials: ${error.message || "Unknown error"}`+ });+ }+ throw new BadRequestError({+ message: "Unable to validate connection: verify credentials"+ });+ }++ return inputCredentials;+};++const getAuthHeaders = async (connection: TExternalInfisicalConnection) => {+ const token = await getExternalInfisicalAccessToken(connection.credentials);+ return { Authorization: `Bearer ${token}` };+};++const getBaseUrl = (connection: TExternalInfisicalConnection) => connection.credentials.instanceUrl.replace(/\/$/, "");++export const listProjects = async (connection: TExternalInfisicalConnection): Promise<TRemoteProject[]> => {+ const baseUrl = getBaseUrl(connection);+ const headers = await getAuthHeaders(connection);+ try {+ const { data } = await request.get<{+ projects: Array<{+ id: string;+ name: string;+ slug: string;+ environments?: Array<{ id: string; name: string; slug: string }>;+ }>;+ }>(`${baseUrl}/api/v1/projects`, { headers });+ return (data.projects ?? []).map((p) => ({+ id: p.id,+ name: p.name,+ slug: p.slug,+ environments: p.environments ?? []+ }));+ } catch (error: unknown) {+ if (error instanceof AxiosError) {+ throw new BadRequestError({+ message: `Failed to list projects from remote Infisical: ${error.message || "Unknown error"}`+ });+ }+ throw new BadRequestError({+ message: "Unable to list projects from remote Infisical",+ error: error as Error+ });+ }+};++export const getEnvironmentFolderTree = async (+ connection: TExternalInfisicalConnection,+ projectId: string+): Promise<TRemoteEnvironmentFolderTree> => {+ const baseUrl = getBaseUrl(connection);+ const headers = await getAuthHeaders(connection);+ try {+ const { data } = await request.get<TRemoteEnvironmentFolderTree>(+ `${baseUrl}/api/v1/projects/${projectId}/environment-folder-tree`,+ { headers }+ );+ return data ?? {};+ } catch (error: unknown) {+ if (error instanceof AxiosError) {+ throw new BadRequestError({+ message: `Failed to get folder tree from remote Infisical: ${error.message || "Unknown error"}`+ });+ }+ throw new BadRequestError({+ message: "Unable to get folder tree from remote Infisical",+ error: error as Error+ });+ }+};diff --git a/backend/src/services/app-connection/external-infisical/external-infisical-connection-schemas.ts b/backend/src/services/app-connection/external-infisical/external-infisical-connection-schemas.tsnew file mode 100644index 0000000000..c656242d17--- /dev/null+++ b/backend/src/services/app-connection/external-infisical/external-infisical-connection-schemas.ts@@ -0,0 +1,85 @@+import z from "zod";++import { AppConnections } from "@app/lib/api-docs";+import { AppConnection } from "@app/services/app-connection/app-connection-enums";+import {+ BaseAppConnectionSchema,+ GenericCreateAppConnectionFieldsSchema,+ GenericUpdateAppConnectionFieldsSchema+} from "@app/services/app-connection/app-connection-schemas";++import { APP_CONNECTION_NAME_MAP } from "../app-connection-maps";+import { ExternalInfisicalConnectionMethod } from "./external-infisical-connection-enums";++export const ExternalInfisicalConnectionMachineIdentityCredentialsSchema = z.object({+ instanceUrl: z+ .string()+ .trim()+ .url("Instance URL must be a valid URL")+ .min(1, "Instance URL is required")+ .max(512, "Instance URL cannot exceed 512 characters"),+ machineIdentityClientId: z+ .string()+ .trim()+ .uuid("Machine Identity Client ID must be a valid UUID")+ .min(1, "Machine Identity Client ID is required"),+ machineIdentityClientSecret: z+ .string()+ .trim()+ .min(1, "Machine Identity Client Secret is required")+ .max(512, "Machine Identity Client Secret cannot exceed 512 characters")+});++const BaseExternalInfisicalConnectionSchema = BaseAppConnectionSchema.extend({+ app: z.literal(AppConnection.ExternalInfisical)+});++export const ExternalInfisicalConnectionSchema = BaseExternalInfisicalConnectionSchema.extend({+ method: z.literal(ExternalInfisicalConnectionMethod.MachineIdentity),+ credentials: ExternalInfisicalConnectionMachineIdentityCredentialsSchema+});++export const SanitizedExternalInfisicalConnectionSchema = z.discriminatedUnion("method", [+ BaseExternalInfisicalConnectionSchema.extend({+ method: z.literal(ExternalInfisicalConnectionMethod.MachineIdentity),+ credentials: ExternalInfisicalConnectionMachineIdentityCredentialsSchema.pick({+ instanceUrl: true,+ machineIdentityClientId: true+ })+ }).describe(+ JSON.stringify({+ title: `${APP_CONNECTION_NAME_MAP[AppConnection.ExternalInfisical]} (Machine Identity)`+ })+ )+]);++export const ValidateExternalInfisicalConnectionCredentialsSchema = z.discriminatedUnion("method", [+ z.object({+ method: z+ .literal(ExternalInfisicalConnectionMethod.MachineIdentity)+ .describe(AppConnections.CREATE(AppConnection.ExternalInfisical).method),+ credentials: ExternalInfisicalConnectionMachineIdentityCredentialsSchema.describe(+ AppConnections.CREATE(AppConnection.ExternalInfisical).credentials+ )+ })+]);++export const CreateExternalInfisicalConnectionSchema = ValidateExternalInfisicalConnectionCredentialsSchema.and(+ GenericCreateAppConnectionFieldsSchema(AppConnection.ExternalInfisical)+);++export const UpdateExternalInfisicalConnectionSchema = z+ .object({+ credentials: ExternalInfisicalConnectionMachineIdentityCredentialsSchema.optional().describe(+ AppConnections.UPDATE(AppConnection.ExternalInfisical).credentials+ )+ })+ .and(GenericUpdateAppConnectionFieldsSchema(AppConnection.ExternalInfisical));++export const ExternalInfisicalConnectionListItemSchema = z+ .object({+ name: z.literal("Infisical"),+ app: z.literal(AppConnection.ExternalInfisical),+ methods: z.nativeEnum(ExternalInfisicalConnectionMethod).array()+ })+ .describe(JSON.stringify({ title: APP_CONNECTION_NAME_MAP[AppConnection.ExternalInfisical] }));diff --git a/backend/src/services/app-connection/external-infisical/external-infisical-connection-service.ts b/backend/src/services/app-connection/external-infisical/external-infisical-connection-service.tsnew file mode 100644index 0000000000..0b47bb1c5a--- /dev/null+++ b/backend/src/services/app-connection/external-infisical/external-infisical-connection-service.ts@@ -0,0 +1,48 @@+import { logger } from "@app/lib/logger";+import { OrgServiceActor } from "@app/lib/types";++import { AppConnection } from "../app-connection-enums";+import {+ getEnvironmentFolderTree as getRemoteEnvironmentFolderTree,+ listProjects as listRemoteProjects,+ TRemoteEnvironmentFolderTree,+ TRemoteProject+} from "./external-infisical-connection-fns";+import { TExternalInfisicalConnection } from "./external-infisical-connection-types";++type TGetAppConnectionFunc = (+ app: AppConnection,+ connectionId: string,+ actor: OrgServiceActor+) => Promise<TExternalInfisicalConnection>;++export const externalInfisicalConnectionService = (getAppConnection: TGetAppConnectionFunc) => {+ const listProjects = async (connectionId: string, actor: OrgServiceActor): Promise<TRemoteProject[]> => {+ const appConnection = await getAppConnection(AppConnection.ExternalInfisical, connectionId, actor);+ try {+ return await listRemoteProjects(appConnection);+ } catch (error) {+ logger.error(error, "Failed to list projects from remote Infisical");+ return [];+ }+ };++ const getEnvironmentFolderTree = async (+ connectionId: string,+ projectId: string,+ actor: OrgServiceActor+ ): Promise<TRemoteEnvironmentFolderTree> => {+ const appConnection = await getAppConnection(AppConnection.ExternalInfisical, connectionId, actor);+ try {+ return await getRemoteEnvironmentFolderTree(appConnection, projectId);+ } catch (error) {+ logger.error(error, "Failed to get environment folder tree from remote Infisical");+ return {};+ }+ };++ return {+ listProjects,+ getEnvironmentFolderTree+ };+};diff --git a/backend/src/services/app-connection/external-infisical/external-infisical-connection-types.ts b/backend/src/services/app-connection/external-infisical/external-infisical-connection-types.tsnew file mode 100644index 0000000000..f71a7e7b3c--- /dev/null+++ b/backend/src/services/app-connection/external-infisical/external-infisical-connection-types.ts@@ -0,0 +1,26 @@+import z from "zod";++import { DiscriminativePick } from "@app/lib/types";++import { AppConnection } from "../app-connection-enums";+import {+ CreateExternalInfisicalConnectionSchema,+ ExternalInfisicalConnectionSchema,+ ValidateExternalInfisicalConnectionCredentialsSchema+} from "./external-infisical-connection-schemas";++export type TExternalInfisicalConnection = z.infer<typeof ExternalInfisicalConnectionSchema>;++export type TExternalInfisicalConnectionInput = z.infer<typeof CreateExternalInfisicalConnectionSchema> & {+ app: AppConnection.ExternalInfisical;+};++export type TValidateExternalInfisicalConnectionCredentialsSchema =+ typeof ValidateExternalInfisicalConnectionCredentialsSchema;++export type TExternalInfisicalConnectionConfig = DiscriminativePick<+ TExternalInfisicalConnectionInput,+ "method" | "app" | "credentials"+> & {+ orgId: string;+};diff --git a/backend/src/services/app-connection/external-infisical/index.ts b/backend/src/services/app-connection/external-infisical/index.tsnew file mode 100644index 0000000000..1f011eae36--- /dev/null+++ b/backend/src/services/app-connection/external-infisical/index.ts@@ -0,0 +1,4 @@+export * from "./external-infisical-connection-enums";+export * from "./external-infisical-connection-fns";+export * from "./external-infisical-connection-schemas";+export * from "./external-infisical-connection-types";