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: add support for mounts that are nested
adilsona3622f26c338
diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.tsindex 6b074adae0..18a1fe2b0e 100644--- a/backend/src/ee/services/audit-log/audit-log-types.ts+++ b/backend/src/ee/services/audit-log/audit-log-types.ts@@ -6827,6 +6827,7 @@ interface ImportVaultSecretsEvent {environment: string;secretPath: string;vaultNamespace: string;+ mountPath: string;vaultSecretPaths: string[];connectionId: string;keepVaultStructure: boolean;diff --git a/backend/src/server/routes/v3/external-migration-router.ts b/backend/src/server/routes/v3/external-migration-router.tsindex a2c763cc67..8e32a88e27 100644--- a/backend/src/server/routes/v3/external-migration-router.ts+++ b/backend/src/server/routes/v3/external-migration-router.ts@@ -275,6 +275,12 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProviderenvironment: z.string(),secretPath: z.string(),vaultNamespace: z.string(),+ mountPath: z+ .string()+ .trim()+ .min(1)+ .max(255)+ .describe("The Vault KV secrets engine the selected paths belong to, e.g. 'kv' or 'apps/kv'."),vaultSecretPaths: z.array(z.string().max(255)).min(1).max(100),connectionId: z.string().uuid(),keepVaultStructure: z@@ -313,6 +319,7 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProviderenvironment: req.body.environment,secretPath: req.body.secretPath,vaultNamespace: req.body.vaultNamespace,+ mountPath: req.body.mountPath,vaultSecretPaths: req.body.vaultSecretPaths,connectionId: req.body.connectionId,keepVaultStructure: req.body.keepVaultStructure,diff --git a/backend/src/services/app-connection/hc-vault/hc-vault-connection-fns.test.ts b/backend/src/services/app-connection/hc-vault/hc-vault-connection-fns.test.tsnew file mode 100644index 0000000000..5f7acbafa7--- /dev/null+++ b/backend/src/services/app-connection/hc-vault/hc-vault-connection-fns.test.ts@@ -0,0 +1,81 @@+import { BadRequestError } from "@app/lib/errors";++import { resolveKvMount, resolveVaultSecretPathWithinMount } from "./hc-vault-connection-fns";+import { THCVaultMount } from "./hc-vault-connection-types";++const kvMount = (overrides: Partial<THCVaultMount> = {}): THCVaultMount => ({+ path: "kv/",+ type: "kv",+ version: "2",+ ...overrides+});++describe("resolveKvMount", () => {+ test("resolves the declared engine and reports its kv version", () => {+ const result = resolveKvMount("kv", [kvMount()]);++ expect(result).toEqual({+ mountSegments: ["kv"],+ mountUrlPath: "kv",+ kvVersion: "2"+ });+ });++ test("treats a kv v1 engine as version 1", () => {+ expect(resolveKvMount("kv", [kvMount({ version: null })]).kvVersion).toBe("1");+ });++ test("resolves a nested engine without matching its parent segment", () => {+ const appsKvMount = kvMount({ path: "apps/kv/" });+ const result = resolveKvMount("apps/kv", [kvMount({ path: "apps/" }), appsKvMount]);++ expect(result.mountSegments).toEqual(["apps", "kv"]);+ expect(result.mountUrlPath).toBe("apps/kv");+ });++ test("accepts the declared engine with the trailing slash vault reports", () => {+ expect(resolveKvMount("apps/kv/", [kvMount({ path: "apps/kv/" })]).mountUrlPath).toBe("apps/kv");+ });++ test("does not resolve a sibling engine sharing the leading segment", () => {+ expect(() => resolveKvMount("apps/kv1", [kvMount({ path: "apps/kv2/" })])).toThrowError(+ /Secrets engine 'apps\/kv1' was not found/+ );+ });++ test("rejects an engine that does not hold secrets", () => {+ expect(() => resolveKvMount("db", [kvMount({ path: "db/", type: "database" })])).toThrowError(BadRequestError);+ expect(() => resolveKvMount("db", [kvMount({ path: "db/", type: "database" })])).toThrowError(+ /is a 'database' engine\. Only KV secrets engines/+ );+ });++ test("URI-encodes each segment of the mount path without escaping the separator", () => {+ const result = resolveKvMount("team#1/kv", [kvMount({ path: "team#1/kv/" })]);++ expect(result.mountUrlPath).toBe("team%231/kv");+ });+});++describe("resolveVaultSecretPathWithinMount", () => {+ test("returns the path inside the engine", () => {+ expect(resolveVaultSecretPathWithinMount("kv/app/db", ["kv"])).toBe("app/db");+ });++ test("strips every segment of a nested engine", () => {+ expect(resolveVaultSecretPathWithinMount("apps/kv/prod/db", ["apps", "kv"])).toBe("prod/db");+ });++ test("throws when the path sits outside the engine", () => {+ expect(() => resolveVaultSecretPathWithinMount("other/app/db", ["kv"])).toThrowError(BadRequestError);+ expect(() => resolveVaultSecretPathWithinMount("other/app/db", ["kv"])).toThrowError(+ /Vault path 'other\/app\/db' is not inside the 'kv' secrets engine/+ );+ });++ test("throws when the path points at the engine itself", () => {+ expect(() => resolveVaultSecretPathWithinMount("apps/kv", ["apps", "kv"])).toThrowError(+ /points at the 'apps\/kv' secrets engine itself/+ );+ });+});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.tsindex 3735b0b5c4..87bb444da3 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@@ -33,7 +33,8 @@ import {THCVaultLdapConfig,THCVaultLdapRole,THCVaultMount,- THCVaultMountResponse+ THCVaultMountResponse,+ TResolvedKvMount} from "./hc-vault-connection-types";// HashiCorp Vault stores JSON data, so values can be any valid JSON type@@ -732,6 +733,7 @@ class NamespaceHeaderNotSupportedError extends Error {const isRootNamespace = (namespace: string) => namespace === "/" || namespace === "root" || !namespace;const isWildcardPath = (path: string) => path.split("/").includes("+");+const isKvMount = (mount: THCVaultMount) => mount.type === "kv" || mount.type.startsWith("kv");const ACL_ALLOWED_CAPABILITIES = ["read", "list"];// Fallback for restricted Vault tokens that lack permission to list a mount from its root.@@ -948,7 +950,7 @@ export const listHCVaultSecretPaths = async (const mounts = await listHCVaultMounts(connection, gatewayService, gatewayV2Service, namespace);// Filter for KV mounts (kv, kv-v1, kv-v2)- let kvMounts = mounts.filter((mount) => mount.type === "kv" || mount.type.startsWith("kv"));+ let kvMounts = mounts.filter(isKvMount);// If filterMountPath is provided, filter to only that mountif (filterMountPath) {@@ -1027,10 +1029,59 @@ export const listHCVaultSecretPaths = async (};};+// the caller declares which secrets engine it is reading from, so the engine is resolved once rather+// than guessed per path. This allow secrets engine that are defined as paths+export const resolveKvMount = (mountPath: string, mounts: THCVaultMount[]): TResolvedKvMount => {+ const mountSegments = mountPath.split("/").filter(Boolean);+ const normalizedMountPath = mountSegments.join("/");++ const mount = mounts.find((m) => m.path.split("/").filter(Boolean).join("/") === normalizedMountPath);++ if (!mount) {+ throw new BadRequestError({+ message: `Secrets engine '${normalizedMountPath}' was not found in HashiCorp Vault`+ });+ }++ if (!isKvMount(mount)) {+ throw new BadRequestError({+ message: `Secrets engine '${normalizedMountPath}' is a '${mount.type}' engine. Only KV secrets engines hold secrets that can be imported.`+ });+ }++ return {+ mountSegments,+ mountUrlPath: mountSegments.map(encodeURIComponent).join("/"),+ kvVersion: mount.version === "2" ? "2" : "1"+ };+};++export const resolveVaultSecretPathWithinMount = (secretPath: string, mountSegments: string[]): string => {+ const pathSegments = secretPath.split("/").filter(Boolean);++ if (!mountSegments.every((segment, idx) => pathSegments[idx] === segment)) {+ throw new BadRequestError({+ message: `Vault path '${secretPath}' is not inside the '${mountSegments.join("/")}' secrets engine`+ });+ }++ const actualPath = pathSegments.slice(mountSegments.length).join("/");++ if (!actualPath) {+ throw new BadRequestError({+ message: `Vault path '${secretPath}' points at the '${mountSegments.join(+ "/"+ )}' secrets engine itself. Expected a secret path inside it.`+ });+ }++ return actualPath;+};+const fetchVaultSecretAtPath = async ({namespace,secretPath,- mounts,+ kvMount,instanceUrl,accessToken,connection,@@ -1040,7 +1091,7 @@ const fetchVaultSecretAtPath = async ({}: {namespace: string;secretPath: string;- mounts: Awaited<ReturnType<typeof listHCVaultMounts>>;+ kvMount: TResolvedKvMount;instanceUrl: string;accessToken: string;connection: THCVaultConnection;@@ -1049,27 +1100,8 @@ const fetchVaultSecretAtPath = async ({skipNamespaceHeader: boolean;}): Promise<Record<string, JsonValue>> => {try {- // Extract mount and path from the secretPath- // secretPath format: {mount}/{path}- const pathParts = secretPath.split("/");- const mountPath = pathParts[0];- const actualPath = pathParts.slice(1).join("/");-- if (!mountPath || !actualPath) {- throw new BadRequestError({- message: "Invalid secret path format. Expected format: {mount}/{path}"- });- }-- const mount = mounts.find((m) => m.path.replace(/\/$/, "") === mountPath);-- if (!mount) {- throw new BadRequestError({- message: `Mount '${mountPath}' not found in HashiCorp Vault`- });- }-- const kvVersion = mount.version === "2" ? "2" : "1";+ const { mountSegments, mountUrlPath, kvVersion } = kvMount;+ const actualPath = resolveVaultSecretPathWithinMount(secretPath, mountSegments);// Fetch secrets based on KV versionif (kvVersion === "2") {@@ -1085,7 +1117,7 @@ const fetchVaultSecretAtPath = async ({};};}>(connection, gatewayService, gatewayV2Service, {- url: `${instanceUrl}/v1/${encodeURIComponent(mountPath)}/data/${actualPath}`,+ url: `${instanceUrl}/v1/${mountUrlPath}/data/${actualPath}`,method: "GET",headers: {"X-Vault-Token": accessToken,@@ -1103,7 +1135,7 @@ const fetchVaultSecretAtPath = async ({lease_id: string;renewable: boolean;}>(connection, gatewayService, gatewayV2Service, {- url: `${instanceUrl}/v1/${encodeURIComponent(mountPath)}/${actualPath}`,+ url: `${instanceUrl}/v1/${mountUrlPath}/${actualPath}`,method: "GET",headers: {"X-Vault-Token": accessToken,@@ -1143,6 +1175,7 @@ const fetchVaultSecretAtPath = async ({export const getHCVaultSecretsForPaths = async (namespace: string,+ mountPath: string,secretPaths: string[],connection: THCVaultConnection,gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,@@ -1157,9 +1190,11 @@ export const getHCVaultSecretsForPaths = async (return [];}+ const kvMount = resolveKvMount(mountPath, mounts);+const fetchParams = {namespace,- mounts,+ kvMount,instanceUrl,accessToken,connection,diff --git a/backend/src/services/app-connection/hc-vault/hc-vault-connection-types.ts b/backend/src/services/app-connection/hc-vault/hc-vault-connection-types.tsindex 7ebc3774ff..8444bf2db0 100644--- a/backend/src/services/app-connection/hc-vault/hc-vault-connection-types.ts+++ b/backend/src/services/app-connection/hc-vault/hc-vault-connection-types.ts@@ -42,6 +42,12 @@ export type THCVaultMount = {version?: string | null;};+export type TResolvedKvMount = {+ mountSegments: string[];+ mountUrlPath: string;+ kvVersion: "1" | "2";+};+export type THCVaultAuthMountResponse = {data: {[key: string]: {diff --git a/backend/src/services/external-migration/external-migration-fns/vault.test.ts b/backend/src/services/external-migration/external-migration-fns/vault.test.tsindex dc5456aefa..12b6ad39fb 100644--- a/backend/src/services/external-migration/external-migration-fns/vault.test.ts+++ b/backend/src/services/external-migration/external-migration-fns/vault.test.ts@@ -4,6 +4,7 @@ describe("buildVaultFolderImportPlan", () => {test("strips the mount and nests the remaining segments under the destination path", () => {const plan = buildVaultFolderImportPlan({secretPath: "/imports",+ mountPath: "kv",secretsPerPath: [{ vaultSecretPath: "kv/app/prod/db", secrets: { DB_USER: "admin", DB_PORT: 5432 } }]});@@ -19,9 +20,36 @@ describe("buildVaultFolderImportPlan", () => {]);});+ test("strips every segment of a nested mount", () => {+ const plan = buildVaultFolderImportPlan({+ secretPath: "/imports",+ mountPath: "apps/kv",+ secretsPerPath: [{ vaultSecretPath: "apps/kv/prod/db", secrets: { DB_USER: "admin" } }]+ });++ expect(plan).toEqual([+ {+ folderPath: "/imports/prod/db",+ vaultSecretPath: "apps/kv/prod/db",+ secrets: [{ secretKey: "DB_USER", secretValue: "admin" }]+ }+ ]);+ });++ test("accepts a mount path carrying the trailing slash vault reports", () => {+ const plan = buildVaultFolderImportPlan({+ secretPath: "/imports",+ mountPath: "apps/kv/",+ secretsPerPath: [{ vaultSecretPath: "apps/kv/prod/db", secrets: {} }]+ });++ expect(plan[0].folderPath).toBe("/imports/prod/db");+ });+test("treats the project root as the destination path", () => {const plan = buildVaultFolderImportPlan({secretPath: "/",+ mountPath: "kv",secretsPerPath: [{ vaultSecretPath: "kv/db", secrets: { KEY: "value" } }]});@@ -31,6 +59,7 @@ describe("buildVaultFolderImportPlan", () => {test("gives every vault path its own folder within the one mount", () => {const plan = buildVaultFolderImportPlan({secretPath: "/imports",+ mountPath: "kv",secretsPerPath: [{ vaultSecretPath: "kv/app/db", secrets: { DB_USER: "admin" } },{ vaultSecretPath: "kv/app/db/replica", secrets: { DB_USER: "reader" } }@@ -54,6 +83,7 @@ describe("buildVaultFolderImportPlan", () => {test("keeps the same key in sibling folders", () => {const plan = buildVaultFolderImportPlan({secretPath: "/imports",+ mountPath: "kv",secretsPerPath: [{ vaultSecretPath: "kv/app/web", secrets: { PORT: "8080" } },{ vaultSecretPath: "kv/app/api", secrets: { PORT: "9090" } }@@ -67,6 +97,7 @@ describe("buildVaultFolderImportPlan", () => {expect(() =>buildVaultFolderImportPlan({secretPath: "/imports",+ mountPath: "kv",secretsPerPath: [{ vaultSecretPath: "kv/my.app/db", secrets: {} },{ vaultSecretPath: "kv/my app/db", secrets: {} },@@ -80,27 +111,63 @@ describe("buildVaultFolderImportPlan", () => {expect(() =>buildVaultFolderImportPlan({secretPath: "/imports",+ mountPath: "kv",secretsPerPath: [{ vaultSecretPath: "kv/new-path", secrets: { DB_USER: "admin" } },{ vaultSecretPath: "kv-2/new-path", secrets: { DB_USER: "root" } }]})- ).toThrowError(/secrets engine, but paths from 2 were selected \('kv', 'kv-2'\)/);+ ).toThrowError(/not inside the 'kv' secrets engine: 'kv-2\/new-path'/);+ });++ test("tells sibling nested mounts apart", () => {+ expect(() =>+ buildVaultFolderImportPlan({+ secretPath: "/imports",+ mountPath: "apps/kv1",+ secretsPerPath: [+ { vaultSecretPath: "apps/kv1/db", secrets: { DB_USER: "admin" } },+ { vaultSecretPath: "apps/kv2/db", secrets: { DB_USER: "root" } }+ ]+ })+ ).toThrowError(/not inside the 'apps\/kv1' secrets engine: 'apps\/kv2\/db'/);+ });++ test("accepts a nested mount whose leading segment matches another engine", () => {+ const plan = buildVaultFolderImportPlan({+ secretPath: "/imports",+ mountPath: "apps/kv2",+ secretsPerPath: [{ vaultSecretPath: "apps/kv2/db", secrets: { DB_USER: "root" } }]+ });++ expect(plan[0].folderPath).toBe("/imports/db");});test("rejects a vault path holding only a mount", () => {expect(() =>buildVaultFolderImportPlan({secretPath: "/imports",+ mountPath: "kv",secretsPerPath: [{ vaultSecretPath: "kv", secrets: { KEY: "value" } }]})).toThrowError(/only a mount/);});+ test("rejects a vault path holding only a nested mount", () => {+ expect(() =>+ buildVaultFolderImportPlan({+ secretPath: "/imports",+ mountPath: "apps/kv",+ secretsPerPath: [{ vaultSecretPath: "apps/kv", secrets: { KEY: "value" } }]+ })+ ).toThrowError(/only a mount/);+ });+// TODO: CHECK THIStest("keeps the folder for an empty vault entry but plans no secrets", () => {const plan = buildVaultFolderImportPlan({secretPath: "/imports",+ mountPath: "kv",secretsPerPath: [{ vaultSecretPath: "kv/app/empty", secrets: {} }]});@@ -110,6 +177,7 @@ describe("buildVaultFolderImportPlan", () => {test("stringifies non-string vault values", () => {const plan = buildVaultFolderImportPlan({secretPath: "/imports",+ mountPath: "kv",secretsPerPath: [{vaultSecretPath: "kv/app/types",diff --git a/backend/src/services/external-migration/external-migration-fns/vault.ts b/backend/src/services/external-migration/external-migration-fns/vault.tsindex 69f43497e0..539783c333 100644--- a/backend/src/services/external-migration/external-migration-fns/vault.ts+++ b/backend/src/services/external-migration/external-migration-fns/vault.ts@@ -616,32 +616,58 @@ type TVaultMappedPath = {relativeSegments: string[];};-const validateVaultFolderImportPaths = (- secretsPerPath: { vaultSecretPath: string; secrets: Record<string, JsonValue> }[]-): TVaultMappedPath[] => {- // the secrets engine is the leading segment and is dropped from the folder tree, so paths from two of them- // would silently merge into one folder- const secretsEngines = new Set(- secretsPerPath.map(({ vaultSecretPath }) => vaultSecretPath.split("/").filter(Boolean)[0]).filter(Boolean)- );+export const toVaultPathSegments = (path: string) => path.split("/").filter(Boolean);++export const assertVaultPathsWithinMount = ({+ mountPath,+ vaultSecretPaths+}: {+ mountPath: string;+ vaultSecretPaths: string[];+}): string[] => {+ const mountSegments = toVaultPathSegments(mountPath);++ if (!mountSegments.length) {+ throw new BadRequestError({+ message: "Cannot import: no Vault secrets engine was selected. Select the secrets engine the paths belong to."+ });+ }- if (secretsEngines.size > 1) {+ const pathsOutsideMount = vaultSecretPaths.filter((vaultSecretPath) => {+ const segments = toVaultPathSegments(vaultSecretPath);+ return !mountSegments.every((mountSegment, idx) => segments[idx] === mountSegment);+ });++ if (pathsOutsideMount.length) {throw new BadRequestError({- message: `Cannot import: preserving the Vault structure requires every selected path to come from a single vault secrets engine, but paths from ${- secretsEngines.size- } were selected (${[...secretsEngines]- .map((secretsEngine) => `'${secretsEngine}'`)- .join(", ")}). Import one secrets engine at a time.`+ message: `Cannot import: the following Vault paths are not inside the '${mountSegments.join(+ "/"+ )}' secrets engine: ${pathsOutsideMount+ .map((vaultSecretPath) => `'${vaultSecretPath}'`)+ .join(", ")}. Select paths from the secrets engine you are importing, or import one secrets engine at a time.`});}+ return mountSegments;+};++const validateVaultFolderImportPaths = (+ mountPath: string,+ secretsPerPath: { vaultSecretPath: string; secrets: Record<string, JsonValue> }[]+): TVaultMappedPath[] => {+ const mountSegments = assertVaultPathsWithinMount({+ mountPath,+ vaultSecretPaths: secretsPerPath.map(({ vaultSecretPath }) => vaultSecretPath)+ });+const mountOnlyPaths: string[] = [];const pathsWithInvalidFolderNames: string[] = [];const mappedPaths: TVaultMappedPath[] = [];for (const { vaultSecretPath, secrets } of secretsPerPath) {- // vault paths arrive as "{mount}/{path}"; the mount is dropped so the folder tree mirrors the path only- const [, ...relativeSegments] = vaultSecretPath.split("/").filter(Boolean);+ // the mount can itself be nested, so every one of its segments is dropped and the folder tree+ // mirrors only the path inside the secrets engine+ const relativeSegments = toVaultPathSegments(vaultSecretPath).slice(mountSegments.length);if (!relativeSegments.length) {mountOnlyPaths.push(vaultSecretPath);@@ -679,13 +705,15 @@ const validateVaultFolderImportPaths = (export const buildVaultFolderImportPlan = ({secretPath,+ mountPath,secretsPerPath}: {secretPath: string;+ mountPath: string;secretsPerPath: { vaultSecretPath: string; secrets: Record<string, JsonValue> }[];}): TVaultFolderImportUnit[] => {- const infisicalBasePath = secretPath.split("/").filter(Boolean);- const mappedPaths = validateVaultFolderImportPaths(secretsPerPath);+ const infisicalBasePath = toVaultPathSegments(secretPath);+ const mappedPaths = validateVaultFolderImportPaths(mountPath, secretsPerPath);return mappedPaths.map(({ vaultSecretPath, secrets, relativeSegments }) => ({folderPath: `/${[...infisicalBasePath, ...relativeSegments].join("/")}`,diff --git a/backend/src/services/external-migration/external-migration-service.ts b/backend/src/services/external-migration/external-migration-service.tsindex 6c19e28886..7da2430628 100644--- a/backend/src/services/external-migration/external-migration-service.ts+++ b/backend/src/services/external-migration/external-migration-service.ts@@ -58,6 +58,7 @@ import { TSecretFolderServiceFactory } from "../secret-folder/secret-folder-servimport { TSecretV2BridgeServiceFactory } from "../secret-v2-bridge/secret-v2-bridge-service";import { TUserDALFactory } from "../user/user-dal";import {+ assertVaultPathsWithinMount,buildVaultFolderImportPlan,decryptEnvKeyDataFn,getDopplerSecrets,@@ -599,6 +600,7 @@ export const externalMigrationServiceFactory = ({projectId,environment,secretPath,+ mountPath,secretsPerPath,auditLogInfo}: {@@ -606,10 +608,11 @@ export const externalMigrationServiceFactory = ({projectId: string;environment: string;secretPath: string;+ mountPath: string;secretsPerPath: { vaultSecretPath: string; secrets: Record<string, JsonValue> }[];auditLogInfo: AuditLogInfo;}) => {- const units: TVaultFolderImportUnit[] = buildVaultFolderImportPlan({ secretPath, secretsPerPath });+ const units: TVaultFolderImportUnit[] = buildVaultFolderImportPlan({ secretPath, mountPath, secretsPerPath });const env = await projectEnvDAL.findOne({ projectId, slug: environment });if (!env) {@@ -750,6 +753,7 @@ export const externalMigrationServiceFactory = ({environment,secretPath,vaultNamespace,+ mountPath,vaultSecretPaths,connectionId,keepVaultStructure,@@ -760,6 +764,7 @@ export const externalMigrationServiceFactory = ({environment: string;secretPath: string;vaultNamespace: string;+ mountPath: string;vaultSecretPaths: string[];connectionId: string;keepVaultStructure: boolean;@@ -777,8 +782,11 @@ export const externalMigrationServiceFactory = ({const uniqueVaultSecretPaths = Array.from(new Set(vaultSecretPaths));+ assertVaultPathsWithinMount({ mountPath, vaultSecretPaths: uniqueVaultSecretPaths });+const secretsPerPath = await getHCVaultSecretsForPaths(vaultNamespace,+ mountPath,uniqueVaultSecretPaths,connection,gatewayService,@@ -791,6 +799,7 @@ export const externalMigrationServiceFactory = ({projectId,environment,secretPath,+ mountPath,secretsPerPath,auditLogInfo});diff --git a/frontend/src/components/external-migrations/VaultImportPreview.utils.test.ts b/frontend/src/components/external-migrations/VaultImportPreview.utils.test.tsindex 68f0256879..3ccc86ddc0 100644--- a/frontend/src/components/external-migrations/VaultImportPreview.utils.test.ts+++ b/frontend/src/components/external-migrations/VaultImportPreview.utils.test.ts@@ -11,6 +11,7 @@ describe("Vault import preview", () => {const { rows, invalidPaths } = buildVaultImportPreview({selectedPaths: ["kv/prod/db"],destinationPath: "/newww",+ mountPath: "kv",keepVaultStructure: true});@@ -22,6 +23,7 @@ describe("Vault import preview", () => {const { rows } = buildVaultImportPreview({selectedPaths: ["kv/new-path", "kv/new-path/api"],destinationPath: "/newww",+ mountPath: "kv",keepVaultStructure: true});@@ -32,6 +34,7 @@ describe("Vault import preview", () => {const { rows } = buildVaultImportPreview({selectedPaths: ["kv/teste/belinha", "kv/prod/db"],destinationPath: "/",+ mountPath: "kv",keepVaultStructure: true});@@ -42,6 +45,7 @@ describe("Vault import preview", () => {const { rows } = buildVaultImportPreview({selectedPaths: ["kv/new-path", "kv/new-path/api"],destinationPath: "/newww",+ mountPath: "kv",keepVaultStructure: true});@@ -62,6 +66,7 @@ describe("Vault import preview", () => {const { rows, headline, invalidPaths } = buildVaultImportPreview({selectedPaths: ["kv/prod/db", "kv/teste"],destinationPath: "/newww",+ mountPath: "kv",keepVaultStructure: false});@@ -78,6 +83,7 @@ describe("Vault import preview", () => {const { rows } = buildVaultImportPreview({selectedPaths: ["kv/prod/db", "kv/teste", "kv/new-path"],destinationPath: "/newww",+ mountPath: "kv",keepVaultStructure: false});@@ -98,6 +104,7 @@ describe("Vault import preview", () => {const { rows } = buildVaultImportPreview({selectedPaths: ["kv/prod/db", "kv/teste"],destinationPath: "/newww",+ mountPath: "kv",keepVaultStructure: true});@@ -111,11 +118,13 @@ describe("Vault import preview", () => {const onePath = buildVaultImportPreview({selectedPaths: ["kv/prod/db"],destinationPath: "/newww",+ mountPath: "kv",keepVaultStructure: true});const manyPaths = buildVaultImportPreview({selectedPaths: ["kv/prod", "kv/teste"],destinationPath: "/newww",+ mountPath: "kv",keepVaultStructure: true});@@ -127,6 +136,7 @@ describe("Vault import preview", () => {const { headline } = buildVaultImportPreview({selectedPaths: ["kv/prod", "kv/my.app"],destinationPath: "/newww",+ mountPath: "kv",keepVaultStructure: true});@@ -137,6 +147,7 @@ describe("Vault import preview", () => {const { rows, headline } = buildVaultImportPreview({selectedPaths: ["kv/prod"],destinationPath: "/one/two/three/four/five",+ mountPath: "kv",keepVaultStructure: false});@@ -151,6 +162,7 @@ describe("Vault import preview", () => {const { rows } = buildVaultImportPreview({selectedPaths: ["kv/prod"],destinationPath: "/one/two/three",+ mountPath: "kv",keepVaultStructure: true});@@ -161,6 +173,7 @@ describe("Vault import preview", () => {const { rows, invalidPaths } = buildVaultImportPreview({selectedPaths: ["kv", "kv/prod"],destinationPath: "/newww",+ mountPath: "kv",keepVaultStructure: true});@@ -172,6 +185,7 @@ describe("Vault import preview", () => {const { invalidPaths } = buildVaultImportPreview({selectedPaths: ["kv/my.app", "kv/my app", "kv/my-app_1"],destinationPath: "/newww",+ mountPath: "kv",keepVaultStructure: true});@@ -182,9 +196,33 @@ describe("Vault import preview", () => {const { invalidPaths } = buildVaultImportPreview({selectedPaths: ["kv/my.app"],destinationPath: "/newww",+ mountPath: "kv",keepVaultStructure: false});assert.deepEqual(invalidPaths, []);});+ it("drops every segment of a nested secrets engine", () => {+ const { rows, invalidPaths } = buildVaultImportPreview({+ selectedPaths: ["apps/kv/prod/db"],+ destinationPath: "/newww",+ mountPath: "apps/kv",+ keepVaultStructure: true+ });++ assert.deepEqual(folderNames(rows), ["/newww", "prod/", "db/"]);+ assert.deepEqual(invalidPaths, []);+ });++ it("rejects paths from a sibling nested secrets engine", () => {+ const { rows, invalidPaths } = buildVaultImportPreview({+ selectedPaths: ["apps/kv1/db", "apps/kv2/db"],+ destinationPath: "/newww",+ mountPath: "apps/kv1",+ keepVaultStructure: true+ });++ assert.deepEqual(invalidPaths, ["apps/kv2/db"]);+ assert.deepEqual(folderNames(rows), ["/newww", "db/"]);+ });});diff --git a/frontend/src/components/external-migrations/VaultImportPreview.utils.ts b/frontend/src/components/external-migrations/VaultImportPreview.utils.tsindex 003e5455bb..79dca4e968 100644--- a/frontend/src/components/external-migrations/VaultImportPreview.utils.ts+++ b/frontend/src/components/external-migrations/VaultImportPreview.utils.ts@@ -16,6 +16,7 @@ export type TVaultImportPreview = {type TBuildVaultImportPreviewArgs = {selectedPaths: string[];destinationPath: string;+ mountPath: string;keepVaultStructure: boolean;};@@ -52,6 +53,7 @@ const createNode = (): TFolderNode => ({ children: new Map(), sources: [] });export const buildVaultImportPreview = ({selectedPaths,destinationPath,+ mountPath,keepVaultStructure}: TBuildVaultImportPreviewArgs): TVaultImportPreview => {const fullDestination = `/${toSegments(destinationPath).join("/")}`;@@ -90,11 +92,17 @@ export const buildVaultImportPreview = ({const root = createNode();let folderCount = 0;+ const mountSegments = toSegments(mountPath);+selectedPaths.forEach((vaultPath) => {- // the secrets engine leads the path and is dropped, matching buildVaultFolderImportPlan- const [, ...relativeSegments] = toSegments(vaultPath);+ // the secrets engine can itself be nested, so all of its segments are dropped, matching+ // buildVaultFolderImportPlan+ const segments = toSegments(vaultPath);+ const isWithinMount = mountSegments.every((segment, index) => segments[index] === segment);+ const relativeSegments = segments.slice(mountSegments.length);if (+ !isWithinMount ||!relativeSegments.length ||relativeSegments.some((segment) => !VALID_FOLDER_SEGMENT.test(segment))) {diff --git a/frontend/src/hooks/api/migration/types.ts b/frontend/src/hooks/api/migration/types.tsindex e591ffa86b..2efc26b044 100644--- a/frontend/src/hooks/api/migration/types.ts+++ b/frontend/src/hooks/api/migration/types.ts@@ -45,6 +45,7 @@ export type TImportVaultSecretsDTO = {environment: string;secretPath: string;vaultNamespace: string;+ mountPath: string;vaultSecretPaths: string[];connectionId: string;keepVaultStructure: boolean;diff --git a/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx b/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsxindex 1c3e4769be..dec2abaacf 100644--- a/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx+++ b/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx@@ -1078,6 +1078,7 @@ const OverviewPageContent = () => {const handleVaultImport = async ({vaultPaths,namespace,+ mountPath,connectionId,keepVaultStructure}: TVaultSecretImportArgs) => {@@ -1086,6 +1087,7 @@ const OverviewPageContent = () => {environment: singleEnvSlug,secretPath,vaultNamespace: namespace,+ mountPath,vaultSecretPaths: vaultPaths,connectionId,keepVaultStructurediff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/VaultSecretImportModal.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/VaultSecretImportModal.tsxindex f3823be0ac..9d0ccdf822 100644--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/VaultSecretImportModal.tsx+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/VaultSecretImportModal.tsx@@ -44,6 +44,7 @@ import { useDiscardChangesGuard } from "@app/hooks/useDiscardChangesGuard";export type TVaultSecretImportArgs = {vaultPaths: string[];namespace: string;+ mountPath: string;connectionId: string;keepVaultStructure: boolean;};@@ -156,8 +157,14 @@ const Content = ({const hiddenSkippedPaths = skippedWildcardPaths.slice(visibleSkippedPaths.length);const preview = useMemo(- () => buildVaultImportPreview({ selectedPaths, destinationPath, keepVaultStructure }),- [selectedPaths, destinationPath, keepVaultStructure]+ () =>+ buildVaultImportPreview({+ selectedPaths,+ destinationPath,+ mountPath: mountPath ?? "",+ keepVaultStructure+ }),+ [selectedPaths, destinationPath, mountPath, keepVaultStructure]);const { invalidPaths } = preview;@@ -184,8 +191,12 @@ const Content = ({});return;}+ if (!mountPath) {+ createNotification({ type: "error", text: "Please select a secrets engine" });+ return;+ }- onImport({ vaultPaths: selectedPaths, namespace, connectionId, keepVaultStructure });+ onImport({ vaultPaths: selectedPaths, namespace, mountPath, connectionId, keepVaultStructure });onClose();};