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 support for gatewayv2 on vault
adilson2985eabb1c09
diff --git a/backend/src/services/external-migration/external-migration-fns/vault.ts b/backend/src/services/external-migration/external-migration-fns/vault.tsindex aee421111b..0aa7d1d655 100644--- a/backend/src/services/external-migration/external-migration-fns/vault.ts+++ b/backend/src/services/external-migration/external-migration-fns/vault.ts@@ -4,8 +4,10 @@ import axios, { AxiosInstance, isAxiosError } from "axios";import { v4 as uuidv4 } from "uuid";import { TGatewayServiceFactory } from "@app/ee/services/gateway/gateway-service";+import { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service";import { BadRequestError } from "@app/lib/errors";import { GatewayProxyProtocol, withGatewayProxy } from "@app/lib/gateway";+import { withGatewayV2Proxy } from "@app/lib/gateway-v2/gateway-v2";import { logger } from "@app/lib/logger";import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";@@ -18,31 +20,44 @@ type VaultData = {secretData: Record<string, string>;};-const vaultFactory = (gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">) => {+const vaultFactory = (+ gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">+) => {const $gatewayProxyWrapper = async <T>(inputs: {gatewayId: string;- targetHost?: string;- targetPort?: number;+ targetProtocol: string;+ targetHostname: string;+ targetPort: number;},gatewayCallback: (host: string, port: number, httpsAgent?: https.Agent) => Promise<T>): Promise<T> => {- const relayDetails = await gatewayService.fnGetGatewayClientTlsByGatewayId(inputs.gatewayId);-- const callbackResult = await withGatewayProxy(- async (port, httpsAgent) => {- const res = await gatewayCallback("http://localhost", port, httpsAgent);- return res;- },- {- protocol: GatewayProxyProtocol.Http,- targetHost: inputs.targetHost,- targetPort: inputs.targetPort,- relayDetails- }- );+ const { gatewayId, targetProtocol, targetHostname, targetPort } = inputs;++ const gatewayV2Details = await gatewayV2Service.getPlatformConnectionDetailsByGatewayId({+ gatewayId,+ targetHost: targetHostname,+ targetPort+ });++ if (gatewayV2Details) {+ return withGatewayV2Proxy(async (port) => gatewayCallback("http://localhost", port), {+ protocol: GatewayProxyProtocol.Tcp,+ relayHost: gatewayV2Details.relayHost,+ gateway: gatewayV2Details.gateway,+ relay: gatewayV2Details.relay+ });+ }++ const relayDetails = await gatewayService.fnGetGatewayClientTlsByGatewayId(gatewayId);- return callbackResult;+ return withGatewayProxy(async (port, httpsAgent) => gatewayCallback("http://localhost", port, httpsAgent), {+ protocol: GatewayProxyProtocol.Http,+ targetHost: `${targetProtocol}://${targetHostname}`,+ targetPort,+ relayDetails+ });};const getMounts = async (request: AxiosInstance) => {@@ -280,7 +295,8 @@ const vaultFactory = (gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewaydata = await $gatewayProxyWrapper({gatewayId,- targetHost: `${cleanedProtocol}://${hostname}`,+ targetProtocol: cleanedProtocol,+ targetHostname: hostname,targetPort: port ? Number(port) : 8200 // 8200, default port for Vault self-hosted/dedicated},getData@@ -532,7 +548,13 @@ export const importVaultDataFn = async (gatewayId?: string;orgId: string;},- { gatewayService }: { gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId"> }+ {+ gatewayService,+ gatewayV2Service+ }: {+ gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">;+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">;+ }) => {await blockLocalAndPrivateIpAddresses(vaultUrl);@@ -561,7 +583,7 @@ export const importVaultDataFn = async (`[importVaultDataFn]: Running ${orgId in vaultMigrationTransformMappings ? "custom" : "default"} transform`);- const vaultApi = vaultFactory(gatewayService);+ const vaultApi = vaultFactory(gatewayService, gatewayV2Service);const vaultData = await vaultApi.collectVaultData({accessToken: vaultAccessToken,diff --git a/backend/src/services/external-migration/external-migration-service.ts b/backend/src/services/external-migration/external-migration-service.tsindex 72e2c25bfe..11084e992b 100644--- a/backend/src/services/external-migration/external-migration-service.ts+++ b/backend/src/services/external-migration/external-migration-service.ts@@ -287,7 +287,8 @@ export const externalMigrationServiceFactory = ({orgId: actorOrgId},{- gatewayService+ gatewayService,+ gatewayV2Service});diff --git a/frontend/src/pages/organization/SettingsPage/components/ExternalMigrationsTab/components/VaultPlatformModal.tsx b/frontend/src/pages/organization/SettingsPage/components/ExternalMigrationsTab/components/VaultPlatformModal.tsxindex 6bcd8ac321..238c91a838 100644--- a/frontend/src/pages/organization/SettingsPage/components/ExternalMigrationsTab/components/VaultPlatformModal.tsx+++ b/frontend/src/pages/organization/SettingsPage/components/ExternalMigrationsTab/components/VaultPlatformModal.tsx@@ -268,7 +268,13 @@ export const VaultPlatformModal = ({ onClose }: Props) => {<Field><FieldLabel>Vault Namespace</FieldLabel><FieldContent>- <Input type="text" placeholder="" {...field} isError={Boolean(error)} />+ <Input+ type="text"+ placeholder="admin"+ autoComplete="off"+ {...field}+ isError={Boolean(error)}+ /></FieldContent><FieldError>{error?.message}</FieldError></Field>@@ -281,7 +287,13 @@ export const VaultPlatformModal = ({ onClose }: Props) => {<Field><FieldLabel>Vault Access Token</FieldLabel><FieldContent>- <Input type="password" placeholder="" {...field} isError={Boolean(error)} />+ <Input+ type="password"+ placeholder="hvs.XXXXXXXXXXXXXXXX"+ autoComplete="new-password"+ {...field}+ isError={Boolean(error)}+ /></FieldContent><FieldError>{error?.message}</FieldError></Field>