Skip to content

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

add validation only for planetscale connections

adilson4ed1d9b7bfba
diff --git a/backend/src/ee/services/secret-rotation-v2/shared/sql-credentials/sql-credentials-rotation-fns.ts b/backend/src/ee/services/secret-rotation-v2/shared/sql-credentials/sql-credentials-rotation-fns.ts
index c367647243..bb029fce5e 100644
--- a/backend/src/ee/services/secret-rotation-v2/shared/sql-credentials/sql-credentials-rotation-fns.ts
+++ b/backend/src/ee/services/secret-rotation-v2/shared/sql-credentials/sql-credentials-rotation-fns.ts
@@ -13,6 +13,7 @@ import { BadRequestError } from "@app/lib/errors";
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
import {
executeWithPotentialGateway,
+ getRoleUsernameForHost,
SQL_CONNECTION_ALTER_LOGIN_STATEMENT
} from "@app/services/app-connection/shared/sql";
import { generatePasswordWithConstraints } from "@app/services/secret-validation-rule/secret-validation-rule-password-generator";
@@ -139,7 +140,7 @@ export const sqlCredentialsRotationFactory: TRotationFactory<
await tx.raw(query);
}
} else {
- const filteredUsername = username.substring(0, username.indexOf("."));
+ const filteredUsername = getRoleUsernameForHost(username, connection.credentials.host);
await tx.raw(...SQL_CONNECTION_ALTER_LOGIN_STATEMENT[connection.app]({ username: filteredUsername, password }));
}
};
diff --git a/backend/src/services/app-connection/shared/sql/sql-connection-fns.ts b/backend/src/services/app-connection/shared/sql/sql-connection-fns.ts
index 4697ec13c7..6dddec196c 100644
--- a/backend/src/services/app-connection/shared/sql/sql-connection-fns.ts
+++ b/backend/src/services/app-connection/shared/sql/sql-connection-fns.ts
@@ -260,6 +260,20 @@ export const validateSqlConnectionCredentials = async (
}
};
+// PlanetScale requires the connection username in `<user>.<branch>` form so its proxy can route to
+// the correct branch, but the underlying DB role is just `<user>`. Strip the branch suffix for
+// role-level statements (ALTER USER / ALTER LOGIN). Only applies to PlanetScale hosts so that
+// legitimate dotted usernames on other providers are left untouched.
+const PLANETSCALE_HOST_SUFFIX = "psdb.cloud";
+
+export const getRoleUsernameForHost = (username: string, host: string) => {
+ const isPlanetScaleHost = host.toLowerCase().includes(PLANETSCALE_HOST_SUFFIX);
+ if (isPlanetScaleHost && username.includes(".")) {
+ return username.slice(0, username.indexOf("."));
+ }
+ return username;
+};
+
export const SQL_CONNECTION_ALTER_LOGIN_STATEMENT: Record<
TSqlCredentialsRotationWithConnection["connection"]["app"],
(credentials: TSqlCredentialsRotationGeneratedCredentials[number]) => [string, Knex.RawBinding]
@@ -283,7 +297,7 @@ export const transferSqlConnectionCredentialsToPlatform = async (
try {
return await executeWithPotentialGateway(config, gatewayService, gatewayV2Service, (client) => {
return client.transaction(async (tx) => {
- const filteredUsername = credentials.username.substring(0, credentials.username.indexOf("."));
+ const filteredUsername = getRoleUsernameForHost(credentials.username, credentials.host);
await tx.raw(
...SQL_CONNECTION_ALTER_LOGIN_STATEMENT[app]({ username: filteredUsername, password: newPassword })