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
add fallback for old vault version
adilsonf8adeabd9410
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 47f47fe9a5..d2d9cfd14e 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@@ -70,6 +70,10 @@ const isGateway404Error = (error: unknown): boolean => {return error instanceof BadRequestError && error.message?.includes("Request failed with status code 404");};+const isGateway301Error = (error: unknown): boolean => {+ return error instanceof BadRequestError && error.message?.includes("Request failed with status code 301");+};+// Helper to extract error message from Vault API errorsconst getVaultErrorMessage = (error: unknown, fallback: string): string => {if (error instanceof AxiosError) {@@ -489,6 +493,41 @@ export const listHCVaultPolicies = async (}};+const fetchHCVaultNamespacesWithoutNamespaceHeader = async ({+ connection,+ gatewayService,+ gatewayV2Service,+ instanceUrl,+ accessToken+}: {+ connection: THCVaultConnection;+ gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">;+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">;+ instanceUrl: string;+ accessToken: string;+}): Promise<string[]> => {+ try {+ const { data } = await requestWithHCVaultGateway<{+ data: { keys: string[] };+ }>(connection, gatewayService, gatewayV2Service, {+ url: `${instanceUrl}/v1/sys/namespaces?list=true`,+ method: "GET",+ headers: {+ "X-Vault-Token": accessToken+ }+ });++ return data.data.keys || [];+ } catch (error: unknown) {+ if (error instanceof AxiosError) {+ throw new BadRequestError({+ message: `Failed to list namespaces: ${error.message || "Unknown error"}`+ });+ }+ throw error;+ }+};+export const listHCVaultNamespaces = async (connection: THCVaultConnection,gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,@@ -528,6 +567,22 @@ export const listHCVaultNamespaces = async (// No child namespaces at this pathreturn null;}++ // vault 1.0.0 does not support namespace root or /, so we need to handle this case+ // if the error is 301 and the namespace path is /, try to fetch the namespaces at the root+ if (+ ((error instanceof AxiosError && error.response?.status === 301) || isGateway301Error(error)) &&+ namespacePath === "/"+ ) {+ return fetchHCVaultNamespacesWithoutNamespaceHeader({+ connection,+ gatewayService,+ gatewayV2Service,+ instanceUrl,+ accessToken+ });+ }+throw error;}};