Skip to content

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

refactor to remove duplicates

Thiago Araujo da Silva2c38f0a136f2
diff --git a/backend/src/lib/slack/slack-webhook.ts b/backend/src/lib/slack/slack-webhook.ts
new file mode 100644
index 0000000000..acf78dbe75
--- /dev/null
+++ b/backend/src/lib/slack/slack-webhook.ts
@@ -0,0 +1,23 @@
+export const SLACK_WEBHOOK_TIMEOUT = 7 * 1000;
+
+export type TSlackBlock =
+ | { type: "header"; text: { type: "plain_text"; text: string; emoji?: boolean } }
+ | { type: "section"; text: { type: "mrkdwn"; text: string } }
+ | { type: "section"; fields: Array<{ type: "mrkdwn"; text: string }> }
+ | { type: "context"; elements: Array<{ type: "mrkdwn"; text: string }> }
+ | { type: "divider" }
+ | {
+ type: "actions";
+ elements: Array<{
+ type: "button";
+ text: { type: "plain_text"; text: string; emoji?: boolean };
+ url: string;
+ style?: "primary" | "danger";
+ }>;
+ };
+
+export type TSlackPayload = {
+ text: string;
+ blocks: TSlackBlock[];
+ attachments?: Array<{ color: string; blocks: TSlackBlock[] }>;
+};
diff --git a/backend/src/services/alarm/alarm-channel-dal.ts b/backend/src/services/alarm/alarm-channel-dal.ts
index 2b655c31f3..c281712223 100644
--- a/backend/src/services/alarm/alarm-channel-dal.ts
+++ b/backend/src/services/alarm/alarm-channel-dal.ts
@@ -1,7 +1,7 @@
import { Knex } from "knex";
import { TDbClient } from "@app/db";
-import { TableName, TAlarmChannels, TAlarmChannelsInsert } from "@app/db/schemas";
+import { TableName, TAlarmChannels } from "@app/db/schemas";
import { DatabaseError } from "@app/lib/errors";
import { ormify, selectAllTableCols } from "@app/lib/knex";
@@ -10,16 +10,6 @@ export type TAlarmChannelDALFactory = ReturnType<typeof alarmChannelDALFactory>;
export const alarmChannelDALFactory = (db: TDbClient) => {
const alarmChannelOrm = ormify(db, TableName.AlarmChannel);
- const insertMany = async (data: TAlarmChannelsInsert[], tx?: Knex): Promise<TAlarmChannels[]> => {
- try {
- if (!data.length) return [];
- const res = await (tx || db)(TableName.AlarmChannel).insert(data).returning("*");
- return res as TAlarmChannels[];
- } catch (error) {
- throw new DatabaseError({ error, name: "InsertMany" });
- }
- };
-
const findByAlarmId = async (alarmId: string, tx?: Knex): Promise<TAlarmChannels[]> => {
try {
const channels = await (tx || db.replicaNode())(TableName.AlarmChannel)
@@ -49,7 +39,6 @@ export const alarmChannelDALFactory = (db: TDbClient) => {
return {
...alarmChannelOrm,
- insertMany,
findByAlarmId,
findByAlarmIds
};
diff --git a/backend/src/services/alarm/alarm-engine.test.ts b/backend/src/services/alarm/alarm-engine.test.ts
index 312d5df4ae..e46e42ebec 100644
--- a/backend/src/services/alarm/alarm-engine.test.ts
+++ b/backend/src/services/alarm/alarm-engine.test.ts
@@ -47,13 +47,14 @@ const makeProvider = (targets: TTarget[]): IResourceAlarmProvider<TTarget> => ({
assertPermission: async () => undefined,
assertResourceInScope: async () => undefined,
targetId: (target) => target.id,
- buildPayload: (_alarm: TAlarmContext, matched: TTarget[]): TAlarmPayload => ({
+ buildViewUrl: async () => "https://app.infisical.com/x",
+ buildPayload: (_alarm: TAlarmContext, matched: TTarget[], viewUrl: string): TAlarmPayload => ({
alarm: {
id: "alarm-1",
name: "test-alarm",
orgId: "org-1",
resourceType: RESOURCE_TYPE,
- viewUrl: "https://app.infisical.com/x"
+ viewUrl
},
eventKey: "test.resource.expiration",
eventLabel: "Expiration",
diff --git a/backend/src/services/alarm/alarm-engine.ts b/backend/src/services/alarm/alarm-engine.ts
index 2afe128e3b..668d807614 100644
--- a/backend/src/services/alarm/alarm-engine.ts
+++ b/backend/src/services/alarm/alarm-engine.ts
@@ -122,9 +122,7 @@ export const alarmEngineFactory = ({
condition: alarm.condition,
filters: alarm.filters
};
- // viewUrl is target-independent; pass no targets so we don't build the full item list (which is
- // discarded here) just to read the link used in the failure notice.
- const { viewUrl } = provider.buildPayload(alarmContext, []).alarm;
+ const viewUrl = await provider.buildViewUrl(alarmContext);
const { decryptor } = await getAlarmChannelCipher(kmsService, {
orgId: alarm.orgId,
@@ -156,7 +154,7 @@ export const alarmEngineFactory = ({
return { ...base, success: false, error: "Failed to decrypt channel config" };
}
- const payload = provider.buildPayload(alarmContext, dueTargets);
+ const payload = provider.buildPayload(alarmContext, dueTargets, viewUrl);
try {
if (definition.directed) {
diff --git a/backend/src/services/alarm/alarm-recipient-dal.ts b/backend/src/services/alarm/alarm-recipient-dal.ts
index 3340fa759e..28d435c5fb 100644
--- a/backend/src/services/alarm/alarm-recipient-dal.ts
+++ b/backend/src/services/alarm/alarm-recipient-dal.ts
@@ -1,7 +1,7 @@
import { Knex } from "knex";
import { TDbClient } from "@app/db";
-import { TableName, TAlarmRecipients, TAlarmRecipientsInsert } from "@app/db/schemas";
+import { TableName, TAlarmRecipients } from "@app/db/schemas";
import { DatabaseError } from "@app/lib/errors";
import { ormify, selectAllTableCols } from "@app/lib/knex";
@@ -10,16 +10,6 @@ export type TAlarmRecipientDALFactory = ReturnType<typeof alarmRecipientDALFacto
export const alarmRecipientDALFactory = (db: TDbClient) => {
const alarmRecipientOrm = ormify(db, TableName.AlarmRecipient);
- const insertMany = async (data: TAlarmRecipientsInsert[], tx?: Knex): Promise<TAlarmRecipients[]> => {
- try {
- if (!data.length) return [];
- const res = await (tx || db)(TableName.AlarmRecipient).insert(data).returning("*");
- return res as TAlarmRecipients[];
- } catch (error) {
- throw new DatabaseError({ error, name: "InsertMany" });
- }
- };
-
const findByAlarmId = async (alarmId: string, tx?: Knex): Promise<TAlarmRecipients[]> => {
try {
const recipients = await (tx || db.replicaNode())(TableName.AlarmRecipient)
@@ -55,7 +45,6 @@ export const alarmRecipientDALFactory = (db: TDbClient) => {
return {
...alarmRecipientOrm,
- insertMany,
findByAlarmId,
findByAlarmIds,
deleteByAlarmId
diff --git a/backend/src/services/alarm/alarm-service.test.ts b/backend/src/services/alarm/alarm-service.test.ts
index 668030ee04..2c512beb49 100644
--- a/backend/src/services/alarm/alarm-service.test.ts
+++ b/backend/src/services/alarm/alarm-service.test.ts
@@ -27,6 +27,7 @@ const buildService = (opts?: {
eventTypes: ["test.resource.expiration"],
conditionSchema: z.object({ alertBefore: z.string() }),
findDueTargets: async () => [],
+ buildViewUrl: async () => "https://app.infisical.com/x",
buildPayload: () => ({}) as TAlarmPayload,
targetId: () => "t",
assertPermission: async (input) => {
diff --git a/backend/src/services/alarm/alarm-service.ts b/backend/src/services/alarm/alarm-service.ts
index c7c9f5da9d..70ad18775f 100644
--- a/backend/src/services/alarm/alarm-service.ts
+++ b/backend/src/services/alarm/alarm-service.ts
@@ -460,42 +460,33 @@ export const alarmServiceFactory = ({
projectId: alarm.projectId
});
- let resolvedChannels: TAlarmChannelInput[] | undefined;
- if (dto.channels) {
- const existingById = new Map(
- (await alarmChannelDAL.findByAlarmId(alarm.id)).map((channel) => [channel.id, channel])
- );
- resolvedChannels = dto.channels.map((channel) => {
- const existing = channel.id ? existingById.get(channel.id) : undefined;
- if (!existing || existing.channelType !== channel.channelType) return channel;
- const existingConfig = decryptChannelConfig<Record<string, unknown>>(existing.encryptedConfig, decryptor);
- return {
- ...channel,
- config: $preserveChannelSecrets(
- channel.channelType,
- channel.config as Record<string, unknown>,
- existingConfig
- )
- };
- });
- }
-
- // When channels are updated without recipients, the alarm keeps its existing recipients (the
- // transaction below only touches recipients when dto.recipients is provided). Validate the
- // directed-channel requirement against those existing recipients, not an empty list, so a
- // channel-only edit of an email alarm isn't wrongly rejected.
- const effectiveRecipients =
- dto.recipients ?? (resolvedChannels ? await alarmRecipientDAL.findByAlarmId(alarm.id) : undefined);
-
- $validate(provider, {
- condition: dto.condition,
- channels: resolvedChannels,
- recipients: effectiveRecipients
- });
-
+ $validate(provider, { condition: dto.condition, recipients: dto.recipients });
if (dto.recipients) await $validateRecipients(alarm.orgId, alarm.projectId, dto.recipients);
await alarmDAL.transaction(async (tx) => {
+ const existingChannels = dto.channels ? await alarmChannelDAL.findByAlarmId(alarm.id, tx) : [];
+ const existingChannelById = new Map(existingChannels.map((channel) => [channel.id, channel]));
+
+ let resolvedChannels: TAlarmChannelInput[] | undefined;
+ if (dto.channels) {
+ resolvedChannels = dto.channels.map((channel) => {
+ const existing = channel.id ? existingChannelById.get(channel.id) : undefined;
+ if (!existing || existing.channelType !== channel.channelType) return channel;
+ const existingConfig = decryptChannelConfig<Record<string, unknown>>(existing.encryptedConfig, decryptor);
+ return {
+ ...channel,
+ config: $preserveChannelSecrets(
+ channel.channelType,
+ channel.config as Record<string, unknown>,
+ existingConfig
+ )
+ };
+ });
+
+ const effectiveRecipients = dto.recipients ?? (await alarmRecipientDAL.findByAlarmId(alarm.id, tx));
+ $validate(provider, { channels: resolvedChannels, recipients: effectiveRecipients });
+ }
+
await alarmDAL.updateById(
alarm.id,
{
@@ -511,9 +502,6 @@ export const alarmServiceFactory = ({
);
if (resolvedChannels) {
- const existingChannels = await alarmChannelDAL.findByAlarmId(alarm.id, tx);
- const existingChannelById = new Map(existingChannels.map((channel) => [channel.id, channel]));
-
const keptIds = new Set<string>();
const toInsert: TAlarmChannelsInsert[] = [];
diff --git a/backend/src/services/alarm/alarm-types.ts b/backend/src/services/alarm/alarm-types.ts
index bbfff5d69c..c644df2b71 100644
--- a/backend/src/services/alarm/alarm-types.ts
+++ b/backend/src/services/alarm/alarm-types.ts
@@ -68,8 +68,13 @@ export interface IResourceAlarmProvider<TTarget = unknown> {
// afterwards, so this returns all current matches in the window (not minus already-alarmed).
findDueTargets(input: TFindDueTargetsInput): Promise<TTarget[]>;
+ // Deep link to the alarm's resource, honouring its scope (org- vs project-scoped). Resolved once
+ // per run by the engine and passed into buildPayload, so it may perform async lookups.
+ buildViewUrl(alarm: TAlarmContext): Promise<string>;
+
// One neutral payload describing all due targets for a firing (channels render it per medium).
- buildPayload(alarm: TAlarmContext, targets: TTarget[]): TAlarmPayload;
+ // Receives the pre-resolved viewUrl so it can stay synchronous.
+ buildPayload(alarm: TAlarmContext, targets: TTarget[], viewUrl: string): TAlarmPayload;
// Stable id per target, used for dedup and history. Must be stable across cron runs.
targetId(target: TTarget): string;
diff --git a/backend/src/services/alarm/channels/alarm-channel-slack-fns.ts b/backend/src/services/alarm/channels/alarm-channel-slack-fns.ts
index b6e1bac483..27fccca434 100644
--- a/backend/src/services/alarm/channels/alarm-channel-slack-fns.ts
+++ b/backend/src/services/alarm/channels/alarm-channel-slack-fns.ts
@@ -1,3 +1,4 @@
+import { SLACK_WEBHOOK_TIMEOUT, TSlackBlock, TSlackPayload } from "@app/lib/slack/slack-webhook";
import { safeRequest } from "@app/lib/validator";
import {
@@ -9,31 +10,8 @@ import {
} from "../alarm-channel-types";
import { isAxiosErrorRetryable, retryWithBackoff } from "./alarm-channel-retry-fns";
-const SLACK_WEBHOOK_TIMEOUT = 7 * 1000;
const MAX_ITEMS_DISPLAYED = 2;
-type TSlackBlock =
- | { type: "header"; text: { type: "plain_text"; text: string; emoji?: boolean } }
- | { type: "section"; text: { type: "mrkdwn"; text: string } }
- | { type: "section"; fields: Array<{ type: "mrkdwn"; text: string }> }
- | { type: "context"; elements: Array<{ type: "mrkdwn"; text: string }> }
- | { type: "divider" }
- | {
- type: "actions";
- elements: Array<{
- type: "button";
- text: { type: "plain_text"; text: string; emoji?: boolean };
- url: string;
- style?: "primary" | "danger";
- }>;
- };
-
-type TSlackPayload = {
- text: string;
- blocks: TSlackBlock[];
- attachments?: Array<{ color: string; blocks: TSlackBlock[] }>;
-};
-
const SEVERITY_COLOR: Record<TAlarmSeverity, string> = {
critical: "#da3633",
error: "#da3633",
diff --git a/backend/src/services/alarm/providers/identity-credential-alarm-dal.ts b/backend/src/services/alarm/providers/identity-credential-alarm-dal.ts
index 255cb20660..d211e0e901 100644
--- a/backend/src/services/alarm/providers/identity-credential-alarm-dal.ts
+++ b/backend/src/services/alarm/providers/identity-credential-alarm-dal.ts
@@ -97,5 +97,17 @@ export const identityCredentialAlarmDALFactory = (db: TDbClient) => {
}
};
- return { findExpiringUaClientSecrets, isIdentityInOrg, isIdentityInProject };
+ const getProjectType = async (projectId: string, tx?: Knex): Promise<string | null> => {
+ try {
+ const row = (await (tx || db.replicaNode())(TableName.Project)
+ .where({ id: projectId })
+ .select("type")
+ .first()) as { type: string } | undefined;
+ return row?.type ?? null;
+ } catch (error) {
+ throw new DatabaseError({ error, name: "GetProjectType" });
+ }
+ };
+
+ return { findExpiringUaClientSecrets, isIdentityInOrg, isIdentityInProject, getProjectType };
};
diff --git a/backend/src/services/alarm/providers/identity-credential-alarm-provider.test.ts b/backend/src/services/alarm/providers/identity-credential-alarm-provider.test.ts
index 90d77e3de0..c056aa2064 100644
--- a/backend/src/services/alarm/providers/identity-credential-alarm-provider.test.ts
+++ b/backend/src/services/alarm/providers/identity-credential-alarm-provider.test.ts
@@ -49,6 +49,7 @@ const buildProvider = (opts?: {
abilityRules?: { action: string; subject: string }[];
inOrg?: boolean;
inProject?: boolean;
+ projectType?: string | null;
}) => {
const dal = {
findExpiringUaClientSecrets: async (args: {
@@ -61,7 +62,8 @@ const buildProvider = (opts?: {
return opts?.secrets ?? [];
},
isIdentityInOrg: async () => opts?.inOrg ?? true,
- isIdentityInProject: async () => opts?.inProject ?? true
+ isIdentityInProject: async () => opts?.inProject ?? true,
+ getProjectType: async () => opts?.projectType ?? null
};
const ability = () => createMongoAbility(opts?.abilityRules ?? [{ action: "read", subject: "identity" }]);
const permissionService = {
@@ -128,22 +130,46 @@ describe("identity credential alarm provider", () => {
expect(seenArgs?.projectId).toBe("proj-1");
});
- test("buildPayload produces neutral items and severity", () => {
+ test("buildPayload produces neutral items and severity", async () => {
const provider = buildProvider();
const target = { credentialType: "ua-client-secret" as const, ...sampleSecret({ expiresAt: futureDate(3) }) };
- const payload = provider.buildPayload(alarmContext(), [target]);
+ const viewUrl = await provider.buildViewUrl(alarmContext());
+ const payload = provider.buildPayload(alarmContext(), [target], viewUrl);
expect(payload.eventKey).toBe(IDENTITY_CREDENTIAL_EXPIRY_EVENT);
expect(payload.severity).toBe("critical"); // 3 days out
expect(payload.items[0].fields?.some((f) => f.label === "Days Until Expiry")).toBe(true);
- expect(payload.alarm.viewUrl).toContain("/organizations/org-1/identities");
+ expect(payload.alarm.viewUrl).toBe(viewUrl);
});
- test("buildPayload deep-links to the bound identity when resourceId is set", () => {
+ test("buildViewUrl points to the org identities list for an org-scoped alarm", async () => {
const provider = buildProvider();
- const target = { credentialType: "ua-client-secret" as const, ...sampleSecret() };
- const payload = provider.buildPayload(alarmContext({ resourceId: "ident-1" }), [target]);
- expect(payload.alarm.viewUrl).toContain("/identities/ident-1");
+ expect(await provider.buildViewUrl(alarmContext())).toContain("/organizations/org-1/identities");
+ });
+
+ test("buildViewUrl deep-links to the bound identity when resourceId is set (org scope)", async () => {
+ const provider = buildProvider();
+ expect(await provider.buildViewUrl(alarmContext({ resourceId: "ident-1" }))).toContain("/identities/ident-1");
+ });
+
+ test("buildViewUrl deep-links into the project for a project-scoped alarm", async () => {
+ const provider = buildProvider({ projectType: "secret-manager" });
+ const url = await provider.buildViewUrl(alarmContext({ projectId: "proj-1", resourceId: "ident-1" }));
+ expect(url).toBe(
+ "https://app.infisical.com/organizations/org-1/projects/secret-management/proj-1/identities/ident-1"
+ );
+ });
+
+ test("buildViewUrl links to project access-management when no resource is bound", async () => {
+ const provider = buildProvider({ projectType: "kms" });
+ const url = await provider.buildViewUrl(alarmContext({ projectId: "proj-1" }));
+ expect(url).toBe("https://app.infisical.com/organizations/org-1/projects/kms/proj-1/access-management");
+ });
+
+ test("buildViewUrl falls back to the org view when the project can't be resolved", async () => {
+ const provider = buildProvider({ projectType: null });
+ const url = await provider.buildViewUrl(alarmContext({ projectId: "proj-gone", resourceId: "ident-1" }));
+ expect(url).toBe("https://app.infisical.com/organizations/org-1/identities/ident-1");
});
test("dedup window spans the lead time (30d -> 720h) with a 24h floor", () => {
diff --git a/backend/src/services/alarm/providers/identity-credential-alarm-provider.ts b/backend/src/services/alarm/providers/identity-credential-alarm-provider.ts
index 70c5903bbd..0f31e204f6 100644
--- a/backend/src/services/alarm/providers/identity-credential-alarm-provider.ts
+++ b/backend/src/services/alarm/providers/identity-credential-alarm-provider.ts
@@ -2,7 +2,7 @@ import { ForbiddenError } from "@casl/ability";
import RE2 from "re2";
import { z } from "zod";
-import { ActionProjectType, OrganizationActionScope } from "@app/db/schemas";
+import { ActionProjectType, OrganizationActionScope, ProjectType } from "@app/db/schemas";
import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ProjectPermissionIdentityActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
@@ -66,9 +66,31 @@ export const identityCredentialAlarmProviderFactory = ({
identityCredentialAlarmDAL,
permissionService
}: TIdentityCredentialAlarmProviderDep): IResourceAlarmProvider<TIdentityCredentialTarget> => {
- const buildViewUrl = (alarm: TAlarmContext): string => {
+ const projectBaseUrl = (siteUrl: string, orgId: string, projectType: string, projectId: string): string => {
+ switch (projectType) {
+ case ProjectType.SecretManager:
+ return `${siteUrl}/organizations/${orgId}/projects/secret-management/${projectId}`;
+ case ProjectType.PAM:
+ // PAM projects live at /organizations/$orgId/pam with no $projectId path segment.
+ return `${siteUrl}/organizations/${orgId}/pam`;
+ default:
+ return `${siteUrl}/organizations/${orgId}/projects/${projectType}/${projectId}`;
+ }
+ };
+
+ const buildViewUrl = async (alarm: TAlarmContext): Promise<string> => {
const appCfg = getConfig();
- const base = `${appCfg.SITE_URL ?? "https://app.infisical.com"}/organizations/${alarm.orgId}/identities`;
+ const siteUrl = appCfg.SITE_URL ?? "https://app.infisical.com";
+
+ if (alarm.projectId) {
+ const projectType = await identityCredentialAlarmDAL.getProjectType(alarm.projectId);
+ if (projectType) {
+ const base = projectBaseUrl(siteUrl, alarm.orgId, projectType, alarm.projectId);
+ return alarm.resourceId ? `${base}/identities/${alarm.resourceId}` : `${base}/access-management`;
+ }
+ }
+
+ const base = `${siteUrl}/organizations/${alarm.orgId}/identities`;
return alarm.resourceId ? `${base}/${alarm.resourceId}` : base;
};
@@ -86,9 +108,8 @@ export const identityCredentialAlarmProviderFactory = ({
return uaSecrets.map((secret) => ({ credentialType: "ua-client-secret" as const, ...secret }));
};
- const buildPayload = (alarm: TAlarmContext, targets: TIdentityCredentialTarget[]): TAlarmPayload => {
+ const buildPayload = (alarm: TAlarmContext, targets: TIdentityCredentialTarget[], viewUrl: string): TAlarmPayload => {
const alertBefore = (alarm.condition as { alertBefore?: string } | null)?.alertBefore;
- const viewUrl = buildViewUrl(alarm);
return {
alarm: {
@@ -181,6 +202,7 @@ export const identityCredentialAlarmProviderFactory = ({
eventTypes: [IDENTITY_CREDENTIAL_EXPIRY_EVENT],
conditionSchema: IdentityCredentialConditionSchema,
findDueTargets,
+ buildViewUrl,
buildPayload,
targetId,
dedupWindowHours: (condition) => {
diff --git a/backend/src/services/pki-alert-v2/pki-alert-v2-channel-slack-fns.ts b/backend/src/services/pki-alert-v2/pki-alert-v2-channel-slack-fns.ts
index 668a47c564..88f92bffe6 100644
--- a/backend/src/services/pki-alert-v2/pki-alert-v2-channel-slack-fns.ts
+++ b/backend/src/services/pki-alert-v2/pki-alert-v2-channel-slack-fns.ts
@@ -5,6 +5,7 @@ import { request } from "@app/lib/config/request";
import { delay } from "@app/lib/delay";
import { BadRequestError } from "@app/lib/errors";
import { logger } from "@app/lib/logger";
+import { SLACK_WEBHOOK_TIMEOUT, TSlackBlock, TSlackPayload } from "@app/lib/slack/slack-webhook";
import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator/validate-url";
import { PKI_ALERT_RETRY_CONFIG, RETRYABLE_NETWORK_ERRORS } from "./pki-alert-v2-constants";
@@ -15,14 +16,10 @@ import {
TBuildSlackPayloadParams,
TCertificatePreview,
TChannelResult,
- TSlackBlock,
- TSlackChannelConfig,
- TSlackPayload
+ TSlackChannelConfig
} from "./pki-alert-v2-types";
import { buildAlertViewUrl } from "./pki-alert-v2-url-fns";
-const SLACK_WEBHOOK_TIMEOUT = 7 * 1000;
-
/**
* Validates a Slack webhook URL for security.
*
diff --git a/backend/src/services/pki-alert-v2/pki-alert-v2-types.ts b/backend/src/services/pki-alert-v2/pki-alert-v2-types.ts
index 2978dd445f..6530cef619 100644
--- a/backend/src/services/pki-alert-v2/pki-alert-v2-types.ts
+++ b/backend/src/services/pki-alert-v2/pki-alert-v2-types.ts
@@ -391,32 +391,6 @@ export type TTestWebhookConfigDTO = TGenericPermission & {
export type TChannelResult = { success: boolean; error?: string };
-// Slack Block Kit types
-export type TSlackBlock =
- | { type: "header"; text: { type: "plain_text"; text: string; emoji?: boolean } }
- | { type: "section"; text: { type: "mrkdwn"; text: string } }
- | { type: "section"; fields: Array<{ type: "mrkdwn"; text: string }> }
- | { type: "context"; elements: Array<{ type: "mrkdwn"; text: string }> }
- | { type: "divider" }
- | {
- type: "actions";
- elements: Array<{
- type: "button";
- text: { type: "plain_text"; text: string; emoji?: boolean };
- url: string;
- style?: "primary" | "danger";
- }>;
- };
-
-export type TSlackPayload = {
- text: string;
- blocks: TSlackBlock[];
- attachments?: Array<{
- color: string;
- blocks: TSlackBlock[];
- }>;
-};
-
export type TBuildSlackPayloadParams = {
alert: TAlertInfo;
certificates: TCertificatePreview[];
diff --git a/frontend/src/hooks/api/alarms/types.ts b/frontend/src/hooks/api/alarms/types.ts
index 2c7a11fc0f..6d08e5f1ec 100644
--- a/frontend/src/hooks/api/alarms/types.ts
+++ b/frontend/src/hooks/api/alarms/types.ts
@@ -235,8 +235,6 @@ export const alarmFormSchema = z
.object({
name: z.string().min(1, "Name is required").max(255),
description: z.string().max(1000).optional(),
- resourceType: z.nativeEnum(AlarmResourceType),
- eventType: z.nativeEnum(AlarmEventType),
alertBeforeValue: z
.number({ invalid_type_error: "Enter a number" })
.int("Must be a whole number")
diff --git a/frontend/src/views/AlarmsPage/components/AlarmForm.tsx b/frontend/src/views/AlarmsPage/components/AlarmForm.tsx
index 26a7b0b59e..6e6989f815 100644
--- a/frontend/src/views/AlarmsPage/components/AlarmForm.tsx
+++ b/frontend/src/views/AlarmsPage/components/AlarmForm.tsx
@@ -1,3 +1,4 @@
+import { ReactNode } from "react";
import { Controller, FormProvider, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { KeyRoundIcon, LockIcon } from "lucide-react";
@@ -61,6 +62,21 @@ const SectionHeader = ({ step, title }: { step: number; title: string }) => (
</p>
);
+// Resource type, event, and scope are fixed for this alarm type, so they render as read-only cards
+// rather than single-option dropdowns.
+const FixedField = ({ label, children }: { label: string; children: ReactNode }) => (
+ <div className="flex flex-col gap-1.5">
+ <FieldLabel>{label}</FieldLabel>
+ <Card className="flex-row items-center justify-between p-4">
+ <div className="flex items-center gap-3">{children}</div>
+ <span className="flex items-center gap-1 text-xs text-muted">
+ <LockIcon className="size-3" />
+ Fixed
+ </span>
+ </Card>
+ </div>
+);
+
const parseAlertBefore = (alertBefore?: string): { value: number; unit: AlarmTimeUnit } => {
const match = alertBefore?.match(/^(\d+)([dwmy])$/);
if (match) return { value: parseInt(match[1], 10), unit: match[2] as AlarmTimeUnit };
@@ -120,8 +136,6 @@ const buildFormDefaults = (alarm?: TAlarm): TAlarmForm => {
return {
name: "",
description: "",
- resourceType: AlarmResourceType.IdentityCredential,
- eventType: AlarmEventType.IdentityCredentialExpiry,
alertBeforeValue: 7,
alertBeforeUnit: AlarmTimeUnit.Days,
enabled: true,
@@ -177,8 +191,6 @@ const buildFormDefaults = (alarm?: TAlarm): TAlarmForm => {
return {
name: alarm.name,
description: alarm.description ?? "",
- resourceType: AlarmResourceType.IdentityCredential,
- eventType: AlarmEventType.IdentityCredentialExpiry,
alertBeforeValue: value,
alertBeforeUnit: unit,
enabled: alarm.enabled,
@@ -310,83 +322,28 @@ export const AlarmForm = ({ projectId, scopeName, alarm, onComplete, onCancel }:
<section className="flex flex-col gap-4">
<SectionHeader step={2} title="Trigger" />
- <Controller
- control={control}
- name="resourceType"
- render={({ field: { value, onChange } }) => (
- <Field>
- <FieldLabel>Resource type</FieldLabel>
- <FieldContent>
- <Select value={value} onValueChange={onChange}>
- <SelectTrigger className="w-full">
- <SelectValue />
- </SelectTrigger>
- <SelectContent position="popper">
- {Object.values(AlarmResourceType).map((resourceType) => (
- <SelectItem key={resourceType} value={resourceType}>
- <span className="flex items-center gap-2">
- <KeyRoundIcon className="size-4 text-blue-400" />
- <span className="font-medium">
- {ALARM_RESOURCE_TYPE_LABELS[resourceType]}
- </span>
- <span className="font-mono text-xs text-mineshaft-400">
- {resourceType}
- </span>
- </span>
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- </FieldContent>
- </Field>
- )}
- />
-
- <div className="flex flex-col gap-1.5">
- <FieldLabel>Scope</FieldLabel>
- <Card className="flex-row items-center justify-between p-4">
- <div className="flex items-center gap-3">
- <ScopeIcon className={`size-5 ${scopeColor}`} />
- <div className="flex flex-col">
- <span className="text-sm text-foreground">{scopeTitle}</span>
- <span className="text-xs text-muted">{scopeDescription}</span>
- </div>
- </div>
- <span className="flex items-center gap-1 text-xs text-muted">
- <LockIcon className="size-3" />
- Fixed
+ <FixedField label="Resource type">
+ <KeyRoundIcon className="size-5 text-blue-400" />
+ <div className="flex flex-col">
+ <span className="text-sm text-foreground">
+ {ALARM_RESOURCE_TYPE_LABELS[RESOURCE_TYPE_VALUE]}
</span>
- </Card>
- </div>
+ <span className="font-mono text-xs text-muted">{RESOURCE_TYPE_VALUE}</span>
+ </div>
+ </FixedField>
- <Controller
- control={control}
- name="eventType"
- render={({ field: { value, onChange } }) => (
- <Field>
- <FieldLabel>Event</FieldLabel>
- <FieldContent>
- <Select value={value} onValueChange={onChange}>
- <SelectTrigger className="w-full">
- <SelectValue />
- </SelectTrigger>
- <SelectContent position="popper">
- {Object.values(AlarmEventType).map((eventType) => (
- <SelectItem key={eventType} value={eventType}>
- <span className="flex items-center gap-2">
- <Badge variant="warning">{ALARM_EVENT_TYPE_LABELS[eventType]}</Badge>
- <span className="text-mineshaft-300">
- Fires as the credential nears expiration
- </span>
- </span>
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- </FieldContent>
- </Field>
- )}
- />
+ <FixedField label="Scope">
+ <ScopeIcon className={`size-5 ${scopeColor}`} />
+ <div className="flex flex-col">
+ <span className="text-sm text-foreground">{scopeTitle}</span>
+ <span className="text-xs text-muted">{scopeDescription}</span>
+ </div>
+ </FixedField>
+
+ <FixedField label="Event">
+ <Badge variant="warning">{ALARM_EVENT_TYPE_LABELS[EVENT_TYPE_VALUE]}</Badge>
+ <span className="text-xs text-muted">Fires as the credential nears expiration</span>
+ </FixedField>
<div className="flex flex-col gap-1.5">
<FieldLabel>Condition</FieldLabel>