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
feat(pki): add slack webhook to alerts (#5369)
Saif Ur Rahmane03a815d8400
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.tsnew file mode 100644index 0000000000..0247bc7536--- /dev/null+++ b/backend/src/services/pki-alert-v2/pki-alert-v2-channel-slack-fns.ts@@ -0,0 +1,272 @@+import { AxiosError } from "axios";++import { getConfig } from "@app/lib/config/env";+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 { blockLocalAndPrivateIpAddresses } from "@app/lib/validator/validate-url";++import { PKI_ALERT_RETRY_CONFIG, RETRYABLE_NETWORK_ERRORS } from "./pki-alert-v2-constants";+import {+ TAlertInfo,+ TBuildSlackPayloadParams,+ TCertificatePreview,+ TChannelResult,+ TSlackBlock,+ TSlackChannelConfig,+ TSlackPayload+} from "./pki-alert-v2-types";++const SLACK_WEBHOOK_TIMEOUT = 7 * 1000;++/**+ * Validates a Slack webhook URL for security.+ *+ * Requirements:+ * - Must be HTTPS+ * - Hostname must be exactly "hooks.slack.com" (prevents bypass via hooks.slack.com.evil.com)+ * - Must not resolve to private/local IP addresses (SSRF protection)+ */+export const validateSlackWebhookUrl = async (url: string): Promise<void> => {+ const parsedUrl = new URL(url);++ // Must be HTTPS+ if (parsedUrl.protocol !== "https:") {+ throw new BadRequestError({ message: "Slack webhook URL must use HTTPS" });+ }++ // Hostname must be exactly hooks.slack.com (not .includes())+ // This prevents: hooks.slack.com.evil.com, evil.hooks.slack.com, etc.+ if (parsedUrl.hostname !== "hooks.slack.com") {+ throw new BadRequestError({+ message: "Invalid Slack webhook URL. Must be from hooks.slack.com"+ });+ }++ // SSRF protection - resolve DNS and block private IPs+ await blockLocalAndPrivateIpAddresses(url);+};++/**+ * Masks the Slack webhook URL path to hide the token in logs.+ * The path contains the webhook token which should not be exposed.+ *+ * Example: https://hooks.slack.com/services/T00/B00/XXX -> https://hooks.slack.com/services/***+ */+export const maskSlackWebhookUrl = (url: string): string => {+ try {+ const parsed = new URL(url);+ return `${parsed.protocol}//${parsed.hostname}/services/***`;+ } catch {+ return "***";+ }+};++/**+ * Builds a Slack Block Kit payload for certificate expiration alerts.+ *+ * Structure:+ * - Header block with alert name+ * - Alert info section (name, alertBefore)+ * - Summary section (N certificates expiring within alertBefore period)+ * - Certificate list (2 most urgent, ordered by expiry)+ * - "+N more" context if there are additional certificates+ * - Action button linking to Infisical+ */+export const buildSlackPayload = ({+ alert,+ certificates,+ appUrl = "https://app.infisical.com"+}: TBuildSlackPayloadParams): TSlackPayload => {+ const totalCertificates = certificates.length;+ const now = new Date();++ // Sort certificates by urgency (days until expiry, ascending - most urgent first)+ const sortedCertificates = [...certificates].sort((a, b) => {+ const aExpiry = new Date(a.notAfter).getTime();+ const bExpiry = new Date(b.notAfter).getTime();+ return aExpiry - bExpiry;+ });++ // Display only the 2 most urgent certificates+ const displayCertificates = sortedCertificates.slice(0, 2);+ const remainingCount = totalCertificates - displayCertificates.length;++ const viewUrl = `${appUrl}/projects/cert-manager/${alert.projectId}/policies`;++ const headerText = `Certificate Expiration Alert: ${alert.name}`;++ // Fallback text for notifications+ const fallbackText = `${headerText} - ${totalCertificates} certificate(s) expiring`;++ // Build header block+ const headerBlock: TSlackBlock = {+ type: "header",+ text: { type: "plain_text", text: headerText, emoji: true }+ };++ // Build certificate blocks+ const certificateBlocks: TSlackBlock[] = [];++ for (const cert of displayCertificates) {+ const notAfter = new Date(cert.notAfter);+ const daysUntilExpiry = Math.ceil((notAfter.getTime() - now.getTime()) / (1000 * 60 * 60 * 24));++ certificateBlocks.push({+ type: "section",+ fields: [+ { type: "mrkdwn", text: `*Common Name:*\n${cert.commonName || "N/A"}` },+ { type: "mrkdwn", text: `*Serial:*\n\`${cert.serialNumber}\`` },+ {+ type: "mrkdwn",+ text: `*Expires:*\n${notAfter.toISOString().split("T")[0]}`+ },+ { type: "mrkdwn", text: `*Days Until Expiry:*\n${daysUntilExpiry}` }+ ]+ });++ // Add divider between certificates (but not after the last one)+ if (displayCertificates.indexOf(cert) < displayCertificates.length - 1) {+ certificateBlocks.push({ type: "divider" });+ }+ }++ // Build attachment blocks (colored sidebar)+ const attachmentBlocks: TSlackBlock[] = [+ // Alert info section+ {+ type: "section",+ fields: [+ { type: "mrkdwn", text: `*Alert Name:*\n${alert.name}` },+ { type: "mrkdwn", text: `*Alert Before:*\n${alert.alertBefore}` }+ ]+ },+ { type: "divider" },+ // Summary section+ {+ type: "section",+ text: {+ type: "mrkdwn",+ text: `*${totalCertificates}* certificate(s) expiring within *${alert.alertBefore}*`+ }+ },+ ...certificateBlocks+ ];++ // Add "more" indicator if there are additional certificates+ if (remainingCount > 0) {+ attachmentBlocks.push({+ type: "context",+ elements: [{ type: "mrkdwn", text: `_+${remainingCount} more certificates..._` }]+ });+ }++ // Add action button+ attachmentBlocks.push({+ type: "actions",+ elements: [+ {+ type: "button",+ text: { type: "plain_text", text: "View in Infisical", emoji: true },+ url: viewUrl,+ style: "primary"+ }+ ]+ });++ return {+ text: fallbackText,+ blocks: [headerBlock],+ attachments: [+ {+ color: "#f0b429", // Warning yellow+ blocks: attachmentBlocks+ }+ ]+ };+};++const isSlackErrorRetryable = (err: AxiosError): boolean => {+ const status = err.response?.status;+ if (status && status >= 500) return true;+ if (err.code && RETRYABLE_NETWORK_ERRORS.includes(err.code)) return true;+ if (err.message?.toLowerCase().includes("timeout")) return true;+ return false;+};++const triggerSlackWebhook = async (url: string, payload: TSlackPayload): Promise<void> => {+ await request.post(url, payload, {+ headers: {+ "Content-Type": "application/json"+ },+ timeout: SLACK_WEBHOOK_TIMEOUT,+ signal: AbortSignal.timeout(SLACK_WEBHOOK_TIMEOUT)+ });+};++const triggerSlackWebhookWithRetry = async (url: string, payload: TSlackPayload): Promise<TChannelResult> => {+ const { maxRetries, delayMs } = PKI_ALERT_RETRY_CONFIG;+ let lastError: AxiosError | undefined;++ for (let attempt = 1; attempt <= maxRetries; attempt += 1) {+ try {+ // eslint-disable-next-line no-await-in-loop+ await triggerSlackWebhook(url, payload);+ return { success: true };+ } catch (err) {+ lastError = err as AxiosError;++ if (!isSlackErrorRetryable(lastError)) {+ logger.info(+ { url: maskSlackWebhookUrl(url), statusCode: lastError.response?.status, error: lastError.message },+ "Slack webhook error is not retryable (4xx or non-transient error)"+ );+ return { success: false, error: lastError.message };+ }++ logger.info(+ {+ url: maskSlackWebhookUrl(url),+ attempt,+ maxRetries,+ statusCode: lastError.response?.status,+ error: lastError.message+ },+ `Slack webhook failed, ${attempt < maxRetries ? `retrying in ${delayMs}ms` : "no more retries"}`+ );++ if (attempt < maxRetries) {+ // eslint-disable-next-line no-await-in-loop+ await delay(delayMs);+ }+ }+ }++ return { success: false, error: lastError?.message };+};++/**+ * Sends a Slack notification with validation and retry logic.+ *+ * Steps:+ * 1. Validate the webhook URL (HTTPS, correct hostname, SSRF protection)+ * 2. Build the Slack Block Kit payload+ * 3. Send with exponential backoff retry on transient failures+ */+export const sendSlackNotificationWithRetry = async (+ config: TSlackChannelConfig,+ alertData: TAlertInfo,+ matchingCertificates: TCertificatePreview[]+): Promise<TChannelResult> => {+ await validateSlackWebhookUrl(config.webhookUrl);++ const appCfg = getConfig();+ const payload = buildSlackPayload({+ alert: alertData,+ certificates: matchingCertificates,+ appUrl: appCfg.SITE_URL+ });++ return triggerSlackWebhookWithRetry(config.webhookUrl, payload);+};diff --git a/backend/src/services/pki-alert-v2/pki-alert-v2-service.ts b/backend/src/services/pki-alert-v2/pki-alert-v2-service.tsindex 02baa30ccf..f314575522 100644--- a/backend/src/services/pki-alert-v2/pki-alert-v2-service.ts+++ b/backend/src/services/pki-alert-v2/pki-alert-v2-service.ts@@ -17,6 +17,11 @@ import { TSmtpService } from "@app/services/smtp/smtp-service";import { TPkiAlertChannelDALFactory } from "./pki-alert-channel-dal";import { TPkiAlertHistoryDALFactory } from "./pki-alert-history-dal";import { sendEmailNotificationWithRetry } from "./pki-alert-v2-channel-email-fns";+import {+ maskSlackWebhookUrl,+ sendSlackNotificationWithRetry,+ validateSlackWebhookUrl+} from "./pki-alert-v2-channel-slack-fns";import { sendWebhookNotification } from "./pki-alert-v2-channel-webhook-fns";import { TAlertWithChannels, TPkiAlertV2DALFactory } from "./pki-alert-v2-dal";import { parseTimeToDays, parseTimeToPostgresInterval } from "./pki-alert-v2-filter-utils";@@ -40,6 +45,7 @@ import {TListMatchingCertificatesDTO,TListMatchingCertificatesResponse,TPkiFilterRule,+ TSlackChannelConfig,TTestWebhookConfigDTO,TUpdateAlertV2DTO,TWebhookChannelConfig@@ -187,12 +193,16 @@ export const pkiAlertV2ServiceFactory = ({throw new BadRequestError({ message: "Invalid alertBefore format. Use format like '30d', '1w', '3m', '1y'" });}- // Validate webhook URLs early to provide immediate SSRF feedback+ // Validate webhook and Slack URLs early to provide immediate SSRF feedbackfor (const channel of channels) {if (channel.channelType === PkiAlertChannelType.WEBHOOK) {const webhookConfig = channel.config as TWebhookChannelConfig;// eslint-disable-next-line no-await-in-loopawait blockLocalAndPrivateIpAddresses(webhookConfig.url);+ } else if (channel.channelType === PkiAlertChannelType.SLACK) {+ const slackConfig = channel.config as TSlackChannelConfig;+ // eslint-disable-next-line no-await-in-loop+ await validateSlackWebhookUrl(slackConfig.webhookUrl);}}@@ -353,13 +363,17 @@ export const pkiAlertV2ServiceFactory = ({if (filters !== undefined) updateData.filters = filters;if (enabled !== undefined) updateData.enabled = enabled;- // Validate webhook URLs early to provide immediate SSRF feedback+ // Validate webhook and Slack URLs early to provide immediate SSRF feedbackif (channels) {for (const channel of channels) {if (channel.channelType === PkiAlertChannelType.WEBHOOK) {const webhookConfig = channel.config as TWebhookChannelConfig;// eslint-disable-next-line no-await-in-loopawait blockLocalAndPrivateIpAddresses(webhookConfig.url);+ } else if (channel.channelType === PkiAlertChannelType.SLACK) {+ const slackConfig = channel.config as TSlackChannelConfig;+ // eslint-disable-next-line no-await-in-loop+ await validateSlackWebhookUrl(slackConfig.webhookUrl);}}}@@ -631,8 +645,13 @@ export const pkiAlertV2ServiceFactory = ({return { ...result, channelType: channel.channelType, url: config.url };}case PkiAlertChannelType.SLACK: {- logger.info(`Slack channel not yet implemented for alert ${alertId}`);- return { success: false, channelType: channel.channelType, error: "Slack not yet implemented" };+ const config = decryptChannelConfig<TSlackChannelConfig>(channel, decryptor);+ const result = await sendSlackNotificationWithRetry(config, alertData, matchingCertificates);+ return {+ ...result,+ channelType: channel.channelType,+ webhookUrl: maskSlackWebhookUrl(config.webhookUrl)+ };}default:return { success: false, channelType: channel.channelType, error: "Unknown channel type" };@@ -674,6 +693,8 @@ export const pkiAlertV2ServiceFactory = ({errors.push(`EMAIL (recipients: ${r.recipients.join(", ")}): ${r.error}`);} else if (r.channelType === PkiAlertChannelType.WEBHOOK && "url" in r && r.url) {errors.push(`WEBHOOK (url: ${r.url}): ${r.error}`);+ } else if (r.channelType === PkiAlertChannelType.SLACK && "webhookUrl" in r && r.webhookUrl) {+ errors.push(`SLACK (url: ${r.webhookUrl}): ${r.error}`);} else {errors.push(`${r.channelType}: ${r.error}`);}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.tsindex 34d18d28e2..569b328d1b 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@@ -141,9 +141,18 @@ export type TWebhookChannelConfigResponse = {};export const SlackChannelConfigSchema = z.object({- webhookUrl: z.string().url(),- channel: z.string().optional(),- mentionUsers: z.array(z.string()).optional()+ webhookUrl: z+ .string()+ .url()+ .refine((url) => url.startsWith("https://"), "Slack webhook URL must use HTTPS")+ .refine((url) => {+ try {+ const parsed = new URL(url);+ return parsed.hostname === "hooks.slack.com";+ } catch {+ return false;+ }+ }, "Slack webhook URL must be from hooks.slack.com")});export const ChannelConfigSchema = z.union([@@ -288,3 +297,35 @@ 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[];+ appUrl?: string;+};diff --git a/docs/documentation/platform/pki/alerting.mdx b/docs/documentation/platform/pki/alerting.mdxindex 4f460a4838..ba6903d954 100644--- a/docs/documentation/platform/pki/alerting.mdx+++ b/docs/documentation/platform/pki/alerting.mdx@@ -31,6 +31,7 @@ Alerts can be delivered through one or more notification channels:- **Email**: Send alert notifications to a list of email recipients. Enter one or more email addresses to notify when the alert triggers.- **Webhook**: Send alert notifications to a webhook URL. The URL must use HTTPS. Optionally configure a signing secret to verify the authenticity of webhook payloads.+- **Slack**: Send alert notifications to a Slack channel via an Incoming Webhook. See [detailed setup steps](#slack-notifications).You can configure up to 10 notification channels per alert.@@ -126,3 +127,39 @@ function verifyWebhookSignature(header, body, secret) {);}```++## Slack Notifications++PKI alerts can be sent to Slack channels using [Incoming Webhooks](https://api.slack.com/messaging/webhooks). Follow these steps to set up Slack notifications:++<Steps>+ <Step title="Create a Slack App">+ 1. Go to the [Slack API Apps page](https://api.slack.com/apps) and click **Create New App**+ 2. Select **From scratch**+ 3. Give your app a name (e.g., "Infisical PKI Alerts") and select the Slack workspace where you want to receive notifications+ 4. Click **Create App**++ + </Step>+ <Step title="Enable Incoming Webhooks">+ 1. In your app settings, navigate to **Incoming Webhooks** in the left sidebar under "Features"+ 2. Toggle **Activate Incoming Webhooks** to **On**+ 3. Click **Add New Webhook** at the bottom of the page+ 4. Select the channel where you want to receive alerts and click **Allow**+ 5. Copy the generated **Webhook URL** (it will look like `https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX`)++ + </Step>+ <Step title="Configure the Alert in Infisical">+ 1. When creating or editing a PKI alert, add a **Slack** notification channel+ 2. Paste the webhook URL you copied from Slack++ + </Step>+</Steps>++<Note>+Keep your webhook URL secure. Anyone with access to it can post messages to your Slack channel.+</Note>++Slack messages include alert details and the two most urgent expiring certificates, with a link to view all certificates in Infisical.diff --git a/docs/images/platform/pki/alerting/alert-create-channels.png b/docs/images/platform/pki/alerting/alert-create-channels.pngindex 7f34de0583..7a0476756b 100644Binary files a/docs/images/platform/pki/alerting/alert-create-channels.png and b/docs/images/platform/pki/alerting/alert-create-channels.png differdiff --git a/docs/images/platform/pki/alerting/slack-configure-alert.png b/docs/images/platform/pki/alerting/slack-configure-alert.pngnew file mode 100644index 0000000000..0e299b6d6fBinary files /dev/null and b/docs/images/platform/pki/alerting/slack-configure-alert.png differdiff --git a/docs/images/platform/pki/alerting/slack-create-app.png b/docs/images/platform/pki/alerting/slack-create-app.pngnew file mode 100644index 0000000000..6196e2331dBinary files /dev/null and b/docs/images/platform/pki/alerting/slack-create-app.png differdiff --git a/docs/images/platform/pki/alerting/slack-enable-webhooks.png b/docs/images/platform/pki/alerting/slack-enable-webhooks.pngnew file mode 100644index 0000000000..78185f3d22Binary files /dev/null and b/docs/images/platform/pki/alerting/slack-enable-webhooks.png differdiff --git a/frontend/src/hooks/api/pkiAlertsV2/index.ts b/frontend/src/hooks/api/pkiAlertsV2/index.tsindex 6424018bda..9d598b49fd 100644--- a/frontend/src/hooks/api/pkiAlertsV2/index.ts+++ b/frontend/src/hooks/api/pkiAlertsV2/index.ts@@ -20,6 +20,7 @@ export type {TGetPkiAlertV2CurrentMatchingCertificatesResponse,TGetPkiAlertV2MatchingCertificates,TPkiAlertChannelConfigEmail,+ TPkiAlertChannelConfigSlack,TPkiAlertChannelConfigWebhook,TPkiAlertChannelConfigWebhookResponse,TPkiAlertChannelV2,diff --git a/frontend/src/hooks/api/pkiAlertsV2/types.ts b/frontend/src/hooks/api/pkiAlertsV2/types.tsindex 536905ab87..8a40ee4a70 100644--- a/frontend/src/hooks/api/pkiAlertsV2/types.ts+++ b/frontend/src/hooks/api/pkiAlertsV2/types.ts@@ -12,7 +12,8 @@ export enum PkiAlertEventTypeV2 {export enum PkiAlertChannelTypeV2 {EMAIL = "email",- WEBHOOK = "webhook"+ WEBHOOK = "webhook",+ SLACK = "slack"}export enum PkiFilterFieldV2 {@@ -51,7 +52,14 @@ export interface TPkiAlertChannelConfigWebhookResponse {hasSigningSecret: boolean;}-export type TPkiAlertChannelConfig = TPkiAlertChannelConfigEmail | TPkiAlertChannelConfigWebhook;+export interface TPkiAlertChannelConfigSlack {+ webhookUrl: string;+}++export type TPkiAlertChannelConfig =+ | TPkiAlertChannelConfigEmail+ | TPkiAlertChannelConfigWebhook+ | TPkiAlertChannelConfigSlack;export interface TPkiAlertChannelV2 {id: string;@@ -215,9 +223,32 @@ const webhookChannelSchema = z.object({enabled: z.boolean().default(true)});+const slackChannelConfigSchema = z.object({+ webhookUrl: z+ .string()+ .url("Must be a valid URL")+ .refine((url) => url.startsWith("https://"), "Slack webhook URL must use HTTPS")+ .refine((url) => {+ try {+ const parsed = new URL(url);+ return parsed.hostname === "hooks.slack.com";+ } catch {+ return false;+ }+ }, "Slack webhook URL must be from hooks.slack.com")+});++const slackChannelSchema = z.object({+ id: z.string().uuid().optional(),+ channelType: z.literal(PkiAlertChannelTypeV2.SLACK),+ config: slackChannelConfigSchema,+ enabled: z.boolean().default(true)+});+export const pkiAlertChannelV2Schema = z.discriminatedUnion("channelType", [emailChannelSchema,- webhookChannelSchema+ webhookChannelSchema,+ slackChannelSchema]);export const createPkiAlertV2Schema = z.object({diff --git a/frontend/src/views/PkiAlertsV2Page/components/CreatePkiAlertV2FormSteps.tsx b/frontend/src/views/PkiAlertsV2Page/components/CreatePkiAlertV2FormSteps.tsxindex 041c70a252..38f215e9e8 100644--- a/frontend/src/views/PkiAlertsV2Page/components/CreatePkiAlertV2FormSteps.tsx+++ b/frontend/src/views/PkiAlertsV2Page/components/CreatePkiAlertV2FormSteps.tsx@@ -1,6 +1,7 @@/* eslint-disable react/no-array-index-key */import { useEffect, useRef, useState } from "react";import { Controller, useFieldArray, useFormContext } from "react-hook-form";+import { faSlack } from "@fortawesome/free-brands-svg-icons";import {faCheck,faChevronDown,@@ -57,6 +58,7 @@ import {PkiFilterOperatorV2,TCreatePkiAlertV2,TPkiAlertChannelConfigEmail,+ TPkiAlertChannelConfigSlack,TPkiAlertChannelConfigWebhook,TPkiFilterRuleV2,useGetPkiAlertV2CurrentMatchingCertificates,@@ -169,9 +171,28 @@ export const CreatePkiAlertV2FormSteps = ({const addChannel = (type: PkiAlertChannelTypeV2) => {if (isChannelLimitReached) return;justAddedRef.current = true;++ let config:+ | TPkiAlertChannelConfigEmail+ | TPkiAlertChannelConfigWebhook+ | TPkiAlertChannelConfigSlack;+ switch (type) {+ case PkiAlertChannelTypeV2.EMAIL:+ config = { recipients: [] };+ break;+ case PkiAlertChannelTypeV2.WEBHOOK:+ config = { url: "" };+ break;+ case PkiAlertChannelTypeV2.SLACK:+ config = { webhookUrl: "" };+ break;+ default:+ config = { recipients: [] };+ }+prependChannel({channelType: type,- config: type === PkiAlertChannelTypeV2.EMAIL ? { recipients: [] } : { url: "" },+ config,enabled: true});trigger("channels");@@ -648,6 +669,10 @@ export const CreatePkiAlertV2FormSteps = ({<FontAwesomeIcon icon={faLink} className="mr-2" />Webhook</DropdownMenuItem>+ <DropdownMenuItem onClick={() => addChannel(PkiAlertChannelTypeV2.SLACK)}>+ <FontAwesomeIcon icon={faSlack} className="mr-2" />+ Slack+ </DropdownMenuItem></DropdownMenuContent></DropdownMenu></div>@@ -824,6 +849,29 @@ export const CreatePkiAlertV2FormSteps = ({</div></div>)}++ {channel?.channelType === PkiAlertChannelTypeV2.SLACK && (+ <Controller+ control={control}+ name={`channels.${index}.config.webhookUrl`}+ render={({ field: urlField, fieldState: { error } }) => (+ <FormControl+ label="Slack Webhook URL"+ isRequired+ isError={Boolean(error)}+ errorText={error?.message}+ helperText="Create an Incoming Webhook in your Slack workspace settings"+ >+ <Input+ value={urlField.value || ""}+ onChange={urlField.onChange}+ onBlur={urlField.onBlur}+ placeholder="https://hooks.slack.com/services/..."+ />+ </FormControl>+ )}+ />+ )}</AccordionContent></AccordionItem>);@@ -949,38 +997,46 @@ export const CreatePkiAlertV2FormSteps = ({))}</div><span className="truncate text-xs text-mineshaft-400">- {channel.channelType === PkiAlertChannelTypeV2.EMAIL- ? (() => {- const config = channel.config as TPkiAlertChannelConfigEmail;- const count = config.recipients.length;- if (count === 0) return "No recipients";- const displayEmails = config.recipients.slice(0, 3);- const truncated = displayEmails.map((e) =>- e.length > 20 ? `${e.slice(0, 20)}...` : e+ {(() => {+ if (channel.channelType === PkiAlertChannelTypeV2.EMAIL) {+ const config = channel.config as TPkiAlertChannelConfigEmail;+ const count = config.recipients.length;+ if (count === 0) return "No recipients";+ const displayEmails = config.recipients.slice(0, 3);+ const truncated = displayEmails.map((e) =>+ e.length > 20 ? `${e.slice(0, 20)}...` : e+ );+ const displayText =+ count <= 3+ ? truncated.join(", ")+ : `${truncated.join(", ")} +${count - 3} more`;++ if (count > 3) {+ return (+ <Tooltip content={config.recipients.join(", ")}>+ <span className="cursor-help">{displayText}</span>+ </Tooltip>);- const displayText =- count <= 3- ? truncated.join(", ")- : `${truncated.join(", ")} +${count - 3} more`;-- if (count > 3) {- return (- <Tooltip content={config.recipients.join(", ")}>- <span className="cursor-help">{displayText}</span>- </Tooltip>- );- }- return displayText;- })()- : (() => {- const config = channel.config as TPkiAlertChannelConfigWebhook;- try {- const url = new URL(config.url);- return url.hostname;- } catch {- return config.url || "Not configured";- }- })()}+ }+ return displayText;+ }+ if (channel.channelType === PkiAlertChannelTypeV2.WEBHOOK) {+ const config = channel.config as TPkiAlertChannelConfigWebhook;+ try {+ const url = new URL(config.url);+ return url.hostname;+ } catch {+ return config.url || "Not configured";+ }+ }+ if (channel.channelType === PkiAlertChannelTypeV2.SLACK) {+ const config = channel.config as TPkiAlertChannelConfigSlack;+ return config.webhookUrl+ ? "Slack webhook configured"+ : "Not configured";+ }+ return "";+ })()}</span></div>{!channel.enabled && (diff --git a/frontend/src/views/PkiAlertsV2Page/components/ViewPkiAlertV2Modal.tsx b/frontend/src/views/PkiAlertsV2Page/components/ViewPkiAlertV2Modal.tsxindex f94d0c6d75..2d5aad41ac 100644--- a/frontend/src/views/PkiAlertsV2Page/components/ViewPkiAlertV2Modal.tsx+++ b/frontend/src/views/PkiAlertsV2Page/components/ViewPkiAlertV2Modal.tsx@@ -252,6 +252,11 @@ export const ViewPkiAlertV2Modal = ({ isOpen, onOpenChange, alertId }: Props) =>)}</div>)}+ {channel.channelType === PkiAlertChannelTypeV2.SLACK && (+ <div className="mt-1 truncate text-sm text-mineshaft-400">+ Slack webhook configured+ </div>+ )}</div></div>))}diff --git a/frontend/src/views/PkiAlertsV2Page/utils/pki-alert-formatters.ts b/frontend/src/views/PkiAlertsV2Page/utils/pki-alert-formatters.tsindex cf157278c9..e97bb65105 100644--- a/frontend/src/views/PkiAlertsV2Page/utils/pki-alert-formatters.ts+++ b/frontend/src/views/PkiAlertsV2Page/utils/pki-alert-formatters.ts@@ -1,10 +1,12 @@import { IconDefinition } from "@fortawesome/fontawesome-svg-core";+import { faSlack } from "@fortawesome/free-brands-svg-icons";import { faEnvelope, faLink } from "@fortawesome/free-solid-svg-icons";import {PkiAlertChannelTypeV2,PkiAlertEventTypeV2,TPkiAlertChannelConfigEmail,+ TPkiAlertChannelConfigSlack,TPkiAlertChannelConfigWebhook} from "@app/hooks/api/pkiAlertsV2";@@ -56,6 +58,8 @@ export const getChannelIcon = (type: PkiAlertChannelTypeV2): IconDefinition => {return faEnvelope;case PkiAlertChannelTypeV2.WEBHOOK:return faLink;+ case PkiAlertChannelTypeV2.SLACK:+ return faSlack;default:return faEnvelope;}@@ -81,10 +85,11 @@ export const getWebhookHostname = (url: string): string => {** For email: shows recipients (truncated if >2)* For webhook: shows hostname from URL+ * For slack: shows "Slack webhook configured"*/export const getChannelSummary = (channel: {channelType: PkiAlertChannelTypeV2;- config: TPkiAlertChannelConfigEmail | TPkiAlertChannelConfigWebhook;+ config: TPkiAlertChannelConfigEmail | TPkiAlertChannelConfigWebhook | TPkiAlertChannelConfigSlack;}): string => {if (channel.channelType === PkiAlertChannelTypeV2.EMAIL) {const config = channel.config as TPkiAlertChannelConfigEmail;@@ -97,5 +102,9 @@ export const getChannelSummary = (channel: {const config = channel.config as TPkiAlertChannelConfigWebhook;return getWebhookHostname(config.url);}+ if (channel.channelType === PkiAlertChannelTypeV2.SLACK) {+ const config = channel.config as TPkiAlertChannelConfigSlack;+ return config.webhookUrl ? "Slack webhook configured" : "Not configured";+ }return "";};