Skip to content

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

add top banner for audit log error

Thiago Araujo da Silva8cec193efc5c
diff --git a/backend/src/ee/services/audit-log-stream/audit-log-stream-service.ts b/backend/src/ee/services/audit-log-stream/audit-log-stream-service.ts
index 0005971fb0..5baf2e3245 100644
--- a/backend/src/ee/services/audit-log-stream/audit-log-stream-service.ts
+++ b/backend/src/ee/services/audit-log-stream/audit-log-stream-service.ts
@@ -283,7 +283,7 @@ export const auditLogStreamServiceFactory = ({
);
};
- const evaluateErrorSlidingWindow = async (orgId: string, streamId: string, provider: string) => {
+ const evaluateErrorBucketSlidingWindow = async (orgId: string, streamId: string, provider: string) => {
try {
const nowMinuteBucket = Math.floor(Date.now() / 60000);
@@ -353,7 +353,7 @@ export const auditLogStreamServiceFactory = ({
);
}
- await evaluateErrorSlidingWindow(orgId, id, provider);
+ await evaluateErrorBucketSlidingWindow(orgId, id, provider);
}
})
);
diff --git a/frontend/src/hooks/api/notifications/types.ts b/frontend/src/hooks/api/notifications/types.ts
index 6a4e3f31a4..227ec30ce8 100644
--- a/frontend/src/hooks/api/notifications/types.ts
+++ b/frontend/src/hooks/api/notifications/types.ts
@@ -21,7 +21,8 @@ export enum NotificationType {
RELAY_HEALTH_ALERT = "relay-health-alert",
APPROVAL_REQUIRED = "approval-required",
PKI_ALERT_CHANNEL_FAILED = "pki-alert-channel-failed",
- CREDENTIAL_ROTATION_FAILED = "credential-rotation-failed"
+ CREDENTIAL_ROTATION_FAILED = "credential-rotation-failed",
+ AUDIT_LOG_STREAM_FAILED = "audit-log-stream-failed"
}
export interface TUserNotification {
@@ -37,7 +38,8 @@ export interface TUserNotification {
export const CRITICAL_NOTIFICATION_TYPES: NotificationType[] = [
NotificationType.GATEWAY_HEALTH_ALERT,
- NotificationType.RELAY_HEALTH_ALERT
+ NotificationType.RELAY_HEALTH_ALERT,
+ NotificationType.AUDIT_LOG_STREAM_FAILED
];
export const isCriticalNotification = (type: NotificationType): boolean =>
diff --git a/frontend/src/layouts/OrganizationLayout/components/NetworkHealthBanner/NetworkHealthBanner.tsx b/frontend/src/layouts/OrganizationLayout/components/NetworkHealthBanner/NetworkHealthBanner.tsx
index e298e26d56..7a21c6a941 100644
--- a/frontend/src/layouts/OrganizationLayout/components/NetworkHealthBanner/NetworkHealthBanner.tsx
+++ b/frontend/src/layouts/OrganizationLayout/components/NetworkHealthBanner/NetworkHealthBanner.tsx
@@ -1,5 +1,10 @@
import { useMemo, useState } from "react";
-import { faExclamationTriangle, faXmark } from "@fortawesome/free-solid-svg-icons";
+import {
+ faChevronDown,
+ faChevronUp,
+ faExclamationTriangle,
+ faXmark
+} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { useQuery } from "@tanstack/react-query";
import { Link } from "@tanstack/react-router";
@@ -9,11 +14,15 @@ import { apiRequest } from "@app/config/request";
import { useOrganization, useOrgPermission } from "@app/context";
import {
OrgGatewayPermissionActions,
+ OrgPermissionActions,
OrgPermissionSubjects,
OrgRelayPermissionActions
} from "@app/context/OrgPermissionContext/types";
import { gatewaysQueryKeys } from "@app/hooks/api/gateways/queries";
import { isGatewayHealthy } from "@app/hooks/api/gateways-v2/utils";
+import { useUpdateNotification } from "@app/hooks/api/notifications/mutations";
+import { useGetMyNotifications } from "@app/hooks/api/notifications/queries";
+import { NotificationType } from "@app/hooks/api/notifications/types";
import { relayQueryKeys } from "@app/hooks/api/relays/queries";
import { TRelay } from "@app/hooks/api/relays/types";
@@ -33,8 +42,46 @@ const wasDismissedWithinLastDay = (): boolean => {
return Date.now() - dismissedTime < ONE_DAY_MS;
};
+type AlertItem = {
+ id: string;
+ message: string;
+ linkLabel?: string;
+ linkTo?: string;
+ onDismiss: () => void;
+};
+
+type SingleAlertRowProps = {
+ alert: AlertItem;
+};
+
+const SingleAlertRow = ({ alert }: SingleAlertRowProps) => (
+ <div className="flex w-full items-center px-4 py-2 text-sm text-red-200">
+ <FontAwesomeIcon icon={faExclamationTriangle} className="mr-2.5 text-base text-red-400" />
+ {alert.message}
+ {alert.linkLabel && alert.linkTo && (
+ <Link
+ to={alert.linkTo}
+ className="ml-1 cursor-pointer underline underline-offset-2 duration-100 hover:text-red-100"
+ >
+ {alert.linkLabel}
+ </Link>
+ )}
+ <IconButton
+ className="ml-auto p-0 text-red-200 hover:text-red-100"
+ ariaLabel="Dismiss alert"
+ variant="plain"
+ onClick={alert.onDismiss}
+ >
+ <FontAwesomeIcon icon={faXmark} />
+ </IconButton>
+ </div>
+);
+
export const NetworkHealthBanner = () => {
- const [isDismissed, setIsDismissed] = useState(() => wasDismissedWithinLastDay());
+ const [isExpanded, setIsExpanded] = useState(true);
+ const [networkDismissed, setNetworkDismissed] = useState(() => wasDismissedWithinLastDay());
+ const [dismissedAlertIds, setDismissedAlertIds] = useState<Set<string>>(() => new Set());
+
const { currentOrg } = useOrganization();
const { permission } = useOrgPermission();
@@ -46,6 +93,7 @@ export const NetworkHealthBanner = () => {
OrgRelayPermissionActions.ListRelays,
OrgPermissionSubjects.Relay
);
+ const canReadSettings = permission.can(OrgPermissionActions.Read, OrgPermissionSubjects.Settings);
const { data: gateways } = useQuery({
...gatewaysQueryKeys.list(),
@@ -59,8 +107,10 @@ export const NetworkHealthBanner = () => {
},
enabled: canListRelays
});
+ const { data: notifications } = useGetMyNotifications();
+ const { mutate: updateNotification } = useUpdateNotification();
- const unreachableGateways = useMemo(
+ const unreachableGatewayCount = useMemo(
() =>
gateways?.filter((g) => {
if (g.isV1) return false;
@@ -69,47 +119,115 @@ export const NetworkHealthBanner = () => {
[gateways]
);
- const unreachableRelays = useMemo(
+ const unreachableRelayCount = useMemo(
() =>
relays?.filter((r) => r.orgId && r.heartbeat && isRelayHeartbeatStale(r.heartbeat)).length ??
0,
[relays]
);
- if (!canListGateways && !canListRelays) return null;
- if (isDismissed || (unreachableGateways === 0 && unreachableRelays === 0)) return null;
+ const failedStreamNotifications = useMemo(
+ () =>
+ canReadSettings
+ ? (notifications?.filter(
+ (n) => n.type === NotificationType.AUDIT_LOG_STREAM_FAILED && !n.isRead
+ ) ?? [])
+ : [],
+ [notifications, canReadSettings]
+ );
+
+ const alerts = useMemo<AlertItem[]>(() => {
+ const items: AlertItem[] = [];
- const parts: string[] = [];
- if (unreachableGateways > 0) {
- parts.push(`${unreachableGateways} gateway${unreachableGateways > 1 ? "s" : ""}`);
- }
- if (unreachableRelays > 0) {
- parts.push(`${unreachableRelays} relay${unreachableRelays > 1 ? "s" : ""}`);
+ if (!networkDismissed && (unreachableGatewayCount > 0 || unreachableRelayCount > 0)) {
+ const parts: string[] = [];
+ if (unreachableGatewayCount > 0) {
+ parts.push(`${unreachableGatewayCount} gateway${unreachableGatewayCount > 1 ? "s" : ""}`);
+ }
+ if (unreachableRelayCount > 0) {
+ parts.push(`${unreachableRelayCount} relay${unreachableRelayCount > 1 ? "s" : ""}`);
+ }
+ const count = unreachableGatewayCount + unreachableRelayCount;
+ items.push({
+ id: "network",
+ message: `${parts.join(" and ")} in your organization ${count > 1 ? "are" : "is"} unreachable.`,
+ linkLabel: "View networking",
+ linkTo: `/organizations/${currentOrg.id}/networking`,
+ onDismiss: () => {
+ localStorage.setItem(DISMISS_STORAGE_KEY, Date.now().toString());
+ setNetworkDismissed(true);
+ }
+ });
+ }
+
+ failedStreamNotifications
+ .filter((n) => !dismissedAlertIds.has(n.id))
+ .forEach((n) => {
+ items.push({
+ id: n.id,
+ message: "Error streaming audit logs.",
+ linkLabel: "View log stream",
+ linkTo: `/organizations/${currentOrg.id}/settings`,
+ onDismiss: () => {
+ updateNotification({ notificationId: n.id, isRead: true });
+ setDismissedAlertIds((prev) => new Set([...prev, n.id]));
+ }
+ });
+ });
+
+ return items;
+ }, [
+ networkDismissed,
+ unreachableGatewayCount,
+ unreachableRelayCount,
+ failedStreamNotifications,
+ dismissedAlertIds,
+ currentOrg.id,
+ updateNotification
+ ]);
+
+ if (!canListGateways && !canListRelays && !canReadSettings) return null;
+ if (alerts.length === 0) return null;
+
+ if (alerts.length === 1) {
+ return (
+ <div className="w-full border-b border-red-500/50 bg-red-500/20">
+ <SingleAlertRow alert={alerts[0]} />
+ </div>
+ );
}
return (
- <div className="flex w-full items-center border-b border-red-500/50 bg-red-500/20 px-4 py-2 text-sm text-red-200">
- <FontAwesomeIcon icon={faExclamationTriangle} className="mr-2.5 text-base text-red-400" />
- {parts.join(" and ")} in your organization{" "}
- {unreachableGateways + unreachableRelays > 1 ? "are" : "is"} unreachable.
- <Link
- to="/organizations/$orgId/networking"
- params={{ orgId: currentOrg.id }}
- className="ml-1 cursor-pointer underline underline-offset-2 duration-100 hover:text-red-100"
- >
- View networking
- </Link>
- <IconButton
- className="ml-auto p-0 text-red-200 hover:text-red-100"
- ariaLabel="Dismiss banner"
- variant="plain"
- onClick={() => {
- localStorage.setItem(DISMISS_STORAGE_KEY, Date.now().toString());
- setIsDismissed(true);
- }}
- >
- <FontAwesomeIcon icon={faXmark} />
- </IconButton>
+ <div className="w-full border-b border-red-500/50 bg-red-500/20">
+ <div className="flex w-full items-center px-4 py-2 text-sm text-red-200">
+ <FontAwesomeIcon icon={faExclamationTriangle} className="mr-2.5 text-base text-red-400" />
+ <span className="font-medium">{alerts.length} errors in your organization</span>
+ <IconButton
+ className="ml-2 p-0 text-red-200 hover:text-red-100"
+ ariaLabel={isExpanded ? "Collapse alerts" : "Expand alerts"}
+ variant="plain"
+ onClick={() => setIsExpanded((prev) => !prev)}
+ >
+ <FontAwesomeIcon icon={isExpanded ? faChevronUp : faChevronDown} className="text-xs" />
+ </IconButton>
+ <IconButton
+ className="ml-auto shrink-0 p-0 text-red-200 hover:text-red-100"
+ ariaLabel="Dismiss all alerts"
+ variant="plain"
+ onClick={() => alerts.forEach((alert) => alert.onDismiss())}
+ >
+ <FontAwesomeIcon icon={faXmark} />
+ </IconButton>
+ </div>
+ {isExpanded && (
+ <div>
+ {alerts.map((alert) => (
+ <div key={alert.id} className="border-t border-red-500/30">
+ <SingleAlertRow alert={alert} />
+ </div>
+ ))}
+ </div>
+ )}
</div>
);
};