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
apply review recommendations
adilsonce10b494a22c
diff --git a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-fns.ts b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-fns.tsindex 1e797c4967..c5950d9b29 100644--- a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-fns.ts+++ b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-fns.ts@@ -273,7 +273,7 @@ export const parseRotationErrorMessage = (err: unknown): string => {};export const getWebhookSanitizedErrorMessage = (err: unknown): string => {- let errorCategory = "an unknown error";+ let errorCategory = null;if (err instanceof AxiosError) {const status = err?.response?.status;@@ -299,7 +299,9 @@ export const getWebhookSanitizedErrorMessage = (err: unknown): string => {}}- return `Credential rotation failed due to ${errorCategory}. Check the rotation status in the dashboard for details.`;+ return errorCategory+ ? `Credential rotation failed due to ${errorCategory}. Check the rotation status in the dashboard for more details.`+ : `Credential rotation failed. Check the rotation status in the dashboard for more details.`;};function haveUnequalProperties<T>(obj1: T, obj2: T, properties: (keyof T)[]): boolean {@@ -400,8 +402,7 @@ export const rotateSecretsFns = async ({jobId: job.id,shouldSendNotification: true,isFinalAttempt: retryCount === retryLimit,- isManualRotation,- retryCount+ isManualRotation});logger.info(`secretRotationV2Queue: Secrets Rotated ${logDetails}`);diff --git a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.ts b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.tsindex 1db3255ad1..62fe98b8f8 100644--- a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.ts+++ b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.ts@@ -926,6 +926,44 @@ export const secretRotationV2ServiceFactory = ({return expandSecretRotation(secretRotation, kmsService);};+ const triggerFailedWebhook = async (+ projectId: string,+ environment: { slug: string; name: string; id: string },+ error: unknown,+ folder: { id: string; path: string },+ secretRotation: TSecretRotationV2Raw,+ isManualRotation: boolean+ ) => {+ const webhookErrorMessage = getWebhookSanitizedErrorMessage(error);++ await queueService.queue(+ QueueName.SecretWebhook,+ QueueJobs.SecWebhook,+ {+ type: WebhookEvents.SecretRotationFailed,+ payload: {+ projectId,+ environment: environment.slug,+ secretPath: folder.path,+ rotationName: secretRotation.name,+ triggeredManually: isManualRotation,+ errorMessage: webhookErrorMessage+ }+ },+ {+ jobId: `secret-rotation-webhook-${secretRotation.id}-${Date.now()}`,+ removeOnFail: { count: 5 },+ removeOnComplete: true,+ delay: 1000,+ attempts: 5,+ backoff: {+ type: "exponential",+ delay: 3000+ }+ }+ );+ };+const rotateGeneratedCredentials = async (secretRotation: TSecretRotationV2Raw,{@@ -933,8 +971,7 @@ export const secretRotationV2ServiceFactory = ({jobId,shouldSendNotification,isFinalAttempt = true,- isManualRotation = false,- retryCount+ isManualRotation = false}: TSecretRotationRotateGeneratedCredentials = {}) => {const {@@ -1100,43 +1137,11 @@ export const secretRotationV2ServiceFactory = ({return updatedRotation;} catch (error) {const errorMessage = parseRotationErrorMessage(error);- const webhookErrorMessage = getWebhookSanitizedErrorMessage(error);- let nextRetryTime: string | undefined;- if (!isManualRotation) {- nextRetryTime = isFinalAttempt- ? "Maximum retry attempts reached"- : new Date(Date.now() + 1000 * 2 ** ((retryCount ?? 1) - 1)).toISOString();+ if (isManualRotation) {+ await triggerFailedWebhook(projectId, environment, error, folder, secretRotation, isManualRotation);}- await queueService.queue(- QueueName.SecretWebhook,- QueueJobs.SecWebhook,- {- type: WebhookEvents.SecretRotationFailed,- payload: {- projectId,- environment: environment.slug,- secretPath: folder.path,- rotationName: secretRotation.name,- triggeredManually: isManualRotation,- errorMessage: webhookErrorMessage,- nextRetryTime- }- },- {- jobId: `secret-rotation-webhook-${secretRotation.id}-${Date.now()}`,- removeOnFail: { count: 5 },- removeOnComplete: true,- delay: 1000,- attempts: 5,- backoff: {- type: "exponential",- delay: 3000- }- }- );-if (isFinalAttempt) {const { encryptor } = await kmsService.createCipherPairWithDataKey({type: KmsDataKey.SecretManager,@@ -1157,6 +1162,7 @@ export const secretRotationV2ServiceFactory = ({if (shouldSendNotification) {await $queueSendSecretRotationStatusNotification(updatedRotation);+ await triggerFailedWebhook(projectId, environment, error, folder, secretRotation, isManualRotation);}}diff --git a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-types.ts b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-types.tsindex 258c24776e..028aa39d76 100644--- a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-types.ts+++ b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-types.ts@@ -317,7 +317,6 @@ export type TSecretRotationRotateGeneratedCredentials = {shouldSendNotification?: boolean;isFinalAttempt?: boolean;isManualRotation?: boolean;- retryCount?: number;};export type TSecretRotationRotateSecretsJobPayload = { rotationId: string; queuedAt: Date; isManualRotation?: boolean };diff --git a/backend/src/services/webhook/webhook-fns.ts b/backend/src/services/webhook/webhook-fns.tsindex 79c68e4200..7cecad90dc 100644--- a/backend/src/services/webhook/webhook-fns.ts+++ b/backend/src/services/webhook/webhook-fns.ts@@ -106,17 +106,8 @@ export const getWebhookPayload = (event: TWebhookPayloads) => {}if (event.type === WebhookEvents.SecretRotationFailed) {- const {- projectName,- projectId,- environment,- secretPath,- type,- rotationName,- errorMessage,- nextRetryTime,- triggeredManually- } = event.payload;+ const { projectName, projectId, environment, secretPath, type, rotationName, errorMessage, triggeredManually } =+ event.payload;switch (type) {case WebhookType.SLACK:@@ -155,16 +146,7 @@ export const getWebhookPayload = (event: TWebhookPayloads) => {title: "Triggered Manually",value: triggeredManually ? "Yes" : "No",short: false- },- ...(nextRetryTime- ? [- {- title: "Next Retry",- value: nextRetryTime,- short: false- }- ]- : [])+ }]}]@@ -181,7 +163,6 @@ export const getWebhookPayload = (event: TWebhookPayloads) => {secretPath,rotationName,errorMessage,- nextRetryTime,triggeredManually}};diff --git a/backend/src/services/webhook/webhook-types.ts b/backend/src/services/webhook/webhook-types.tsindex 5f838b3d32..5c87635978 100644--- a/backend/src/services/webhook/webhook-types.ts+++ b/backend/src/services/webhook/webhook-types.ts@@ -72,7 +72,6 @@ type TWebhookSecretRotationFailedEventPayload = {projectId: string;environment: string;secretPath?: string;- nextRetryTime?: string;triggeredManually?: boolean;errorMessage?: string;type?: string | null;diff --git a/docs/documentation/platform/webhooks.mdx b/docs/documentation/platform/webhooks.mdxindex 835224b22b..ebc1150541 100644--- a/docs/documentation/platform/webhooks.mdx+++ b/docs/documentation/platform/webhooks.mdx@@ -27,45 +27,44 @@ If the signature in the header matches the signature that you generated, then yo```json{- "event": "secrets.modified",- "project": {- "workspaceId": "the workspace id",- "environment": "project environment",- "secretPath": "project folder path"- },- "timestamp": ""+ "event": "secrets.modified",+ "project": {+ "workspaceId": "the workspace id",+ "environment": "project environment",+ "secretPath": "project folder path"+ },+ "timestamp": ""}``````json{- "event": "secrets.reminder-expired",- "project": {- "workspaceId": "the workspace id",- "environment": "project environment",- "secretPath": "project folder path",- "secretName": "name of the secret",- "secretId": "id of the secret",- "reminderNote": "reminder note of the secret"- },- "timestamp": ""+ "event": "secrets.reminder-expired",+ "project": {+ "workspaceId": "the workspace id",+ "environment": "project environment",+ "secretPath": "project folder path",+ "secretName": "name of the secret",+ "secretId": "id of the secret",+ "reminderNote": "reminder note of the secret"+ },+ "timestamp": ""}``````json{- "event": "secrets.rotation-failed",- "project": {- "workspaceId": "the workspace id",- "projectId": "the project id",- "projectName": "the project name",- "environment": "project environment",- "secretPath": "project folder path",- "rotationName": "name of the failed rotation",- "errorMessage": "error details",- "nextRetryTime": "next retry timestamp (if applicable)",- "triggeredManually": false- },- "timestamp": ""+ "event": "secrets.rotation-failed",+ "project": {+ "workspaceId": "the workspace id",+ "projectId": "the project id",+ "projectName": "the project name",+ "environment": "project environment",+ "secretPath": "project folder path",+ "rotationName": "name of the failed rotation",+ "errorMessage": "error details",+ "triggeredManually": false+ },+ "timestamp": ""}```