Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

remove config id and support for vault config and doppler config from the backend

adilson84285da2f64a
diff --git a/backend/src/server/routes/v3/external-migration-router.ts b/backend/src/server/routes/v3/external-migration-router.ts
index c2a4af10b6..d5fc36fda6 100644
--- a/backend/src/server/routes/v3/external-migration-router.ts
+++ b/backend/src/server/routes/v3/external-migration-router.ts
@@ -130,7 +130,7 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
schema: {
operationId: "getVaultNamespacesV3",
querystring: z.object({
- connectionId: z.string().uuid().optional()
+ connectionId: z.string().uuid()
}),
response: {
200: z.object({
@@ -159,7 +159,7 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
operationId: "getVaultPoliciesV3",
querystring: z.object({
namespace: z.string(),
- connectionId: z.string().uuid().optional()
+ connectionId: z.string().uuid()
}),
response: {
200: z.object({
@@ -189,7 +189,7 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
operationId: "getVaultMountsV3",
querystring: z.object({
namespace: z.string(),
- connectionId: z.string().uuid().optional()
+ connectionId: z.string().uuid()
}),
response: {
200: z.object({
@@ -220,7 +220,7 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
querystring: z.object({
namespace: z.string(),
authType: z.string().optional(),
- connectionId: z.string().uuid().optional()
+ connectionId: z.string().uuid()
}),
response: {
200: z.object({
@@ -255,7 +255,7 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
secretPath: z.string(),
vaultNamespace: z.string(),
vaultSecretPaths: z.array(z.string()).min(1),
- connectionId: z.string().uuid().optional()
+ connectionId: z.string().uuid()
}),
response: {
200: z.object({
@@ -286,7 +286,7 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
querystring: z.object({
namespace: z.string(),
mountPath: z.string(),
- connectionId: z.string().uuid().optional()
+ connectionId: z.string().uuid()
}),
response: {
200: z.object({
@@ -339,7 +339,7 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
querystring: z.object({
namespace: z.string(),
mountPath: z.string(),
- connectionId: z.string().uuid().optional()
+ connectionId: z.string().uuid()
}),
response: {
200: z.object({
@@ -391,7 +391,7 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
querystring: z.object({
namespace: z.string(),
mountPath: z.string(),
- connectionId: z.string().uuid().optional()
+ connectionId: z.string().uuid()
}),
response: {
200: z.object({
@@ -423,7 +423,7 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
querystring: z.object({
namespace: z.string(),
mountPath: z.string(),
- connectionId: z.string().uuid().optional()
+ connectionId: z.string().uuid()
}),
response: {
@@ -481,7 +481,7 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
querystring: z.object({
namespace: z.string(),
mountPath: z.string(),
- connectionId: z.string().uuid().optional()
+ connectionId: z.string().uuid()
}),
response: {
200: z.object({
@@ -520,14 +520,6 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
// ─── Doppler In-Platform Migration Routes ────────────────────────────────────
- const assertExactlyOneDopplerSelector = (configId?: string, connectionId?: string) => {
- if (Boolean(configId) === Boolean(connectionId)) {
- throw new BadRequestError({
- message: "Exactly one of configId or connectionId must be provided"
- });
- }
- };
-
server.route({
method: "GET",
url: "/doppler/projects",
@@ -535,8 +527,7 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
schema: {
operationId: "getDopplerProjectsV3",
querystring: z.object({
- configId: z.string().uuid().optional(),
- connectionId: z.string().uuid().optional()
+ connectionId: z.string().uuid()
}),
response: {
200: z.object({
@@ -553,9 +544,7 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
- assertExactlyOneDopplerSelector(req.query.configId, req.query.connectionId);
const projects = await server.services.migration.getDopplerProjects({
- configId: req.query.configId,
connectionId: req.query.connectionId,
actor: req.permission
});
@@ -570,8 +559,7 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
schema: {
operationId: "getDopplerEnvironmentsV3",
querystring: z.object({
- configId: z.string().uuid().optional(),
- connectionId: z.string().uuid().optional(),
+ connectionId: z.string().uuid(),
projectSlug: z.string().min(1)
}),
response: {
@@ -590,9 +578,7 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
- assertExactlyOneDopplerSelector(req.query.configId, req.query.connectionId);
const environments = await server.services.migration.getDopplerEnvironments({
- configId: req.query.configId,
connectionId: req.query.connectionId,
projectSlug: req.query.projectSlug,
actor: req.permission
@@ -608,8 +594,7 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
schema: {
operationId: "getDopplerConfigsV3",
querystring: z.object({
- configId: z.string().uuid().optional(),
- connectionId: z.string().uuid().optional(),
+ connectionId: z.string().uuid(),
projectSlug: z.string().min(1)
}),
response: {
@@ -628,9 +613,7 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
- assertExactlyOneDopplerSelector(req.query.configId, req.query.connectionId);
const configs = await server.services.migration.getDopplerConfigs({
- configId: req.query.configId,
connectionId: req.query.connectionId,
projectSlug: req.query.projectSlug,
actor: req.permission
@@ -646,8 +629,7 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
schema: {
operationId: "importDopplerSecretsV3",
body: z.object({
- configId: z.string().uuid().optional(),
- connectionId: z.string().uuid().optional(),
+ connectionId: z.string().uuid(),
dopplerProject: z.string().min(1),
dopplerEnvironment: z.string().min(1),
targetProjectId: z.string().min(1),
@@ -660,7 +642,6 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
- assertExactlyOneDopplerSelector(req.body.configId, req.body.connectionId);
const result = await server.services.migration.importDopplerSecrets({
...req.body,
actor: req.permission,
diff --git a/backend/src/services/app-connection/app-connection-fns.ts b/backend/src/services/app-connection/app-connection-fns.ts
index 7722271fae..b634d38a98 100644
--- a/backend/src/services/app-connection/app-connection-fns.ts
+++ b/backend/src/services/app-connection/app-connection-fns.ts
@@ -397,7 +397,7 @@ export const decryptAppConnectionCredentials = async ({
encryptedCredentials: Buffer;
kmsService: TAppConnectionServiceFactoryDep["kmsService"];
projectId: string | null | undefined;
-}): Promise<TAppConnection["credentials"]> => {
+}) => {
const { decryptor } = await kmsService.createCipherPairWithDataKey(
projectId
? { type: KmsDataKey.SecretManager, projectId }
@@ -411,7 +411,7 @@ export const decryptAppConnectionCredentials = async ({
cipherTextBlob: encryptedCredentials
});
- return JSON.parse(decryptedPlainTextBlob.toString()) as unknown as TAppConnection["credentials"];
+ return JSON.parse(decryptedPlainTextBlob.toString()) as TAppConnection["credentials"];
};
export const validateAppConnectionCredentials = async (
diff --git a/backend/src/services/external-migration/external-migration-service.ts b/backend/src/services/external-migration/external-migration-service.ts
index 010a720f5f..85f4e4c59a 100644
--- a/backend/src/services/external-migration/external-migration-service.ts
+++ b/backend/src/services/external-migration/external-migration-service.ts
@@ -153,10 +153,6 @@ export const externalMigrationServiceFactory = ({
return gatewayDetails;
};
- // CASL is enforced inside connectAppConnectionById for project- or org-scoped connections.
- const getVaultConnectionById = async (connectionId: string, actor: OrgServiceActor) =>
- appConnectionService.connectAppConnectionById<THCVaultConnection>(AppConnection.HCVault, connectionId, actor);
-
const getVaultConnectionForImport = async (connectionId: string, projectId: string, actor: OrgServiceActor) =>
(await appConnectionService.validateAppConnectionUsageById(
AppConnection.HCVault,
@@ -231,14 +227,6 @@ export const externalMigrationServiceFactory = ({
} as THCVaultConnection;
};
- const resolveVaultConnection = async (
- actor: OrgServiceActor,
- { namespace, connectionId, action }: { namespace: string; connectionId?: string; action: string }
- ) =>
- connectionId
- ? getVaultConnectionById(connectionId, actor)
- : getVaultConnectionForNamespace(actor, namespace, action);
-
const importEnvKeyData = async ({
decryptionKey,
encryptedJson,
@@ -395,50 +383,13 @@ export const externalMigrationServiceFactory = ({
return actorOrgId in vaultMigrationTransformMappings;
};
- const getVaultNamespaces = async ({ actor, connectionId }: { actor: OrgServiceActor; connectionId?: string }) => {
- if (connectionId) {
- const connection = await getVaultConnectionById(connectionId, actor);
- return listHCVaultNamespaces(connection, gatewayService, gatewayV2Service);
- }
-
- const { hasRole } = await permissionService.getOrgPermission({
- actorId: actor.id,
- actor: actor.type,
- orgId: actor.orgId,
- actorOrgId: actor.orgId,
- actorAuthMethod: actor.authMethod,
- scope: OrganizationActionScope.Any
- });
-
- if (!hasRole(OrgMembershipRole.Admin)) {
- throw new ForbiddenRequestError({ message: "Only admins can view vault namespaces" });
- }
-
- // Get all configured namespaces for this org
- const vaultConfigs = await externalMigrationConfigDAL.find({
- orgId: actor.orgId,
- provider: ExternalMigrationProviders.Vault
- });
-
- const { decryptor } = await kmsService.createCipherPairWithDataKey({
- type: KmsDataKey.Organization,
- orgId: actor.orgId
- });
-
- // Return the configured namespaces as an array of objects with id and name
- // where both id and name are the namespace path
- const namespaces = vaultConfigs.map((config) => {
- const decryptedConfig = decryptor({ cipherTextBlob: config.encryptedConfig });
-
- const parsedConfig = ExternalMigrationConfigVaultConfigSchema.parse(JSON.parse(decryptedConfig.toString()));
-
- return {
- id: parsedConfig.namespace,
- name: parsedConfig.namespace
- };
- });
-
- return namespaces;
+ const getVaultNamespaces = async ({ actor, connectionId }: { actor: OrgServiceActor; connectionId: string }) => {
+ const connection = await appConnectionService.connectAppConnectionById<THCVaultConnection>(
+ AppConnection.HCVault,
+ connectionId,
+ actor
+ );
+ return listHCVaultNamespaces(connection, gatewayService, gatewayV2Service);
};
const getVaultPolicies = async ({
@@ -448,13 +399,13 @@ export const externalMigrationServiceFactory = ({
}: {
actor: OrgServiceActor;
namespace: string;
- connectionId?: string;
+ connectionId: string;
}) => {
- const connection = await resolveVaultConnection(actor, {
- namespace,
+ const connection = await appConnectionService.connectAppConnectionById<THCVaultConnection>(
+ AppConnection.HCVault,
connectionId,
- action: "view vault policies"
- });
+ actor
+ );
const gatewayDetails = await getGatewayDetails(connection);
@@ -468,13 +419,13 @@ export const externalMigrationServiceFactory = ({
}: {
actor: OrgServiceActor;
namespace: string;
- connectionId?: string;
+ connectionId: string;
}) => {
- const connection = await resolveVaultConnection(actor, {
- namespace,
+ const connection = await appConnectionService.connectAppConnectionById<THCVaultConnection>(
+ AppConnection.HCVault,
connectionId,
- action: "view vault mounts"
- });
+ actor
+ );
const gatewayDetails = await getGatewayDetails(connection);
@@ -490,13 +441,13 @@ export const externalMigrationServiceFactory = ({
actor: OrgServiceActor;
namespace: string;
mountPath: string;
- connectionId?: string;
+ connectionId: string;
}) => {
- const connection = await resolveVaultConnection(actor, {
- namespace,
+ const connection = await appConnectionService.connectAppConnectionById<THCVaultConnection>(
+ AppConnection.HCVault,
connectionId,
- action: "view vault secret paths"
- });
+ actor
+ );
const gatewayDetails = await getGatewayDetails(connection);
@@ -624,13 +575,13 @@ export const externalMigrationServiceFactory = ({
actor: OrgServiceActor;
namespace: string;
authType?: string;
- connectionId?: string;
+ connectionId: string;
}) => {
- const connection = await resolveVaultConnection(actor, {
- namespace,
+ const connection = await appConnectionService.connectAppConnectionById<THCVaultConnection>(
+ AppConnection.HCVault,
connectionId,
- action: "view vault auth mounts"
- });
+ actor
+ );
return getHCVaultAuthMounts(namespace, authType as HCVaultAuthType, connection, gatewayService, gatewayV2Service);
};
@@ -643,13 +594,13 @@ export const externalMigrationServiceFactory = ({
actor: OrgServiceActor;
namespace: string;
mountPath: string;
- connectionId?: string;
+ connectionId: string;
}) => {
- const connection = await resolveVaultConnection(actor, {
- namespace,
+ const connection = await appConnectionService.connectAppConnectionById<THCVaultConnection>(
+ AppConnection.HCVault,
connectionId,
- action: "view vault Kubernetes auth roles"
- });
+ actor
+ );
return getHCVaultKubernetesAuthRoles(namespace, mountPath, connection, gatewayService, gatewayV2Service);
};
@@ -662,13 +613,13 @@ export const externalMigrationServiceFactory = ({
actor: OrgServiceActor;
namespace: string;
mountPath: string;
- connectionId?: string;
+ connectionId: string;
}) => {
- const connection = await resolveVaultConnection(actor, {
- namespace,
+ const connection = await appConnectionService.connectAppConnectionById<THCVaultConnection>(
+ AppConnection.HCVault,
connectionId,
- action: "get Kubernetes roles"
- });
+ actor
+ );
return getHCVaultKubernetesRoles(namespace, mountPath, connection, gatewayService, gatewayV2Service);
};
@@ -681,13 +632,13 @@ export const externalMigrationServiceFactory = ({
actor: OrgServiceActor;
namespace: string;
mountPath: string;
- connectionId?: string;
+ connectionId: string;
}) => {
- const connection = await resolveVaultConnection(actor, {
- namespace,
+ const connection = await appConnectionService.connectAppConnectionById<THCVaultConnection>(
+ AppConnection.HCVault,
connectionId,
- action: "get database roles"
- });
+ actor
+ );
return getHCVaultDatabaseRoles(namespace, mountPath, connection, gatewayService, gatewayV2Service);
};
@@ -700,13 +651,13 @@ export const externalMigrationServiceFactory = ({
actor: OrgServiceActor;
namespace: string;
mountPath: string;
- connectionId?: string;
+ connectionId: string;
}) => {
- const connection = await resolveVaultConnection(actor, {
- namespace,
+ const connection = await appConnectionService.connectAppConnectionById<THCVaultConnection>(
+ AppConnection.HCVault,
connectionId,
- action: "get LDAP roles"
- });
+ actor
+ );
return getHCVaultLdapRoles(namespace, mountPath, connection, gatewayService, gatewayV2Service);
};
@@ -723,87 +674,38 @@ export const externalMigrationServiceFactory = ({
actor
) as Promise<TDopplerConnection>;
- const getDopplerConnectionForConfig = async (configId: string, actor: OrgServiceActor) => {
- 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 use Doppler migration" });
- }
-
- const config = await externalMigrationConfigDAL.findById(configId);
- if (!config || config.orgId !== actor.orgId || config.provider !== ExternalMigrationProviders.Doppler) {
- throw new NotFoundError({ message: "Doppler migration config not found" });
- }
- if (!config.connectionId) {
- throw new BadRequestError({ message: "Doppler migration config has no connection configured" });
- }
- return appConnectionService.connectAppConnectionById<TDopplerConnection>(
- AppConnection.Doppler,
- config.connectionId,
- actor
- );
- };
-
- const resolveDopplerConnection = (
- actor: OrgServiceActor,
- { configId, connectionId }: { configId?: string; connectionId?: string }
- ) => {
- if (connectionId) return getDopplerConnection(connectionId, actor);
- if (configId) return getDopplerConnectionForConfig(configId, actor);
- throw new BadRequestError({ message: "Either connectionId or configId must be provided" });
- };
-
- const getDopplerProjects = async ({
- configId,
- connectionId,
- actor
- }: {
- configId?: string;
- connectionId?: string;
- actor: OrgServiceActor;
- }) => {
- const appConnection = await resolveDopplerConnection(actor, { configId, connectionId });
+ const getDopplerProjects = async ({ connectionId, actor }: { connectionId: string; actor: OrgServiceActor }) => {
+ const appConnection = await getDopplerConnection(connectionId, actor);
return listDopplerProjects(appConnection);
};
const getDopplerEnvironments = async ({
- configId,
connectionId,
projectSlug,
actor
}: {
- configId?: string;
- connectionId?: string;
+ connectionId: string;
projectSlug: string;
actor: OrgServiceActor;
}) => {
- const appConnection = await resolveDopplerConnection(actor, { configId, connectionId });
+ const appConnection = await getDopplerConnection(connectionId, actor);
return listDopplerEnvironments(appConnection, projectSlug);
};
const getDopplerConfigs = async ({
- configId,
connectionId,
projectSlug,
actor
}: {
- configId?: string;
- connectionId?: string;
+ connectionId: string;
projectSlug: string;
actor: OrgServiceActor;
}) => {
- const appConnection = await resolveDopplerConnection(actor, { configId, connectionId });
+ const appConnection = await getDopplerConnection(connectionId, actor);
return listDopplerConfigs(appConnection, projectSlug);
};
const importDopplerSecrets = async ({
- configId,
connectionId,
dopplerProject,
dopplerEnvironment,
@@ -813,9 +715,7 @@ export const externalMigrationServiceFactory = ({
actor,
auditLogInfo
}: TImportDopplerSecretsDTO) => {
- const appConnection = connectionId
- ? await getDopplerConnectionForImport(connectionId, targetProjectId, actor)
- : await resolveDopplerConnection(actor, { configId });
+ const appConnection = await getDopplerConnectionForImport(connectionId, targetProjectId, actor);
const dopplerSecrets = await getDopplerSecrets(appConnection, dopplerProject, dopplerEnvironment);
diff --git a/backend/src/services/external-migration/external-migration-types.ts b/backend/src/services/external-migration/external-migration-types.ts
index fc6c0424e0..16f08e8623 100644
--- a/backend/src/services/external-migration/external-migration-types.ts
+++ b/backend/src/services/external-migration/external-migration-types.ts
@@ -132,8 +132,7 @@ export enum ExternalMigrationImportStatus {
}
export type TImportDopplerSecretsDTO = {
- configId?: string;
- connectionId?: string;
+ connectionId: string;
dopplerProject: string;
dopplerEnvironment: string;
targetProjectId: string;