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
refactor(encryption): rename supersede to replacePending in key rotation logic
Victor Hugo dos Santos954b0eed7d5d
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.mdindex 61c5e3e01c..f24d34110d 100644--- a/backend/CLAUDE.md+++ b/backend/CLAUDE.md@@ -465,7 +465,7 @@ is why there is no `kekFingerprint` column. Fingerprints exist only as human lab*pending* row and does not touch the sentinel, so generating a key changes nothing and discarding it is a rowdelete. `$resolveRootKey` promotes it on the first boot that decrypts it: the sentinel takes the newciphertext, the old one moves to a retained copy, and **every** pending row is dropped (an abandoned pending-row is a live working key, so a superseded key left in someone's clipboard must not be able to promote+row is a live working key, so a replaced pending key left in someone's clipboard must not be able to promoteitself later). There is no rollback after promotion, only the retention window during which the old key stillboots.diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.tsindex 38483494d4..8d8949e092 100644--- a/backend/src/lib/api-docs/constants.ts+++ b/backend/src/lib/api-docs/constants.ts@@ -3967,12 +3967,12 @@ export const ENCRYPTION_KEY_ROTATION = {CREATE: {description:"Generate a new value for ENCRYPTION_KEY. The key is returned once and never stored, and nothing changes until an instance starts with it.",- supersede:+ replacePending:"Replace an already-generated key that has not been applied yet. The replaced key stops working immediately.",fingerprint:"A non-reversible label for the new key. Record it alongside the key so a backup can be matched to it later.",key: "The new value for ENCRYPTION_KEY. Shown only in this response and never recoverable. Store it before closing.",- supersedesRetainedKey:+ removesRetainedKey:"Present when the previous rotation's key has not been removed yet. Applying this key removes it immediately, so any instance still running it will fail to restart."},DISCARD: {diff --git a/backend/src/server/routes/v1/admin-router.ts b/backend/src/server/routes/v1/admin-router.tsindex 89274550be..9b4003d5b4 100644--- a/backend/src/server/routes/v1/admin-router.ts+++ b/backend/src/server/routes/v1/admin-router.ts@@ -705,7 +705,7 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => {operationId: "createAdminEncryptionKeyRotation",description: ENCRYPTION_KEY_ROTATION.CREATE.description,querystring: z.object({- supersede: booleanSchema.default(false).describe(ENCRYPTION_KEY_ROTATION.CREATE.supersede)+ replacePending: booleanSchema.default(false).describe(ENCRYPTION_KEY_ROTATION.CREATE.replacePending)}),response: {201: z.object({@@ -713,10 +713,10 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => {id: z.string().uuid(),fingerprint: z.string().describe(ENCRYPTION_KEY_ROTATION.CREATE.fingerprint),key: z.string().describe(ENCRYPTION_KEY_ROTATION.CREATE.key),- supersedesRetainedKey: z+ removesRetainedKey: z.object({ fingerprint: z.string().nullable(), lastResolvedAt: z.date().nullable() }).optional()- .describe(ENCRYPTION_KEY_ROTATION.CREATE.supersedesRetainedKey)+ .describe(ENCRYPTION_KEY_ROTATION.CREATE.removesRetainedKey)})})}@@ -728,7 +728,7 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => {},handler: async (req, res) => {const rotation = await server.services.encryptionKeyRotation.createRotation({- supersede: req.query.supersede+ replacePending: req.query.replacePending});// The key appears here and nowhere else, so it must not be cached along the way.diff --git a/backend/src/services/encryption-key-rotation/encryption-key-rotation-service.ts b/backend/src/services/encryption-key-rotation/encryption-key-rotation-service.tsindex 7f100b96ee..445d03da28 100644--- a/backend/src/services/encryption-key-rotation/encryption-key-rotation-service.ts+++ b/backend/src/services/encryption-key-rotation/encryption-key-rotation-service.ts@@ -102,7 +102,7 @@ export const encryptionKeyRotationServiceFactory = ({};/** Inert by design: the active key is untouched until a pod boots with the new value. */- const createRotation = async ({ supersede }: TCreateRotationDTO): Promise<TCreatedRotation> => {+ const createRotation = async ({ replacePending }: TCreateRotationDTO): Promise<TCreatedRotation> => {const sentinel = await kmsRootConfigDAL.findById(KMS_ROOT_CONFIG_UUID);if (!sentinel) throw new NotFoundError({ message: "KMS root config not found" });@@ -114,9 +114,10 @@ export const encryptionKeyRotationServiceFactory = ({}const existingPending = await kmsRootConfigDAL.findPending();- if (existingPending.length && !supersede) {+ if (existingPending.length && !replacePending) {throw new BadRequestError({- message: "A rotation is already pending. Deploy that key, discard it, or retry with supersede to replace it."+ message:+ "A rotation is already pending. Deploy that key, discard it, or retry with replacePending=true to replace it."});}@@ -128,10 +129,10 @@ export const encryptionKeyRotationServiceFactory = ({const stillPending = await kmsRootConfigDAL.findPending(tx);if (stillPending.length) {- if (!supersede) {+ if (!replacePending) {throw new BadRequestError({message:- "A rotation is already pending. Deploy that key, discard it, or retry with supersede to replace it."+ "A rotation is already pending. Deploy that key, discard it, or retry with replacePending=true to replace it."});}await kmsRootConfigDAL.deleteAllPending(tx);@@ -171,7 +172,7 @@ export const encryptionKeyRotationServiceFactory = ({key: staged.key,...(staged.retained? {- supersedesRetainedKey: {+ removesRetainedKey: {fingerprint: staged.retained.kekFingerprint ?? null,lastResolvedAt: staged.retained.lastResolvedAt ?? null}@@ -271,7 +272,7 @@ export const encryptionKeyRotationServiceFactory = ({const runGarbageCollection = async () => {const [retained, pending] = await Promise.all([kmsRootConfigDAL.findRetained(), kmsRootConfigDAL.findPending()]);- // Supersede caps pending at one, so this is for the admin who generated a key and walked away.+ // replacePending caps pending at one, so this is for the admin who generated a key and walked away.const now = Date.now();const abandoned = pending.filter((row) => now - new Date(row.createdAt).getTime() >= ABANDONED_ROTATION_MAX_AGE_MS);for (const row of abandoned) {diff --git a/backend/src/services/encryption-key-rotation/encryption-key-rotation-types.ts b/backend/src/services/encryption-key-rotation/encryption-key-rotation-types.tsindex f44240dbc2..81395ac848 100644--- a/backend/src/services/encryption-key-rotation/encryption-key-rotation-types.ts+++ b/backend/src/services/encryption-key-rotation/encryption-key-rotation-types.ts@@ -23,7 +23,7 @@ export type TEncryptionStatus = {};export type TCreateRotationDTO = {- supersede?: boolean;+ replacePending?: boolean;};export type TCompleteRotationDTO = {@@ -40,5 +40,5 @@ export type TCreatedRotation = {* Set when the previous rotation's key has not been removed yet. Applying this key removes it* immediately, so an instance still running it will fail to restart.*/- supersedesRetainedKey?: { fingerprint: string | null; lastResolvedAt: Date | null };+ removesRetainedKey?: { fingerprint: string | null; lastResolvedAt: Date | null };};diff --git a/frontend/src/hooks/api/admin/mutation.ts b/frontend/src/hooks/api/admin/mutation.tsindex 364595209b..4632ca27ba 100644--- a/frontend/src/hooks/api/admin/mutation.ts+++ b/frontend/src/hooks/api/admin/mutation.ts@@ -196,9 +196,9 @@ export const useUpdateServerEncryptionStrategy = () => {export const useCreateEncryptionKeyRotation = () => {const queryClient = useQueryClient();return useMutation({- mutationFn: async ({ supersede }: { supersede?: boolean } = {}) => {+ mutationFn: async ({ replacePending }: { replacePending?: boolean } = {}) => {const { data } = await apiRequest.post<{ rotation: TCreatedEncryptionKeyRotation }>(- `/api/v1/admin/encryption/rotations${supersede ? "?supersede=true" : ""}`+ `/api/v1/admin/encryption/rotations${replacePending ? "?replacePending=true" : ""}`);return data.rotation;diff --git a/frontend/src/hooks/api/admin/types.ts b/frontend/src/hooks/api/admin/types.tsindex 1c56ce5174..8925fe04a2 100644--- a/frontend/src/hooks/api/admin/types.ts+++ b/frontend/src/hooks/api/admin/types.ts@@ -269,7 +269,7 @@ export type TCreatedEncryptionKeyRotation = {id: string;fingerprint: string;key: string;- supersedesRetainedKey?: { fingerprint: string | null; lastResolvedAt: string | null };+ removesRetainedKey?: { fingerprint: string | null; lastResolvedAt: string | null };};export type TCompleteEncryptionKeyRotationDTO = {diff --git a/frontend/src/pages/admin/EncryptionPage/components/EncryptionKeyRotationSection.tsx b/frontend/src/pages/admin/EncryptionPage/components/EncryptionKeyRotationSection.tsxindex 6d63a31b1c..408e772e09 100644--- a/frontend/src/pages/admin/EncryptionPage/components/EncryptionKeyRotationSection.tsx+++ b/frontend/src/pages/admin/EncryptionPage/components/EncryptionKeyRotationSection.tsx@@ -86,7 +86,7 @@ export const EncryptionKeyRotationSection = () => {const canRotate = rotateBlockers.length === 0;const handleGenerate = async () => {- const rotation = await createRotation({ supersede: Boolean(status.pendingRotation) });+ const rotation = await createRotation({ replacePending: Boolean(status.pendingRotation) });setGeneratedKey(rotation);};@@ -265,7 +265,7 @@ export const EncryptionKeyRotationSection = () => {</p></div>- {generatedKey?.supersedesRetainedKey && (+ {generatedKey?.removesRetainedKey && (<Alert variant="warning"><AlertTriangleIcon /><AlertTitle>This will remove your previous key</AlertTitle>@@ -274,11 +274,10 @@ export const EncryptionKeyRotationSection = () => {The key from your last rotation has not been removed yet. Applying this new keyremoves it immediately, and any instance still running it will fail to restart.</p>- {generatedKey.supersedesRetainedKey.lastResolvedAt && (+ {generatedKey.removesRetainedKey.lastResolvedAt && (<p className="mt-2">An instance started on it{" "}- {new Date(generatedKey.supersedesRetainedKey.lastResolvedAt).toLocaleString()}- .+ {new Date(generatedKey.removesRetainedKey.lastResolvedAt).toLocaleString()}.</p>)}</AlertDescription>