Skip to content

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

swap to dedicated connection test protocol

x817333010226
diff --git a/backend/src/ee/routes/v2/gateway-router.ts b/backend/src/ee/routes/v2/gateway-router.ts
index fe71339d2a..49f57f2ec8 100644
--- a/backend/src/ee/routes/v2/gateway-router.ts
+++ b/backend/src/ee/routes/v2/gateway-router.ts
@@ -73,8 +73,7 @@ export const registerGatewayV2Router = async (server: FastifyZodProvider) => {
.object({
capabilities: z
.object({
- pkcs11: z.boolean().optional(),
- connectionTest: z.boolean().optional()
+ pkcs11: z.boolean().optional()
})
.optional()
})
diff --git a/backend/src/ee/services/gateway-v2/gateway-v2-fns.ts b/backend/src/ee/services/gateway-v2/gateway-v2-fns.ts
index 5082ebee7f..f5a7eff493 100644
--- a/backend/src/ee/services/gateway-v2/gateway-v2-fns.ts
+++ b/backend/src/ee/services/gateway-v2/gateway-v2-fns.ts
@@ -1,7 +1,7 @@
import { BadRequestError } from "@app/lib/errors";
import { GatewayProxyProtocol } from "@app/lib/gateway";
import { withGatewayV2Proxy } from "@app/lib/gateway-v2/gateway-v2";
-import { callTestConnection } from "@app/lib/gateway-v2/test-connection-rpc";
+import { callTestConnection, TestConnectionResponse } from "@app/lib/gateway-v2/test-connection-rpc";
import { verifyHostInputValidity } from "../dynamic-secret/dynamic-secret-fns";
import { TGatewayV2ServiceFactory } from "./gateway-v2-service";
@@ -17,7 +17,7 @@ export const testConnectionWithGateway = async (
request: Record<string, unknown>,
timeoutMs: number,
signal?: AbortSignal
-): Promise<void> => {
+): Promise<TestConnectionResponse> => {
const [host] = await verifyHostInputValidity({ host: targetHost, isGateway: true, isDynamicSecret: false });
const platform = await gatewayV2Service.getPlatformConnectionDetailsByGatewayId({
gatewayId,
@@ -26,16 +26,10 @@ export const testConnectionWithGateway = async (
});
if (!platform) throw new BadRequestError({ message: "Unable to connect to gateway" });
- await withGatewayV2Proxy(
- async (proxyPort) => {
- const response = await callTestConnection({ port: proxyPort, body: request, timeoutMs, signal });
- if (!response.ok) throw new Error(response.errorMessage);
- },
- {
- protocol: GatewayProxyProtocol.Discovery,
- relayHost: platform.relayHost,
- gateway: platform.gateway,
- relay: platform.relay
- }
- );
+ return withGatewayV2Proxy((proxyPort) => callTestConnection({ port: proxyPort, body: request, timeoutMs, signal }), {
+ protocol: GatewayProxyProtocol.ConnectionTest,
+ relayHost: platform.relayHost,
+ gateway: platform.gateway,
+ relay: platform.relay
+ });
};
diff --git a/backend/src/ee/services/gateway-v2/gateway-v2-service.ts b/backend/src/ee/services/gateway-v2/gateway-v2-service.ts
index 9d59d520b9..b3229ca68d 100644
--- a/backend/src/ee/services/gateway-v2/gateway-v2-service.ts
+++ b/backend/src/ee/services/gateway-v2/gateway-v2-service.ts
@@ -963,7 +963,7 @@ export const gatewayV2ServiceFactory = ({
capabilities
}: {
orgPermission: OrgServiceActor;
- capabilities?: { pkcs11?: boolean; connectionTest?: boolean };
+ capabilities?: { pkcs11?: boolean };
}) => {
const nextCapabilities = capabilities ?? {};
diff --git a/backend/src/ee/services/pam-account/pam-account-service.ts b/backend/src/ee/services/pam-account/pam-account-service.ts
index 1447cb156f..90bba91423 100644
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@ -142,7 +142,6 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>
membershipRoleDAL,
permissionService,
kmsService,
- gatewayV2DAL,
gatewayV2Service,
gatewayPoolService,
licenseService
@@ -309,19 +308,15 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>
throw new BadRequestError({ message: "A gateway must be attached to this account." });
}
- // gateways that predate connection testing don't advertise the capability; skip the test
- const resolvedGateway = await gatewayV2DAL.findOne({ id: gatewayId });
- const capabilities = resolvedGateway?.capabilities as { connectionTest?: boolean } | null | undefined;
- if (!capabilities?.connectionTest) return;
-
const cd = connectionDetails as { host: string; port: number };
const request =
credentials === null || !isCredentialConfigured(accountType, credentials)
? { mode: TestConnectionMode.Tcp }
: buildRequest(connectionDetails, credentials);
+ let result;
try {
- await testConnectionWithGateway(
+ result = await testConnectionWithGateway(
cd.host,
cd.port,
gatewayId,
@@ -329,10 +324,13 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>
request,
CONNECTION_TEST_TIMEOUT_MS
);
- } catch (err) {
- throw new BadRequestError({
- message: `Connection test failed: ${(err as Error).message || "unable to connect to the target"}`
- });
+ } catch {
+ // gateway is unreachable or predates the connection-test protocol; don't block the write
+ return;
+ }
+
+ if (!result.ok) {
+ throw new BadRequestError({ message: `Connection test failed: ${result.errorMessage}` });
}
};
diff --git a/backend/src/lib/gateway-v2/gateway-v2.ts b/backend/src/lib/gateway-v2/gateway-v2.ts
index 597a900ae9..e98c6ff695 100644
--- a/backend/src/lib/gateway-v2/gateway-v2.ts
+++ b/backend/src/lib/gateway-v2/gateway-v2.ts
@@ -99,6 +99,7 @@ export const createGatewayConnection = async (
[GatewayProxyProtocol.Pkcs11]: ["infisical-pkcs11"],
[GatewayProxyProtocol.Adcs]: ["infisical-adcs"],
[GatewayProxyProtocol.Discovery]: ["infisical-discovery"],
+ [GatewayProxyProtocol.ConnectionTest]: ["infisical-connection-test"],
[GatewayProxyProtocol.WinRm]: ["infisical-winrm"]
};
diff --git a/backend/src/lib/gateway/types.ts b/backend/src/lib/gateway/types.ts
index 9b7e1f553e..45d12f2ea9 100644
--- a/backend/src/lib/gateway/types.ts
+++ b/backend/src/lib/gateway/types.ts
@@ -15,6 +15,7 @@ export enum GatewayProxyProtocol {
Pkcs11 = "pkcs11",
Adcs = "adcs",
Discovery = "discovery",
+ ConnectionTest = "connection-test",
WinRm = "winrm"
}