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
Fix
Carlos Monastyrski7294c6360567
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.mdindex 58f07120f0..270d7e9e24 100644--- a/backend/CLAUDE.md+++ b/backend/CLAUDE.md@@ -978,9 +978,10 @@ pointing at something. Things that rely on that:- **Discovery matches deleted rows by fingerprint, and certificates issued before 2026-01-27 have none.** Thedelete computes and stores a missing fingerprint before it removes the body, so discovery can still find thedeleted row. If the body can't be read, the delete fails and nothing is removed.-- **A deleted certificate can keep `keySource = hsm` after its HSM connector is deleted.** The key source CHECK- allows a null `hsmConnectorId` on deleted rows, so deleting a connector only detaches them and the record- still says the key lived in an HSM.+- **A deleted certificate keeps its HSM key reference** (`keySource`, connector, key label and id), so the+ record stays true for audits. Deleting the connector detaches deleted rows (`hsmConnectorId` set to null),+ which is why the key source CHECK requires only a key label for `hsm`, not a connector. The rollback leaves+ that CHECK in place.- **Serial numbers stay globally unique, deleted rows included** (`certificates_serialnumber_unique`), so adeleted certificate still holds its serial: re-importing it restores the row, and a re-import that cannot berestored (another Application, profile or CA) is refused with a message naming where to import it instead.diff --git a/backend/src/db/migrations/20261020143827_add-soft-delete-to-certificates.ts b/backend/src/db/migrations/20261020143827_add-soft-delete-to-certificates.tsindex abd2037f52..4d59f35d94 100644--- a/backend/src/db/migrations/20261020143827_add-soft-delete-to-certificates.ts+++ b/backend/src/db/migrations/20261020143827_add-soft-delete-to-certificates.ts@@ -6,8 +6,7 @@ const DELETED_INDEX_NAME = "certificates_projectid_deleted_index";const DELETION_AWARE_QUOTA_KEY_INDEX = "certificates_projectid_quotakey_deletion_index";const LEGACY_QUOTA_KEY_INDEX = "certificates_projectid_quotakey_index";const KEY_SOURCE_CHECK_NAME = "certificates_key_source_chk";-const LIVE_HSM_KEY_SOURCE_CHECK = `("keySource" = 'infisical') OR ("keySource" = 'hsm' AND "hsmConnectorId" IS NOT NULL AND "hsmKeyLabel" IS NOT NULL)`;-const SOFT_DELETE_HSM_KEY_SOURCE_CHECK = `("keySource" = 'infisical') OR ("keySource" = 'hsm' AND "hsmKeyLabel" IS NOT NULL AND ("hsmConnectorId" IS NOT NULL OR "deletedAt" IS NOT NULL))`;+const KEY_SOURCE_CHECK = `("keySource" = 'infisical') OR ("keySource" = 'hsm' AND "hsmKeyLabel" IS NOT NULL)`;const ALTER_LOCK_TIMEOUT = 10 * 1000;const MIGRATION_TIMEOUT = 60 * 60 * 1000;@@ -46,11 +45,11 @@ const createIndexConcurrently = async (raw: (sql: string) => Knex.Raw, name: strawait raw(`CREATE INDEX CONCURRENTLY IF NOT EXISTS "${name}" ${definition}`);};-const replaceKeySourceCheck = async (knex: Knex, checkExpression: string) => {+const replaceKeySourceCheck = async (knex: Knex) => {await knex.transaction(async (tx) => {await tx.raw(`SET LOCAL lock_timeout = ${ALTER_LOCK_TIMEOUT}`);await tx.raw(`ALTER TABLE ?? DROP CONSTRAINT IF EXISTS ??`, [TableName.Certificate, KEY_SOURCE_CHECK_NAME]);- await tx.raw(`ALTER TABLE ?? ADD CONSTRAINT ?? CHECK (${checkExpression}) NOT VALID`, [+ await tx.raw(`ALTER TABLE ?? ADD CONSTRAINT ?? CHECK (${KEY_SOURCE_CHECK}) NOT VALID`, [TableName.Certificate,KEY_SOURCE_CHECK_NAME]);@@ -74,7 +73,7 @@ export async function up(knex: Knex): Promise<void> {);});- await replaceKeySourceCheck(knex, SOFT_DELETE_HSM_KEY_SOURCE_CHECK);+ await replaceKeySourceCheck(knex);const hasQuotaKey = await knex.schema.hasColumn(TableName.Certificate, "quotaKey");await withMigrationConnection(knex, async (raw) => {@@ -111,11 +110,6 @@ export async function down(knex: Knex): Promise<void> {await raw(`DROP INDEX CONCURRENTLY IF EXISTS "${DELETED_INDEX_NAME}"`);});- if (await knex.schema.hasColumn(TableName.Certificate, "deletedAt")) {- await knex(TableName.Certificate).whereNotNull("deletedAt").delete();- await replaceKeySourceCheck(knex, LIVE_HSM_KEY_SOURCE_CHECK);- }-await knex.transaction(async (tx) => {await tx.raw(`SET LOCAL lock_timeout = ${ALTER_LOCK_TIMEOUT}`);await tx.raw(