diff --git a/backend/src/ee/services/dynamic-secret/providers/sql-database.ts b/backend/src/ee/services/dynamic-secret/providers/sql-database.ts index 7513109a8..32bac4e6a 100644 --- a/backend/src/ee/services/dynamic-secret/providers/sql-database.ts +++ b/backend/src/ee/services/dynamic-secret/providers/sql-database.ts @@ -69,13 +69,13 @@ export const SqlDatabaseProvider = ({ gatewayService }: TSqlDatabaseProviderDTO) const gatewayProxyWrapper = async ( providerInputs: z.infer, - gatewayCallback: (port: number) => Promise + gatewayCallback: (host: string, port: number) => Promise ) => { const relayDetails = await gatewayService.fnGetGatewayClientTls(providerInputs.projectGatewayId as string); const [relayHost, relayPort] = relayDetails.relayAddress.split(":"); await withGatewayProxy( async (port) => { - await gatewayCallback(port); + await gatewayCallback("localhost", port); }, { targetHost: providerInputs.host, @@ -96,8 +96,8 @@ export const SqlDatabaseProvider = ({ gatewayService }: TSqlDatabaseProviderDTO) const validateConnection = async (inputs: unknown) => { const providerInputs = await validateProviderInputs(inputs); let isConnected = false; - const gatewayCallback = async (port = providerInputs.port) => { - const db = await $getClient({ ...providerInputs, port }); + const gatewayCallback = async (host = providerInputs.host, port = providerInputs.port) => { + const db = await $getClient({ ...providerInputs, port, host }); // oracle needs from keyword const testStatement = providerInputs.client === SqlProviders.Oracle ? "SELECT 1 FROM DUAL" : "SELECT 1"; @@ -106,8 +106,10 @@ export const SqlDatabaseProvider = ({ gatewayService }: TSqlDatabaseProviderDTO) }; if (providerInputs.projectGatewayId) { + console.log(">>>>>> inside gateway"); await gatewayProxyWrapper(providerInputs, gatewayCallback); } else { + console.log(">>>>>> outside gateway"); await gatewayCallback(); } return isConnected; @@ -117,8 +119,8 @@ export const SqlDatabaseProvider = ({ gatewayService }: TSqlDatabaseProviderDTO) const providerInputs = await validateProviderInputs(inputs); const username = generateUsername(providerInputs.client); const password = generatePassword(providerInputs.client); - const gatewayCallback = async (port = providerInputs.port) => { - const db = await $getClient({ ...providerInputs, port }); + const gatewayCallback = async (host = providerInputs.host, port = providerInputs.port) => { + const db = await $getClient({ ...providerInputs, port, host }); const { database } = providerInputs; const expiration = new Date(expireAt).toISOString(); @@ -150,8 +152,8 @@ export const SqlDatabaseProvider = ({ gatewayService }: TSqlDatabaseProviderDTO) const providerInputs = await validateProviderInputs(inputs); const username = entityId; const { database } = providerInputs; - const gatewayCallback = async (port = providerInputs.port) => { - const db = await $getClient({ ...providerInputs, port }); + const gatewayCallback = async (host = providerInputs.host, port = providerInputs.port) => { + const db = await $getClient({ ...providerInputs, port, host }); const revokeStatement = handlebars.compile(providerInputs.revocationStatement)({ username, database }); const queries = revokeStatement.toString().split(";").filter(Boolean); await db.transaction(async (tx) => { @@ -175,8 +177,8 @@ export const SqlDatabaseProvider = ({ gatewayService }: TSqlDatabaseProviderDTO) const providerInputs = await validateProviderInputs(inputs); if (!providerInputs.renewStatement) return { entityId }; - const gatewayCallback = async (port = providerInputs.port) => { - const db = await $getClient({ ...providerInputs, port }); + const gatewayCallback = async (host = providerInputs.host, port = providerInputs.port) => { + const db = await $getClient({ ...providerInputs, port, host }); const expiration = new Date(expireAt).toISOString(); const { database } = providerInputs; diff --git a/backend/src/ee/services/gateway/gateway-service.ts b/backend/src/ee/services/gateway/gateway-service.ts index 7940f9235..10314335b 100644 --- a/backend/src/ee/services/gateway/gateway-service.ts +++ b/backend/src/ee/services/gateway/gateway-service.ts @@ -88,9 +88,14 @@ export const gatewayServiceFactory = ({ }; const getGatewayRelayDetails = async (actorId: string, actorOrgId: string, actorAuthMethod: ActorAuthMethod) => { - const TURN_CRED_EXPIRY = 5 * 60; + const TURN_CRED_EXPIRY = 10 * 60; // 10 minutes + const envCfg = getConfig(); await $validateOrgAccessToGateway(actorOrgId, actorId, actorAuthMethod); + const { encryptor, decryptor } = await kmsService.createCipherPairWithDataKey({ + type: KmsDataKey.Organization, + orgId: actorOrgId + }); if ( !envCfg.GATEWAY_RELAY_AUTH_SECRET || @@ -108,7 +113,9 @@ export const gatewayServiceFactory = ({ // keep it in redis for 5mins to avoid generating so many credentials const previousCredential = await keyStore.getItem(KeyStorePrefixes.GatewayIdentityCredential(actorId)); if (previousCredential) { - const el = await TURN_SERVER_CREDENTIALS_SCHEMA.parseAsync(JSON.parse(previousCredential)); + const el = await TURN_SERVER_CREDENTIALS_SCHEMA.parseAsync( + JSON.parse(decryptor({ cipherTextBlob: Buffer.from(previousCredential, "hex") }).toString()) + ); turnServerUsername = el.username; turnServerPassword = el.password; } else { @@ -116,7 +123,9 @@ export const gatewayServiceFactory = ({ await keyStore.setItemWithExpiry( KeyStorePrefixes.GatewayIdentityCredential(actorId), TURN_CRED_EXPIRY, - JSON.stringify({ username: el.username, password: el.password }) + encryptor({ + plainText: Buffer.from(JSON.stringify({ username: el.username, password: el.password })) + }).cipherTextBlob.toString("hex") ); turnServerUsername = el.username; turnServerPassword = el.password; diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/SqlDatabaseInputForm.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/SqlDatabaseInputForm.tsx index 4d832063e..a4962d10c 100644 --- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/SqlDatabaseInputForm.tsx +++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/SqlDatabaseInputForm.tsx @@ -35,7 +35,7 @@ const formSchema = z.object({ revocationStatement: z.string().min(1), renewStatement: z.string().optional(), ca: z.string().optional(), - gatewayId: z.string().optional() + projectGatewayId: z.string().optional() }), defaultTTL: z.string().superRefine((val, ctx) => { const valMs = ms(val); @@ -233,7 +233,7 @@ export const SqlDatabaseInputForm = ({
( {projectGateways?.map((el) => ( - + {el.name} ))}