misc: allow connecting to dbs with ssl via proxy

This commit is contained in:
Sheen Capadngan
2025-10-04 22:36:16 +08:00
parent d0d623c4dc
commit db97223a40
@@ -1,4 +1,5 @@
import knex, { Knex } from "knex"; import knex, { Knex } from "knex";
import tls, { PeerCertificate } from "tls";
import { verifyHostInputValidity } from "@app/ee/services/dynamic-secret/dynamic-secret-fns"; import { verifyHostInputValidity } from "@app/ee/services/dynamic-secret/dynamic-secret-fns";
import { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service"; import { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service";
@@ -30,7 +31,12 @@ const getConnectionConfig = (
? { ? {
rejectUnauthorized: sslRejectUnauthorized, rejectUnauthorized: sslRejectUnauthorized,
ca: sslCertificate, ca: sslCertificate,
servername: host servername: host,
// When using proxy, we need to bypass hostname validation since we connect to localhost
// but validate the certificate against the actual hostname
checkServerIdentity: (hostname: string, cert: PeerCertificate) => {
return tls.checkServerIdentity(host, cert);
}
} }
: false : false
}; };
@@ -114,6 +120,10 @@ export const sqlResourceFactory: TPamResourceFactory<TSqlResourceConnectionDetai
return connectionDetails; return connectionDetails;
} }
if (error.message.includes("no pg_hba.conf entry for host")) {
return connectionDetails;
}
if (error.message === "Connection terminated unexpectedly") { if (error.message === "Connection terminated unexpectedly") {
throw new BadRequestError({ throw new BadRequestError({
message: "Connection terminated unexpectedly. Verify that host and port are correct" message: "Connection terminated unexpectedly. Verify that host and port are correct"