Skip to content

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

fix(clickhouse): authorise both ports on the heartbeat check

bernie-g7c6785d7b115
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 33ccd35a31..e12bcadbbf 100644
--- a/backend/src/ee/services/gateway-v2/gateway-v2-fns.ts
+++ b/backend/src/ee/services/gateway-v2/gateway-v2-fns.ts
@@ -43,6 +43,26 @@ export const testConnectionWithGateway = async (
}
};
+// Takes the built test whole, so the ports its certificate must authorise travel with it. Passing them
+// separately meant a caller could omit them and have the gateway refuse a port it was meant to probe.
+export const testBuiltConnectionWithGateway = async (
+ test: { host: string; port: number; request: Record<string, unknown>; additionalPorts?: number[] },
+ gatewayId: string,
+ gatewayV2Service: TGatewayDep,
+ timeoutMs: number,
+ signal?: AbortSignal
+): Promise<TestConnectionResponse | null> =>
+ testConnectionWithGateway(
+ test.host,
+ test.port,
+ gatewayId,
+ gatewayV2Service,
+ test.request,
+ timeoutMs,
+ signal,
+ test.additionalPorts
+ );
+
export const rotateSqlCredentialWithGateway = async (
targetHost: string,
targetPort: number,
diff --git a/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-service.test.ts b/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-service.test.ts
index b518a39c2c..64ef29c32a 100644
--- a/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-service.test.ts
+++ b/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-service.test.ts
@@ -17,10 +17,20 @@ vi.mock("@app/lib/logger", () => ({
}));
const gatewayTestConnection = vi.fn<(...args: unknown[]) => Promise<unknown>>();
+const gatewayBuiltTestConnection = vi.fn<(...args: unknown[]) => Promise<unknown>>();
vi.mock("@app/ee/services/gateway-v2/gateway-v2-fns", () => ({
- testConnectionWithGateway: (...args: unknown[]) => gatewayTestConnection(...args)
+ testConnectionWithGateway: (...args: unknown[]) => gatewayTestConnection(...args),
+ testBuiltConnectionWithGateway: (...args: unknown[]) => gatewayBuiltTestConnection(...args)
}));
+// The heartbeat takes the built test whole; unwrap it so the existing per-argument expectations still apply.
+gatewayBuiltTestConnection.mockImplementation(
+ (built: unknown, gatewayId: unknown, service: unknown, timeoutMs: unknown, signal: unknown) => {
+ const t = built as { host: string; port: number; request: unknown; additionalPorts?: number[] };
+ return gatewayTestConnection(t.host, t.port, gatewayId, service, t.request, timeoutMs, signal, t.additionalPorts);
+ }
+);
+
const blobOf = (data: Record<string, unknown>) => Buffer.from(JSON.stringify(data));
const buildWindowsAccount = (overrides: Record<string, unknown> = {}) => ({
diff --git a/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-service.ts b/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-service.ts
index de6f4c1983..e36b8490d8 100644
--- a/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-service.ts
+++ b/backend/src/ee/services/pam-account-heartbeat/pam-account-heartbeat-service.ts
@@ -1,5 +1,5 @@
import { TGatewayPoolServiceFactory } from "@app/ee/services/gateway-pool/gateway-pool-service";
-import { testConnectionWithGateway } from "@app/ee/services/gateway-v2/gateway-v2-fns";
+import { testBuiltConnectionWithGateway } from "@app/ee/services/gateway-v2/gateway-v2-fns";
import { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ResourcePermissionPamResourceActions } from "@app/ee/services/permission/resource-permission";
@@ -247,14 +247,7 @@ export const pamAccountHeartbeatServiceFactory = ({
return { status: PamHeartbeatStatus.CannotCheck, message: "No gateway is attached to this account" };
}
- const result = await testConnectionWithGateway(
- test.host,
- test.port,
- gatewayId,
- gatewayV2Service,
- test.request,
- HEARTBEAT_TIMEOUT_MS
- );
+ const result = await testBuiltConnectionWithGateway(test, gatewayId, gatewayV2Service, HEARTBEAT_TIMEOUT_MS);
if (!result) {
return { status: PamHeartbeatStatus.CannotCheck, message: "The gateway could not be reached" };
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 80f7791fe4..2c01af08c9 100644
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@ -29,7 +29,7 @@ import { TMfaSessionServiceFactory } from "@app/services/mfa-session/mfa-session
import { TOrgDALFactory } from "@app/services/org/org-dal";
import { TUserDALFactory } from "@app/services/user/user-dal";
-import { testConnectionWithGateway } from "../gateway-v2/gateway-v2-fns";
+import { testBuiltConnectionWithGateway } from "../gateway-v2/gateway-v2-fns";
import {
accountTypeSupportsSessionLogMasking,
PamAccessStatus,
@@ -650,16 +650,7 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>
const test = await buildGatewayConnectionTest(accountType, connectionDetails, credentials, orgId);
if (!test) return false;
- const result = await testConnectionWithGateway(
- test.host,
- test.port,
- gatewayId,
- gatewayV2Service,
- test.request,
- CONNECTION_TEST_TIMEOUT_MS,
- undefined,
- test.additionalPorts
- );
+ const result = await testBuiltConnectionWithGateway(test, gatewayId, gatewayV2Service, CONNECTION_TEST_TIMEOUT_MS);
// a null result means the gateway couldn't be reached (offline / pre-protocol) — skip rather than block
if (result && !result.ok) {