Skip to content

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

feat: improved gateway typings

Daniel Hougaard03954fd72c9d
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 168b6e173e..9ae9099a3a 100644
--- a/backend/src/ee/services/gateway-v2/gateway-v2-service.ts
+++ b/backend/src/ee/services/gateway-v2/gateway-v2-service.ts
@@ -34,6 +34,7 @@ import { TRelayDALFactory } from "../relay/relay-dal";
import { TRelayServiceFactory } from "../relay/relay-service";
import { GATEWAY_ACTOR_OID, GATEWAY_ROUTING_INFO_OID, PAM_INFO_OID } from "./gateway-v2-constants";
import { TGatewayV2DALFactory } from "./gateway-v2-dal";
+import { TGatewayV2ConnectionDetails } from "./gateway-v2-types";
import { TOrgGatewayConfigV2DALFactory } from "./org-gateway-config-v2-dal";
type TGatewayV2ServiceFactoryDep = {
@@ -276,7 +277,7 @@ export const gatewayV2ServiceFactory = ({
gatewayId: string;
targetHost: string;
targetPort: number;
- }) => {
+ }): Promise<TGatewayV2ConnectionDetails | undefined> => {
const gateway = await gatewayV2DAL.findById(gatewayId);
if (!gateway) {
return;
diff --git a/backend/src/ee/services/gateway-v2/gateway-v2-types.ts b/backend/src/ee/services/gateway-v2/gateway-v2-types.ts
new file mode 100644
index 0000000000..d004053831
--- /dev/null
+++ b/backend/src/ee/services/gateway-v2/gateway-v2-types.ts
@@ -0,0 +1,13 @@
+export type TGatewayV2ConnectionDetails = {
+ relayHost: string;
+ gateway: {
+ clientCertificate: string;
+ clientPrivateKey: string;
+ serverCertificateChain: string;
+ };
+ relay: {
+ clientCertificate: string;
+ clientPrivateKey: string;
+ serverCertificateChain: string;
+ };
+};
diff --git a/backend/src/ee/services/gateway/gateway-service.ts b/backend/src/ee/services/gateway/gateway-service.ts
index 261640cc92..54be2e7146 100644
--- a/backend/src/ee/services/gateway/gateway-service.ts
+++ b/backend/src/ee/services/gateway/gateway-service.ts
@@ -8,6 +8,7 @@ import { getConfig } from "@app/lib/config/env";
import { crypto } from "@app/lib/crypto/cryptography";
import { BadRequestError, NotFoundError } from "@app/lib/errors";
import { pingGatewayAndVerify } from "@app/lib/gateway";
+import { TGatewayV1RelayDetails } from "@app/lib/gateway/types";
import { alphaNumericNanoId } from "@app/lib/nanoid";
import { getTurnCredentials } from "@app/lib/turn/credentials";
import { ActorAuthMethod, ActorType } from "@app/services/auth/auth-type";
@@ -567,7 +568,7 @@ export const gatewayServiceFactory = ({
return gateway;
};
- const fnGetGatewayClientTlsByGatewayId = async (gatewayId: string) => {
+ const fnGetGatewayClientTlsByGatewayId = async (gatewayId: string): Promise<TGatewayV1RelayDetails> => {
const gateway = await gatewayDAL.findById(gatewayId);
if (!gateway) throw new NotFoundError({ message: `Gateway with ID ${gatewayId} not found.` });
@@ -607,11 +608,19 @@ export const gatewayServiceFactory = ({
type: "pkcs8"
});
+ const relayAddress = orgKmsDecryptor({ cipherTextBlob: gateway.relayAddress }).toString();
+
+ const [relayHost, relayPort] = relayAddress.split(":");
+
return {
- relayAddress: orgKmsDecryptor({ cipherTextBlob: gateway.relayAddress }).toString(),
- privateKey: clientSkObj.export({ type: "pkcs8", format: "pem" }),
- certificate: clientCert.toString("pem"),
- certChain: `${gatewayCaCert.toString("pem")}\n${rootCaCert.toString("pem")}`.trim(),
+ relayAddress,
+ relayHost,
+ relayPort: Number(relayPort),
+ tlsOptions: {
+ key: clientSkObj.export({ type: "pkcs8", format: "pem" }).toString(),
+ cert: clientCert.toString("pem"),
+ ca: `${gatewayCaCert.toString("pem")}\n${rootCaCert.toString("pem")}`.trim()
+ },
identityId: gateway.identityId,
orgId: orgGatewayConfig.orgId
};
diff --git a/backend/src/ee/services/gateway/gateway-types.ts b/backend/src/ee/services/gateway/gateway-types.ts
index 823028154f..d63c9cd6ff 100644
--- a/backend/src/ee/services/gateway/gateway-types.ts
+++ b/backend/src/ee/services/gateway/gateway-types.ts
@@ -36,3 +36,19 @@ export type TGetProjectGatewayByIdDTO = {
export type THeartBeatDTO = {
orgPermission: OrgServiceActor;
};
+
+export type TGatewayV1ConnectionDetails = {
+ targetHost?: string;
+ targetPort?: number;
+ relayHost: string;
+ relayPort: string | number;
+ identityId: string;
+ orgId: string;
+ identityId: relayDetails.identityId,
+ orgId: relayDetails.orgId,
+ tlsOptions: {
+ ca: relayDetails.certChain,
+ cert: relayDetails.certificate,
+ key: relayDetails.privateKey.toString()
+ }
+}
\ No newline at end of file
diff --git a/backend/src/lib/gateway-v2/gateway-v2.ts b/backend/src/lib/gateway-v2/gateway-v2.ts
index e99c24a478..8aeed6c1ed 100644
--- a/backend/src/lib/gateway-v2/gateway-v2.ts
+++ b/backend/src/lib/gateway-v2/gateway-v2.ts
@@ -5,6 +5,7 @@ import axios from "axios";
import https from "https";
import { verifyHostInputValidity } from "@app/ee/services/dynamic-secret/dynamic-secret-fns";
+import { TGatewayV2ConnectionDetails } from "@app/ee/services/gateway-v2/gateway-v2-types";
import { splitPemChain } from "@app/services/certificate/certificate-fns";
import { getConfig } from "../config/env";
@@ -263,11 +264,8 @@ export const withGatewayV2Proxy = async <T>(
callback: (port: number) => Promise<T>,
options: {
protocol: GatewayProxyProtocol;
- relayHost: string;
- gateway: { clientCertificate: string; clientPrivateKey: string; serverCertificateChain: string };
- relay: { clientCertificate: string; clientPrivateKey: string; serverCertificateChain: string };
httpsAgent?: https.Agent;
- }
+ } & TGatewayV2ConnectionDetails
): Promise<T> => {
const { protocol, relayHost, gateway, relay, httpsAgent } = options;
diff --git a/backend/src/lib/gateway/gateway.ts b/backend/src/lib/gateway/gateway.ts
index 6bc6e204e5..9a4dd789b1 100644
--- a/backend/src/lib/gateway/gateway.ts
+++ b/backend/src/lib/gateway/gateway.ts
@@ -392,17 +392,17 @@ export const withGatewayProxy = async <T>(
callback: (port: number, httpsAgent?: https.Agent) => Promise<T>,
options: IGatewayProxyOptions
): Promise<T> => {
- const { relayHost, relayPort, targetHost, targetPort, tlsOptions, identityId, orgId, protocol, httpsAgent } = options;
+ const { targetHost, targetPort, relayDetails, protocol, httpsAgent } = options;
// Setup the proxy server
const { port, cleanup, getProxyError } = await setupProxyServer({
targetHost,
targetPort,
- relayPort,
- relayHost,
- tlsOptions,
- identityId,
- orgId,
+ relayPort: relayDetails.relayPort,
+ relayHost: relayDetails.relayHost,
+ tlsOptions: relayDetails.tlsOptions,
+ identityId: relayDetails.identityId,
+ orgId: relayDetails.orgId,
protocol,
httpsAgent
});
diff --git a/backend/src/lib/gateway/types.ts b/backend/src/lib/gateway/types.ts
index aafdd28f02..4b821db872 100644
--- a/backend/src/lib/gateway/types.ts
+++ b/backend/src/lib/gateway/types.ts
@@ -20,13 +20,9 @@ export enum GatewayHttpProxyActions {
export interface IGatewayProxyOptions {
targetHost?: string;
targetPort?: number;
- relayHost: string;
- relayPort: number;
- tlsOptions: TGatewayTlsOptions;
- identityId: string;
- orgId: string;
protocol: GatewayProxyProtocol;
httpsAgent?: https.Agent;
+ relayDetails: TGatewayV1RelayDetails;
}
export type TPingGatewayAndVerifyDTO = {
@@ -44,3 +40,17 @@ export interface IGatewayProxyServer {
cleanup: () => Promise<void>;
getProxyError: () => string;
}
+
+export type TGatewayV1RelayDetails = {
+ relayAddress: string;
+ tlsOptions: TGatewayTlsOptions;
+ identityId: string;
+ orgId: string;
+ relayHost: string;
+ relayPort: number;
+};
+
+export enum GatewayVersion {
+ V1 = "v1",
+ V2 = "v2"
+}
diff --git a/backend/src/services/app-connection/hc-vault/hc-vault-connection-types.ts b/backend/src/services/app-connection/hc-vault/hc-vault-connection-types.ts
index 21fd24653c..7ebc3774ff 100644
--- a/backend/src/services/app-connection/hc-vault/hc-vault-connection-types.ts
+++ b/backend/src/services/app-connection/hc-vault/hc-vault-connection-types.ts
@@ -1,5 +1,7 @@
import z from "zod";
+import { TGatewayV2ConnectionDetails } from "@app/ee/services/gateway-v2/gateway-v2-types";
+import { GatewayVersion, TGatewayV1RelayDetails } from "@app/lib/gateway/types";
import { DiscriminativePick } from "@app/lib/types";
import { AppConnection } from "../app-connection-enums";
@@ -158,3 +160,21 @@ export type THCVaultLdapRole = {
config: THCVaultLdapConfig;
mountPath: string;
};
+
+export type TGatewayDetails =
+ | {
+ gatewayVersion: GatewayVersion.V1;
+ details: TGatewayV1RelayDetails;
+ target: {
+ host: string;
+ port: number;
+ };
+ }
+ | {
+ gatewayVersion: GatewayVersion.V2;
+ details: TGatewayV2ConnectionDetails;
+ target: {
+ host: string;
+ port: number;
+ };
+ };