Skip to content

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

fix: gateway v2 support for hashicorp vault connection

Daniel Hougaardb5a87f9b74d4
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index 66b66e10ae..90b39a3603 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -2642,7 +2642,8 @@ export const registerRoutes = async (
appConnectionService,
vaultExternalMigrationConfigDAL,
secretService,
- auditLogService
+ auditLogService,
+ gatewayV2Service
});
// setup the communication with license key server
diff --git a/backend/src/services/app-connection/app-connection-service.ts b/backend/src/services/app-connection/app-connection-service.ts
index 1a89f9501b..8369521409 100644
--- a/backend/src/services/app-connection/app-connection-service.ts
+++ b/backend/src/services/app-connection/app-connection-service.ts
@@ -893,7 +893,7 @@ export const appConnectionServiceFactory = ({
azureClientSecrets: azureClientSecretsConnectionService(connectAppConnectionById, appConnectionDAL, kmsService),
azureDevOps: azureDevOpsConnectionService(connectAppConnectionById, appConnectionDAL, kmsService),
auth0: auth0ConnectionService(connectAppConnectionById, appConnectionDAL, kmsService),
- hcvault: hcVaultConnectionService(connectAppConnectionById, gatewayService),
+ hcvault: hcVaultConnectionService(connectAppConnectionById, gatewayService, gatewayV2Service),
windmill: windmillConnectionService(connectAppConnectionById),
teamcity: teamcityConnectionService(connectAppConnectionById),
oci: ociConnectionService(connectAppConnectionById, licenseService),
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 82cc463ba2..938f50988d 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
@@ -8,6 +8,7 @@ import { request } from "@app/lib/config/request";
import { BadRequestError } from "@app/lib/errors";
import { removeTrailingSlash } from "@app/lib/fn";
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";
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
@@ -127,6 +128,7 @@ type TokenRespData = {
export const requestWithHCVaultGateway = async <T>(
appConnection: { gatewayId?: string | null },
gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">,
requestConfig: AxiosRequestConfig
): Promise<AxiosResponse<T>> => {
const { gatewayId } = appConnection;
@@ -140,6 +142,57 @@ export const requestWithHCVaultGateway = async <T>(
}
const [targetHost] = await verifyHostInputValidity({ host: url.hostname, isGateway: true, isDynamicSecret: false });
+ const targetPort = url.port ? Number(url.port) : 8200; // 8200 is the default port for Vault self-hosted/dedicated
+
+ const gatewayConnectionDetails = await gatewayV2Service.getPlatformConnectionDetailsByGatewayId({
+ gatewayId,
+ targetHost,
+ targetPort
+ });
+
+ if (gatewayConnectionDetails) {
+ return withGatewayV2Proxy(
+ async (proxyPort) => {
+ const isHttps = url.protocol === "https:";
+
+ url.host = `localhost:${proxyPort}`;
+
+ const finalRequestConfig: AxiosRequestConfig = {
+ ...requestConfig,
+ url: url.toString(),
+ headers: {
+ ...requestConfig.headers,
+ Host: targetHost
+ },
+ ...(isHttps && {
+ httpsAgent: new https.Agent({
+ servername: targetHost,
+ rejectUnauthorized: false
+ })
+ })
+ };
+
+ try {
+ return await request.request(finalRequestConfig);
+ } catch (error) {
+ if (error instanceof AxiosError) {
+ logger.error(
+ { message: error.message, data: (error.response as undefined | { data: unknown })?.data },
+ "Error during HashiCorp Vault gateway request:"
+ );
+ }
+ throw error;
+ }
+ },
+ {
+ protocol: GatewayProxyProtocol.Tcp,
+ relayHost: gatewayConnectionDetails.relayHost,
+ gateway: gatewayConnectionDetails.gateway,
+ relay: gatewayConnectionDetails.relay
+ }
+ );
+ }
+
const relayDetails = await gatewayService.fnGetGatewayClientTlsByGatewayId(gatewayId);
const [relayHost, relayPort] = relayDetails.relayAddress.split(":");
@@ -177,7 +230,7 @@ export const requestWithHCVaultGateway = async <T>(
{
protocol: GatewayProxyProtocol.Tcp,
targetHost,
- targetPort: url.port ? Number(url.port) : 8200, // 8200 is the default port for Vault self-hosted/dedicated
+ targetPort,
relayHost,
relayPort: Number(relayPort),
identityId: relayDetails.identityId,
@@ -193,7 +246,8 @@ export const requestWithHCVaultGateway = async <T>(
export const getHCVaultAccessToken = async (
connection: THCVaultConnection,
- gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">
+ gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">
) => {
// Return access token directly if not using AppRole method
if (connection.method !== HCVaultConnectionMethod.AppRole) {
@@ -204,7 +258,7 @@ export const getHCVaultAccessToken = async (
try {
const { instanceUrl, roleId, secretId } = connection.credentials;
- const tokenResp = await requestWithHCVaultGateway<TokenRespData>(connection, gatewayService, {
+ const tokenResp = await requestWithHCVaultGateway<TokenRespData>(connection, gatewayService, gatewayV2Service, {
url: `${removeTrailingSlash(instanceUrl)}/v1/auth/approle/login`,
method: "POST",
headers: {
@@ -232,16 +286,15 @@ export const getHCVaultAccessToken = async (
export const validateHCVaultConnectionCredentials = async (
connection: THCVaultConnection,
gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
- _gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">
) => {
const instanceUrl = await getHCVaultInstanceUrl(connection);
try {
- const accessToken = await getHCVaultAccessToken(connection, gatewayService);
+ const accessToken = await getHCVaultAccessToken(connection, gatewayService, gatewayV2Service);
// Verify token
- await requestWithHCVaultGateway(connection, gatewayService, {
+ await requestWithHCVaultGateway(connection, gatewayService, gatewayV2Service, {
url: `${instanceUrl}/v1/auth/token/lookup-self`,
method: "GET",
headers: { "X-Vault-Token": accessToken }
@@ -270,17 +323,18 @@ export const validateHCVaultConnectionCredentials = async (
export const listHCVaultPolicies = async (
namespace: string,
connection: THCVaultConnection,
- gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">
+ gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">
) => {
const instanceUrl = await getHCVaultInstanceUrl(connection);
- const accessToken = await getHCVaultAccessToken(connection, gatewayService);
+ const accessToken = await getHCVaultAccessToken(connection, gatewayService, gatewayV2Service);
try {
const { data: listData } = await requestWithHCVaultGateway<{
data: {
policies: string[];
};
- }>(connection, gatewayService, {
+ }>(connection, gatewayService, gatewayV2Service, {
url: `${instanceUrl}/v1/sys/policy`,
method: "GET",
headers: {
@@ -302,7 +356,7 @@ export const listHCVaultPolicies = async (
name: string;
rules: string;
};
- }>(connection, gatewayService, {
+ }>(connection, gatewayService, gatewayV2Service, {
url: `${instanceUrl}/v1/sys/policy/${policyName}`,
method: "GET",
headers: {
@@ -344,10 +398,11 @@ export const listHCVaultPolicies = async (
export const listHCVaultNamespaces = async (
connection: THCVaultConnection,
- gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">
+ gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">
) => {
const instanceUrl = await getHCVaultInstanceUrl(connection);
- const accessToken = await getHCVaultAccessToken(connection, gatewayService);
+ const accessToken = await getHCVaultAccessToken(connection, gatewayService, gatewayV2Service);
const currentNamespace = connection.credentials.namespace || "/";
@@ -365,7 +420,7 @@ export const listHCVaultNamespaces = async (
};
};
};
- }>(connection, gatewayService, {
+ }>(connection, gatewayService, gatewayV2Service, {
url: `${instanceUrl}/v1/sys/namespaces?list=true`,
method: "GET",
headers: {
@@ -461,21 +516,27 @@ export const listHCVaultNamespaces = async (
export const listHCVaultMounts = async (
connection: THCVaultConnection,
gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">,
namespace?: string
) => {
const instanceUrl = await getHCVaultInstanceUrl(connection);
- const accessToken = await getHCVaultAccessToken(connection, gatewayService);
+ const accessToken = await getHCVaultAccessToken(connection, gatewayService, gatewayV2Service);
const targetNamespace = namespace || connection.credentials.namespace;
- const { data } = await requestWithHCVaultGateway<THCVaultMountResponse>(connection, gatewayService, {
- url: `${instanceUrl}/v1/sys/mounts`,
- method: "GET",
- headers: {
- "X-Vault-Token": accessToken,
- ...(targetNamespace ? { "X-Vault-Namespace": targetNamespace } : {})
+ const { data } = await requestWithHCVaultGateway<THCVaultMountResponse>(
+ connection,
+ gatewayService,
+ gatewayV2Service,
+ {
+ url: `${instanceUrl}/v1/sys/mounts`,
+ method: "GET",
+ headers: {
+ "X-Vault-Token": accessToken,
+ ...(targetNamespace ? { "X-Vault-Namespace": targetNamespace } : {})
+ }
}
- });
+ );
const mounts: THCVaultMount[] = [];
@@ -494,10 +555,11 @@ export const listHCVaultSecretPaths = async (
namespace: string,
connection: THCVaultConnection,
gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">,
filterMountPath?: string
) => {
const instanceUrl = await getHCVaultInstanceUrl(connection);
- const accessToken = await getHCVaultAccessToken(connection, gatewayService);
+ const accessToken = await getHCVaultAccessToken(connection, gatewayService, gatewayV2Service);
const getPaths = async (mountPath: string, secretPath: string, kvVersion: "1" | "2"): Promise<string[] | null> => {
try {
@@ -514,7 +576,7 @@ export const listHCVaultSecretPaths = async (
data: {
keys: string[];
};
- }>(connection, gatewayService, {
+ }>(connection, gatewayService, gatewayV2Service, {
url: `${instanceUrl}/v1/${path}?list=true`,
method: "GET",
headers: {
@@ -568,7 +630,7 @@ export const listHCVaultSecretPaths = async (
};
// Get all mounts
- const mounts = await listHCVaultMounts(connection, gatewayService, namespace);
+ 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"));
@@ -601,10 +663,11 @@ export const getHCVaultSecretsForPath = async (
namespace: string,
secretPath: string,
connection: THCVaultConnection,
- gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">
+ gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">
) => {
const instanceUrl = await getHCVaultInstanceUrl(connection);
- const accessToken = await getHCVaultAccessToken(connection, gatewayService);
+ const accessToken = await getHCVaultAccessToken(connection, gatewayService, gatewayV2Service);
try {
// Extract mount and path from the secretPath
@@ -620,7 +683,7 @@ export const getHCVaultSecretsForPath = async (
}
// Get mounts to determine KV version
- const mounts = await listHCVaultMounts(connection, gatewayService, namespace);
+ const mounts = await listHCVaultMounts(connection, gatewayService, gatewayV2Service, namespace);
const mount = mounts.find((m) => m.path.replace(/\/$/, "") === mountPath);
if (!mount) {
@@ -644,7 +707,7 @@ export const getHCVaultSecretsForPath = async (
version: number;
};
};
- }>(connection, gatewayService, {
+ }>(connection, gatewayService, gatewayV2Service, {
url: `${instanceUrl}/v1/${encodeURIComponent(mountPath)}/data/${actualPath}`,
method: "GET",
headers: {
@@ -662,7 +725,7 @@ export const getHCVaultSecretsForPath = async (
lease_duration: number;
lease_id: string;
renewable: boolean;
- }>(connection, gatewayService, {
+ }>(connection, gatewayService, gatewayV2Service, {
url: `${instanceUrl}/v1/${encodeURIComponent(mountPath)}/${actualPath}`,
method: "GET",
headers: {
@@ -695,20 +758,26 @@ export const getHCVaultAuthMounts = async (
namespace: string,
authType: HCVaultAuthType | undefined,
connection: THCVaultConnection,
- gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">
+ gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">
): Promise<THCVaultAuthMount[]> => {
const instanceUrl = await getHCVaultInstanceUrl(connection);
- const accessToken = await getHCVaultAccessToken(connection, gatewayService);
+ const accessToken = await getHCVaultAccessToken(connection, gatewayService, gatewayV2Service);
try {
- const { data } = await requestWithHCVaultGateway<THCVaultAuthMountResponse>(connection, gatewayService, {
- url: `${instanceUrl}/v1/sys/auth`,
- method: "GET",
- headers: {
- "X-Vault-Token": accessToken,
- "X-Vault-Namespace": namespace
+ const { data } = await requestWithHCVaultGateway<THCVaultAuthMountResponse>(
+ connection,
+ gatewayService,
+ gatewayV2Service,
+ {
+ url: `${instanceUrl}/v1/sys/auth`,
+ method: "GET",
+ headers: {
+ "X-Vault-Token": accessToken,
+ "X-Vault-Namespace": namespace
+ }
}
- });
+ );
const authMounts: THCVaultAuthMount[] = [];
@@ -745,10 +814,11 @@ export const getHCVaultKubernetesAuthRoles = async (
namespace: string,
mountPath: string,
connection: THCVaultConnection,
- gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">
+ gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">
): Promise<THCVaultKubernetesAuthRoleWithConfig[]> => {
const instanceUrl = await getHCVaultInstanceUrl(connection);
- const accessToken = await getHCVaultAccessToken(connection, gatewayService);
+ const accessToken = await getHCVaultAccessToken(connection, gatewayService, gatewayV2Service);
// Remove trailing slash from mount path
const cleanMountPath = mountPath.endsWith("/") ? mountPath.slice(0, -1) : mountPath;
@@ -758,6 +828,7 @@ export const getHCVaultKubernetesAuthRoles = async (
const { data: configResponse } = await requestWithHCVaultGateway<{ data: THCVaultKubernetesAuthConfig }>(
connection,
gatewayService,
+ gatewayV2Service,
{
url: `${instanceUrl}/v1/auth/${encodeURIComponent(cleanMountPath)}/config`,
method: "GET",
@@ -774,6 +845,7 @@ export const getHCVaultKubernetesAuthRoles = async (
const { data: roleListResponse } = await requestWithHCVaultGateway<{ data: { keys: string[] } }>(
connection,
gatewayService,
+ gatewayV2Service,
{
url: `${instanceUrl}/v1/auth/${cleanMountPath}/role`,
method: "LIST",
@@ -798,6 +870,7 @@ export const getHCVaultKubernetesAuthRoles = async (
const { data: roleResponse } = await requestWithHCVaultGateway<{ data: THCVaultKubernetesAuthRole }>(
connection,
gatewayService,
+ gatewayV2Service,
{
url: `${instanceUrl}/v1/auth/${encodeURIComponent(cleanMountPath)}/role/${encodeURIComponent(roleName)}`,
method: "GET",
@@ -842,18 +915,20 @@ export const getHCVaultKubernetesRoles = async (
namespace: string,
mountPath: string,
connection: THCVaultConnection,
- gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">
+ gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">
): Promise<THCVaultKubernetesRole[]> => {
// Remove trailing slash from mount path
const cleanMountPath = mountPath.endsWith("/") ? mountPath.slice(0, -1) : mountPath;
try {
const instanceUrl = await getHCVaultInstanceUrl(connection);
- const accessToken = await getHCVaultAccessToken(connection, gatewayService);
+ const accessToken = await getHCVaultAccessToken(connection, gatewayService, gatewayV2Service);
// 1. Get the Kubernetes secrets engine configuration for this mount
const { data: configResponse } = await requestWithHCVaultGateway<{ data: THCVaultKubernetesSecretsConfig }>(
connection,
gatewayService,
+ gatewayV2Service,
{
url: `${instanceUrl}/v1/${encodeURIComponent(cleanMountPath)}/config`,
method: "GET",
@@ -872,6 +947,7 @@ export const getHCVaultKubernetesRoles = async (
const { data: roleListResponse } = await requestWithHCVaultGateway<{ data: { keys: string[] } }>(
connection,
gatewayService,
+ gatewayV2Service,
{
url: `${instanceUrl}/v1/${encodeURIComponent(cleanMountPath)}/roles?list=true`,
method: "GET",
@@ -911,7 +987,7 @@ export const getHCVaultKubernetesRoles = async (
extra_annotations?: Record<string, string>;
extra_labels?: Record<string, string>;
};
- }>(connection, gatewayService, {
+ }>(connection, gatewayService, gatewayV2Service, {
url: `${instanceUrl}/v1/${encodeURIComponent(cleanMountPath)}/roles/${encodeURIComponent(roleName)}`,
method: "GET",
headers: {
@@ -942,14 +1018,15 @@ export const getHCVaultDatabaseRoles = async (
namespace: string,
mountPath: string,
connection: THCVaultConnection,
- gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">
+ gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">
): Promise<THCVaultDatabaseRole[]> => {
// Remove trailing slash from mount path
const cleanMountPath = mountPath.endsWith("/") ? mountPath.slice(0, -1) : mountPath;
try {
const instanceUrl = await getHCVaultInstanceUrl(connection);
- const accessToken = await getHCVaultAccessToken(connection, gatewayService);
+ const accessToken = await getHCVaultAccessToken(connection, gatewayService, gatewayV2Service);
// 1. List all database connections in this mount to get their configs
let connectionNames: string[] = [];
@@ -957,6 +1034,7 @@ export const getHCVaultDatabaseRoles = async (
const { data: connectionListResponse } = await requestWithHCVaultGateway<{ data: { keys: string[] } }>(
connection,
gatewayService,
+ gatewayV2Service,
{
url: `${instanceUrl}/v1/${encodeURIComponent(cleanMountPath)}/config?list=true`,
method: "GET",
@@ -982,7 +1060,7 @@ export const getHCVaultDatabaseRoles = async (
try {
const { data: configResponse } = await requestWithHCVaultGateway<{
data: THCVaultDatabaseConfig;
- }>(connection, gatewayService, {
+ }>(connection, gatewayService, gatewayV2Service, {
url: `${instanceUrl}/v1/${encodeURIComponent(cleanMountPath)}/config/${encodeURIComponent(connName)}`,
method: "GET",
headers: {
@@ -1004,6 +1082,7 @@ export const getHCVaultDatabaseRoles = async (
const { data: roleListResponse } = await requestWithHCVaultGateway<{ data: { keys: string[] } }>(
connection,
gatewayService,
+ gatewayV2Service,
{
url: `${instanceUrl}/v1/${encodeURIComponent(cleanMountPath)}/roles?list=true`,
method: "GET",
@@ -1035,7 +1114,7 @@ export const getHCVaultDatabaseRoles = async (
revocation_statements?: string[];
renew_statements?: string[];
};
- }>(connection, gatewayService, {
+ }>(connection, gatewayService, gatewayV2Service, {
url: `${instanceUrl}/v1/${encodeURIComponent(cleanMountPath)}/roles/${encodeURIComponent(roleName)}`,
method: "GET",
headers: {
@@ -1076,19 +1155,21 @@ export const getHCVaultLdapRoles = async (
namespace: string,
mountPath: string,
connection: THCVaultConnection,
- gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">
+ gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">
): Promise<THCVaultLdapRole[]> => {
// Remove trailing slash from mount path
const cleanMountPath = mountPath.endsWith("/") ? mountPath.slice(0, -1) : mountPath;
try {
const instanceUrl = await getHCVaultInstanceUrl(connection);
- const accessToken = await getHCVaultAccessToken(connection, gatewayService);
+ const accessToken = await getHCVaultAccessToken(connection, gatewayService, gatewayV2Service);
// 1. Get the LDAP secrets engine configuration for this mount
const { data: configResponse } = await requestWithHCVaultGateway<{ data: THCVaultLdapConfig }>(
connection,
gatewayService,
+ gatewayV2Service,
{
url: `${instanceUrl}/v1/${encodeURIComponent(cleanMountPath)}/config`,
method: "GET",
@@ -1107,6 +1188,7 @@ export const getHCVaultLdapRoles = async (
const { data: roleListResponse } = await requestWithHCVaultGateway<{ data: { keys: string[] } }>(
connection,
gatewayService,
+ gatewayV2Service,
{
url: `${instanceUrl}/v1/${encodeURIComponent(cleanMountPath)}/role?list=true`,
method: "GET",
@@ -1140,7 +1222,7 @@ export const getHCVaultLdapRoles = async (
rollback_ldif?: string;
username_template?: string;
};
- }>(connection, gatewayService, {
+ }>(connection, gatewayService, gatewayV2Service, {
url: `${instanceUrl}/v1/${encodeURIComponent(cleanMountPath)}/role/${encodeURIComponent(roleName)}`,
method: "GET",
headers: {
diff --git a/backend/src/services/app-connection/hc-vault/hc-vault-connection-service.ts b/backend/src/services/app-connection/hc-vault/hc-vault-connection-service.ts
index 037964da45..fb5695596b 100644
--- a/backend/src/services/app-connection/hc-vault/hc-vault-connection-service.ts
+++ b/backend/src/services/app-connection/hc-vault/hc-vault-connection-service.ts
@@ -1,4 +1,5 @@
import { TGatewayServiceFactory } from "@app/ee/services/gateway/gateway-service";
+import { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service";
import { logger } from "@app/lib/logger";
import { OrgServiceActor } from "@app/lib/types";
@@ -14,13 +15,14 @@ type TGetAppConnectionFunc = (
export const hcVaultConnectionService = (
getAppConnection: TGetAppConnectionFunc,
- gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">
+ gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">
) => {
const listMounts = async (connectionId: string, actor: OrgServiceActor) => {
const appConnection = await getAppConnection(AppConnection.HCVault, connectionId, actor);
try {
- const mounts = await listHCVaultMounts(appConnection, gatewayService);
+ const mounts = await listHCVaultMounts(appConnection, gatewayService, gatewayV2Service);
// Filter for KV version 2 mounts only and extract just the paths
return mounts.filter((mount) => mount.type === "kv" && mount.version === "2").map((mount) => mount.path);
} catch (error) {
diff --git a/backend/src/services/external-migration/external-migration-service.ts b/backend/src/services/external-migration/external-migration-service.ts
index f7798e2f2d..4f32a5bc01 100644
--- a/backend/src/services/external-migration/external-migration-service.ts
+++ b/backend/src/services/external-migration/external-migration-service.ts
@@ -6,6 +6,7 @@ import {
TAuditLogServiceFactory
} from "@app/ee/services/audit-log/audit-log-types";
import { TGatewayServiceFactory } from "@app/ee/services/gateway/gateway-service";
+import { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { crypto } from "@app/lib/crypto/cryptography";
import { DatabaseErrorCode } from "@app/lib/error-codes";
@@ -65,6 +66,7 @@ type TExternalMigrationServiceFactoryDep = {
>;
userDAL: Pick<TUserDALFactory, "findById">;
gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">;
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">;
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
};
@@ -75,6 +77,7 @@ export const externalMigrationServiceFactory = ({
externalMigrationQueue,
userDAL,
gatewayService,
+ gatewayV2Service,
secretService,
auditLogService,
appConnectionService,
@@ -279,13 +282,13 @@ export const externalMigrationServiceFactory = ({
}
try {
- await listHCVaultPolicies(namespace, connection, gatewayService);
- await getHCVaultAuthMounts(namespace, HCVaultAuthType.Kubernetes, connection, gatewayService);
+ await listHCVaultPolicies(namespace, connection, gatewayService, gatewayV2Service);
+ await getHCVaultAuthMounts(namespace, HCVaultAuthType.Kubernetes, connection, gatewayService, gatewayV2Service);
- const mounts = await listHCVaultMounts(connection, gatewayService);
+ const mounts = await listHCVaultMounts(connection, gatewayService, gatewayV2Service);
const sampleKvMount = mounts.find((mount) => mount.type === "kv");
if (sampleKvMount) {
- await listHCVaultSecretPaths(namespace, connection, gatewayService, sampleKvMount.path);
+ await listHCVaultSecretPaths(namespace, connection, gatewayService, gatewayV2Service, sampleKvMount.path);
}
} catch (error) {
throw new BadRequestError({
@@ -433,12 +436,12 @@ export const externalMigrationServiceFactory = ({
const getVaultPolicies = async ({ actor, namespace }: { actor: OrgServiceActor; namespace: string }) => {
const connection = await getVaultConnectionForNamespace(actor, namespace, "view vault policies");
- return listHCVaultPolicies(namespace, connection, gatewayService);
+ return listHCVaultPolicies(namespace, connection, gatewayService, gatewayV2Service);
};
const getVaultMounts = async ({ actor, namespace }: { actor: OrgServiceActor; namespace: string }) => {
const connection = await getVaultConnectionForNamespace(actor, namespace, "view vault mounts");
- return listHCVaultMounts(connection, gatewayService, namespace);
+ return listHCVaultMounts(connection, gatewayService, gatewayV2Service, namespace);
};
const getVaultSecretPaths = async ({
@@ -451,7 +454,7 @@ export const externalMigrationServiceFactory = ({
mountPath: string;
}) => {
const connection = await getVaultConnectionForNamespace(actor, namespace, "view vault secret paths");
- return listHCVaultSecretPaths(namespace, connection, gatewayService, mountPath);
+ return listHCVaultSecretPaths(namespace, connection, gatewayService, gatewayV2Service, mountPath);
};
const importVaultSecrets = async ({
@@ -472,7 +475,13 @@ export const externalMigrationServiceFactory = ({
auditLogInfo: AuditLogInfo;
}) => {
const connection = await getVaultConnectionForNamespace(actor, vaultNamespace, "import vault secrets");
- const vaultSecrets = await getHCVaultSecretsForPath(vaultNamespace, vaultSecretPath, connection, gatewayService);
+ const vaultSecrets = await getHCVaultSecretsForPath(
+ vaultNamespace,
+ vaultSecretPath,
+ connection,
+ gatewayService,
+ gatewayV2Service
+ );
try {
const secretOperation = await secretService.createManySecretsRaw({
@@ -559,7 +568,7 @@ export const externalMigrationServiceFactory = ({
authType?: string;
}) => {
const connection = await getVaultConnectionForNamespace(actor, namespace, "view vault auth mounts");
- return getHCVaultAuthMounts(namespace, authType as HCVaultAuthType, connection, gatewayService);
+ return getHCVaultAuthMounts(namespace, authType as HCVaultAuthType, connection, gatewayService, gatewayV2Service);
};
const getVaultKubernetesAuthRoles = async ({
@@ -572,7 +581,7 @@ export const externalMigrationServiceFactory = ({
mountPath: string;
}) => {
const connection = await getVaultConnectionForNamespace(actor, namespace, "view vault Kubernetes auth roles");
- return getHCVaultKubernetesAuthRoles(namespace, mountPath, connection, gatewayService);
+ return getHCVaultKubernetesAuthRoles(namespace, mountPath, connection, gatewayService, gatewayV2Service);
};
const getVaultKubernetesRoles = async ({
@@ -585,7 +594,7 @@ export const externalMigrationServiceFactory = ({
mountPath: string;
}) => {
const connection = await getVaultConnectionForNamespace(actor, namespace, "get Kubernetes roles");
- return getHCVaultKubernetesRoles(namespace, mountPath, connection, gatewayService);
+ return getHCVaultKubernetesRoles(namespace, mountPath, connection, gatewayService, gatewayV2Service);
};
const getVaultDatabaseRoles = async ({
@@ -598,7 +607,7 @@ export const externalMigrationServiceFactory = ({
mountPath: string;
}) => {
const connection = await getVaultConnectionForNamespace(actor, namespace, "get database roles");
- return getHCVaultDatabaseRoles(namespace, mountPath, connection, gatewayService);
+ return getHCVaultDatabaseRoles(namespace, mountPath, connection, gatewayService, gatewayV2Service);
};
const getVaultLdapRoles = async ({
@@ -611,7 +620,7 @@ export const externalMigrationServiceFactory = ({
mountPath: string;
}) => {
const connection = await getVaultConnectionForNamespace(actor, namespace, "get LDAP roles");
- return getHCVaultLdapRoles(namespace, mountPath, connection, gatewayService);
+ return getHCVaultLdapRoles(namespace, mountPath, connection, gatewayService, gatewayV2Service);
};
return {
diff --git a/backend/src/services/secret-sync/hc-vault/hc-vault-sync-fns.ts b/backend/src/services/secret-sync/hc-vault/hc-vault-sync-fns.ts
index 9168c96a66..4e9857f2c9 100644
--- a/backend/src/services/secret-sync/hc-vault/hc-vault-sync-fns.ts
+++ b/backend/src/services/secret-sync/hc-vault/hc-vault-sync-fns.ts
@@ -1,6 +1,7 @@
import { isAxiosError } from "axios";
import { TGatewayServiceFactory } from "@app/ee/services/gateway/gateway-service";
+import { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service";
import { removeTrailingSlash } from "@app/lib/fn";
import {
getHCVaultAccessToken,
@@ -21,17 +22,23 @@ import { TSecretMap } from "@app/services/secret-sync/secret-sync-types";
const listHCVaultVariables = async (
{ instanceUrl, namespace, mount, accessToken, path }: THCVaultListVariables,
connection: THCVaultConnection,
- gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">
+ gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">
) => {
try {
- const { data } = await requestWithHCVaultGateway<THCVaultListVariablesResponse>(connection, gatewayService, {
- url: `${instanceUrl}/v1/${removeTrailingSlash(mount)}/data/${path}`,
- method: "GET",
- headers: {
- "X-Vault-Token": accessToken,
- ...(namespace ? { "X-Vault-Namespace": namespace } : {})
+ const { data } = await requestWithHCVaultGateway<THCVaultListVariablesResponse>(
+ connection,
+ gatewayService,
+ gatewayV2Service,
+ {
+ url: `${instanceUrl}/v1/${removeTrailingSlash(mount)}/data/${path}`,
+ method: "GET",
+ headers: {
+ "X-Vault-Token": accessToken,
+ ...(namespace ? { "X-Vault-Namespace": namespace } : {})
+ }
}
- });
+ );
return data.data.data;
} catch (error: unknown) {
@@ -47,9 +54,10 @@ const listHCVaultVariables = async (
const updateHCVaultVariables = async (
{ path, instanceUrl, namespace, accessToken, mount, data }: TPostHCVaultVariable,
connection: THCVaultConnection,
- gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">
+ gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">
) => {
- return requestWithHCVaultGateway(connection, gatewayService, {
+ return requestWithHCVaultGateway(connection, gatewayService, gatewayV2Service, {
url: `${instanceUrl}/v1/${removeTrailingSlash(mount)}/data/${path}`,
method: "POST",
headers: {
@@ -65,7 +73,8 @@ export const HCVaultSyncFns = {
syncSecrets: async (
secretSync: THCVaultSyncWithCredentials,
secretMap: TSecretMap,
- gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">
+ gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">
) => {
const {
connection,
@@ -75,7 +84,7 @@ export const HCVaultSyncFns = {
} = secretSync;
const { namespace } = connection.credentials;
- const accessToken = await getHCVaultAccessToken(connection, gatewayService);
+ const accessToken = await getHCVaultAccessToken(connection, gatewayService, gatewayV2Service);
const instanceUrl = await getHCVaultInstanceUrl(connection);
const variables = await listHCVaultVariables(
@@ -87,7 +96,8 @@ export const HCVaultSyncFns = {
path
},
connection,
- gatewayService
+ gatewayService,
+ gatewayV2Service
);
let tainted = false;
@@ -118,7 +128,8 @@ export const HCVaultSyncFns = {
await updateHCVaultVariables(
{ accessToken, instanceUrl, namespace, mount, path, data: variables },
connection,
- gatewayService
+ gatewayService,
+ gatewayV2Service
);
} catch (error) {
throw new SecretSyncError({
@@ -129,7 +140,8 @@ export const HCVaultSyncFns = {
removeSecrets: async (
secretSync: THCVaultSyncWithCredentials,
secretMap: TSecretMap,
- gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">
+ gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">
) => {
const {
connection,
@@ -137,13 +149,14 @@ export const HCVaultSyncFns = {
} = secretSync;
const { namespace } = connection.credentials;
- const accessToken = await getHCVaultAccessToken(connection, gatewayService);
+ const accessToken = await getHCVaultAccessToken(connection, gatewayService, gatewayV2Service);
const instanceUrl = await getHCVaultInstanceUrl(connection);
const variables = await listHCVaultVariables(
{ instanceUrl, namespace, accessToken, mount, path },
connection,
- gatewayService
+ gatewayService,
+ gatewayV2Service
);
for await (const [key] of Object.entries(variables)) {
@@ -156,7 +169,8 @@ export const HCVaultSyncFns = {
await updateHCVaultVariables(
{ accessToken, instanceUrl, namespace, mount, path, data: variables },
connection,
- gatewayService
+ gatewayService,
+ gatewayV2Service
);
} catch (error) {
throw new SecretSyncError({
@@ -166,7 +180,8 @@ export const HCVaultSyncFns = {
},
getSecrets: async (
secretSync: THCVaultSyncWithCredentials,
- gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">
+ gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,
+ gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">
) => {
const {
connection,
@@ -174,7 +189,7 @@ export const HCVaultSyncFns = {
} = secretSync;
const { namespace } = connection.credentials;
- const accessToken = await getHCVaultAccessToken(connection, gatewayService);
+ const accessToken = await getHCVaultAccessToken(connection, gatewayService, gatewayV2Service);
const instanceUrl = await getHCVaultInstanceUrl(connection);
const variables = await listHCVaultVariables(
@@ -186,7 +201,8 @@ export const HCVaultSyncFns = {
path
},
connection,
- gatewayService
+ gatewayService,
+ gatewayV2Service
);
return Object.fromEntries(Object.entries(variables).map(([key, value]) => [key, { value }]));
diff --git a/backend/src/services/secret-sync/secret-sync-fns.ts b/backend/src/services/secret-sync/secret-sync-fns.ts
index 534960559a..4e1e66e71d 100644
--- a/backend/src/services/secret-sync/secret-sync-fns.ts
+++ b/backend/src/services/secret-sync/secret-sync-fns.ts
@@ -288,7 +288,7 @@ export const SecretSyncFns = {
case SecretSync.Windmill:
return WindmillSyncFns.syncSecrets(secretSync, schemaSecretMap);
case SecretSync.HCVault:
- return HCVaultSyncFns.syncSecrets(secretSync, schemaSecretMap, gatewayService);
+ return HCVaultSyncFns.syncSecrets(secretSync, schemaSecretMap, gatewayService, gatewayV2Service);
case SecretSync.TeamCity:
return TeamCitySyncFns.syncSecrets(secretSync, schemaSecretMap);
case SecretSync.OCIVault:
@@ -337,7 +337,7 @@ export const SecretSyncFns = {
},
getSecrets: async (
secretSync: TSecretSyncWithCredentials,
- { kmsService, appConnectionDAL, gatewayService }: TSyncSecretDeps
+ { kmsService, appConnectionDAL, gatewayService, gatewayV2Service }: TSyncSecretDeps
): Promise<TSecretMap> => {
let secretMap: TSecretMap;
switch (secretSync.destination) {
@@ -398,7 +398,7 @@ export const SecretSyncFns = {
secretMap = await WindmillSyncFns.getSecrets(secretSync);
break;
case SecretSync.HCVault:
- secretMap = await HCVaultSyncFns.getSecrets(secretSync, gatewayService);
+ secretMap = await HCVaultSyncFns.getSecrets(secretSync, gatewayService, gatewayV2Service);
break;
case SecretSync.TeamCity:
secretMap = await TeamCitySyncFns.getSecrets(secretSync);
@@ -523,7 +523,7 @@ export const SecretSyncFns = {
case SecretSync.Windmill:
return WindmillSyncFns.removeSecrets(secretSync, schemaSecretMap);
case SecretSync.HCVault:
- return HCVaultSyncFns.removeSecrets(secretSync, schemaSecretMap, gatewayService);
+ return HCVaultSyncFns.removeSecrets(secretSync, schemaSecretMap, gatewayService, gatewayV2Service);
case SecretSync.TeamCity:
return TeamCitySyncFns.removeSecrets(secretSync, schemaSecretMap);
case SecretSync.OCIVault: