Skip to content

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

feat: ignore paths that have the + wildcard

adilsonab516a1beb35
diff --git a/backend/src/server/routes/v3/external-migration-router.ts b/backend/src/server/routes/v3/external-migration-router.ts
index cb8467054b..e3fc53487e 100644
--- a/backend/src/server/routes/v3/external-migration-router.ts
+++ b/backend/src/server/routes/v3/external-migration-router.ts
@@ -415,20 +415,21 @@ export const registerExternalMigrationRouter = async (server: FastifyZodProvider
}),
response: {
200: z.object({
- secretPaths: z.string().array()
+ secretPaths: z.string().array(),
+ skippedWildcardPaths: z.string().array()
})
}
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
- const secretPaths = await server.services.migration.getVaultSecretPaths({
+ const result = await server.services.migration.getVaultSecretPaths({
actor: req.permission,
namespace: req.query.namespace,
mountPath: req.query.mountPath,
connectionId: req.query.connectionId
});
- return { secretPaths };
+ return result;
}
});
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 83290b4417..25a336fb76 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
@@ -733,6 +733,8 @@ class NamespaceHeaderNotSupportedError extends Error {
const isRootNamespace = (namespace: string) => namespace === "/" || namespace === "root" || !namespace;
+const isWildcardPath = (path: string) => path.split("/").includes("+");
+
// Fallback for restricted Vault tokens that lack permission to list a mount from its root.
// We ask Vault for the resultant ACL of the current token and derive the sub-paths within the
// given mount that the token is authorized for. These are returned relative to the mount, with the
@@ -741,6 +743,7 @@ const isRootNamespace = (namespace: string) => namespace === "/" || namespace ==
const listHCVaultAccessiblePathsFromAcl = async (
namespace: string,
mountPath: string,
+ kvVersion: "1" | "2",
instanceUrl: string,
accessToken: string,
connection: THCVaultConnection,
@@ -790,6 +793,13 @@ const listHCVaultAccessiblePathsFromAcl = async (
const nsPrefix = isRootNamespace(namespace) ? "" : `${removeTrailingSlash(namespace)}/`;
const mountPrefix = `${removeTrailingSlash(mountPath)}/`;
+ const stripKvV2Prefix = (path: string): string => {
+ if (kvVersion !== "2") return path;
+ if (path.startsWith("data/")) return path.slice("data/".length);
+ if (path.startsWith("metadata/")) return path.slice("metadata/".length);
+ return path;
+ };
+
const collectRelativePaths = (paths?: Record<string, { capabilities: string[] }>): string[] => {
if (!paths) return [];
@@ -797,6 +807,7 @@ const listHCVaultAccessiblePathsFromAcl = async (
.map((path) => (nsPrefix && path.startsWith(nsPrefix) ? path.slice(nsPrefix.length) : path))
.filter((path) => path.startsWith(mountPrefix))
.map((path) => path.slice(mountPrefix.length))
+ .map(stripKvV2Prefix)
.filter((path) => removeTrailingSlash(path).length > 0); // drop the bare mount root (can't list it anyway)
};
@@ -870,7 +881,6 @@ export const listHCVaultSecretPaths = async (
}
};
- // Recursive function to get all secret paths in a mount with controlled parallelization
const recursivelyGetAllPaths = async (
mountPath: string,
kvVersion: "1" | "2",
@@ -942,17 +952,25 @@ export const listHCVaultSecretPaths = async (
// Create concurrency limiter to avoid overwhelming the Vault instance
const limiter = createConcurrencyLimiter(HC_VAULT_CONCURRENCY_LIMIT);
- // Collect all secret paths from all KV mounts in parallel
- const allSecretPathsArrays = await Promise.all(
- kvMounts.map(async (mount) => {
+ // Collect all secret paths from all KV mounts in parallel. Each entry returns the discovered secret
+ // paths plus any paths skipped because they contain a "+" wildcard (only the resultant-ACL fallback
+ // can surface wildcards; the normal listing flow always returns an empty skipped list).
+ const perMountResults = await Promise.all(
+ kvMounts.map(async (mount): Promise<{ secretPaths: string[]; skippedWildcardPaths: string[] }> => {
const kvVersion = mount.version === "2" ? "2" : "1";
const cleanMountPath = mount.path.replace(/\/$/, ""); // Remove trailing slash
try {
- return await recursivelyGetAllPaths(cleanMountPath, kvVersion, limiter);
+ return {
+ secretPaths: await recursivelyGetAllPaths(cleanMountPath, kvVersion, limiter),
+ skippedWildcardPaths: []
+ };
} catch (error) {
// Vault rejected the namespace header (301 on root/"/"), retry the mount without it.
if (error instanceof NamespaceHeaderNotSupportedError) {
- return recursivelyGetAllPaths(cleanMountPath, kvVersion, limiter, "", true);
+ return {
+ secretPaths: await recursivelyGetAllPaths(cleanMountPath, kvVersion, limiter, "", true),
+ skippedWildcardPaths: []
+ };
}
// Restricted tokens may lack permission to list the mount from its root, returning a 403 on the
@@ -961,6 +979,7 @@ export const listHCVaultSecretPaths = async (
const accessiblePaths = await listHCVaultAccessiblePathsFromAcl(
namespace,
cleanMountPath,
+ kvVersion,
instanceUrl,
accessToken,
connection,
@@ -969,17 +988,24 @@ export const listHCVaultSecretPaths = async (
gatewayDetails
);
- const directSecretPaths = accessiblePaths
+ // Drop "+" wildcard paths: they can't be listed/recursed. Surface them so the user is informed.
+ const skippedWildcardPaths = accessiblePaths
+ .filter(isWildcardPath)
+ .map((path) => `${cleanMountPath}/${removeTrailingSlash(path)}`);
+ const usablePaths = accessiblePaths.filter((path) => !isWildcardPath(path));
+
+ const directSecretPaths = usablePaths
.filter((path) => !path.endsWith("/"))
.map((path) => `${cleanMountPath}/${path}`);
- const folderPaths = accessiblePaths
- .filter((path) => path.endsWith("/"))
- .map((path) => removeTrailingSlash(path));
+ const folderPaths = usablePaths.filter((path) => path.endsWith("/")).map((path) => removeTrailingSlash(path));
const recursedSecretPaths = await recurseFromPaths(cleanMountPath, kvVersion, limiter, folderPaths);
- return Array.from(new Set([...directSecretPaths, ...recursedSecretPaths]));
+ return {
+ secretPaths: Array.from(new Set([...directSecretPaths, ...recursedSecretPaths])),
+ skippedWildcardPaths
+ };
}
throw error;
@@ -987,10 +1013,11 @@ export const listHCVaultSecretPaths = async (
})
);
- // Flatten the arrays into a single array
- const allSecretPaths = allSecretPathsArrays.flat();
-
- return allSecretPaths;
+ // Flatten across mounts and dedupe both lists
+ return {
+ secretPaths: Array.from(new Set(perMountResults.flatMap((result) => result.secretPaths))),
+ skippedWildcardPaths: Array.from(new Set(perMountResults.flatMap((result) => result.skippedWildcardPaths)))
+ };
};
const fetchVaultSecretAtPath = async ({
diff --git a/docs/documentation/platform/external-migrations/vault.mdx b/docs/documentation/platform/external-migrations/vault.mdx
index eeb4dce529..56d557ad83 100644
--- a/docs/documentation/platform/external-migrations/vault.mdx
+++ b/docs/documentation/platform/external-migrations/vault.mdx
@@ -129,6 +129,10 @@ KV secrets are imported into a specific **environment** (e.g., Development, Stag
**First time?** You'll need to [create a project](/documentation/platform/project) first. A project in Infisical typically represents a single application or microservice.
</Info>
+<Warning>
+ If your Vault token is restricted and cannot list a mount from its root, Infisical discovers the available secret paths from the token's resultant ACL (`sys/internal/ui/resultant-acl`). Any path that contains a `+` wildcard (Vault's single-segment wildcard, e.g. `secret/+/db`) cannot be expanded and is **skipped** — those secrets will not be imported. To migrate them, grant the token access to the explicit KV paths instead of relying on `+`.
+</Warning>
+
**To import secrets from Vault:**
1. Navigate to your project and select a specific environment (e.g., Development, Production)
diff --git a/frontend/src/hooks/api/migration/queries.tsx b/frontend/src/hooks/api/migration/queries.tsx
index b614bbdde8..7cc5307ff2 100644
--- a/frontend/src/hooks/api/migration/queries.tsx
+++ b/frontend/src/hooks/api/migration/queries.tsx
@@ -156,6 +156,7 @@ export const useGetVaultSecretPaths = (
const { data } = await apiRequest.get<{
secretPaths: string[];
+ skippedWildcardPaths: string[];
}>("/api/v3/external-migration/vault/secret-paths", {
params: {
namespace,
@@ -164,7 +165,7 @@ export const useGetVaultSecretPaths = (
}
});
- return data.secretPaths;
+ return data;
},
enabled: enabled && !!namespace && !!mountPath && !!connectionId
});
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 c35d2466c7..b3a3ffd64c 100644
--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/VaultSecretImportModal.tsx
+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/VaultSecretImportModal.tsx
@@ -1,6 +1,7 @@
import { useEffect, useState } from "react";
import { faInfoCircle } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import { TriangleAlertIcon } from "lucide-react";
import {
defaultVaultConnectionId,
@@ -15,6 +16,7 @@ import {
ModalClose,
ModalContent
} from "@app/components/v2";
+import { Alert, AlertDescription, AlertTitle } from "@app/components/v3/generic/Alert";
import { TAvailableAppConnection } from "@app/hooks/api/appConnections/types";
import { useGetVaultMounts, useGetVaultSecretPaths } from "@app/hooks/api/migration/queries";
@@ -48,12 +50,14 @@ const Content = ({ onClose, environment, secretPath, appConnections, onImport }:
const activeConnectionId = hasAppConnections ? (selectedConnectionId ?? undefined) : undefined;
- const { data: secretPaths, isLoading: isLoadingPaths } = useGetVaultSecretPaths(
+ const { data: vaultSecretPaths, isLoading: isLoadingPaths } = useGetVaultSecretPaths(
shouldFetchPaths,
selectedNamespace ?? undefined,
selectedMountPath ?? undefined,
activeConnectionId
);
+ const secretPaths = vaultSecretPaths?.secretPaths;
+ const skippedWildcardPaths = vaultSecretPaths?.skippedWildcardPaths ?? [];
const { data: mounts, isLoading: isLoadingMounts } = useGetVaultMounts(
shouldFetchMounts,
selectedNamespace ?? undefined,
@@ -180,6 +184,17 @@ const Content = ({ onClose, environment, secretPath, appConnections, onImport }:
</>
</FormControl>
+ {skippedWildcardPaths.length > 0 && (
+ <Alert variant="warning" className="mb-4">
+ <TriangleAlertIcon />
+ <AlertTitle>Some paths were skipped</AlertTitle>
+ <AlertDescription>
+ Some paths use a Vault + wildcard and can&apos;t be imported. Grant the token access to
+ explicit paths instead.
+ </AlertDescription>
+ </Alert>
+ )}
+
<FormControl label="Vault Secret Path" className="mb-6">
<>
<FilterableSelect