Skip to content

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

feat: block creation of rotation of users that have a key that is not managed by infisical

adilson29790d167fbe
diff --git a/backend/src/ee/services/secret-rotation-v2/snowflake-user-key-pair/snowflake-user-key-pair-rotation-fns.ts b/backend/src/ee/services/secret-rotation-v2/snowflake-user-key-pair/snowflake-user-key-pair-rotation-fns.ts
index 120146fcb9..90f1af00f4 100644
--- a/backend/src/ee/services/secret-rotation-v2/snowflake-user-key-pair/snowflake-user-key-pair-rotation-fns.ts
+++ b/backend/src/ee/services/secret-rotation-v2/snowflake-user-key-pair/snowflake-user-key-pair-rotation-fns.ts
@@ -170,6 +170,21 @@ export const snowflakeUserKeyPairRotationFactory: TRotationFactory<
// On creation the first credential always occupies slot 0 (activeIndex defaults to 0).
const keyPair = await generateRsaKeyPair();
await ensureUserExists();
+
+ // Block creation if the RSA_PUBLIC_KEY slot already holds a key, so we never overwrite a
+ // pre-existing key that was set outside this rotation. We resolve the slot occupancy outside
+ // runSnowflake so the BadRequestError isn't re-wrapped by sanitizeSnowflakeError.
+ const fingerprints = await runSnowflake(async (client) => {
+ const resolvedUsername = (await resolveSnowflakeUsername(client)) ?? username;
+ return readFingerprints(client, resolvedUsername);
+ }, `Failed to read existing RSA public keys for Snowflake user "${username}"`);
+
+ if (fingerprints.RSA_PUBLIC_KEY) {
+ throw new BadRequestError({
+ message: `Snowflake user "${username}" already has a key set in the RSA_PUBLIC_KEY slot. Remove it before creating this rotation so an existing key is not overwritten.`
+ });
+ }
+
await setPublicKeyForSlot(slotForIndex(0), keyPair);
return callback(keyPair);
};
diff --git a/docs/documentation/platform/secret-rotation/snowflake-user-key-pair.mdx b/docs/documentation/platform/secret-rotation/snowflake-user-key-pair.mdx
index a3c5861c82..401f061652 100644
--- a/docs/documentation/platform/secret-rotation/snowflake-user-key-pair.mdx
+++ b/docs/documentation/platform/secret-rotation/snowflake-user-key-pair.mdx
@@ -43,6 +43,11 @@ Infisical's Snowflake User Key Pair rotation generates a **2048-bit RSA key pair
If the user is created by Infisical, in case the credentials are revoked the user continue to exists.
</Note>
+ <Warning>
+ If the target user already has a key set in the `RSA_PUBLIC_KEY` slot, creating the rotation is
+ blocked so an existing key is never overwritten. Remove that key (or choose a user without one)
+ before creating the rotation.
+ </Warning>
3. Ensure your network security policies allow incoming requests from Infisical to your Snowflake account, if network restrictions apply.