Skip to content

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

add support for several paths in vault migration

adilsonfdd81d3ac721
diff --git a/backend/src/server/routes/v3/external-migration-router.ts b/backend/src/server/routes/v3/external-migration-router.ts
index 5240e57090..59592bcfad 100644
--- a/backend/src/server/routes/v3/external-migration-router.ts
+++ b/backend/src/server/routes/v3/external-migration-router.ts
@@ -440,7 +440,7 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
environment: z.string(),
secretPath: z.string(),
vaultNamespace: z.string(),
- vaultSecretPath: z.string()
+ vaultSecretPaths: z.array(z.string()).min(1)
}),
response: {
200: z.object({
diff --git a/backend/src/services/app-connection/hc-vault/hc-vault-connection-fns.ts b/backend/src/services/app-connection/hc-vault/hc-vault-connection-fns.ts
index 877b150a6a..2be68f0ad6 100644
--- a/backend/src/services/app-connection/hc-vault/hc-vault-connection-fns.ts
+++ b/backend/src/services/app-connection/hc-vault/hc-vault-connection-fns.ts
@@ -36,7 +36,7 @@ import {
} from "./hc-vault-connection-types";
// HashiCorp Vault stores JSON data, so values can be any valid JSON type
-type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue };
+export type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue };
export const convertVaultValueToString = (value: JsonValue): string => {
if (value === null) {
diff --git a/backend/src/services/external-migration/external-migration-service.ts b/backend/src/services/external-migration/external-migration-service.ts
index 993fd035b9..a84b4dd313 100644
--- a/backend/src/services/external-migration/external-migration-service.ts
+++ b/backend/src/services/external-migration/external-migration-service.ts
@@ -29,6 +29,7 @@ import {
getHCVaultPolicyNames,
getHCVaultSecretsForPath,
HCVaultAuthType,
+ JsonValue,
listHCVaultMounts,
listHCVaultPolicies,
listHCVaultSecretPaths,
@@ -614,7 +615,7 @@ export const externalMigrationServiceFactory = ({
environment,
secretPath,
vaultNamespace,
- vaultSecretPath,
+ vaultSecretPaths,
auditLogInfo
}: {
actor: OrgServiceActor;
@@ -622,18 +623,43 @@ export const externalMigrationServiceFactory = ({
environment: string;
secretPath: string;
vaultNamespace: string;
- vaultSecretPath: string;
+ vaultSecretPaths: string[];
auditLogInfo: AuditLogInfo;
}) => {
const connection = await getVaultConnectionForNamespace(actor, vaultNamespace, "import vault secrets");
- const vaultSecrets = await getHCVaultSecretsForPath(
- vaultNamespace,
- vaultSecretPath,
- connection,
- gatewayService,
- gatewayV2Service
+
+ if (!vaultSecretPaths.length) {
+ throw new BadRequestError({ message: "At least one Vault secret path is required" });
+ }
+
+ const secretsPerPath = await Promise.all(
+ vaultSecretPaths.map((vaultSecretPath) =>
+ getHCVaultSecretsForPath(vaultNamespace, vaultSecretPath, connection, gatewayService, gatewayV2Service).then(
+ (secrets) => ({ vaultSecretPath, secrets })
+ )
+ )
);
+ let vaultSecrets: Record<string, JsonValue>;
+ if (vaultSecretPaths.length === 1) {
+ vaultSecrets = secretsPerPath[0].secrets;
+ } else {
+ vaultSecrets = {};
+ for (const { vaultSecretPath, secrets } of secretsPerPath) {
+ const pathParts = vaultSecretPath.split("/").filter(Boolean);
+ const pathLabel = (pathParts.slice(1).join("/") || pathParts.join("_")).replace(/\//g, "_");
+ for (const [secretKey, secretValue] of Object.entries(secrets)) {
+ let compositeKey = `${pathLabel}__${secretKey}`;
+ let suffix = 1;
+ while (compositeKey in vaultSecrets) {
+ compositeKey = `${pathLabel}__${secretKey}__${suffix}`;
+ suffix += 1;
+ }
+ vaultSecrets[compositeKey] = secretValue;
+ }
+ }
+ }
+
try {
const secretOperation = await secretService.createManySecretsRaw({
actorId: actor.id,
diff --git a/frontend/src/hooks/api/migration/types.ts b/frontend/src/hooks/api/migration/types.ts
index 15af6ffcd0..64e9b3a92c 100644
--- a/frontend/src/hooks/api/migration/types.ts
+++ b/frontend/src/hooks/api/migration/types.ts
@@ -82,7 +82,7 @@ export type TImportVaultSecretsDTO = {
environment: string;
secretPath: string;
vaultNamespace: string;
- vaultSecretPath: string;
+ vaultSecretPaths: string[];
};
export type VaultKubernetesAuthRole = {
diff --git a/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx b/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx
index 0455e2d23a..4de809c8a8 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx
@@ -832,24 +832,30 @@ const OverviewPageContent = () => {
handlePopUpOpen("addSecretImport");
};
- const handleVaultImport = async (vaultPath: string, namespace: string) => {
- const result = await importVaultSecrets({
+ const handleVaultImport = async (vaultPaths: string[], namespace: string) => {
+ const { status } = await importVaultSecrets({
projectId,
environment: singleEnvSlug,
secretPath,
vaultNamespace: namespace,
- vaultSecretPath: vaultPath
+ vaultSecretPaths: vaultPaths
});
- if (result.status === ExternalMigrationImportStatus.ApprovalRequired) {
+ if (status === ExternalMigrationImportStatus.ApprovalRequired) {
createNotification({
type: "info",
- text: "Secret change request created successfully. Awaiting approval."
+ text:
+ vaultPaths.length > 1
+ ? `Secret change request created for ${vaultPaths.length} Vault paths. Awaiting approval.`
+ : "Secret change request created successfully. Awaiting approval."
});
} else {
createNotification({
type: "success",
- text: "Successfully imported secrets from HashiCorp Vault"
+ text:
+ vaultPaths.length > 1
+ ? `Successfully imported secrets from ${vaultPaths.length} HashiCorp Vault paths`
+ : "Successfully imported secrets from HashiCorp Vault"
});
}
};
diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/ActionBar.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/ActionBar.tsx
index c1c0339dc9..8552c821fd 100644
--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/ActionBar.tsx
+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/ActionBar.tsx
@@ -672,24 +672,30 @@ export const ActionBar = ({
}
};
- const handleVaultImport = async (vaultPath: string, namespace: string) => {
- const result = await importVaultSecrets({
+ const handleVaultImport = async (vaultPaths: string[], namespace: string) => {
+ const { status } = await importVaultSecrets({
projectId,
environment,
secretPath,
vaultNamespace: namespace,
- vaultSecretPath: vaultPath
+ vaultSecretPaths: vaultPaths
});
- if (result.status === ExternalMigrationImportStatus.ApprovalRequired) {
+ if (status === ExternalMigrationImportStatus.ApprovalRequired) {
createNotification({
type: "info",
- text: "Secret change request created successfully. Awaiting approval."
+ text:
+ vaultPaths.length > 1
+ ? `Secret change request created for ${vaultPaths.length} Vault paths. Awaiting approval.`
+ : "Secret change request created successfully. Awaiting approval."
});
} else {
createNotification({
type: "success",
- text: "Successfully imported secrets from HashiCorp Vault"
+ text:
+ vaultPaths.length > 1
+ ? `Successfully imported secrets from ${vaultPaths.length} HashiCorp Vault paths`
+ : "Successfully imported secrets from HashiCorp Vault"
});
}
};
diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/VaultSecretImportModal.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/VaultSecretImportModal.tsx
index 820a21f4d4..2f52bd73c4 100644
--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/VaultSecretImportModal.tsx
+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/VaultSecretImportModal.tsx
@@ -22,20 +22,20 @@ type Props = {
onOpenChange: (isOpen: boolean) => void;
environment: string;
secretPath: string;
- onImport: (vaultPath: string, namespace: string) => void;
+ onImport: (vaultPaths: string[], namespace: string) => void;
};
type ContentProps = {
onClose: () => void;
environment: string;
secretPath: string;
- onImport: (vaultPath: string, namespace: string) => void;
+ onImport: (vaultPaths: string[], namespace: string) => void;
};
const Content = ({ onClose, environment, secretPath, onImport }: ContentProps) => {
const [selectedNamespace, setSelectedNamespace] = useState<string | null>(null);
const [selectedMountPath, setSelectedMountPath] = useState<string | null>(null);
- const [selectedPath, setSelectedPath] = useState<string | null>(null);
+ const [selectedPaths, setSelectedPaths] = useState<string[]>([]);
const [shouldFetchPaths, setShouldFetchPaths] = useState(false);
const [shouldFetchMounts, setShouldFetchMounts] = useState(false);
@@ -70,8 +70,11 @@ const Content = ({ onClose, environment, secretPath, onImport }: ContentProps) =
}, [selectedNamespace, selectedMountPath]);
const handleImport = () => {
- if (!selectedPath) {
- createNotification({ type: "error", text: "Please select a Vault secret path to import" });
+ if (!selectedPaths.length) {
+ createNotification({
+ type: "error",
+ text: "Please select at least one Vault secret path to import"
+ });
return;
}
@@ -88,7 +91,7 @@ const Content = ({ onClose, environment, secretPath, onImport }: ContentProps) =
return;
}
- onImport(selectedPath, selectedNamespace);
+ onImport(selectedPaths, selectedNamespace);
onClose();
};
@@ -103,9 +106,9 @@ const Content = ({ onClose, environment, secretPath, onImport }: ContentProps) =
</div>
<div className="space-y-1.5 text-xs leading-relaxed">
<p>
- Select a Vault namespace and secret path to import secrets into the current
- Infisical environment (<code className="text-xs">{environment}</code>) at path{" "}
- <code className="text-xs">{secretPath}</code>.
+ Select a Vault namespace and one or more secret paths to import secrets into the
+ current Infisical environment (<code className="text-xs">{environment}</code>) at
+ path <code className="text-xs">{secretPath}</code>.
</p>
</div>
</div>
@@ -125,7 +128,7 @@ const Content = ({ onClose, environment, secretPath, onImport }: ContentProps) =
const namespace = value as { id: string; name: string };
setSelectedNamespace(namespace.name);
setSelectedMountPath(null);
- setSelectedPath(null);
+ setSelectedPaths([]);
}
}}
options={namespaces || []}
@@ -153,7 +156,7 @@ const Content = ({ onClose, environment, secretPath, onImport }: ContentProps) =
if (value && !Array.isArray(value)) {
const mount = value as { path: string; type: string; version: string | null };
setSelectedMountPath(mount.path.replace(/\/$/, "")); // Remove trailing slash
- setSelectedPath(null);
+ setSelectedPaths([]);
}
}}
options={kvMounts || []}
@@ -172,12 +175,13 @@ const Content = ({ onClose, environment, secretPath, onImport }: ContentProps) =
<FormControl label="Vault Secret Path" className="mb-6">
<>
<FilterableSelect
- value={selectedPath ? { path: selectedPath } : null}
+ isMulti
+ value={selectedPaths.map((path) => ({ path }))}
onChange={(value) => {
- if (value && !Array.isArray(value)) {
- setSelectedPath((value as { path: string }).path);
- } else {
- setSelectedPath(null);
+ if (!value) {
+ setSelectedPaths([]);
+ } else if (Array.isArray(value)) {
+ setSelectedPaths(value.map((option) => option.path));
}
}}
options={(secretPaths || []).map((path) => ({ path }))}
@@ -187,13 +191,13 @@ const Content = ({ onClose, environment, secretPath, onImport }: ContentProps) =
placeholder={
!selectedMountPath
? "Select a mount path first..."
- : "Select a Vault path to import..."
+ : "Select Vault path(s) to import..."
}
isClearable
className="w-full"
/>
<p className="mt-1 text-xs text-mineshaft-400">
- Choose a secret path from the selected mount to import into Infisical
+ Choose one or more secret paths from the selected mount to import into Infisical
</p>
</>
</FormControl>
@@ -201,7 +205,7 @@ const Content = ({ onClose, environment, secretPath, onImport }: ContentProps) =
<div className="mt-8 flex space-x-4">
<Button
onClick={handleImport}
- isDisabled={!selectedPath || isLoadingMounts || isLoadingPaths}
+ isDisabled={!selectedPaths.length || isLoadingMounts || isLoadingPaths}
>
Import Secrets
</Button>
@@ -227,7 +231,7 @@ export const VaultSecretImportModal = ({
<ModalContent
bodyClassName="overflow-visible"
title="Import from HashiCorp Vault"
- subTitle="Select a Vault namespace and secret path to import secrets into the current environment and folder."
+ subTitle="Select a Vault namespace and one or more secret paths to import secrets into the current environment and folder."
className="max-w-2xl"
>
<Content