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
entrypoint on identity details
Thiago Araujo da Silvab64da24a743f
diff --git a/backend/src/db/migrations/20260714120000_add-alerts.ts b/backend/src/db/migrations/20260714120000_add-alerts.tsindex a9794e050a..03df171602 100644--- a/backend/src/db/migrations/20260714120000_add-alerts.ts+++ b/backend/src/db/migrations/20260714120000_add-alerts.ts@@ -30,6 +30,11 @@ export async function up(knex: Knex): Promise<void> {t.index(["resourceType", "triggerType", "enabled"]);});+ await knex.schema.raw(+ `CREATE UNIQUE INDEX "alert_unique_scope_resource_event" ON "${TableName.Alert}"+ ("orgId", (COALESCE("projectId", '')), "resourceType", (COALESCE("resourceId", '')), "eventType")`+ );+await createOnUpdateTrigger(knex, TableName.Alert);}diff --git a/backend/src/services/alert/alert-dal.ts b/backend/src/services/alert/alert-dal.tsindex 9ae4a5b2cc..6da65c8efe 100644--- a/backend/src/services/alert/alert-dal.ts+++ b/backend/src/services/alert/alert-dal.ts@@ -77,10 +77,39 @@ export const alertDALFactory = (db: TDbClient) => {}};+ const findScopedDuplicate = async (+ filter: {+ orgId: string;+ projectId?: string | null;+ resourceType: string;+ resourceId?: string | null;+ eventType: string;+ },+ tx?: Knex+ ): Promise<TAlerts | undefined> => {+ try {+ const query = (tx || db.replicaNode())(TableName.Alert)+ .where(`${TableName.Alert}.orgId`, filter.orgId)+ .where(`${TableName.Alert}.resourceType`, filter.resourceType)+ .where(`${TableName.Alert}.eventType`, filter.eventType);++ if (filter.projectId) void query.where(`${TableName.Alert}.projectId`, filter.projectId);+ else void query.whereNull(`${TableName.Alert}.projectId`);+ if (filter.resourceId) void query.where(`${TableName.Alert}.resourceId`, filter.resourceId);+ else void query.whereNull(`${TableName.Alert}.resourceId`);++ const alert = await query.select(selectAllTableCols(TableName.Alert)).first();+ return alert as TAlerts | undefined;+ } catch (error) {+ throw new DatabaseError({ error, name: "FindScopedDuplicate" });+ }+ };+return {...alertOrm,findEnabledByResourceType,findActiveById,- findActiveByScope+ findActiveByScope,+ findScopedDuplicate};};diff --git a/backend/src/services/alert/alert-service.ts b/backend/src/services/alert/alert-service.tsindex b72510b784..f0062eb8ea 100644--- a/backend/src/services/alert/alert-service.ts+++ b/backend/src/services/alert/alert-service.ts@@ -131,6 +131,21 @@ export const alertServiceFactory = ({resourceId: dto.resourceId});+ const duplicate = await alertDAL.findScopedDuplicate({+ orgId: dto.actorOrgId,+ projectId: dto.projectId,+ resourceType: dto.resourceType,+ resourceId: dto.resourceId,+ eventType: dto.eventType+ });+ if (duplicate) {+ throw new BadRequestError({+ message: dto.resourceId+ ? "An alert for this resource and event already exists"+ : "An alert for this event already exists in this scope"+ });+ }+await $resolveChannelsInScope(dto.channelIds, { orgId: dto.actorOrgId, projectId: dto.projectId });const { created, channels } = await alertDAL.transaction(async (tx) => {diff --git a/frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityAlertDetail.tsx b/frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityAlertDetail.tsxnew file mode 100644index 0000000000..b8ac8515aa--- /dev/null+++ b/frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityAlertDetail.tsx@@ -0,0 +1,122 @@+import { BellPlusIcon, PencilIcon } from "lucide-react";++import { OrgPermissionCan } from "@app/components/permissions";+import {+ Badge,+ Button,+ Detail,+ DetailLabel,+ DetailValue,+ IconButton,+ Tooltip,+ TooltipContent,+ TooltipTrigger+} from "@app/components/v3";+import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/context";+import { usePopUp } from "@app/hooks";+import {+ ALERT_CHANNEL_TYPE_LABELS,+ ALERT_EVENT_TYPE_LABELS,+ AlertEventType,+ AlertResourceType,+ TAlert,+ useListAlerts+} from "@app/hooks/api/alerts";+import { AddAlertModal } from "@app/views/AlertsPage/components/AddAlertModal";+import { getChannelIcon } from "@app/views/AlertsPage/components/channelIcons";++type Props = {+ identityId: string;+ identityName: string;+};++// "Alert" subsection of the identity Details card. Shows the single alert bound to this identity+// (name, event, channel icons) and opens the drawer in edit mode when clicked. When none exists it+// offers a create action pre-bound to the identity. Uniqueness (one alert per resource + event) is+// enforced by the backend, so at most one alert is ever returned here.+export const IdentityAlertDetail = ({ identityId, identityName }: Props) => {+ const { data: alerts = [] } = useListAlerts({+ resourceType: AlertResourceType.IdentityCredential,+ resourceId: identityId+ });++ const { popUp, handlePopUpOpen, handlePopUpToggle } = usePopUp(["alert"] as const);++ const existingAlert = alerts[0] as TAlert | undefined;+ const eventLabel = existingAlert+ ? (ALERT_EVENT_TYPE_LABELS[existingAlert.eventType as AlertEventType] ??+ existingAlert.eventType)+ : "";++ return (+ <Detail>+ <DetailLabel>Alert</DetailLabel>+ <DetailValue>+ {existingAlert ? (+ <div className="flex w-full items-center justify-between gap-2 rounded-md border border-mineshaft-600 p-3">+ <div className="flex min-w-0 flex-col gap-2">+ <span className="truncate font-medium text-foreground">{existingAlert.name}</span>+ <div className="flex flex-wrap items-center gap-1.5">+ <Badge variant="warning">{eventLabel}</Badge>+ {existingAlert.channels.map((channel) => {+ const Icon = getChannelIcon(channel.channelType);+ return (+ <Tooltip key={channel.id}>+ <TooltipTrigger asChild>+ <span className="flex size-6 items-center justify-center rounded border border-mineshaft-600 text-muted">+ <Icon className="size-3.5" />+ </span>+ </TooltipTrigger>+ <TooltipContent>+ {channel.name} · {ALERT_CHANNEL_TYPE_LABELS[channel.channelType]}+ </TooltipContent>+ </Tooltip>+ );+ })}+ </div>+ </div>+ <OrgPermissionCan+ I={OrgPermissionIdentityActions.Edit}+ a={OrgPermissionSubjects.Identity}+ >+ {(isAllowed) => (+ <IconButton+ isDisabled={!isAllowed}+ onClick={() => handlePopUpOpen("alert")}+ variant="ghost"+ size="xs"+ >+ <PencilIcon />+ </IconButton>+ )}+ </OrgPermissionCan>+ </div>+ ) : (+ <OrgPermissionCan+ I={OrgPermissionIdentityActions.Edit}+ a={OrgPermissionSubjects.Identity}+ >+ {(isAllowed) => (+ <Button+ variant="outline"+ size="xs"+ isDisabled={!isAllowed}+ onClick={() => handlePopUpOpen("alert")}+ >+ <BellPlusIcon />+ Create Alert+ </Button>+ )}+ </OrgPermissionCan>+ )}+ </DetailValue>+ <AddAlertModal+ isOpen={popUp.alert.isOpen}+ onOpenChange={(isOpen) => handlePopUpToggle("alert", isOpen)}+ resourceId={identityId}+ resourceName={identityName}+ alert={existingAlert}+ />+ </Detail>+ );+};diff --git a/frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityDetailsSection.tsx b/frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityDetailsSection.tsxindex d812d5d28c..7a9b34f71a 100644--- a/frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityDetailsSection.tsx+++ b/frontend/src/pages/organization/IdentityDetailsByIDPage/components/IdentityDetailsSection.tsx@@ -25,6 +25,8 @@ import { useTimedReset } from "@app/hooks";import { identityAuthToNameMap, useGetOrgIdentityMembershipById } from "@app/hooks/api";import { UsePopUpState } from "@app/hooks/usePopUp";+import { IdentityAlertDetail } from "./IdentityAlertDetail";+type Props = {identityId: string;isCurrentOrgIdentity?: boolean;@@ -187,6 +189,7 @@ export const IdentityDetailsSection = ({)}</DetailValue></Detail>+ <IdentityAlertDetail identityId={identityId} identityName={data.identity.name} /></>)}</DetailGroup>diff --git a/frontend/src/views/AlertsPage/components/AddAlertModal.tsx b/frontend/src/views/AlertsPage/components/AddAlertModal.tsxindex 37143e8daf..7fa96460dc 100644--- a/frontend/src/views/AlertsPage/components/AddAlertModal.tsx+++ b/frontend/src/views/AlertsPage/components/AddAlertModal.tsx@@ -8,10 +8,20 @@ type Props = {onOpenChange: (isOpen: boolean) => void;projectId?: string;scopeName?: string;+ resourceId?: string;+ resourceName?: string;alert?: TAlert;};-export const AddAlertModal = ({ isOpen, onOpenChange, projectId, scopeName, alert }: Props) => {+export const AddAlertModal = ({+ isOpen,+ onOpenChange,+ projectId,+ scopeName,+ resourceId,+ resourceName,+ alert+}: Props) => {const isEditing = Boolean(alert);return (@@ -28,6 +38,8 @@ export const AddAlertModal = ({ isOpen, onOpenChange, projectId, scopeName, alerkey={alert?.id ?? "new"}projectId={projectId}scopeName={scopeName}+ resourceId={resourceId}+ resourceName={resourceName}alert={alert}onComplete={() => onOpenChange(false)}onCancel={() => onOpenChange(false)}diff --git a/frontend/src/views/AlertsPage/components/AlertForm.tsx b/frontend/src/views/AlertsPage/components/AlertForm.tsxindex 568d93747d..ddad102a9d 100644--- a/frontend/src/views/AlertsPage/components/AlertForm.tsx+++ b/frontend/src/views/AlertsPage/components/AlertForm.tsx@@ -1,7 +1,7 @@import { ReactNode } from "react";import { Controller, FormProvider, useForm } from "react-hook-form";import { zodResolver } from "@hookform/resolvers/zod";-import { CircleHelpIcon, KeyRoundIcon, LockIcon } from "lucide-react";+import { CircleHelpIcon, FingerprintIcon, KeyRoundIcon, LockIcon } from "lucide-react";import { createNotification } from "@app/components/notifications";import {@@ -48,6 +48,10 @@ import { AttachChannelsField } from "./AttachChannelsField";type Props = {projectId?: string;scopeName?: string;+ // When set, the alert is bound to a single resource (e.g. one machine identity) rather than+ // watching every credential in the scope. resourceName is used only for display.+ resourceId?: string;+ resourceName?: string;alert?: TAlert;onComplete: () => void;onCancel: () => void;@@ -110,7 +114,15 @@ const buildFormDefaults = (alert?: TAlert): TAlertForm => {};};-export const AlertForm = ({ projectId, scopeName, alert, onComplete, onCancel }: Props) => {+export const AlertForm = ({+ projectId,+ scopeName,+ resourceId,+ resourceName,+ alert,+ onComplete,+ onCancel+}: Props) => {const isEditing = Boolean(alert);const scopeVariant = useScopeVariant();const createAlert = useCreateAlert();@@ -129,21 +141,32 @@ export const AlertForm = ({ projectId, scopeName, alert, onComplete, onCancel }:} = formMethods;const isProjectScope = Boolean(projectId);- const ScopeIcon =- // eslint-disable-next-line no-nested-ternary- isProjectScope ? ProjectIcon : scopeVariant === "sub-org" ? SubOrgIcon : OrgIcon;+ const isResourceScope = Boolean(resourceId ?? alert?.resourceId);+ const resolveScopeIcon = () => {+ if (isResourceScope) return FingerprintIcon;+ if (isProjectScope) return ProjectIcon;+ if (scopeVariant === "sub-org") return SubOrgIcon;+ return OrgIcon;+ };+ const ScopeIcon = resolveScopeIcon();// eslint-disable-next-line no-nested-ternaryconst scopeColor = isProjectScope? "text-project": scopeVariant === "sub-org"? "text-sub-org": "text-org";- const scopeTitle = isProjectScope- ? `Project · ${scopeName ?? "this project"}`- : "Organization-wide";- const scopeDescription = isProjectScope- ? "Watches every identity credential in this project"- : "Watches every identity credential in this organization";+ // eslint-disable-next-line no-nested-ternary+ const scopeTitle = isResourceScope+ ? `Machine Identity · ${resourceName ?? "this identity"}`+ : isProjectScope+ ? `Project · ${scopeName ?? "this project"}`+ : "Organization-wide";+ // eslint-disable-next-line no-nested-ternary+ const scopeDescription = isResourceScope+ ? "Watches this machine identity's credentials"+ : isProjectScope+ ? "Watches every identity credential in this project"+ : "Watches every identity credential in this organization";const onSubmit = async (data: TAlertForm) => {const alertBefore = `${data.alertBeforeValue}${data.alertBeforeUnit}`;@@ -166,7 +189,7 @@ export const AlertForm = ({ projectId, scopeName, alert, onComplete, onCancel }:name: data.name,description: data.description || undefined,resourceType: data.resourceType,- resourceId: null,+ resourceId: resourceId ?? null,eventType: data.eventType,condition,filters: null,