Skip to content

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

feat(insights): draw who can read a secret, how, and its ghost readers as a graph

Dimitris Staratzise385b0e68266
diff --git a/frontend/src/components/secrets/SecretAccessGraph/SecretAccessGraph.tsx b/frontend/src/components/secrets/SecretAccessGraph/SecretAccessGraph.tsx
new file mode 100644
index 0000000000..390f9cf55d
--- /dev/null
+++ b/frontend/src/components/secrets/SecretAccessGraph/SecretAccessGraph.tsx
@@ -0,0 +1,186 @@
+import { useCallback, useEffect, useMemo, useState } from "react";
+import {
+ Background,
+ BackgroundVariant,
+ ConnectionLineType,
+ Edge,
+ Node,
+ NodeMouseHandler,
+ ReactFlow,
+ ReactFlowProvider,
+ useEdgesState,
+ useNodesState,
+ useReactFlow
+} from "@xyflow/react";
+import { MaximizeIcon, MinusIcon, PlusIcon } from "lucide-react";
+
+import { IconButton } from "@app/components/v3";
+
+import { buildAccessGraph, TAccessGraphInput } from "./buildAccessGraph";
+import { BandLabelNode, GhostNode, GroupNode, ReaderNode, SecretNode } from "./nodes";
+
+const NODE_TYPES = {
+ reader: ReaderNode,
+ group: GroupNode,
+ secret: SecretNode,
+ ghost: GhostNode,
+ bandLabel: BandLabelNode
+};
+
+const DIMMED_OPACITY = 0.2;
+
+type Props = {
+ input: TAccessGraphInput;
+};
+
+// Everything reachable from a node along its edges, both ways: a reader lights up its group and the
+// secret, a group lights up its members and the secret.
+const connectedTo = (nodeId: string, edges: Edge[]) => {
+ const reached = new Set([nodeId]);
+ const walk = (from: string, direction: "source" | "target") => {
+ const to = direction === "source" ? "target" : "source";
+ edges.forEach((edge) => {
+ if (edge[direction] === from && !reached.has(edge[to])) {
+ reached.add(edge[to]);
+ walk(edge[to], direction);
+ }
+ });
+ };
+ walk(nodeId, "source");
+ walk(nodeId, "target");
+ return reached;
+};
+
+const SecretAccessGraphContent = ({ input }: Props) => {
+ const {
+ nodes: builtNodes,
+ edges: builtEdges,
+ contentHeight,
+ contentWidth
+ } = useMemo(() => buildAccessGraph(input), [input]);
+
+ const [nodes, setNodes, onNodesChange] = useNodesState<Node>(builtNodes);
+ const [edges, setEdges, onEdgesChange] = useEdgesState<Edge>(builtEdges);
+ const [focusedId, setFocusedId] = useState<string>();
+
+ useEffect(() => {
+ setNodes(builtNodes);
+ setEdges(builtEdges);
+ setFocusedId(undefined);
+ }, [builtNodes, builtEdges, setNodes, setEdges]);
+
+ // Focus dims rather than hides, so the viewer keeps their bearings.
+ const focused = useMemo(
+ () => (focusedId ? connectedTo(focusedId, builtEdges) : undefined),
+ [focusedId, builtEdges]
+ );
+ const displayedNodes = useMemo(
+ () =>
+ nodes.map((node) => ({
+ ...node,
+ style: {
+ ...node.style,
+ opacity:
+ !focused || focused.has(node.id) || node.type === "bandLabel" ? 1 : DIMMED_OPACITY
+ }
+ })),
+ [nodes, focused]
+ );
+ const displayedEdges = useMemo(
+ () =>
+ edges.map((edge) => ({
+ ...edge,
+ style: {
+ ...edge.style,
+ opacity:
+ !focused || (focused.has(edge.source) && focused.has(edge.target))
+ ? edge.style?.opacity
+ : DIMMED_OPACITY * 0.5
+ }
+ })),
+ [edges, focused]
+ );
+
+ // Selecting a reader or group focuses its path; selecting it again, or anything else, clears the focus.
+ const onNodeClick: NodeMouseHandler = useCallback((_, node) => {
+ const isFocusable = node.type === "reader" || node.type === "group";
+ setFocusedId((current) => (isFocusable && current !== node.id ? node.id : undefined));
+ }, []);
+
+ return (
+ <div
+ className="flex flex-1 flex-col"
+ style={{ minHeight: contentHeight, minWidth: contentWidth }}
+ >
+ <ReactFlow
+ nodes={displayedNodes}
+ edges={displayedEdges}
+ onNodesChange={onNodesChange}
+ onEdgesChange={onEdgesChange}
+ onNodeClick={onNodeClick}
+ onPaneClick={() => setFocusedId(undefined)}
+ nodeTypes={NODE_TYPES}
+ connectionLineType={ConnectionLineType.SmoothStep}
+ defaultEdgeOptions={{ type: "smoothstep" }}
+ proOptions={{ hideAttribution: true }}
+ nodesDraggable={false}
+ nodesConnectable={false}
+ edgesFocusable={false}
+ elementsSelectable={false}
+ // The canvas sits in a scrolling sheet, so the wheel belongs to the sheet. Zoom stays on the
+ // controls and pinch, otherwise scrolling past the graph traps the viewer inside it.
+ zoomOnScroll={false}
+ preventScrolling={false}
+ minZoom={0.4}
+ maxZoom={1.6}
+ className="h-full flex-1 bg-background"
+ >
+ <Background
+ variant={BackgroundVariant.Dots}
+ gap={16}
+ size={1}
+ color="var(--color-border)"
+ />
+ </ReactFlow>
+ </div>
+ );
+};
+
+// Outside the scrolling element, so the controls stay put however tall the graph gets.
+const ZoomControls = () => {
+ const { zoomIn, zoomOut, setViewport } = useReactFlow();
+ return (
+ <div className="absolute right-3 bottom-3 z-10 flex flex-col overflow-hidden rounded-md border border-border bg-card">
+ <IconButton variant="ghost" size="xs" aria-label="Zoom in" onClick={() => zoomIn()}>
+ <PlusIcon />
+ </IconButton>
+ <IconButton variant="ghost" size="xs" aria-label="Zoom out" onClick={() => zoomOut()}>
+ <MinusIcon />
+ </IconButton>
+ <IconButton
+ variant="ghost"
+ size="xs"
+ aria-label="Reset zoom"
+ onClick={() => setViewport({ x: 0, y: 0, zoom: 1 })}
+ >
+ <MaximizeIcon />
+ </IconButton>
+ </div>
+ );
+};
+
+export const SecretAccessGraph = ({ input }: Props) => (
+ <ReactFlowProvider>
+ <div className="relative flex h-[560px] min-h-0 rounded-md border border-border">
+ <div className="flex min-h-0 thin-scrollbar flex-1 overflow-auto">
+ <SecretAccessGraphContent input={input} />
+ </div>
+ <ZoomControls />
+ </div>
+ <p className="text-xs text-muted">
+ {input.hasReadActivity
+ ? `Solid lines are reads in the last ${input.windowDays} days, dashed lines are access with no reads. Select a reader or group to follow its path.`
+ : "Read activity is not visible for your role, so the lines only show who can read the value. Select a reader or group to follow its path."}
+ </p>
+ </ReactFlowProvider>
+);
diff --git a/frontend/src/components/secrets/SecretAccessGraph/buildAccessGraph.test.ts b/frontend/src/components/secrets/SecretAccessGraph/buildAccessGraph.test.ts
new file mode 100644
index 0000000000..31cf827271
--- /dev/null
+++ b/frontend/src/components/secrets/SecretAccessGraph/buildAccessGraph.test.ts
@@ -0,0 +1,102 @@
+import { describe, expect, test } from "vitest";
+
+import {
+ buildAccessGraph,
+ groupNodeId,
+ readerNodeId,
+ SECRET_NODE_ID,
+ TAccessGraphInput
+} from "./buildAccessGraph";
+
+const input: TAccessGraphInput = {
+ secret: { key: "DB_PASSWORD", environment: "dev", secretPath: "/" },
+ readers: [
+ {
+ id: "alice",
+ type: "user",
+ isDirect: true,
+ groupIds: [],
+ lastReadAt: "2026-10-18T00:00:00.000Z"
+ },
+ { id: "ci", name: "ci", type: "identity", isDirect: false, groupIds: ["devs"] },
+ {
+ id: "bob",
+ type: "user",
+ isDirect: true,
+ groupIds: ["devs"],
+ lastReadAt: "2026-10-01T00:00:00.000Z"
+ }
+ ],
+ groups: [{ id: "devs", name: "devs", memberCount: 2 }],
+ ghosts: [{ id: "gone", name: null, type: "identity", lastReadAt: "2026-10-10T00:00:00.000Z" }],
+ hasReadActivity: true,
+ windowDays: 30
+};
+
+describe("buildAccessGraph", () => {
+ const { nodes, edges } = buildAccessGraph(input);
+ const nodeById = new Map(nodes.map((node) => [node.id, node]));
+
+ test("lays readers, groups and the secret out in three columns with ghosts under the readers", () => {
+ const reader = nodeById.get(readerNodeId({ type: "user", id: "alice" }));
+ const group = nodeById.get(groupNodeId({ id: "devs" }));
+ const secret = nodeById.get(SECRET_NODE_ID);
+ const ghost = nodeById.get("ghost-identity-gone");
+ expect(reader && group && secret && ghost).toBeTruthy();
+ expect(reader!.position.x).toBeLessThan(group!.position.x);
+ expect(group!.position.x).toBeLessThan(secret!.position.x);
+ expect(ghost!.position.x).toBe(reader!.position.x);
+ expect(ghost!.position.y).toBeGreaterThan(
+ Math.max(...input.readers.map((entry) => nodeById.get(readerNodeId(entry))!.position.y))
+ );
+ });
+
+ test("puts the readers with no reads first", () => {
+ const readerYs = input.readers.map((entry) => [
+ entry.id,
+ nodeById.get(readerNodeId(entry))!.position.y
+ ]);
+ const sorted = [...readerYs].sort((a, b) => Number(a[1]) - Number(b[1])).map(([id]) => id);
+ expect(sorted).toEqual(["ci", "alice", "bob"]);
+ });
+
+ test("connects direct readers to the secret and group-only readers through their group", () => {
+ const edgeOf = (source: string) => edges.filter((edge) => edge.source === source);
+ expect(edgeOf(readerNodeId({ type: "user", id: "alice" })).map((edge) => edge.target)).toEqual([
+ SECRET_NODE_ID
+ ]);
+ expect(edgeOf(readerNodeId({ type: "user", id: "bob" })).map((edge) => edge.target)).toEqual([
+ SECRET_NODE_ID
+ ]);
+ expect(edgeOf(readerNodeId({ type: "identity", id: "ci" })).map((edge) => edge.target)).toEqual(
+ [groupNodeId({ id: "devs" })]
+ );
+ expect(edgeOf(groupNodeId({ id: "devs" })).map((edge) => edge.target)).toEqual([
+ SECRET_NODE_ID
+ ]);
+ expect(edgeOf("ghost-identity-gone")).toEqual([]);
+ });
+
+ test("dashes the edge of a reader with no reads, and no edge when read activity is unknown", () => {
+ const unread = edges.find(
+ (edge) => edge.source === readerNodeId({ type: "identity", id: "ci" })
+ );
+ const read = edges.find((edge) => edge.source === readerNodeId({ type: "user", id: "alice" }));
+ expect(unread?.style?.strokeDasharray).toBe("5 5");
+ expect(read?.style?.strokeDasharray).toBeUndefined();
+
+ const unknown = buildAccessGraph({ ...input, hasReadActivity: false });
+ expect(unknown.edges.every((edge) => edge.style?.strokeDasharray === undefined)).toBe(true);
+ });
+
+ test("drops the group column when no reader depends on a group", () => {
+ const direct = buildAccessGraph({ ...input, readers: [input.readers[0]], groups: [] });
+ const withGroups = buildAccessGraph(input);
+ const secretX = (graph: ReturnType<typeof buildAccessGraph>) =>
+ graph.nodes.find((node) => node.id === SECRET_NODE_ID)!.position.x;
+ expect(secretX(direct)).toBeLessThan(secretX(withGroups));
+ expect(direct.nodes.some((node) => node.type === "group")).toBe(false);
+ });
+});
diff --git a/frontend/src/components/secrets/SecretAccessGraph/buildAccessGraph.ts b/frontend/src/components/secrets/SecretAccessGraph/buildAccessGraph.ts
new file mode 100644
index 0000000000..e23842ea7c
--- /dev/null
+++ b/frontend/src/components/secrets/SecretAccessGraph/buildAccessGraph.ts
@@ -0,0 +1,267 @@
+import { Edge, Node } from "@xyflow/react";
+
+import { TSecretExposure } from "@app/hooks/api/secretInsights/types";
+
+export type TAccessGraphActorType = "user" | "identity";
+
+export type TAccessGraphReader = {
+ id: string;
+ name: string;
+ type: TAccessGraphActorType;
+ // Granted on their own, as opposed to only through a group.
+ isDirect: boolean;
+ groupIds: string[];
+ lastReadAt?: string;
+};
+
+export type TAccessGraphGroup = {
+ id: string;
+ name: string;
+ memberCount: number;
+};
+
+export type TAccessGraphGhost = {
+ id: string;
+ // Null when the reader has since been deleted.
+ name: string | null;
+ type: TAccessGraphActorType;
+ lastReadAt: string;
+};
+
+export type TAccessGraphSecret = {
+ key: string;
+ environment: string;
+ secretPath: string;
+ exposure?: TSecretExposure;
+};
+
+export type TAccessGraphInput = {
+ secret: TAccessGraphSecret;
+ readers: TAccessGraphReader[];
+ groups: TAccessGraphGroup[];
+ ghosts: TAccessGraphGhost[];
+ // False when the viewer cannot see read activity, so no edge claims a read or its absence.
+ hasReadActivity: boolean;
+ windowDays: number;
+};
+
+export type TReaderNodeData = {
+ reader: TAccessGraphReader;
+ groupNames: string[];
+ hasReadActivity: boolean;
+ windowDays: number;
+};
+
+export type TGroupNodeData = { group: TAccessGraphGroup };
+export type TSecretNodeData = { secret: TAccessGraphSecret };
+export type TGhostNodeData = { ghost: TAccessGraphGhost };
+export type TBandLabelNodeData = { label: string; detail: string; tone?: "neutral" | "warning" };
+
+export const NODE_WIDTH = 208;
+const READER_NODE_HEIGHT = 84;
+const GROUP_NODE_HEIGHT = 64;
+const SECRET_NODE_HEIGHT = 104;
+const GHOST_NODE_HEIGHT = 76;
+const BAND_LABEL_HEIGHT = 36;
+const BAND_GAP = 20;
+const HEADER_GAP = 8;
+// Three columns plus their gaps fit the sheet without horizontal panning.
+const COLUMN_GAP = 96;
+const ROW_GAP = 16;
+const MARGIN = 24;
+const COLUMN_TOP = MARGIN + BAND_LABEL_HEIGHT + HEADER_GAP;
+
+export const SECRET_NODE_ID = "secret";
+export const readerNodeId = (reader: Pick<TAccessGraphReader, "type" | "id">) =>
+ `reader-${reader.type}-${reader.id}`;
+export const groupNodeId = (group: Pick<TAccessGraphGroup, "id">) => `group-${group.id}`;
+
+const columnHeight = (count: number, height: number) =>
+ count ? count * height + (count - 1) * ROW_GAP : 0;
+
+// Centres a column of `count` nodes against the tallest one. Positions are exact, so the canvas is sized to
+// the content and nothing has to be fitted after the nodes are measured.
+const centredOffset = (count: number, height: number, tallest: number) =>
+ COLUMN_TOP + Math.max(0, (tallest - columnHeight(count, height)) / 2);
+
+const stackColumn = (offset: number, height: number) => (index: number) =>
+ offset + index * (height + ROW_GAP);
+
+const bandLabelNode = (
+ id: string,
+ x: number,
+ firstNodeY: number,
+ data: TBandLabelNodeData
+): Node => ({
+ id,
+ type: "bandLabel",
+ position: { x, y: firstNodeY - HEADER_GAP - BAND_LABEL_HEIGHT },
+ width: NODE_WIDTH,
+ height: BAND_LABEL_HEIGHT,
+ selectable: false,
+ data
+});
+
+// Solid means a read in the window, dashed means entitled with none. Without read activity every edge is
+// neutral, because unknown is not the same as unused.
+const readerEdgeStyle = (reader: TAccessGraphReader, hasReadActivity: boolean) => {
+ if (!hasReadActivity) return { stroke: "var(--color-muted)", strokeWidth: 1, opacity: 0.5 };
+ return reader.lastReadAt
+ ? { stroke: "var(--color-foreground)", strokeWidth: 1.5, opacity: 0.55 }
+ : { stroke: "var(--color-muted)", strokeWidth: 1, strokeDasharray: "5 5", opacity: 0.45 };
+};
+
+export const buildAccessGraph = ({
+ secret,
+ readers,
+ groups,
+ ghosts,
+ hasReadActivity,
+ windowDays
+}: TAccessGraphInput) => {
+ const nodes: Node[] = [];
+ const edges: Edge[] = [];
+
+ // The ones with no reads come first: they are what the viewer is here to find.
+ const orderedReaders = [...readers].sort((a, b) => {
+ if (hasReadActivity && Boolean(a.lastReadAt) !== Boolean(b.lastReadAt)) {
+ return a.lastReadAt ? 1 : -1;
+ }
+ return a.name.localeCompare(b.name);
+ });
+ const groupById = new Map(groups.map((group) => [group.id, group]));
+
+ const secretColumnX = MARGIN + (NODE_WIDTH + COLUMN_GAP) * (groups.length ? 2 : 1);
+ const groupColumnX = MARGIN + NODE_WIDTH + COLUMN_GAP;
+
+ const tallestColumn = Math.max(
+ columnHeight(orderedReaders.length, READER_NODE_HEIGHT),
+ columnHeight(groups.length, GROUP_NODE_HEIGHT),
+ SECRET_NODE_HEIGHT
+ );
+ const readerOffset = centredOffset(orderedReaders.length, READER_NODE_HEIGHT, tallestColumn);
+ const groupOffset = centredOffset(groups.length, GROUP_NODE_HEIGHT, tallestColumn);
+ const secretOffset = COLUMN_TOP + (tallestColumn - SECRET_NODE_HEIGHT) / 2;
+ const readerY = stackColumn(readerOffset, READER_NODE_HEIGHT);
+ const groupY = stackColumn(groupOffset, GROUP_NODE_HEIGHT);
+
+ nodes.push(
+ bandLabelNode("band-readers", MARGIN, readerOffset, {
+ label: `Can read · ${orderedReaders.length}`,
+ detail: "can read the value today"
+ }),
+ bandLabelNode("band-secret", secretColumnX, secretOffset, {
+ label: "Secret",
+ detail: "the value they read"
+ })
+ );
+ if (groups.length) {
+ nodes.push(
+ bandLabelNode("band-groups", groupColumnX, groupOffset, {
+ label: `Groups · ${groups.length}`,
+ detail: "grant the access"
+ })
+ );
+ }
+
+ orderedReaders.forEach((reader, index) => {
+ const nodeId = readerNodeId(reader);
+ const viaGroups = reader.isDirect
+ ? []
+ : reader.groupIds.flatMap((groupId) => groupById.get(groupId) ?? []);
+ nodes.push({
+ id: nodeId,
+ type: "reader",
+ position: { x: MARGIN, y: readerY(index) },
+ width: NODE_WIDTH,
+ height: READER_NODE_HEIGHT,
+ data: {
+ reader,
+ groupNames: viaGroups.map((group) => group.name),
+ hasReadActivity,
+ windowDays
+ } satisfies TReaderNodeData
+ });
+
+ const style = readerEdgeStyle(reader, hasReadActivity);
+ // A reader granted access on their own connects straight to the secret, even if a group grants it too:
+ // the group is not what gives them the value.
+ if (reader.isDirect || !viaGroups.length) {
+ edges.push({ id: `edge-${nodeId}-secret`, source: nodeId, target: SECRET_NODE_ID, style });
+ } else {
+ viaGroups.forEach((group) => {
+ edges.push({
+ id: `edge-${nodeId}-${groupNodeId(group)}`,
+ source: nodeId,
+ target: groupNodeId(group),
+ style
+ });
+ });
+ }
+ });
+
+ groups.forEach((group, index) => {
+ const nodeId = groupNodeId(group);
+ nodes.push({
+ id: nodeId,
+ type: "group",
+ position: { x: groupColumnX, y: groupY(index) },
+ width: NODE_WIDTH,
+ height: GROUP_NODE_HEIGHT,
+ data: { group } satisfies TGroupNodeData
+ });
+ edges.push({
+ id: `edge-${nodeId}-secret`,
+ source: nodeId,
+ target: SECRET_NODE_ID,
+ style: { stroke: "var(--color-accent)", strokeWidth: 1.5, opacity: 0.5 }
+ });
+ });
+
+ nodes.push({
+ id: SECRET_NODE_ID,
+ type: "secret",
+ position: { x: secretColumnX, y: secretOffset },
+ width: NODE_WIDTH,
+ height: SECRET_NODE_HEIGHT,
+ data: { secret } satisfies TSecretNodeData
+ });
+
+ // No edges from here on: a ghost reader has no current path to the secret, and drawing one would say
+ // they can still read the value.
+ const firstGhostY =
+ readerOffset +
+ columnHeight(orderedReaders.length, READER_NODE_HEIGHT) +
+ BAND_GAP +
+ BAND_LABEL_HEIGHT +
+ HEADER_GAP;
+ const ghostY = stackColumn(firstGhostY, GHOST_NODE_HEIGHT);
+ if (ghosts.length) {
+ nodes.push(
+ bandLabelNode("band-ghosts", MARGIN, firstGhostY, {
+ label: `Ghost readers · ${ghosts.length}`,
+ detail: "no path to the secret",
+ tone: "warning"
+ })
+ );
+ ghosts.forEach((ghost, index) => {
+ nodes.push({
+ id: `ghost-${ghost.type}-${ghost.id}`,
+ type: "ghost",
+ position: { x: MARGIN, y: ghostY(index) },
+ width: NODE_WIDTH,
+ height: GHOST_NODE_HEIGHT,
+ selectable: false,
+ data: { ghost } satisfies TGhostNodeData
+ });
+ });
+ }
+
+ const contentHeight =
+ (ghosts.length
+ ? firstGhostY + columnHeight(ghosts.length, GHOST_NODE_HEIGHT)
+ : COLUMN_TOP + tallestColumn) + MARGIN;
+ const contentWidth = secretColumnX + NODE_WIDTH + MARGIN;
+
+ return { nodes, edges, contentHeight, contentWidth };
+};
diff --git a/frontend/src/components/secrets/SecretAccessGraph/index.ts b/frontend/src/components/secrets/SecretAccessGraph/index.ts
new file mode 100644
index 0000000000..a45b7218e2
--- /dev/null
+++ b/frontend/src/components/secrets/SecretAccessGraph/index.ts
@@ -0,0 +1,2 @@
+export type { TAccessGraphInput } from "./buildAccessGraph";
+export { SecretAccessGraph } from "./SecretAccessGraph";
diff --git a/frontend/src/components/secrets/SecretAccessGraph/nodes.tsx b/frontend/src/components/secrets/SecretAccessGraph/nodes.tsx
new file mode 100644
index 0000000000..2233464da3
--- /dev/null
+++ b/frontend/src/components/secrets/SecretAccessGraph/nodes.tsx
@@ -0,0 +1,143 @@
+import { Handle, NodeProps, Position } from "@xyflow/react";
+
+import { SecretExposureBadge } from "@app/components/secrets/SecretExposureScore";
+import { formatReadDay } from "@app/components/secrets/SecretReadStatusBadge";
+import { cn } from "@app/components/v3/utils";
+
+import {
+ TAccessGraphActorType,
+ TBandLabelNodeData,
+ TGhostNodeData,
+ TGroupNodeData,
+ TReaderNodeData,
+ TSecretNodeData
+} from "./buildAccessGraph";
+
+const TYPE_LABEL: Record<TAccessGraphActorType, string> = {
+ user: "user",
+ identity: "machine identity"
+};
+
+const hiddenHandle = "!opacity-0";
+
+export const ReaderNode = ({ data }: NodeProps & { data: TReaderNodeData }) => {
+ const { reader, groupNames, hasReadActivity, windowDays } = data;
+ const hasReads = Boolean(reader.lastReadAt);
+
+ let status: string | undefined;
+ if (hasReadActivity) {
+ status = reader.lastReadAt
+ ? `Read ${formatReadDay(reader.lastReadAt).toLowerCase()}`
+ : `No reads in ${windowDays} days`;
+ }
+
+ return (
+ <div
+ className={cn(
+ "flex h-full w-full cursor-pointer flex-col gap-1 rounded-md border px-2.5 py-2",
+ hasReads || !hasReadActivity
+ ? "border-border bg-card"
+ : "border-dashed border-border bg-transparent"
+ )}
+ >
+ <div className="flex items-baseline justify-between gap-2">
+ <p
+ className={cn(
+ "truncate font-mono text-xs",
+ hasReads || !hasReadActivity ? "text-foreground" : "text-accent"
+ )}
+ >
+ {reader.name}
+ </p>
+ <span className="shrink-0 text-xs text-muted">{TYPE_LABEL[reader.type]}</span>
+ </div>
+ {status && (
+ <span className={cn("truncate text-xs", hasReads ? "text-accent" : "text-warning")}>
+ {status}
+ </span>
+ )}
+ <span className="mt-auto truncate text-xs text-muted">
+ {groupNames.length ? `Via ${groupNames.join(", ")}` : "Direct access"}
+ </span>
+ <Handle type="source" position={Position.Right} className={hiddenHandle} />
+ </div>
+ );
+};
+
+export const GroupNode = ({ data }: NodeProps & { data: TGroupNodeData }) => {
+ const { group } = data;
+ return (
+ <div className="flex h-full w-full flex-col gap-1 rounded-md border border-border bg-card px-2.5 py-2">
+ <div className="flex items-baseline justify-between gap-2">
+ <p className="truncate font-mono text-xs text-foreground">{group.name}</p>
+ <span className="shrink-0 text-xs text-muted">group</span>
+ </div>
+ <span className="mt-auto truncate text-xs text-muted">
+ {group.memberCount} {group.memberCount === 1 ? "member" : "members"} can read the value
+ </span>
+ <Handle type="target" position={Position.Left} className={hiddenHandle} />
+ <Handle type="source" position={Position.Right} className={hiddenHandle} />
+ </div>
+ );
+};
+
+export const SecretNode = ({ data }: NodeProps & { data: TSecretNodeData }) => {
+ const { secret } = data;
+ return (
+ <div className="flex h-full w-full flex-col gap-1 rounded-md border border-secret/50 bg-secret/10 px-2.5 py-2">
+ <span className="text-xs tracking-wide text-accent uppercase">Secret</span>
+ <p className="truncate font-mono text-sm text-foreground">{secret.key}</p>
+ <p className="truncate font-mono text-xs text-accent">
+ {secret.secretPath} · {secret.environment}
+ </p>
+ {secret.exposure && (
+ <div className="mt-auto flex items-center gap-1.5 border-t border-secret/25 pt-1.5 text-xs text-muted">
+ Exposure <SecretExposureBadge exposure={secret.exposure} />
+ </div>
+ )}
+ <Handle type="target" position={Position.Left} className={hiddenHandle} />
+ </div>
+ );
+};
+
+// A reader of this value who cannot read it today. No handle on purpose: there is no current path from
+// them to the secret, and an edge would say otherwise.
+export const GhostNode = ({ data }: NodeProps & { data: TGhostNodeData }) => {
+ const { ghost } = data;
+ return (
+ <div className="flex h-full w-full flex-col gap-1 rounded-md border border-warning/40 bg-warning/5 px-2.5 py-2">
+ <div className="flex items-baseline justify-between gap-2">
+ <p
+ className={cn(
+ "truncate font-mono text-xs",
+ ghost.name ? "text-foreground" : "text-muted italic"
+ )}
+ >
+ {ghost.name ?? `Deleted ${TYPE_LABEL[ghost.type]}`}
+ </p>
+ <span className="shrink-0 text-xs text-muted">{TYPE_LABEL[ghost.type]}</span>
+ </div>
+ <span className="truncate text-xs text-warning">
+ {ghost.name ? "Access removed" : "Deleted"} · still knows the value
+ </span>
+ <span className="mt-auto truncate text-xs text-accent">
+ Read {formatReadDay(ghost.lastReadAt).toLowerCase()}
+ </span>
+ </div>
+ );
+};
+
+// A section heading inside the canvas, so it takes part in the same column math as the nodes it labels.
+export const BandLabelNode = ({ data }: NodeProps & { data: TBandLabelNodeData }) => (
+ <div className="flex h-full w-full flex-col justify-end gap-0.5 whitespace-nowrap">
+ <span
+ className={cn(
+ "text-xs tracking-wide uppercase",
+ data.tone === "warning" ? "text-warning" : "text-accent"
+ )}
+ >
+ {data.label}
+ </span>
+ <span className="text-xs text-muted">{data.detail}</span>
+ </div>
+);
diff --git a/frontend/src/components/secrets/SecretReadStatusBadge.tsx b/frontend/src/components/secrets/SecretReadStatusBadge.tsx
index 154fc85c50..38f2613f34 100644
--- a/frontend/src/components/secrets/SecretReadStatusBadge.tsx
+++ b/frontend/src/components/secrets/SecretReadStatusBadge.tsx
@@ -7,7 +7,7 @@ type Props = {
};
// Only a reader's first read of the day is recorded, so the time of day would understate later reads.
-const formatReadDay = (lastReadAt: string) => {
+export const formatReadDay = (lastReadAt: string) => {
const days = differenceInCalendarDays(new Date(), new Date(lastReadAt));
if (days <= 0) return "Today";
if (days === 1) return "Yesterday";
diff --git a/frontend/src/pages/secret-manager/InsightsPage/components/SecretExposureCard.tsx b/frontend/src/pages/secret-manager/InsightsPage/components/SecretExposureCard.tsx
index 535ac8cc7f..11ea0148e4 100644
--- a/frontend/src/pages/secret-manager/InsightsPage/components/SecretExposureCard.tsx
+++ b/frontend/src/pages/secret-manager/InsightsPage/components/SecretExposureCard.tsx
@@ -289,6 +289,7 @@ export const SecretExposureCard = () => {
secretKey={selectedSecret.secretKey}
environment={selectedSecret.environment}
secretPath={selectedSecret.secretPath}
+ defaultView="graph"
/>
</>
)}
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretAccessInsights.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretAccessInsights.tsx
index 48a6989294..8a75371428 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretAccessInsights.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretAccessInsights.tsx
@@ -11,8 +11,10 @@ import {
HardDriveIcon,
InfoIcon,
MoreHorizontalIcon,
+ NetworkIcon,
PlusIcon,
SearchIcon,
+ TableIcon,
TriangleAlertIcon,
UserIcon,
UserPlusIcon,
@@ -20,10 +22,12 @@ import {
} from "lucide-react";
import { createNotification } from "@app/components/notifications";
+import { SecretAccessGraph, TAccessGraphInput } from "@app/components/secrets/SecretAccessGraph";
import { SecretExposurePanel } from "@app/components/secrets/SecretExposureScore";
import { SecretReadStatusBadge } from "@app/components/secrets/SecretReadStatusBadge";
import {
Button,
+ ButtonGroup,
Command,
CommandEmpty,
CommandGroup,
@@ -100,8 +104,20 @@ type Props = {
secretKey: string;
environment: string;
secretPath: string;
+ defaultView?: AccessView;
};
+type AccessView = "graph" | "table";
+
+const READ_ACTIVITY_WINDOW_DAYS = 30;
+
+const grantsReadValue = (actions: Iterable<string>) =>
+ [...actions].some(
+ (action) =>
+ action === ProjectPermissionSecretActions.ReadValue ||
+ action === ProjectPermissionSecretActions.DescribeAndReadValue
+ );
+
type EditingPrivilege = {
type: "user" | "identity";
membershipId: string;
@@ -411,7 +427,12 @@ function AddMemberPopover({
);
}
-export function SecretAccessInsights({ secretKey, environment, secretPath }: Props) {
+export function SecretAccessInsights({
+ secretKey,
+ environment,
+ secretPath,
+ defaultView = "table"
+}: Props) {
const { currentOrg } = useOrganization();
const { currentProject } = useProject();
const { permission } = useProjectPermission();
@@ -421,6 +442,7 @@ export function SecretAccessInsights({ secretKey, environment, secretPath }: Pro
const [searchFilter, setSearchFilter] = useState("");
const [typeFilters, setTypeFilters] = useState<Set<AccessRowType>>(() => new Set());
const [showAllEntities, setShowAllEntities] = useState(true);
+ const [view, setView] = useState<AccessView>(defaultView);
const toggleTypeFilter = (type: AccessRowType) => {
setTypeFilters((prev) => {
@@ -496,14 +518,77 @@ export function SecretAccessInsights({ secretKey, environment, secretPath }: Pro
readActivityDescription = `Reads by users and machine identities since ${format(new Date(readActivity.trackedSince), "PP")}, including reads through imports and references.`;
}
+ // Readers connect to the secret directly, or through the groups that grant them the value; ghost readers
+ // hang below with no path to it.
+ const graphInput = useMemo<TAccessGraphInput | undefined>(() => {
+ if (!secretAccessList) return undefined;
+ const groups = secretAccessList.groups.filter((group) => grantsReadValue(group.allowedActions));
+ const toReader = (
+ entry: SecretAccessListEntry,
+ type: "user" | "identity",
+ memberField: "userIds" | "identityIds"
+ ) => {
+ const isDirect = grantsReadValue(entry.allowedActions);
+ const groupIds = groups
+ .filter((group) => group[memberField].includes(entry.id))
+ .map((group) => group.id);
+ if (!isDirect && !groupIds.length) return [];
+ return [
+ {
+ id: entry.id,
+ name: entry.name,
+ type,
+ isDirect,
+ groupIds,
+ lastReadAt: lastReads.get(`${type}:${entry.id}`)?.lastReadAt
+ }
+ ];
+ };
+ const readers = [
+ ...secretAccessList.users.flatMap((user) => toReader(user, "user", "userIds")),
+ ...secretAccessList.identities.flatMap((identity) =>
+ toReader(identity, "identity", "identityIds")
+ )
+ ];
+ const groupIdsInUse = new Set(
+ readers.flatMap((reader) => (reader.isDirect ? [] : reader.groupIds))
+ );
+ return {
+ secret: { key: secretKey, environment, secretPath, exposure: readActivity?.exposure },
+ readers,
+ groups: groups
+ .filter((group) => groupIdsInUse.has(group.id))
+ .map((group) => ({
+ id: group.id,
+ name: group.name,
+ memberCount: group.userIds.length + group.identityIds.length
+ })),
+ ghosts: (readActivity?.ghostReaders ?? []).map((ghost) => ({
+ id: ghost.actorId,
+ name: ghost.actorName,
+ type: ghost.actorType,
+ lastReadAt: ghost.lastReadAt
+ })),
+ hasReadActivity: Boolean(canReadInsights && readActivity),
+ windowDays: READ_ACTIVITY_WINDOW_DAYS
+ };
+ }, [
+ secretAccessList,
+ lastReads,
+ readActivity,
+ canReadInsights,
+ secretKey,
+ environment,
+ secretPath
+ ]);
+
const renderLastRead = (row: AccessRow) => {
if (row.type === "group") return null;
// A folder read is credited to every secret in the folder, including ones this row can only describe.
- const canReadValue = [...row.entry.allowedActions, ...(row.inheritedActions ?? [])].some(
- (action) =>
- action === ProjectPermissionSecretActions.ReadValue ||
- action === ProjectPermissionSecretActions.DescribeAndReadValue
- );
+ const canReadValue = grantsReadValue([
+ ...row.entry.allowedActions,
+ ...(row.inheritedActions ?? [])
+ ]);
if (!canReadValue) return null;
if (isReadActivityLoading) return <Skeleton className="h-4 w-20 rounded" />;
if (!readActivity) return null;
@@ -645,309 +730,348 @@ export function SecretAccessInsights({ secretKey, environment, secretPath }: Pro
<SecretExposurePanel exposure={readActivity?.exposure} />
)}
<div className="flex items-center gap-2">
- <Label className="cursor-pointer gap-1.5 text-xs whitespace-nowrap text-muted">
- <Toggle
- size="sm"
- variant="project"
- checked={showAllEntities}
- onCheckedChange={setShowAllEntities}
- />
- Show all members
- <Tooltip>
- <TooltipTrigger asChild>
- <InfoIcon className="size-3.5 text-muted" />
- </TooltipTrigger>
- <TooltipContent side="bottom" className="max-w-60">
- When enabled, all project members are shown including those without any access to
- this secret.
- </TooltipContent>
- </Tooltip>
- </Label>
- <InputGroup className="flex-1">
- <InputGroupAddon>
- <SearchIcon />
- </InputGroupAddon>
- <InputGroupInput
- value={searchFilter}
- onChange={(e) => setSearchFilter(e.target.value)}
- placeholder="Search by name..."
- />
- </InputGroup>
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <IconButton
- variant={isFilterActive ? "project" : "outline"}
- aria-label="Filter by type"
- >
- <FilterIcon />
- </IconButton>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- {ALL_TYPE_FILTERS.map((type) => {
- const { icon: TypeIcon, label } = TYPE_CONFIG[type];
- return (
- <DropdownMenuCheckboxItem
- key={type}
- checked={typeFilters.has(type)}
- onCheckedChange={() => toggleTypeFilter(type)}
- onSelect={(e) => e.preventDefault()}
+ <ButtonGroup>
+ <Button
+ size="xs"
+ variant={view === "graph" ? "project" : "outline"}
+ aria-pressed={view === "graph"}
+ onClick={() => setView("graph")}
+ >
+ <NetworkIcon />
+ Graph
+ </Button>
+ <Button
+ size="xs"
+ variant={view === "table" ? "project" : "outline"}
+ aria-pressed={view === "table"}
+ onClick={() => setView("table")}
+ >
+ <TableIcon />
+ Table
+ </Button>
+ </ButtonGroup>
+ {view === "table" && (
+ <>
+ <Label className="cursor-pointer gap-1.5 text-xs whitespace-nowrap text-muted">
+ <Toggle
+ size="sm"
+ variant="project"
+ checked={showAllEntities}
+ onCheckedChange={setShowAllEntities}
+ />
+ Show all members
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <InfoIcon className="size-3.5 text-muted" />
+ </TooltipTrigger>
+ <TooltipContent side="bottom" className="max-w-60">
+ When enabled, all project members are shown including those without any access
+ to this secret.
+ </TooltipContent>
+ </Tooltip>
+ </Label>
+ <InputGroup className="flex-1">
+ <InputGroupAddon>
+ <SearchIcon />
+ </InputGroupAddon>
+ <InputGroupInput
+ value={searchFilter}
+ onChange={(e) => setSearchFilter(e.target.value)}
+ placeholder="Search by name..."
+ />
+ </InputGroup>
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <IconButton
+ variant={isFilterActive ? "project" : "outline"}
+ aria-label="Filter by type"
>
- <TypeIcon className="size-4" />
- {label}
- </DropdownMenuCheckboxItem>
- );
- })}
- </DropdownMenuContent>
- </DropdownMenu>
+ <FilterIcon />
+ </IconButton>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ {ALL_TYPE_FILTERS.map((type) => {
+ const { icon: TypeIcon, label } = TYPE_CONFIG[type];
+ return (
+ <DropdownMenuCheckboxItem
+ key={type}
+ checked={typeFilters.has(type)}
+ onCheckedChange={() => toggleTypeFilter(type)}
+ onSelect={(e) => e.preventDefault()}
+ >
+ <TypeIcon className="size-4" />
+ {label}
+ </DropdownMenuCheckboxItem>
+ );
+ })}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </>
+ )}
+ {view === "graph" && <div className="flex-1" />}
<AddMemberPopover
secretKey={secretKey}
environment={environment}
secretPath={secretPath}
/>
</div>
- {/* eslint-disable-next-line no-nested-ternary */}
- {isLoading ? (
- <Table>
- <TableHeader>
- <TableRow>
- <TableHead>Type</TableHead>
- <TableHead>Name</TableHead>
- {canReadInsights && <TableHead className="w-40">Last Read</TableHead>}
- {PERMISSION_COLUMNS.filter((col) => !col.isLegacy).map((col) => (
- <TableHead key={col.action} className="w-[100px] text-center">
- {col.label}
- </TableHead>
- ))}
- <TableHead className="w-10" />
- </TableRow>
- </TableHeader>
- <TableBody>
- {Array.from({ length: 10 }).map((_, i) => (
- <TableRow key={`skeleton-row-${String(i)}`}>
- <TableCell>
- <Skeleton className="h-4 w-16 rounded" />
- </TableCell>
- <TableCell>
- <Skeleton className="h-4 w-24 rounded" />
- </TableCell>
- {canReadInsights && (
- <TableCell className="w-40">
- <Skeleton className="h-4 w-20 rounded" />
- </TableCell>
- )}
- {PERMISSION_COLUMNS.filter((col) => !col.isLegacy).map((col) => (
- <TableCell key={col.action} className="w-[100px] text-center">
- <Skeleton className="mx-auto h-4 w-4 rounded" />
- </TableCell>
+ {view === "graph" &&
+ (isLoading || !graphInput ? (
+ <Skeleton className="h-[560px] w-full" />
+ ) : (
+ <SecretAccessGraph input={graphInput} />
+ ))}
+ {view === "table" && (
+ <>
+ {/* eslint-disable-next-line no-nested-ternary */}
+ {isLoading ? (
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead>Type</TableHead>
+ <TableHead>Name</TableHead>
+ {canReadInsights && <TableHead className="w-40">Last Read</TableHead>}
+ {PERMISSION_COLUMNS.filter((col) => !col.isLegacy).map((col) => (
+ <TableHead key={col.action} className="w-[100px] text-center">
+ {col.label}
+ </TableHead>
+ ))}
+ <TableHead className="w-10" />
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {Array.from({ length: 10 }).map((_, i) => (
+ <TableRow key={`skeleton-row-${String(i)}`}>
+ <TableCell>
+ <Skeleton className="h-4 w-16 rounded" />
+ </TableCell>
+ <TableCell>
+ <Skeleton className="h-4 w-24 rounded" />
+ </TableCell>
+ {canReadInsights && (
+ <TableCell className="w-40">
+ <Skeleton className="h-4 w-20 rounded" />
+ </TableCell>
+ )}
+ {PERMISSION_COLUMNS.filter((col) => !col.isLegacy).map((col) => (
+ <TableCell key={col.action} className="w-[100px] text-center">
+ <Skeleton className="mx-auto h-4 w-4 rounded" />
+ </TableCell>
+ ))}
+ <TableCell>
+ <Skeleton className="h-4 w-6 rounded" />
+ </TableCell>
+ </TableRow>
))}
- <TableCell>
- <Skeleton className="h-4 w-6 rounded" />
- </TableCell>
- </TableRow>
- ))}
- </TableBody>
- </Table>
- ) : filteredRows.length === 0 ? (
- <Empty className="border">
- <EmptyHeader>
- <EmptyTitle>No Results Found</EmptyTitle>
- <EmptyDescription>
- No users, groups, or identities match your search.
- </EmptyDescription>
- </EmptyHeader>
- </Empty>
- ) : (
- <Table containerClassName="overflow-auto">
- <TableHeader className="sticky -top-px z-20 bg-container [&_tr]:border-b-0">
- <TableRow>
- <TableHead className="w-48 border-b-0 shadow-[inset_0_-1px_0_var(--color-border)]">
- Type
- </TableHead>
- <TableHead className="border-b-0 shadow-[inset_0_-1px_0_var(--color-border)]">
- Name
- </TableHead>
- {canReadInsights && (
- <TableHead className="w-40 border-b-0 shadow-[inset_0_-1px_0_var(--color-border)]">
- <Tooltip>
- <TooltipTrigger asChild>
- <span className="inline-flex items-center gap-1">
- Last Read
- <InfoIcon className="size-3.5 text-muted" />
- </span>
- </TooltipTrigger>
- <TooltipContent>{readActivityDescription}</TooltipContent>
- </Tooltip>
- </TableHead>
- )}
- {visibleColumns.map((col) => (
- <TableHead
- key={col.action}
- className="w-[100px] border-b-0 text-center shadow-[inset_0_-1px_0_var(--color-border)]"
- >
- {col.isLegacy ? (
- <Tooltip>
- <TooltipTrigger asChild>
- <span className="inline-flex items-center gap-1">
- {col.label}
- <TriangleAlertIcon className="size-3.5 text-warning" />
- </span>
- </TooltipTrigger>
- <TooltipContent>
- This is a legacy permission. Migrate to Describe and Read Value for
- finer-grained access control.
- </TooltipContent>
- </Tooltip>
- ) : (
- col.label
+ </TableBody>
+ </Table>
+ ) : filteredRows.length === 0 ? (
+ <Empty className="border">
+ <EmptyHeader>
+ <EmptyTitle>No Results Found</EmptyTitle>
+ <EmptyDescription>
+ No users, groups, or identities match your search.
+ </EmptyDescription>
+ </EmptyHeader>
+ </Empty>
+ ) : (
+ <Table containerClassName="overflow-auto">
+ <TableHeader className="sticky -top-px z-20 bg-container [&_tr]:border-b-0">
+ <TableRow>
+ <TableHead className="w-48 border-b-0 shadow-[inset_0_-1px_0_var(--color-border)]">
+ Type
+ </TableHead>
+ <TableHead className="border-b-0 shadow-[inset_0_-1px_0_var(--color-border)]">
+ Name
+ </TableHead>
+ {canReadInsights && (
+ <TableHead className="w-40 border-b-0 shadow-[inset_0_-1px_0_var(--color-border)]">
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <span className="inline-flex items-center gap-1">
+ Last Read
+ <InfoIcon className="size-3.5 text-muted" />
+ </span>
+ </TooltipTrigger>
+ <TooltipContent>{readActivityDescription}</TooltipContent>
+ </Tooltip>
+ </TableHead>
)}
- </TableHead>
- ))}
- <TableHead className="w-10 border-b-0 shadow-[inset_0_-1px_0_var(--color-border)]" />
- </TableRow>
- </TableHeader>
- <TableBody>
- {filteredRows.map((row) => {
- const { icon: TypeIcon, label: typeLabel } = TYPE_CONFIG[row.type];
- return (
- <TableRow key={`${row.type}-${row.entry.id}`}>
- <TableCell>
- <span className="flex items-center gap-2">
- <TypeIcon className="size-4 text-accent" />
- {typeLabel}
- </span>
- </TableCell>
- <TableCell isTruncatable className="max-w-[180px] font-medium">
- <div className="flex items-center gap-1.5">
- <span className="truncate">{row.entry.name}</span>
- {row.inheritedFromGroups && row.inheritedFromGroups.length > 0 && (
+ {visibleColumns.map((col) => (
+ <TableHead
+ key={col.action}
+ className="w-[100px] border-b-0 text-center shadow-[inset_0_-1px_0_var(--color-border)]"
+ >
+ {col.isLegacy ? (
<Tooltip>
<TooltipTrigger asChild>
- <span className="inline-flex shrink-0 items-center gap-1 rounded bg-foreground/5 px-1.5 py-0.5 text-xs text-muted">
- <UsersIcon className="size-3" />
- {row.inheritedFromGroups.length}
+ <span className="inline-flex items-center gap-1">
+ {col.label}
+ <TriangleAlertIcon className="size-3.5 text-warning" />
</span>
</TooltipTrigger>
- <TooltipContent side="bottom">
- Access through{" "}
- {row.inheritedFromGroups.length === 1
- ? `group: ${row.inheritedFromGroups[0]}`
- : `groups: ${row.inheritedFromGroups.join(", ")}`}
+ <TooltipContent>
+ This is a legacy permission. Migrate to Describe and Read Value for
+ finer-grained access control.
</TooltipContent>
</Tooltip>
+ ) : (
+ col.label
)}
- </div>
- </TableCell>
- {canReadInsights && (
- <TableCell className="w-40 whitespace-nowrap">
- {renderLastRead(row)}
- </TableCell>
- )}
- {visibleColumns.map((col) => {
- const hasDirect = row.entry.allowedActions.includes(col.action);
- const hasInherited = row.inheritedActions?.has(col.action);
- return (
- <TableCell key={col.action} className="w-[100px] text-center">
- {/* eslint-disable-next-line no-nested-ternary */}
- {hasDirect ? (
- <CheckIcon className="mx-auto size-4 text-success" />
- ) : hasInherited ? (
- <Tooltip>
- <TooltipTrigger asChild>
- <UsersIcon className="mx-auto size-4 text-success" />
- </TooltipTrigger>
- <TooltipContent>Inherited from group</TooltipContent>
- </Tooltip>
- ) : (
- <BanIcon className="mx-auto size-4 text-muted" />
- )}
- </TableCell>
- );
- })}
- <TableCell className="text-right">
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <IconButton size="xs" variant="ghost">
- <MoreHorizontalIcon />
- </IconButton>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- {row.onEdit && (
- <Tooltip open={row.canEdit ? false : undefined}>
- <TooltipTrigger>
- <DropdownMenuItem
- isDisabled={!row.canEdit}
- onClick={() => row.onEdit?.()}
- >
- <PlusIcon />
- Add Additional Privilege
- </DropdownMenuItem>
- </TooltipTrigger>
- <TooltipContent side="left">
- {row.isSelf
- ? "You cannot modify your own privileges"
- : "You do not have permission to perform this action"}
- </TooltipContent>
- </Tooltip>
- )}
- <DropdownMenuItem asChild>
- <Link to={row.linkTo as "."} params={row.linkParams} target="_blank">
- <ExternalLinkIcon />
- {row.isSelf ? "View" : "Manage"} Access
- </Link>
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- </TableCell>
+ </TableHead>
+ ))}
+ <TableHead className="w-10 border-b-0 shadow-[inset_0_-1px_0_var(--color-border)]" />
</TableRow>
- );
- })}
- </TableBody>
- </Table>
- )}
- {canReadInsights && readActivity && readActivity.ghostReaders.length > 0 && (
- <div className="flex flex-col gap-3">
- <div>
- <h3 className="text-sm font-medium">Ghost Readers</h3>
- <p className="text-xs text-muted">
- Read this secret since {format(new Date(readActivity.trackedSince), "PP")} but can
- no longer access it. They still know the value.
- </p>
- </div>
- <Table>
- <TableHeader>
- <TableRow>
- <TableHead className="w-48">Type</TableHead>
- <TableHead>Name</TableHead>
- <TableHead className="w-40">Last Read</TableHead>
- </TableRow>
- </TableHeader>
- <TableBody>
- {readActivity.ghostReaders.map((reader) => {
- const { icon: TypeIcon, label: typeLabel } = TYPE_CONFIG[reader.actorType];
- return (
- <TableRow key={`${reader.actorType}-${reader.actorId}`}>
- <TableCell>
- <span className="flex items-center gap-2">
- <TypeIcon className="size-4 text-accent" />
- {typeLabel}
- </span>
- </TableCell>
- <TableCell isTruncatable className="max-w-[180px] font-medium">
- {reader.actorName ?? (
- <span className="text-muted italic">
- Deleted {reader.actorType === "user" ? "user" : "machine identity"}
+ </TableHeader>
+ <TableBody>
+ {filteredRows.map((row) => {
+ const { icon: TypeIcon, label: typeLabel } = TYPE_CONFIG[row.type];
+ return (
+ <TableRow key={`${row.type}-${row.entry.id}`}>
+ <TableCell>
+ <span className="flex items-center gap-2">
+ <TypeIcon className="size-4 text-accent" />
+ {typeLabel}
</span>
+ </TableCell>
+ <TableCell isTruncatable className="max-w-[180px] font-medium">
+ <div className="flex items-center gap-1.5">
+ <span className="truncate">{row.entry.name}</span>
+ {row.inheritedFromGroups && row.inheritedFromGroups.length > 0 && (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <span className="inline-flex shrink-0 items-center gap-1 rounded bg-foreground/5 px-1.5 py-0.5 text-xs text-muted">
+ <UsersIcon className="size-3" />
+ {row.inheritedFromGroups.length}
+ </span>
+ </TooltipTrigger>
+ <TooltipContent side="bottom">
+ Access through{" "}
+ {row.inheritedFromGroups.length === 1
+ ? `group: ${row.inheritedFromGroups[0]}`
+ : `groups: ${row.inheritedFromGroups.join(", ")}`}
+ </TooltipContent>
+ </Tooltip>
+ )}
+ </div>
+ </TableCell>
+ {canReadInsights && (
+ <TableCell className="w-40 whitespace-nowrap">
+ {renderLastRead(row)}
+ </TableCell>
)}
- </TableCell>
- <TableCell className="w-40 whitespace-nowrap">
- <SecretReadStatusBadge lastReadAt={reader.lastReadAt} />
- </TableCell>
+ {visibleColumns.map((col) => {
+ const hasDirect = row.entry.allowedActions.includes(col.action);
+ const hasInherited = row.inheritedActions?.has(col.action);
+ return (
+ <TableCell key={col.action} className="w-[100px] text-center">
+ {/* eslint-disable-next-line no-nested-ternary */}
+ {hasDirect ? (
+ <CheckIcon className="mx-auto size-4 text-success" />
+ ) : hasInherited ? (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <UsersIcon className="mx-auto size-4 text-success" />
+ </TooltipTrigger>
+ <TooltipContent>Inherited from group</TooltipContent>
+ </Tooltip>
+ ) : (
+ <BanIcon className="mx-auto size-4 text-muted" />
+ )}
+ </TableCell>
+ );
+ })}
+ <TableCell className="text-right">
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <IconButton size="xs" variant="ghost">
+ <MoreHorizontalIcon />
+ </IconButton>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ {row.onEdit && (
+ <Tooltip open={row.canEdit ? false : undefined}>
+ <TooltipTrigger>
+ <DropdownMenuItem
+ isDisabled={!row.canEdit}
+ onClick={() => row.onEdit?.()}
+ >
+ <PlusIcon />
+ Add Additional Privilege
+ </DropdownMenuItem>
+ </TooltipTrigger>
+ <TooltipContent side="left">
+ {row.isSelf
+ ? "You cannot modify your own privileges"
+ : "You do not have permission to perform this action"}
+ </TooltipContent>
+ </Tooltip>
+ )}
+ <DropdownMenuItem asChild>
+ <Link
+ to={row.linkTo as "."}
+ params={row.linkParams}
+ target="_blank"
+ >
+ <ExternalLinkIcon />
+ {row.isSelf ? "View" : "Manage"} Access
+ </Link>
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </TableCell>
+ </TableRow>
+ );
+ })}
+ </TableBody>
+ </Table>
+ )}
+ {canReadInsights && readActivity && readActivity.ghostReaders.length > 0 && (
+ <div className="flex flex-col gap-3">
+ <div>
+ <h3 className="text-sm font-medium">Ghost Readers</h3>
+ <p className="text-xs text-muted">
+ Read this secret since {format(new Date(readActivity.trackedSince), "PP")} but
+ can no longer access it. They still know the value.
+ </p>
+ </div>
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead className="w-48">Type</TableHead>
+ <TableHead>Name</TableHead>
+ <TableHead className="w-40">Last Read</TableHead>
</TableRow>
- );
- })}
- </TableBody>
- </Table>
- </div>
+ </TableHeader>
+ <TableBody>
+ {readActivity.ghostReaders.map((reader) => {
+ const { icon: TypeIcon, label: typeLabel } = TYPE_CONFIG[reader.actorType];
+ return (
+ <TableRow key={`${reader.actorType}-${reader.actorId}`}>
+ <TableCell>
+ <span className="flex items-center gap-2">
+ <TypeIcon className="size-4 text-accent" />
+ {typeLabel}
+ </span>
+ </TableCell>
+ <TableCell isTruncatable className="max-w-[180px] font-medium">
+ {reader.actorName ?? (
+ <span className="text-muted italic">
+ Deleted {reader.actorType === "user" ? "user" : "machine identity"}
+ </span>
+ )}
+ </TableCell>
+ <TableCell className="w-40 whitespace-nowrap">
+ <SecretReadStatusBadge lastReadAt={reader.lastReadAt} />
+ </TableCell>
+ </TableRow>
+ );
+ })}
+ </TableBody>
+ </Table>
+ </div>
+ )}
+ </>
)}
</div>