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
gateway failover
Andrey1710e2302fde
diff --git a/backend/src/services/app-connection/jira/jira-connection-fns.ts b/backend/src/services/app-connection/jira/jira-connection-fns.tsindex 9aff58421d..95f1d24371 100644--- a/backend/src/services/app-connection/jira/jira-connection-fns.ts+++ b/backend/src/services/app-connection/jira/jira-connection-fns.ts@@ -25,7 +25,7 @@ const JIRA_MAX_ERROR_DETAIL_LENGTH = 300;export type TJiraGatewayDeps = {gatewayV2Service?: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">;- gatewayPoolService?: Pick<TGatewayPoolServiceFactory, "resolveEffectiveGatewayId">;+ gatewayPoolService?: Pick<TGatewayPoolServiceFactory, "runWithPoolFailover">;};export type TJiraRequestConfig = DiscriminativePick<@@ -88,16 +88,6 @@ export const jiraRequest = async <T>(});}- const gatewayId =- gatewayPoolId && gatewayPoolService- ? await gatewayPoolService.resolveEffectiveGatewayId({ gatewayId: directGatewayId, gatewayPoolId })- : directGatewayId;-- // a pinned gateway must never fall through to the direct request below- if (gatewayId && !gatewayV2Service) {- throw new NotFoundError({ message: getMissingGatewayMessage(gatewayId) });- }-const url = new URL(`${removeTrailingSlash(config.credentials.instanceUrl)}${path}`);const headers = { Authorization: getJiraAuthorizationHeader(config), Accept: "application/json", ...extraHeaders };const { ca, rejectUnauthorized } = getJiraTlsOptions(config);@@ -109,62 +99,77 @@ export const jiraRequest = async <T>(maxContentLength: JIRA_MAX_RESPONSE_BYTES};- if (!gatewayId || !gatewayV2Service) {- const { data } = await safeRequest.request<T>({- ...baseRequestConfig,- url: url.toString(),- headers,- ca,- rejectUnauthorized+ const requestThroughGateway = async (gatewayId: string) => {+ // a pinned gateway must never fall through to the direct request below+ if (!gatewayV2Service) {+ throw new NotFoundError({ message: getMissingGatewayMessage(gatewayId) });+ }++ const [targetHost] = await verifyHostInputValidity({ host: url.hostname, isGateway: true, isDynamicSecret: false });+ const isHttps = url.protocol === "https:";+ const targetPort = url.port ? Number(url.port) : (isHttps && 443) || 80;++ const platformConnectionDetails = await gatewayV2Service.getPlatformConnectionDetailsByGatewayId({+ gatewayId,+ targetHost,+ targetPort});- return data;- }+ if (!platformConnectionDetails) {+ throw new NotFoundError({ message: getMissingGatewayMessage(gatewayId) });+ }- const [targetHost] = await verifyHostInputValidity({ host: url.hostname, isGateway: true, isDynamicSecret: false });- const isHttps = url.protocol === "https:";- const targetPort = url.port ? Number(url.port) : (isHttps && 443) || 80;+ const outcome = await withGatewayV2Proxy<{ data: T } | { error: AxiosError }>(+ async (proxyPort) => {+ const proxiedUrl = new URL(url.toString());+ proxiedUrl.host = `localhost:${proxyPort}`;++ try {+ const { data } = await request.request<T>({+ ...baseRequestConfig,+ url: proxiedUrl.toString(),+ headers: { ...headers, Host: url.host },+ maxRedirects: 0,+ ...(isHttps && {+ httpsAgent: getSharedHttpsAgent({ servername: targetHost, ca, rejectUnauthorized })+ })+ });+ return { data };+ } catch (error) {+ // The proxy reduces a thrown error to its message, so Jira's own responses are passed out whole+ if (isAxiosError(error) && error.response) return { error };+ throw error;+ }+ },+ {+ protocol: GatewayProxyProtocol.Tcp,+ ...platformConnectionDetails+ }+ );- const platformConnectionDetails = await gatewayV2Service.getPlatformConnectionDetailsByGatewayId({- gatewayId,- targetHost,- targetPort- });+ if ("error" in outcome) throw outcome.error;+ return outcome.data;+ };- if (!platformConnectionDetails) {- throw new NotFoundError({ message: getMissingGatewayMessage(gatewayId) });+ if (gatewayPoolId && gatewayPoolService) {+ const { result } = await gatewayPoolService.runWithPoolFailover(+ { poolId: gatewayPoolId, gatewayId: directGatewayId },+ requestThroughGateway+ );+ return result;}- const outcome = await withGatewayV2Proxy<{ data: T } | { error: AxiosError }>(- async (proxyPort) => {- const proxiedUrl = new URL(url.toString());- proxiedUrl.host = `localhost:${proxyPort}`;-- try {- const { data } = await request.request<T>({- ...baseRequestConfig,- url: proxiedUrl.toString(),- headers: { ...headers, Host: url.host },- maxRedirects: 0,- ...(isHttps && {- httpsAgent: getSharedHttpsAgent({ servername: targetHost, ca, rejectUnauthorized })- })- });- return { data };- } catch (error) {- // The proxy reduces a thrown error to its message, so Jira's own responses are passed out whole- if (isAxiosError(error) && error.response) return { error };- throw error;- }- },- {- protocol: GatewayProxyProtocol.Tcp,- ...platformConnectionDetails- }- );+ if (directGatewayId) return requestThroughGateway(directGatewayId);++ const { data } = await safeRequest.request<T>({+ ...baseRequestConfig,+ url: url.toString(),+ headers,+ ca,+ rejectUnauthorized+ });- if ("error" in outcome) throw outcome.error;- return outcome.data;+ return data;};export const isJiraNotFoundError = (error: unknown) => isAxiosError(error) && error.response?.status === 404;diff --git a/backend/src/services/approval-policy/auto-approval/auto-approval-service.ts b/backend/src/services/approval-policy/auto-approval/auto-approval-service.tsindex cdeed8eaa0..de7eebb4d6 100644--- a/backend/src/services/approval-policy/auto-approval/auto-approval-service.ts+++ b/backend/src/services/approval-policy/auto-approval/auto-approval-service.ts@@ -58,7 +58,7 @@ type TAutoApprovalServiceFactoryDep = {>;kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">;- gatewayPoolService: Pick<TGatewayPoolServiceFactory, "resolveEffectiveGatewayId">;+ gatewayPoolService: Pick<TGatewayPoolServiceFactory, "runWithPoolFailover">;};export type TAutoApprovalServiceFactory = ReturnType<typeof autoApprovalServiceFactory>;diff --git a/backend/src/services/approval-policy/auto-approval/auto-approval-types.ts b/backend/src/services/approval-policy/auto-approval/auto-approval-types.tsindex 071e9f361e..df8f742194 100644--- a/backend/src/services/approval-policy/auto-approval/auto-approval-types.ts+++ b/backend/src/services/approval-policy/auto-approval/auto-approval-types.ts@@ -15,7 +15,7 @@ export type TAutoApprovalOption = { value: string; label: string };export type TAutoApprovalProviderDeps = {gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">;- gatewayPoolService: Pick<TGatewayPoolServiceFactory, "resolveEffectiveGatewayId">;+ gatewayPoolService: Pick<TGatewayPoolServiceFactory, "runWithPoolFailover">;};// Infisical runs this check itself, against its own approved requests, on every record a requester links