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
chore: removal of external migration config DAL's & cleanup
Daniel305bd91b38bd
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.tsindex 259384ef0a..9411fb27d3 100644--- a/backend/src/server/routes/index.ts+++ b/backend/src/server/routes/index.ts@@ -306,7 +306,6 @@ import { estEnrollmentConfigDALFactory } from "@app/services/enrollment-config/eimport { scepEnrollmentConfigDALFactory } from "@app/services/enrollment-config/scep-enrollment-config-dal";import { externalGroupOrgRoleMappingDALFactory } from "@app/services/external-group-org-role-mapping/external-group-org-role-mapping-dal";import { externalGroupOrgRoleMappingServiceFactory } from "@app/services/external-group-org-role-mapping/external-group-org-role-mapping-service";-import { externalMigrationConfigDALFactory } from "@app/services/external-migration/external-migration-config-dal";import { externalMigrationQueueFactory } from "@app/services/external-migration/external-migration-queue";import { externalMigrationServiceFactory } from "@app/services/external-migration/external-migration-service";import { folderCheckpointDALFactory } from "@app/services/folder-checkpoint/folder-checkpoint-dal";@@ -721,8 +720,6 @@ export const registerRoutes = async (const appConnectionCredentialRotationDAL = appConnectionCredentialRotationDALFactory(db);- const externalMigrationConfigDAL = externalMigrationConfigDALFactory(db);-// New event bus for inter-container communicationconst eventBusService = eventBusServiceFactory({ redis: server.redis });@@ -3303,9 +3300,7 @@ export const registerRoutes = async (userDAL,permissionService,gatewayService,- kmsService,appConnectionService,- externalMigrationConfigDAL,secretService,auditLogService,gatewayV2Service,diff --git a/backend/src/services/external-migration/external-migration-config-dal.ts b/backend/src/services/external-migration/external-migration-config-dal.tsdeleted file mode 100644index f4c05b49f2..0000000000--- a/backend/src/services/external-migration/external-migration-config-dal.ts+++ /dev/null@@ -1,94 +0,0 @@-import { Knex } from "knex";--import { TDbClient } from "@app/db";-import { TableName, TExternalMigrationConfigs } from "@app/db/schemas";-import { DatabaseError } from "@app/lib/errors";-import { buildFindFilter, ormify, prependTableNameToFindFilter, selectAllTableCols } from "@app/lib/knex";--export type TExternalMigrationConfigDALFactory = ReturnType<typeof externalMigrationConfigDALFactory>;--const buildConnectionJoin = (qb: Knex.QueryBuilder, db: TDbClient) =>- qb- .leftJoin(- TableName.AppConnection,- `${TableName.AppConnection}.id`,- `${TableName.ExternalMigrationConfig}.connectionId`- )- .select(selectAllTableCols(TableName.ExternalMigrationConfig))- .select(- db.ref("id").withSchema(TableName.AppConnection).as("appConnectionId"),- db.ref("name").withSchema(TableName.AppConnection).as("appConnectionName"),- db.ref("app").withSchema(TableName.AppConnection).as("appConnectionApp"),- db.ref("encryptedCredentials").withSchema(TableName.AppConnection).as("appConnectionEncryptedCredentials"),- db.ref("orgId").withSchema(TableName.AppConnection).as("appConnectionOrgId"),- db.ref("isAutoRotationEnabled").withSchema(TableName.AppConnection).as("appConnectionIsAutoRotationEnabled"),- db.ref("method").withSchema(TableName.AppConnection).as("appConnectionMethod"),- db.ref("description").withSchema(TableName.AppConnection).as("appConnectionDescription"),- db.ref("version").withSchema(TableName.AppConnection).as("appConnectionVersion"),- db.ref("gatewayId").withSchema(TableName.AppConnection).as("appConnectionGatewayId"),- db.ref("gatewayPoolId").withSchema(TableName.AppConnection).as("appConnectionGatewayPoolId"),- db.ref("projectId").withSchema(TableName.AppConnection).as("appConnectionProjectId"),- db.ref("createdAt").withSchema(TableName.AppConnection).as("appConnectionCreatedAt"),- db.ref("updatedAt").withSchema(TableName.AppConnection).as("appConnectionUpdatedAt")- );--const mapResultToConnection = (raw: Record<string, unknown>) => {- const result = raw as TExternalMigrationConfigs & Record<string, unknown>;- return {- ...result,- connection: raw.appConnectionId- ? {- id: raw.appConnectionId as string,- name: raw.appConnectionName as string,- app: raw.appConnectionApp,- encryptedCredentials: raw.appConnectionEncryptedCredentials as Buffer,- orgId: raw.appConnectionOrgId as string,- method: raw.appConnectionMethod,- description: raw.appConnectionDescription,- version: raw.appConnectionVersion,- gatewayId: raw.appConnectionGatewayId,- gatewayPoolId: raw.appConnectionGatewayPoolId,- projectId: raw.appConnectionProjectId,- createdAt: raw.appConnectionCreatedAt as Date,- updatedAt: raw.appConnectionUpdatedAt as Date,- isAutoRotationEnabled: raw.appConnectionIsAutoRotationEnabled as boolean- }- : undefined- };-};--export const externalMigrationConfigDALFactory = (db: TDbClient) => {- const orm = ormify(db, TableName.ExternalMigrationConfig);-- const findOne = async (filter: { orgId: string; provider?: string; connectionId?: string | null }, tx?: Knex) => {- try {- const qb = buildConnectionJoin((tx || db?.replicaNode?.() || db)(TableName.ExternalMigrationConfig), db);- /* eslint-disable @typescript-eslint/no-misused-promises */- void qb.where(buildFindFilter(prependTableNameToFindFilter(TableName.ExternalMigrationConfig, filter)));- /* eslint-enable @typescript-eslint/no-misused-promises */-- const result = (await qb.first()) as Record<string, unknown> | undefined;- if (!result) return undefined;-- return mapResultToConnection(result);- } catch (error) {- throw new DatabaseError({ error, name: "Find one" });- }- };-- const findWithConnection = async (filter: { orgId: string; provider?: string }, tx?: Knex) => {- try {- const qb = buildConnectionJoin((tx || db?.replicaNode?.() || db)(TableName.ExternalMigrationConfig), db);- /* eslint-disable @typescript-eslint/no-misused-promises */- void qb.where(buildFindFilter(prependTableNameToFindFilter(TableName.ExternalMigrationConfig, filter)));- /* eslint-enable @typescript-eslint/no-misused-promises */-- const results = (await qb) as Record<string, unknown>[];- return results.map(mapResultToConnection);- } catch (error) {- throw new DatabaseError({ error, name: "Find with connection" });- }- };-- return { ...orm, findOne, findWithConnection };-};diff --git a/backend/src/services/external-migration/external-migration-service.ts b/backend/src/services/external-migration/external-migration-service.tsindex 85f4e4c59a..d34cab3a3d 100644--- a/backend/src/services/external-migration/external-migration-service.ts+++ b/backend/src/services/external-migration/external-migration-service.ts@@ -11,12 +11,11 @@ import { TGatewayPoolServiceFactory } from "@app/ee/services/gateway-pool/gatewaimport { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service";import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";import { crypto } from "@app/lib/crypto/cryptography";-import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";+import { BadRequestError, ForbiddenRequestError } from "@app/lib/errors";import { GatewayVersion } from "@app/lib/gateway/types";import { OrgServiceActor } from "@app/lib/types";import { AppConnection } from "../app-connection/app-connection-enums";-import { decryptAppConnectionCredentials } from "../app-connection/app-connection-fns";import { TAppConnectionServiceFactory } from "../app-connection/app-connection-service";import { TDopplerConnection } from "../app-connection/doppler";import {@@ -37,12 +36,9 @@ import {TGatewayDetails,THCVaultConnection} from "../app-connection/hc-vault";-import { TKmsServiceFactory } from "../kms/kms-service";-import { KmsDataKey } from "../kms/kms-types";import { TSecretServiceFactory } from "../secret/secret-service";import { SecretProtectionType } from "../secret/secret-types";import { TUserDALFactory } from "../user/user-dal";-import { TExternalMigrationConfigDALFactory } from "./external-migration-config-dal";import {decryptEnvKeyDataFn,getDopplerSecrets,@@ -54,7 +50,7 @@ import {vaultMigrationTransformMappings} from "./external-migration-fns";import { TExternalMigrationQueueFactory } from "./external-migration-queue";-import { ExternalMigrationConfigVaultConfigSchema, ExternalMigrationProviders } from "./external-migration-schemas";+import { ExternalMigrationProviders } from "./external-migration-schemas";import {ExternalMigrationImportStatus,ExternalPlatforms,@@ -73,7 +69,6 @@ type TExternalMigrationServiceFactoryDep = {TAppConnectionServiceFactory,"connectAppConnectionById" | "validateAppConnectionUsageById">;- externalMigrationConfigDAL: Pick<TExternalMigrationConfigDALFactory, "find" | "findWithConnection" | "findById">;userDAL: Pick<TUserDALFactory, "findById">;gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">;gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">;@@ -81,7 +76,6 @@ type TExternalMigrationServiceFactoryDep = {TGatewayPoolServiceFactory,"resolveEffectiveGatewayId" | "resolveAttachableGatewayFromPool" | "pickRandomHealthyGateway">;- kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;};export type TExternalMigrationServiceFactory = ReturnType<typeof externalMigrationServiceFactory>;@@ -95,9 +89,7 @@ export const externalMigrationServiceFactory = ({gatewayPoolService,secretService,auditLogService,- appConnectionService,- externalMigrationConfigDAL,- kmsService+ appConnectionService}: TExternalMigrationServiceFactoryDep) => {const getGatewayDetails = async (connection: THCVaultConnection) => {let gatewayDetails: TGatewayDetails | undefined;@@ -153,80 +145,6 @@ export const externalMigrationServiceFactory = ({return gatewayDetails;};- const getVaultConnectionForImport = async (connectionId: string, projectId: string, actor: OrgServiceActor) =>- (await appConnectionService.validateAppConnectionUsageById(- AppConnection.HCVault,- { connectionId, projectId },- actor- )) as THCVaultConnection;-- // Org-admin only; resolves via the org-level external migration config matched by namespace.- const getVaultConnectionForNamespace = async (actor: OrgServiceActor, namespace: string, action: string) => {- const { hasRole } = await permissionService.getOrgPermission({- scope: OrganizationActionScope.Any,- actor: actor.type,- actorId: actor.id,- orgId: actor.orgId,- actorAuthMethod: actor.authMethod,- actorOrgId: actor.orgId- });-- if (!hasRole(OrgMembershipRole.Admin)) {- throw new ForbiddenRequestError({ message: `Only admins can ${action}` });- }-- const existingConfig = await externalMigrationConfigDAL.findWithConnection({- orgId: actor.orgId,- provider: ExternalMigrationProviders.Vault- });-- const { decryptor } = await kmsService.createCipherPairWithDataKey({- type: KmsDataKey.Organization,- orgId: actor.orgId- });-- const migrationConfig = existingConfig- .map((config) => {- const decryptedConfig = decryptor({ cipherTextBlob: config.encryptedConfig });-- return {- ...config,- config: ExternalMigrationConfigVaultConfigSchema.parse(JSON.parse(decryptedConfig.toString()))- };- })- .find((config) => config.config.namespace === namespace);-- if (!migrationConfig) {- throw new NotFoundError({ message: "Vault migration config not found for this namespace" });- }-- if (!migrationConfig.connection) {- throw new BadRequestError({ message: "Vault migration connection is not configured for this namespace" });- }-- const credentials = await decryptAppConnectionCredentials({- orgId: migrationConfig.orgId,- encryptedCredentials: migrationConfig.connection?.encryptedCredentials,- kmsService,- projectId: null- });-- const connectionGatewayId = migrationConfig.connection.gatewayId as string | null | undefined;- const connectionGatewayPoolId = migrationConfig.connection.gatewayPoolId as string | null | undefined;-- const effectiveGatewayId = await gatewayPoolService.resolveEffectiveGatewayId({- gatewayId: connectionGatewayId,- gatewayPoolId: connectionGatewayPoolId- });-- return {- ...migrationConfig.connection,- credentials,- gatewayId: effectiveGatewayId,- gatewayPoolId: null- } as THCVaultConnection;- };-const importEnvKeyData = async ({decryptionKey,encryptedJson,@@ -470,12 +388,14 @@ export const externalMigrationServiceFactory = ({secretPath: string;vaultNamespace: string;vaultSecretPaths: string[];- connectionId?: string;+ connectionId: string;auditLogInfo: AuditLogInfo;}) => {- const connection = connectionId- ? await getVaultConnectionForImport(connectionId, projectId, actor)- : await getVaultConnectionForNamespace(actor, vaultNamespace, "import vault secrets");+ const connection = (await appConnectionService.validateAppConnectionUsageById(+ AppConnection.HCVault,+ { connectionId, projectId },+ actor+ )) as THCVaultConnection;if (!vaultSecretPaths.length) {throw new BadRequestError({ message: "At least one Vault secret path is required" });