Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
Move pwd rotation stuff to the new sql conn obj
Fang-Pen Lin3e8b6bf3e776
diff --git a/backend/src/ee/services/pam-resource/shared/sql/sql-resource-factory.ts b/backend/src/ee/services/pam-resource/shared/sql/sql-resource-factory.tsindex 6cb65854ac..55a2c0fb03 100644--- a/backend/src/ee/services/pam-resource/shared/sql/sql-resource-factory.ts+++ b/backend/src/ee/services/pam-resource/shared/sql/sql-resource-factory.ts@@ -33,6 +33,15 @@ export interface SqlResourceConnection {*/validate: (connectOnly: boolean) => Promise<void>;+ /**+ * Rotate password and return the new credentials.+ *+ * @param currentCredentials the current credentials to rotate+ *+ * @returns Promise to be resolved with the new credentials+ */+ rotateCredentials: (currentCredentials: TSqlAccountCredentials) => Promise<TSqlAccountCredentials>;+/*** Close the connection.*@@ -103,6 +112,11 @@ const makeSqlConnection = (});}},+ rotateCredentials: async (currentCredentials) => {+ const newPassword = alphaNumericNanoId(32);+ await client.raw(`ALTER USER ?? WITH PASSWORD ?'`, [currentCredentials.username, newPassword]);+ return { username: currentCredentials.username, password: newPassword };+ },close: () => client.destroy()};}@@ -148,6 +162,12 @@ const makeSqlConnection = (await client?.end();}},+ rotateCredentials: async (currentCredentials) => {+ // TODO: the pwd rotation for MySQL is not supported yet+ throw new BadRequestError({+ message: "Unsupported operation"+ });+ },close: async () => {}};}@@ -269,9 +289,7 @@ export const sqlResourceFactory: TPamResourceFactory<TSqlResourceConnectionDetaicurrentCredentials) => {try {- const newPassword = alphaNumericNanoId(32);-- await executeWithGateway(+ return await executeWithGateway({connectionDetails,gatewayId,@@ -280,20 +298,8 @@ export const sqlResourceFactory: TPamResourceFactory<TSqlResourceConnectionDetaipassword: rotationAccountCredentials.password},gatewayV2Service,- async (client) => {- switch (resourceType) {- case PamResource.Postgres:- await client.raw(`ALTER USER ?? WITH PASSWORD '${newPassword}'`, [currentCredentials.username]);- break;- default:- throw new BadRequestError({- message: `Password rotation for ${resourceType as PamResource} is not supported.`- });- }- }+ (client) => client.rotateCredentials(currentCredentials));-- return { username: currentCredentials.username, password: newPassword };} catch (error) {if (error instanceof BadRequestError) {if (error.message === `password authentication failed for user "${rotationAccountCredentials.username}"`) {