Skip to content

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

chore: make gateway errors more visible

Sheen Capadngan68c22590421a
diff --git a/frontend/src/hooks/api/notifications/types.ts b/frontend/src/hooks/api/notifications/types.ts
index 97552046c7..450e401efa 100644
--- a/frontend/src/hooks/api/notifications/types.ts
+++ b/frontend/src/hooks/api/notifications/types.ts
@@ -1,10 +1,43 @@
+export enum NotificationType {
+ ACCESS_APPROVAL_REQUEST = "access-approval-request",
+ ACCESS_APPROVAL_REQUEST_UPDATED = "access-approval-request-updated",
+ ACCESS_POLICY_BYPASSED = "access-policy-bypassed",
+ SECRET_CHANGE_REQUEST = "secret-change-request",
+ SECRET_CHANGE_POLICY_BYPASSED = "secret-change-policy-bypassed",
+ SECRET_ROTATION_FAILED = "secret-rotation-failed",
+ SECRET_SCANNING_SECRETS_DETECTED = "secret-scanning-secrets-detected",
+ SECRET_SCANNING_SCAN_FAILED = "secret-scanning-scan-failed",
+ LOGIN_FROM_NEW_DEVICE = "login-from-new-device",
+ ADMIN_SSO_BYPASS = "admin-sso-bypass",
+ IMPORT_STARTED = "import-started",
+ IMPORT_SUCCESSFUL = "import-successful",
+ IMPORT_FAILED = "import-failed",
+ DIRECT_PROJECT_ACCESS_ISSUED_TO_ADMIN = "direct-project-access-issued-to-admin",
+ PROJECT_ACCESS_REQUEST = "project-access-request",
+ PROJECT_INVITATION = "project-invitation",
+ SECRET_SYNC_FAILED = "secret-sync-failed",
+ GATEWAY_HEALTH_ALERT = "gateway-health-alert",
+ RELAY_HEALTH_ALERT = "relay-health-alert",
+ APPROVAL_REQUIRED = "approval-required",
+ PKI_ALERT_CHANNEL_FAILED = "pki-alert-channel-failed",
+ CREDENTIAL_ROTATION_FAILED = "credential-rotation-failed"
+}
+
export interface TUserNotification {
id: string;
userId: string;
- type: string;
+ type: NotificationType;
title: string;
body?: string | null;
link?: string | null;
isRead: boolean;
createdAt: string;
}
+
+export const CRITICAL_NOTIFICATION_TYPES: NotificationType[] = [
+ NotificationType.GATEWAY_HEALTH_ALERT,
+ NotificationType.RELAY_HEALTH_ALERT
+];
+
+export const isCriticalNotification = (type: NotificationType): boolean =>
+ CRITICAL_NOTIFICATION_TYPES.includes(type);
diff --git a/frontend/src/layouts/OrganizationLayout/OrganizationLayout.tsx b/frontend/src/layouts/OrganizationLayout/OrganizationLayout.tsx
index c91917423b..038cf84da0 100644
--- a/frontend/src/layouts/OrganizationLayout/OrganizationLayout.tsx
+++ b/frontend/src/layouts/OrganizationLayout/OrganizationLayout.tsx
@@ -10,6 +10,7 @@ import { useFetchServerStatus } from "@app/hooks/api";
import { AuditLogBanner } from "./components/AuditLogBanner";
import { InsecureConnectionBanner } from "./components/InsecureConnectionBanner";
import { Navbar } from "./components/NavBar";
+import { NetworkHealthBanner } from "./components/NetworkHealthBanner";
import { OrgNavBar } from "./components/OrgNavBar";
import { RedisBanner } from "./components/RedisBanner";
import { SmtpBanner } from "./components/SmtpBanner";
@@ -42,6 +43,7 @@ export const OrganizationLayout = () => {
{!isLoading && !isInsideProject && !serverDetails?.emailConfigured && <SmtpBanner />}
{!isLoading && !isInsideProject && subscription.auditLogs && <AuditLogBanner />}
{!window.isSecureContext && !isInsideProject && <InsecureConnectionBanner />}
+ <NetworkHealthBanner />
<main
className={twMerge(
"flex-1 overflow-x-hidden bg-bunker-800 px-12 pt-10 pb-4 dark:scheme-dark",
diff --git a/frontend/src/layouts/OrganizationLayout/components/NavBar/Notification.tsx b/frontend/src/layouts/OrganizationLayout/components/NavBar/Notification.tsx
index ade478c695..f2f0eb8ce7 100644
--- a/frontend/src/layouts/OrganizationLayout/components/NavBar/Notification.tsx
+++ b/frontend/src/layouts/OrganizationLayout/components/NavBar/Notification.tsx
@@ -5,7 +5,7 @@ import { formatDistance } from "date-fns";
import { twMerge } from "tailwind-merge";
import { IconButton, Tooltip } from "@app/components/v2";
-import { TUserNotification } from "@app/hooks/api/notifications/types";
+import { isCriticalNotification, TUserNotification } from "@app/hooks/api/notifications/types";
type Props = {
notification: TUserNotification;
@@ -13,18 +13,29 @@ type Props = {
};
export const Notification = ({ notification, onDelete }: Props) => {
+ const isCritical = isCriticalNotification(notification.type);
+
return (
<div
className={twMerge(
"group relative flex cursor-pointer items-start border-b border-mineshaft-600 p-2 transition-colors",
notification.link ? "hover:bg-mineshaft-700" : "cursor-default",
- !notification.isRead && "bg-mineshaft-800"
+ !notification.isRead && "bg-mineshaft-800",
+ isCritical && !notification.isRead && "border-l-2 border-l-red-500"
)}
>
<div className="flex w-full min-w-0 flex-col p-1">
- <div className="flex gap-2">
+ <div className="flex items-start gap-2">
{!notification.isRead && (
- <FontAwesomeIcon icon={faCircle} className="mt-0.5 size-2 text-yellow-400" />
+ <div className="flex h-5 items-center">
+ <FontAwesomeIcon
+ icon={faCircle}
+ className={twMerge(
+ "size-2 shrink-0",
+ isCritical ? "text-red-500" : "text-yellow-400"
+ )}
+ />
+ </div>
)}
<Tooltip
content={<Markdown>{notification.title}</Markdown>}
diff --git a/frontend/src/layouts/OrganizationLayout/components/NavBar/NotificationDropdown.tsx b/frontend/src/layouts/OrganizationLayout/components/NavBar/NotificationDropdown.tsx
index d72d9d59ef..6b5bcc54c4 100644
--- a/frontend/src/layouts/OrganizationLayout/components/NavBar/NotificationDropdown.tsx
+++ b/frontend/src/layouts/OrganizationLayout/components/NavBar/NotificationDropdown.tsx
@@ -2,6 +2,7 @@ import { useMemo } from "react";
import { faBell } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { useRouter } from "@tanstack/react-router";
+import { twMerge } from "tailwind-merge";
import {
ContentLoader,
@@ -15,6 +16,7 @@ import {
useUpdateNotification
} from "@app/hooks/api/notifications/mutations";
import { useGetMyNotifications } from "@app/hooks/api/notifications/queries";
+import { isCriticalNotification } from "@app/hooks/api/notifications/types";
import { Notification } from "./Notification";
@@ -31,13 +33,25 @@ export const NotificationDropdown = () => {
[notifications]
);
+ const criticalCount = useMemo(
+ () => notifications?.filter((n) => !n.isRead && isCriticalNotification(n.type)).length || 0,
+ [notifications]
+ );
+
+ const hasCritical = criticalCount > 0;
+
return (
<DropdownMenu modal={false}>
<DropdownMenuTrigger>
<div className="relative border border-r-0 border-mineshaft-500 px-2.5 py-1 hover:bg-mineshaft-600">
<FontAwesomeIcon icon={faBell} className="text-mineshaft-200" />
{unreadCount > 0 && (
- <span className="absolute -top-1 -right-1 flex h-4 min-w-4 items-center justify-center rounded-full bg-yellow-400 px-1 text-[10px] text-black">
+ <span
+ className={twMerge(
+ "absolute -top-1 -right-1 flex h-4 min-w-4 items-center justify-center rounded-full px-1 text-[10px]",
+ hasCritical ? "bg-red-500 text-white" : "bg-yellow-400 text-black"
+ )}
+ >
{unreadCount > 99 ? "99+" : unreadCount}
</span>
)}
@@ -50,7 +64,14 @@ export const NotificationDropdown = () => {
>
<div className="flex w-full flex-col">
<div className="flex items-center justify-between border-b border-mineshaft-500 px-3 py-2">
- <span className="font-medium text-white">Notifications</span>
+ <div className="flex items-center gap-2">
+ <span className="font-medium text-white">Notifications</span>
+ {hasCritical && (
+ <span className="rounded-full bg-red-500 px-1.5 py-0.5 text-[10px] font-medium text-white">
+ {criticalCount > 99 ? "99+" : criticalCount} critical
+ </span>
+ )}
+ </div>
<button
type="button"
className="text-xs font-medium text-mineshaft-300 hover:text-primary-400 disabled:pointer-events-none disabled:opacity-50"
diff --git a/frontend/src/layouts/OrganizationLayout/components/NetworkHealthBanner/NetworkHealthBanner.tsx b/frontend/src/layouts/OrganizationLayout/components/NetworkHealthBanner/NetworkHealthBanner.tsx
new file mode 100644
index 0000000000..79fd118d2a
--- /dev/null
+++ b/frontend/src/layouts/OrganizationLayout/components/NetworkHealthBanner/NetworkHealthBanner.tsx
@@ -0,0 +1,99 @@
+import { useMemo } from "react";
+import { 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";
+
+import { IconButton } from "@app/components/v2";
+import { apiRequest } from "@app/config/request";
+import { useOrganization, useOrgPermission } from "@app/context";
+import {
+ OrgGatewayPermissionActions,
+ OrgPermissionSubjects,
+ OrgRelayPermissionActions
+} from "@app/context/OrgPermissionContext/types";
+import { useToggle } from "@app/hooks";
+import { gatewaysQueryKeys } from "@app/hooks/api/gateways/queries";
+import { relayQueryKeys } from "@app/hooks/api/relays/queries";
+import { TRelay } from "@app/hooks/api/relays/types";
+
+const ONE_HOUR_MS = 60 * 60 * 1000;
+
+const isHeartbeatStale = (heartbeat?: string | null): boolean => {
+ if (!heartbeat) return true;
+ const heartbeatDate = new Date(heartbeat);
+ return heartbeatDate.getTime() < Date.now() - ONE_HOUR_MS;
+};
+
+export const NetworkHealthBanner = () => {
+ const [isDismissed, setIsDismissed] = useToggle(false);
+ const { currentOrg } = useOrganization();
+ const { permission } = useOrgPermission();
+
+ const canListGateways = permission.can(
+ OrgGatewayPermissionActions.ListGateways,
+ OrgPermissionSubjects.Gateway
+ );
+ const canListRelays = permission.can(
+ OrgRelayPermissionActions.ListRelays,
+ OrgPermissionSubjects.Relay
+ );
+
+ const { data: gateways } = useQuery({
+ ...gatewaysQueryKeys.list(),
+ enabled: canListGateways
+ });
+ const { data: relays } = useQuery({
+ queryKey: relayQueryKeys.list(),
+ queryFn: async (): Promise<TRelay[]> => {
+ const { data } = await apiRequest.get<TRelay[]>("/api/v1/relays");
+ return data;
+ },
+ enabled: canListRelays
+ });
+
+ const unreachableGateways = useMemo(
+ () => gateways?.filter((g) => isHeartbeatStale(g.heartbeat)).length ?? 0,
+ [gateways]
+ );
+
+ const unreachableRelays = useMemo(
+ () =>
+ relays?.filter((r) => r.orgId && r.heartbeat && isHeartbeatStale(r.heartbeat)).length ?? 0,
+ [relays]
+ );
+
+ if (!canListGateways && !canListRelays) return null;
+ if (isDismissed || (unreachableGateways === 0 && unreachableRelays === 0)) return null;
+
+ const parts: string[] = [];
+ if (unreachableGateways > 0) {
+ parts.push(`${unreachableGateways} gateway${unreachableGateways > 1 ? "s" : ""}`);
+ }
+ if (unreachableRelays > 0) {
+ parts.push(`${unreachableRelays} relay${unreachableRelays > 1 ? "s" : ""}`);
+ }
+
+ 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={() => setIsDismissed.on()}
+ >
+ <FontAwesomeIcon icon={faXmark} />
+ </IconButton>
+ </div>
+ );
+};
diff --git a/frontend/src/layouts/OrganizationLayout/components/NetworkHealthBanner/index.ts b/frontend/src/layouts/OrganizationLayout/components/NetworkHealthBanner/index.ts
new file mode 100644
index 0000000000..dd5cd43d99
--- /dev/null
+++ b/frontend/src/layouts/OrganizationLayout/components/NetworkHealthBanner/index.ts
@@ -0,0 +1 @@
+export { NetworkHealthBanner } from "./NetworkHealthBanner";