Skip to content

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

remove duplicates

Thiago Araujo da Silvae3ead5b90dd9
diff --git a/backend/src/lib/retry/network-errors.ts b/backend/src/lib/retry/network-errors.ts
new file mode 100644
index 0000000000..813194c223
--- /dev/null
+++ b/backend/src/lib/retry/network-errors.ts
@@ -0,0 +1,10 @@
+// Node/OS-level socket error codes that indicate a transient network failure worth retrying.
+export const RETRYABLE_NETWORK_ERRORS = [
+ "ECONNREFUSED",
+ "ENOTFOUND",
+ "ETIMEDOUT",
+ "ECONNRESET",
+ "ECONNABORTED",
+ "ENETUNREACH",
+ "EHOSTUNREACH"
+];
diff --git a/backend/src/services/alert/alert-channel-constants.ts b/backend/src/services/alert/alert-channel-constants.ts
index 6a42e4b70a..01504c4a1e 100644
--- a/backend/src/services/alert/alert-channel-constants.ts
+++ b/backend/src/services/alert/alert-channel-constants.ts
@@ -1,11 +1,3 @@
-export const ALERT_CHANNEL_RETRY_CONFIG = { maxRetries: 3, delayMs: 3000 };
+export { RETRYABLE_NETWORK_ERRORS } from "@app/lib/retry/network-errors";
-export const RETRYABLE_NETWORK_ERRORS = [
- "ECONNREFUSED",
- "ENOTFOUND",
- "ETIMEDOUT",
- "ECONNRESET",
- "ECONNABORTED",
- "ENETUNREACH",
- "EHOSTUNREACH"
-];
+export const ALERT_CHANNEL_RETRY_CONFIG = { maxRetries: 3, delayMs: 3000 };
diff --git a/backend/src/services/alert/alert-channel-service.ts b/backend/src/services/alert/alert-channel-service.ts
index 5c3d830dc4..19a679bef7 100644
--- a/backend/src/services/alert/alert-channel-service.ts
+++ b/backend/src/services/alert/alert-channel-service.ts
@@ -1,5 +1,6 @@
import { ForbiddenError } from "@casl/ability";
import { Knex } from "knex";
+import { z } from "zod";
import { ActionProjectType, OrganizationActionScope, TAlertChannels } from "@app/db/schemas";
import { TGroupDALFactory } from "@app/ee/services/group/group-dal";
@@ -72,6 +73,13 @@ export type TUpdateChannelInTxInput = {
const capitalize = (value: string): string => value.charAt(0).toUpperCase() + value.slice(1);
+const ORG_TO_PROJECT_ACTION: Record<OrgPermissionActions, ProjectPermissionActions> = {
+ [OrgPermissionActions.Read]: ProjectPermissionActions.Read,
+ [OrgPermissionActions.Create]: ProjectPermissionActions.Create,
+ [OrgPermissionActions.Edit]: ProjectPermissionActions.Edit,
+ [OrgPermissionActions.Delete]: ProjectPermissionActions.Delete
+};
+
export const alertChannelServiceFactory = ({
alertChannelDAL,
alertChannelRecipientDAL,
@@ -103,10 +111,7 @@ export const alertChannelServiceFactory = ({
actorOrgId: actor.actorOrgId,
actionProjectType: ActionProjectType.Any
});
- ForbiddenError.from(permission).throwUnlessCan(
- action as unknown as ProjectPermissionActions,
- ProjectPermissionSub.Settings
- );
+ ForbiddenError.from(permission).throwUnlessCan(ORG_TO_PROJECT_ACTION[action], ProjectPermissionSub.Settings);
return;
}
@@ -202,7 +207,10 @@ export const alertChannelServiceFactory = ({
try {
definition.configSchema.parse(config);
} catch (err) {
- throw new BadRequestError({ message: `Invalid ${channelType} channel config` });
+ const detail = err instanceof z.ZodError ? err.issues.map((i) => i.message).join(", ") : null;
+ throw new BadRequestError({
+ message: detail ? `Invalid ${channelType} channel config: ${detail}` : `Invalid ${channelType} channel config`
+ });
}
};
@@ -219,11 +227,6 @@ export const alertChannelServiceFactory = ({
return redacted;
};
- // Three-state merge of secret fields on update:
- // - field omitted -> keep the existing secret
- // - field empty / null -> clear it (valid only for optional secrets; the config schema rejects
- // clearing a required secret)
- // - field with a value -> set the new secret
const $mergeConfigForUpdate = (
channelType: string,
incomingConfig: Record<string, unknown>,
diff --git a/backend/src/services/alert/alert-queue.ts b/backend/src/services/alert/alert-queue.ts
index 74ba56953d..b7fe2a35e0 100644
--- a/backend/src/services/alert/alert-queue.ts
+++ b/backend/src/services/alert/alert-queue.ts
@@ -10,7 +10,7 @@ import { TAlertProviderRegistry } from "./alert-provider-registry";
type TAlertQueueServiceFactoryDep = {
cronJob: TCronJobFactory;
queueService: TQueueServiceFactory;
- alertDAL: Pick<TAlertDALFactory, "findEnabledByResourceType" | "findById">;
+ alertDAL: Pick<TAlertDALFactory, "findEnabledByResourceType" | "findActiveById">;
alertProviderRegistry: TAlertProviderRegistry;
alertEngine: Pick<TAlertEngine, "runAlert">;
};
@@ -56,7 +56,7 @@ export const alertQueueServiceFactory = ({
QueueName.AlertDispatch,
async (job) => {
const { alertId } = job.data;
- const alert = await alertDAL.findById(alertId);
+ const alert = await alertDAL.findActiveById(alertId);
if (!alert || !alert.enabled) return;
await alertEngine.runAlert(alert);
},
diff --git a/backend/src/services/alert/alert-service.ts b/backend/src/services/alert/alert-service.ts
index 9ab1a24bbc..4a72ff26d1 100644
--- a/backend/src/services/alert/alert-service.ts
+++ b/backend/src/services/alert/alert-service.ts
@@ -3,6 +3,7 @@ import { z } from "zod";
import { TAlertChannels, TAlerts } from "@app/db/schemas";
import { BadRequestError, NotFoundError } from "@app/lib/errors";
+import { TGenericPermission } from "@app/lib/types";
import { TKmsServiceFactory } from "@app/services/kms/kms-service";
import { getAlertChannelCipher } from "./alert-channel-crypto-fns";
@@ -52,6 +53,27 @@ export const alertServiceFactory = ({
return provider;
};
+ const $toActor = (dto: TGenericPermission): TGenericPermission => ({
+ actor: dto.actor,
+ actorId: dto.actorId,
+ actorAuthMethod: dto.actorAuthMethod,
+ actorOrgId: dto.actorOrgId
+ });
+
+ const $assertAlertPermission = (
+ provider: IResourceAlertProvider,
+ action: AlertPermissionAction,
+ scope: { orgId: string; projectId?: string | null; resourceId?: string | null },
+ dto: TGenericPermission
+ ) =>
+ provider.assertPermission({
+ action,
+ orgId: scope.orgId,
+ projectId: scope.projectId,
+ resourceId: scope.resourceId,
+ actor: $toActor(dto)
+ });
+
const $validate = (
provider: IResourceAlertProvider,
input: { eventType?: string; condition?: unknown },
@@ -94,18 +116,12 @@ export const alertServiceFactory = ({
const provider = $getProvider(dto.resourceType);
$validate(provider, dto, { alwaysValidateCondition: true });
- await provider.assertPermission({
- action: AlertPermissionAction.Create,
- orgId: dto.actorOrgId,
- projectId: dto.projectId,
- resourceId: dto.resourceId,
- actor: {
- actor: dto.actor,
- actorId: dto.actorId,
- actorAuthMethod: dto.actorAuthMethod,
- actorOrgId: dto.actorOrgId
- }
- });
+ await $assertAlertPermission(
+ provider,
+ AlertPermissionAction.Create,
+ { orgId: dto.actorOrgId, projectId: dto.projectId, resourceId: dto.resourceId },
+ dto
+ );
await provider.assertResourceInScope({
orgId: dto.actorOrgId,
@@ -187,18 +203,12 @@ export const alertServiceFactory = ({
if (!alert) throw new NotFoundError({ message: `Alert with ID '${dto.alertId}' not found` });
const provider = $getProvider(alert.resourceType);
- await provider.assertPermission({
- action: AlertPermissionAction.Read,
- orgId: alert.orgId,
- projectId: alert.projectId,
- resourceId: alert.resourceId,
- actor: {
- actor: dto.actor,
- actorId: dto.actorId,
- actorAuthMethod: dto.actorAuthMethod,
- actorOrgId: dto.actorOrgId
- }
- });
+ await $assertAlertPermission(
+ provider,
+ AlertPermissionAction.Read,
+ { orgId: alert.orgId, projectId: alert.projectId, resourceId: alert.resourceId },
+ dto
+ );
const channels = await alertChannelDAL.findByAlertId(alert.id);
const cipher = await getAlertChannelCipher(kmsService, { orgId: alert.orgId, projectId: alert.projectId });
@@ -208,18 +218,12 @@ export const alertServiceFactory = ({
const listAlerts = async (dto: TListAlertsDTO): Promise<TAlertResponse[]> => {
const provider = $getProvider(dto.resourceType);
- await provider.assertPermission({
- action: AlertPermissionAction.Read,
- orgId: dto.actorOrgId,
- projectId: dto.projectId,
- resourceId: dto.resourceId,
- actor: {
- actor: dto.actor,
- actorId: dto.actorId,
- actorAuthMethod: dto.actorAuthMethod,
- actorOrgId: dto.actorOrgId
- }
- });
+ await $assertAlertPermission(
+ provider,
+ AlertPermissionAction.Read,
+ { orgId: dto.actorOrgId, projectId: dto.projectId, resourceId: dto.resourceId },
+ dto
+ );
const alerts = await alertDAL.findActiveByScope({
orgId: dto.actorOrgId,
@@ -317,18 +321,12 @@ export const alertServiceFactory = ({
if (!alert) throw new NotFoundError({ message: `Alert with ID '${dto.alertId}' not found` });
const provider = $getProvider(alert.resourceType);
- await provider.assertPermission({
- action: AlertPermissionAction.Edit,
- orgId: alert.orgId,
- projectId: alert.projectId,
- resourceId: alert.resourceId,
- actor: {
- actor: dto.actor,
- actorId: dto.actorId,
- actorAuthMethod: dto.actorAuthMethod,
- actorOrgId: dto.actorOrgId
- }
- });
+ await $assertAlertPermission(
+ provider,
+ AlertPermissionAction.Edit,
+ { orgId: alert.orgId, projectId: alert.projectId, resourceId: alert.resourceId },
+ dto
+ );
if (dto.condition !== undefined) $validate(provider, { condition: dto.condition });
if (dto.channels !== undefined && dto.channels.length === 0) {
@@ -368,18 +366,12 @@ export const alertServiceFactory = ({
if (!alert) throw new NotFoundError({ message: `Alert with ID '${dto.alertId}' not found` });
const provider = $getProvider(alert.resourceType);
- await provider.assertPermission({
- action: AlertPermissionAction.Delete,
- orgId: alert.orgId,
- projectId: alert.projectId,
- resourceId: alert.resourceId,
- actor: {
- actor: dto.actor,
- actorId: dto.actorId,
- actorAuthMethod: dto.actorAuthMethod,
- actorOrgId: dto.actorOrgId
- }
- });
+ await $assertAlertPermission(
+ provider,
+ AlertPermissionAction.Delete,
+ { orgId: alert.orgId, projectId: alert.projectId, resourceId: alert.resourceId },
+ dto
+ );
await alertDAL.transaction(async (tx) => {
const channels = await alertChannelDAL.findByAlertId(alert.id, tx);
diff --git a/backend/src/services/alert/channels/alert-channel-email-fns.ts b/backend/src/services/alert/channels/alert-channel-email-fns.ts
index 5e5c39fab7..86a8b2b59f 100644
--- a/backend/src/services/alert/channels/alert-channel-email-fns.ts
+++ b/backend/src/services/alert/channels/alert-channel-email-fns.ts
@@ -7,7 +7,7 @@ import {
TAlertPayload,
TChannelResult
} from "../alert-channel-types";
-import { retryWithBackoff } from "./alert-channel-retry-fns";
+import { deliverWithRetry } from "./alert-channel-retry-fns";
const isEmailErrorRetryable = (err: unknown): boolean => {
const msg = (err instanceof Error ? err.message : String(err)).toLowerCase();
@@ -23,7 +23,6 @@ const buildSubstitutions = (payload: TAlertPayload) => ({
resourceKind: payload.resourceKind,
summary: payload.summary,
severity: payload.severity,
- condition: payload.alert.condition,
viewUrl: payload.alert.viewUrl,
items: payload.items.map((item) => ({
title: item.title,
@@ -53,7 +52,7 @@ export const sendEmailNotification = async (ctx: TAlertChannelSendContext): Prom
}
const recipients = [ctx.recipient.email];
- return retryWithBackoff(() => sendEmail(ctx.deps.smtpService, recipients, ctx.payload), isEmailErrorRetryable, {
+ return deliverWithRetry(() => sendEmail(ctx.deps.smtpService, recipients, ctx.payload), isEmailErrorRetryable, {
channelId: ctx.channelId,
channelLabel: "email"
});
diff --git a/backend/src/services/alert/channels/alert-channel-pagerduty-fns.ts b/backend/src/services/alert/channels/alert-channel-pagerduty-fns.ts
index 1be16fea0d..ee11a20d99 100644
--- a/backend/src/services/alert/channels/alert-channel-pagerduty-fns.ts
+++ b/backend/src/services/alert/channels/alert-channel-pagerduty-fns.ts
@@ -1,8 +1,5 @@
-import { AxiosError } from "axios";
-
import { safeRequest } from "@app/lib/validator";
-import { RETRYABLE_NETWORK_ERRORS } from "../alert-channel-constants";
import {
PagerDutyChannelConfigSchema,
pagerDutyIntegrationKeyRegex,
@@ -11,7 +8,7 @@ import {
TAlertPayload,
TChannelResult
} from "../alert-channel-types";
-import { retryWithBackoff } from "./alert-channel-retry-fns";
+import { deliverWithRetry, isAxiosErrorRetryable } from "./alert-channel-retry-fns";
const PAGERDUTY_EVENTS_URL = "https://events.pagerduty.com/v2/enqueue";
const PAGERDUTY_TIMEOUT = 7 * 1000;
@@ -70,17 +67,6 @@ export const buildPagerDutyEvent = (
links: [{ href: payload.alert.viewUrl, text: "View in Infisical" }]
});
-const isPagerDutyErrorRetryable = (err: unknown): boolean => {
- const axiosErr = err as AxiosError;
- const status = axiosErr.response?.status;
- if (status === 400) return false;
- if (status === 429) return true;
- if (status && status >= 500) return true;
- if (axiosErr.code && RETRYABLE_NETWORK_ERRORS.includes(axiosErr.code)) return true;
- if (axiosErr.message?.toLowerCase().includes("timeout")) return true;
- return false;
-};
-
const triggerPagerDutyEvent = async (payload: TPagerDutyPayload): Promise<void> => {
await safeRequest.post(PAGERDUTY_EVENTS_URL, payload, {
headers: { "Content-Type": "application/json" },
@@ -98,9 +84,9 @@ export const sendPagerDutyNotification = async (ctx: TAlertChannelSendContext):
const results = await Promise.all(
ctx.payload.items.map((item) =>
- retryWithBackoff(
+ deliverWithRetry(
() => triggerPagerDutyEvent(buildPagerDutyEvent(ctx.payload, item, config.integrationKey)),
- isPagerDutyErrorRetryable,
+ isAxiosErrorRetryable,
{ channelId: ctx.channelId, channelLabel: "PagerDuty" }
)
)
diff --git a/backend/src/services/alert/channels/alert-channel-retry-fns.ts b/backend/src/services/alert/channels/alert-channel-retry-fns.ts
index f242cbde24..eb31a25c51 100644
--- a/backend/src/services/alert/channels/alert-channel-retry-fns.ts
+++ b/backend/src/services/alert/channels/alert-channel-retry-fns.ts
@@ -6,7 +6,7 @@ import { logger } from "@app/lib/logger";
import { ALERT_CHANNEL_RETRY_CONFIG, RETRYABLE_NETWORK_ERRORS } from "../alert-channel-constants";
import { TChannelResult } from "../alert-channel-types";
-export const retryWithBackoff = async (
+export const deliverWithRetry = async (
fn: () => Promise<void>,
isRetryable: (err: unknown) => boolean,
ctx: { channelId: string; channelLabel: string }
diff --git a/backend/src/services/alert/channels/alert-channel-slack-fns.ts b/backend/src/services/alert/channels/alert-channel-slack-fns.ts
index 67933e09a8..fbc1db3819 100644
--- a/backend/src/services/alert/channels/alert-channel-slack-fns.ts
+++ b/backend/src/services/alert/channels/alert-channel-slack-fns.ts
@@ -8,7 +8,7 @@ import {
TAlertSeverity,
TChannelResult
} from "../alert-channel-types";
-import { isAxiosErrorRetryable, retryWithBackoff } from "./alert-channel-retry-fns";
+import { deliverWithRetry, isAxiosErrorRetryable } from "./alert-channel-retry-fns";
const MAX_ITEMS_DISPLAYED = 2;
@@ -93,7 +93,7 @@ export const sendSlackNotification = async (ctx: TAlertChannelSendContext): Prom
const config = SlackChannelConfigSchema.parse(ctx.config);
const payload = buildSlackPayload(ctx.payload);
- return retryWithBackoff(() => triggerSlackWebhook(config.webhookUrl, payload), isAxiosErrorRetryable, {
+ return deliverWithRetry(() => triggerSlackWebhook(config.webhookUrl, payload), isAxiosErrorRetryable, {
channelId: ctx.channelId,
channelLabel: "Slack"
});
diff --git a/backend/src/services/alert/channels/alert-channel-webhook-fns.ts b/backend/src/services/alert/channels/alert-channel-webhook-fns.ts
index 4effe5d6cb..7d5d12301f 100644
--- a/backend/src/services/alert/channels/alert-channel-webhook-fns.ts
+++ b/backend/src/services/alert/channels/alert-channel-webhook-fns.ts
@@ -8,7 +8,7 @@ import {
TChannelResult,
WebhookChannelConfigSchema
} from "../alert-channel-types";
-import { isAxiosErrorRetryable, retryWithBackoff } from "./alert-channel-retry-fns";
+import { deliverWithRetry, isAxiosErrorRetryable } from "./alert-channel-retry-fns";
const ALERT_WEBHOOK_TIMEOUT = 7 * 1000;
@@ -81,7 +81,7 @@ export const sendWebhookNotification = async (ctx: TAlertChannelSendContext): Pr
const config = WebhookChannelConfigSchema.parse(ctx.config);
const payload = buildWebhookPayload(ctx.payload);
- return retryWithBackoff(
+ return deliverWithRetry(
() => triggerWebhook({ url: config.url, payload, signingSecret: config.signingSecret }),
isAxiosErrorRetryable,
{ channelId: ctx.channelId, channelLabel: "webhook" }
diff --git a/backend/src/services/pki-alert-v2/pki-alert-v2-constants.ts b/backend/src/services/pki-alert-v2/pki-alert-v2-constants.ts
index c20f7bf29d..16c44fd3a5 100644
--- a/backend/src/services/pki-alert-v2/pki-alert-v2-constants.ts
+++ b/backend/src/services/pki-alert-v2/pki-alert-v2-constants.ts
@@ -1,11 +1,3 @@
-export const PKI_ALERT_RETRY_CONFIG = { maxRetries: 3, delayMs: 3000 };
+export { RETRYABLE_NETWORK_ERRORS } from "@app/lib/retry/network-errors";
-export const RETRYABLE_NETWORK_ERRORS = [
- "ECONNREFUSED",
- "ENOTFOUND",
- "ETIMEDOUT",
- "ECONNRESET",
- "ECONNABORTED",
- "ENETUNREACH",
- "EHOSTUNREACH"
-];
+export const PKI_ALERT_RETRY_CONFIG = { maxRetries: 3, delayMs: 3000 };
diff --git a/backend/src/services/smtp/emails/AlertNotificationTemplate.tsx b/backend/src/services/smtp/emails/AlertNotificationTemplate.tsx
index f472da1d9c..169e80af33 100644
--- a/backend/src/services/smtp/emails/AlertNotificationTemplate.tsx
+++ b/backend/src/services/smtp/emails/AlertNotificationTemplate.tsx
@@ -9,7 +9,6 @@ interface AlertNotificationTemplateProps extends Omit<BaseEmailWrapperProps, "ti
resourceKind: string;
summary: string;
severity?: string;
- condition?: string;
viewUrl: string;
items: { title: string; identifier?: string; fields?: { label: string; value: string }[] }[];
}
@@ -115,7 +114,6 @@ AlertNotificationTemplate.PreviewProps = {
resourceKind: "Identity Credential",
summary: "2 identity credential(s) expiring within 30d",
severity: "critical",
- condition: "30d",
viewUrl: "https://infisical.com/organizations/org-1/access-management?selectedTab=identities",
siteUrl: "https://infisical.com",
items: [