Skip to content

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

feat(insights): one line per reader on the access graph, with their groups named on the node

Dimitris Staratzisda4e469e7aba
diff --git a/frontend/src/components/secrets/SecretAccessGraph/SecretAccessGraph.tsx b/frontend/src/components/secrets/SecretAccessGraph/SecretAccessGraph.tsx
index c0847b685d..c2a1dec841 100644
--- a/frontend/src/components/secrets/SecretAccessGraph/SecretAccessGraph.tsx
+++ b/frontend/src/components/secrets/SecretAccessGraph/SecretAccessGraph.tsx
@@ -2,7 +2,6 @@ import { useCallback, useEffect, useMemo, useState } from "react";
import {
Background,
BackgroundVariant,
- ConnectionLineType,
Edge,
Node,
NodeMouseHandler,
@@ -18,24 +17,24 @@ 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";
+import { BandLabelNode, GhostNode, LaneEdge, ReaderNode, SecretNode } from "./nodes";
const NODE_TYPES = {
reader: ReaderNode,
- group: GroupNode,
secret: SecretNode,
ghost: GhostNode,
bandLabel: BandLabelNode
};
+const EDGE_TYPES = { lane: LaneEdge };
+
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.
+// Everything reachable from a node along its edges, both ways: a reader lights up the secret.
const connectedTo = (nodeId: string, edges: Edge[]) => {
const reached = new Set([nodeId]);
const walk = (from: string, direction: "source" | "target") => {
@@ -102,9 +101,9 @@ const SecretAccessGraphContent = ({ input }: Props) => {
[edges, focused]
);
- // Selecting a reader or group focuses its path; selecting it again, or anything else, clears the focus.
+ // Selecting a reader focuses its line; selecting it again, or anything else, clears the focus.
const onNodeClick: NodeMouseHandler = useCallback((_, node) => {
- const isFocusable = node.type === "reader" || node.type === "group";
+ const isFocusable = node.type === "reader";
setFocusedId((current) => (isFocusable && current !== node.id ? node.id : undefined));
}, []);
@@ -121,8 +120,7 @@ const SecretAccessGraphContent = ({ input }: Props) => {
onNodeClick={onNodeClick}
onPaneClick={() => setFocusedId(undefined)}
nodeTypes={NODE_TYPES}
- connectionLineType={ConnectionLineType.SmoothStep}
- defaultEdgeOptions={{ type: "smoothstep" }}
+ edgeTypes={EDGE_TYPES}
proOptions={{ hideAttribution: true }}
nodesDraggable={false}
nodesConnectable={false}
@@ -180,8 +178,8 @@ export const SecretAccessGraph = ({ input }: Props) => (
</div>
<p className="text-xs text-muted">
{input.hasReadActivity
- ? `Solid lines are reads since ${input.trackedSince ? format(new Date(input.trackedSince), "PP") : "tracking began"}, dashed lines are access with no reads yet. 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."}
+ ? `Solid lines are reads since ${input.trackedSince ? format(new Date(input.trackedSince), "PP") : "tracking began"}, dashed lines are access with no reads yet. Select a reader to highlight their line.`
+ : "Read activity is not visible for your role, so the lines only show who can read the value. Select a reader to highlight their line."}
</p>
</ReactFlowProvider>
);
diff --git a/frontend/src/components/secrets/SecretAccessGraph/buildAccessGraph.test.ts b/frontend/src/components/secrets/SecretAccessGraph/buildAccessGraph.test.ts
index b2469a1a0a..86f9ede9ce 100644
--- a/frontend/src/components/secrets/SecretAccessGraph/buildAccessGraph.test.ts
+++ b/frontend/src/components/secrets/SecretAccessGraph/buildAccessGraph.test.ts
@@ -2,7 +2,6 @@ import { describe, expect, test } from "vitest";
import {
buildAccessGraph,
- groupNodeId,
readerNodeId,
SECRET_NODE_ID,
TAccessGraphInput
@@ -24,7 +23,7 @@ const input: TAccessGraphInput = {
name: "ci",
type: "identity",
isDirect: false,
- groupIds: ["devs"],
+ groupIds: ["devs", "ops"],
unreadSince: "2026-09-19T00:00:00.000Z"
},
{ id: "newcomer", name: "newcomer", type: "identity", isDirect: true, groupIds: [] },
@@ -35,9 +34,20 @@ const input: TAccessGraphInput = {
isDirect: true,
groupIds: ["devs"],
lastReadAt: "2026-10-01T00:00:00.000Z"
+ },
+ {
+ id: "root",
+ type: "user",
+ isDirect: true,
+ groupIds: [],
+ isAdmin: true
}
],
- groups: [{ id: "devs", name: "devs", memberCount: 2 }],
+ groups: [
+ { id: "devs", name: "devs", memberCount: 2 },
+ { id: "ops", name: "ops", memberCount: 1 }
+ ],
ghosts: [{ id: "gone", name: null, type: "identity", lastReadAt: "2026-10-10T00:00:00.000Z" }],
hasReadActivity: true,
trackedSince: "2026-09-19T00:00:00.000Z"
@@ -46,93 +56,72 @@ const input: TAccessGraphInput = {
describe("buildAccessGraph", () => {
const { nodes, edges } = buildAccessGraph(input);
const nodeById = new Map(nodes.map((node) => [node.id, node]));
+ const readerNode = (type: "user" | "identity", id: string) =>
+ nodeById.get(readerNodeId({ type, id }))!;
- 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("lays readers and the secret out in two columns with ghosts under the readers, and no group boxes", () => {
+ const secret = nodeById.get(SECRET_NODE_ID)!;
+ const ghost = nodeById.get("ghost-identity-gone")!;
+ expect(readerNode("user", "alice").position.x).toBeLessThan(secret.position.x);
+ expect(ghost.position.x).toBe(readerNode("user", "alice").position.x);
+ expect(ghost.position.y).toBeGreaterThan(
+ Math.max(...input.readers.map((entry) => readerNode(entry.type, entry.id).position.y))
);
+ expect(
+ nodes.every((node) => ["reader", "secret", "ghost", "bandLabel"].includes(node.type ?? ""))
+ ).toBe(true);
});
- test("puts unused access first, then readers too new to judge, then the ones who have read", () => {
- 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", "newcomer", "alice", "bob"]);
+ test("puts unused access first, then readers too new to judge, then readers, then admins", () => {
+ const order = [...input.readers]
+ .sort((a, b) => readerNode(a.type, a.id).position.y - readerNode(b.type, b.id).position.y)
+ .map((entry) => entry.id);
+ expect(order).toEqual(["ci", "newcomer", "alice", "bob", "root"]);
});
- test("draws every path a reader has: direct to the secret, and through each 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,
- groupNodeId({ id: "devs" })
- ]);
- 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("gives every reader one line to the secret, and names every group on the node", () => {
+ input.readers.forEach((entry) => {
+ const lines = edges.filter((edge) => edge.source === readerNodeId(entry));
+ expect(lines.map((edge) => edge.target)).toEqual([SECRET_NODE_ID]);
+ });
+ expect(readerNode("identity", "ci").data.groupNames).toEqual(["devs", "ops"]);
+ expect(readerNode("user", "bob").data.groupNames).toEqual(["devs"]);
+ expect(readerNode("user", "alice").data.groupNames).toEqual([]);
+ expect(edges.some((edge) => edge.source.startsWith("ghost-"))).toBe(false);
});
- test("draws admins last, with a plain edge whether or not they read", () => {
- const withAdmin = buildAccessGraph({
- ...input,
- readers: [
- ...input.readers,
- {
- id: "root",
- type: "user",
- isDirect: true,
- groupIds: [],
- isAdmin: true
- }
- ]
+ test("bends each line in its own lane, in the gap before the secret", () => {
+ const secret = nodeById.get(SECRET_NODE_ID)!;
+ const alice = readerNode("user", "alice");
+ const readersRight = alice.position.x + Number(alice.width);
+ const secretCenter = secret.position.y + Number(secret.height) / 2;
+ const lines = edges.map((edge) => {
+ const source = nodeById.get(edge.source)!;
+ return {
+ above: source.position.y + Number(source.height) / 2 <= secretCenter,
+ centerX: (edge.data as { centerX: number }).centerX
+ };
});
- const readerYs = withAdmin.nodes
- .filter((node) => node.type === "reader")
- .sort((a, b) => a.position.y - b.position.y)
- .map((node) => node.id);
- expect(readerYs[readerYs.length - 1]).toBe(readerNodeId({ type: "user", id: "root" }));
- const adminEdge = withAdmin.edges.find(
- (edge) => edge.source === readerNodeId({ type: "user", id: "root" })
- );
- expect(adminEdge?.target).toBe(SECRET_NODE_ID);
- expect(adminEdge?.style?.strokeDasharray).toBeUndefined();
+ // Lines from above and from below may share a lane: their vertical runs never overlap.
+ [true, false].forEach((above) => {
+ const lanes = lines.filter((line) => line.above === above).map((line) => line.centerX);
+ expect(new Set(lanes).size).toBe(lanes.length);
+ });
+ lines.forEach(({ centerX }) => {
+ expect(centerX).toBeGreaterThan(readersRight);
+ expect(centerX).toBeLessThan(secret.position.x);
+ });
+ expect(edges.every((edge) => edge.type === "lane")).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);
+ test("dashes the line of a reader with no reads; admins and unknown activity get plain lines", () => {
+ const lineOf = (type: "user" | "identity", id: string) =>
+ edges.find((edge) => edge.source === readerNodeId({ type, id }));
+ expect(lineOf("identity", "ci")?.style?.strokeDasharray).toBe("5 5");
+ expect(lineOf("user", "alice")?.style?.strokeDasharray).toBeUndefined();
+ expect(lineOf("user", "root")?.style?.strokeDasharray).toBeUndefined();
+
+ const unknown = buildAccessGraph({ ...input, hasReadActivity: false });
+ expect(unknown.edges.every((edge) => edge.style?.strokeDasharray === undefined)).toBe(true);
});
});
diff --git a/frontend/src/components/secrets/SecretAccessGraph/buildAccessGraph.ts b/frontend/src/components/secrets/SecretAccessGraph/buildAccessGraph.ts
index 61f6a09856..5c0d0eb141 100644
--- a/frontend/src/components/secrets/SecretAccessGraph/buildAccessGraph.ts
+++ b/frontend/src/components/secrets/SecretAccessGraph/buildAccessGraph.ts
@@ -54,41 +54,35 @@ export type TReaderNodeData = {
reader: TAccessGraphReader;
groupNames: string[];
hasReadActivity: boolean;
- trackedSince?: string;
};
-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 type TLaneEdgeData = { centerX: number };
-export const NODE_WIDTH = 208;
-const READER_NODE_HEIGHT = 84;
-const GROUP_NODE_HEIGHT = 64;
+export const NODE_WIDTH = 240;
+const READER_NODE_HEIGHT = 74;
const SECRET_NODE_HEIGHT = 104;
-const GHOST_NODE_HEIGHT = 76;
+const GHOST_NODE_HEIGHT = 74;
const BAND_LABEL_HEIGHT = 36;
-const BAND_GAP = 20;
+const BAND_GAP = 24;
const HEADER_GAP = 8;
-// Three columns plus their gaps fit the sheet without horizontal panning.
-const COLUMN_GAP = 96;
-const ROW_GAP = 16;
+const COLUMN_GAP = 160;
+const ROW_GAP = 14;
const MARGIN = 24;
const COLUMN_TOP = MARGIN + BAND_LABEL_HEIGHT + HEADER_GAP;
+// Where the first line bends before the secret, and how far apart parallel bends are.
+const LANE_INSET = 24;
+const MAX_LANE_STEP = 10;
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);
@@ -119,19 +113,41 @@ const readerEdgeStyle = (reader: TAccessGraphReader, hasReadActivity: boolean) =
return { stroke: "var(--color-muted)", strokeWidth: 1, strokeDasharray: "5 5", opacity: 0.45 };
};
+// Each line bends in its own vertical lane before the secret. The reader farthest above (or below) the
+// secret bends closest to it, so no line's horizontal run crosses another's bend. Lines from above and from
+// below can share a lane: their vertical runs never overlap.
+const assignLanes = (
+ sources: { edgeId: string; y: number }[],
+ targetY: number,
+ targetX: number
+) => {
+ const centerXByEdgeId = new Map<string, number>();
+ const place = (side: typeof sources) => {
+ const step = Math.min(MAX_LANE_STEP, (COLUMN_GAP - 2 * LANE_INSET) / Math.max(1, side.length));
+ [...side]
+ .sort((a, b) => Math.abs(b.y - targetY) - Math.abs(a.y - targetY))
+ .forEach((source, index) => {
+ centerXByEdgeId.set(source.edgeId, targetX - LANE_INSET - index * step);
+ });
+ };
+ place(sources.filter((source) => source.y <= targetY));
+ place(sources.filter((source) => source.y > targetY));
+ return centerXByEdgeId;
+};
+
export const buildAccessGraph = ({
secret,
readers,
groups,
ghosts,
- hasReadActivity,
- trackedSince
+ hasReadActivity
}: TAccessGraphInput) => {
const nodes: Node[] = [];
const edges: Edge[] = [];
+ const groupNameById = new Map(groups.map((group) => [group.id, group.name]));
- // Unused access first, then readers too new to judge, then the ones who have read, then admins: the first
- // group is what the viewer is here to find.
+ // Unused access first, then readers too new to judge, then the ones who have read, then admins: the
+ // first group is what the viewer is here to find.
const rankOf = (reader: TAccessGraphReader) => {
if (reader.isAdmin) return 3;
if (!hasReadActivity) return 0;
@@ -141,44 +157,33 @@ export const buildAccessGraph = ({
const orderedReaders = [...readers].sort(
(a, b) => rankOf(a) - rankOf(b) || 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);
+ const secretColumnX = MARGIN + NODE_WIDTH + COLUMN_GAP;
+ const readerY = stackColumn(COLUMN_TOP, READER_NODE_HEIGHT);
+ const readerCenterY = (index: number) => readerY(index) + READER_NODE_HEIGHT / 2;
+ const readersBottom = COLUMN_TOP + columnHeight(orderedReaders.length, READER_NODE_HEIGHT);
+ // The secret sits level with the middle of the readers.
+ const secretY = Math.max(COLUMN_TOP, (COLUMN_TOP + readersBottom - SECRET_NODE_HEIGHT) / 2);
nodes.push(
- bandLabelNode("band-readers", MARGIN, readerOffset, {
+ bandLabelNode("band-readers", MARGIN, COLUMN_TOP, {
label: `Can read · ${orderedReaders.length}`,
- detail: "can read the value today"
- }),
- bandLabelNode("band-secret", secretColumnX, secretOffset, {
- label: "Secret",
- detail: "the value they read"
+ detail: "users and machine identities, directly or through a group"
})
);
- if (groups.length) {
- nodes.push(
- bandLabelNode("band-groups", groupColumnX, groupOffset, {
- label: `Groups · ${groups.length}`,
- detail: "grant the access"
- })
- );
- }
+ // Every reader has one line to the secret; how they have the value, directly or through which groups, is
+ // written on the reader rather than drawn, which keeps the lines from crossing.
+ const lanes = assignLanes(
+ orderedReaders.map((reader, index) => ({
+ edgeId: `edge-${readerNodeId(reader)}-secret`,
+ y: readerCenterY(index)
+ })),
+ secretY + SECRET_NODE_HEIGHT / 2,
+ secretColumnX
+ );
orderedReaders.forEach((reader, index) => {
const nodeId = readerNodeId(reader);
- const viaGroups = reader.groupIds.flatMap((groupId) => groupById.get(groupId) ?? []);
nodes.push({
id: nodeId,
type: "reader",
@@ -187,50 +192,25 @@ export const buildAccessGraph = ({
height: READER_NODE_HEIGHT,
data: {
reader,
- groupNames: viaGroups.map((group) => group.name),
- hasReadActivity,
- trackedSince
+ groupNames: reader.groupIds.flatMap((groupId) => groupNameById.get(groupId) ?? []),
+ hasReadActivity
} satisfies TReaderNodeData
});
-
- const style = readerEdgeStyle(reader, hasReadActivity);
- // Every path that gives the reader the value is drawn: straight to the secret for their own grant, and
- // through each group that grants it too, so removing one path visibly leaves the others.
- if (reader.isDirect || !viaGroups.length) {
- edges.push({ id: `edge-${nodeId}-secret`, source: nodeId, target: SECRET_NODE_ID, style });
- }
- 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
- });
+ const edgeId = `edge-${nodeId}-secret`;
edges.push({
- id: `edge-${nodeId}-secret`,
+ id: edgeId,
source: nodeId,
target: SECRET_NODE_ID,
- style: { stroke: "var(--color-accent)", strokeWidth: 1.5, opacity: 0.5 }
+ type: "lane",
+ style: readerEdgeStyle(reader, hasReadActivity),
+ data: { centerX: lanes.get(edgeId) ?? secretColumnX - LANE_INSET } satisfies TLaneEdgeData
});
});
nodes.push({
id: SECRET_NODE_ID,
type: "secret",
- position: { x: secretColumnX, y: secretOffset },
+ position: { x: secretColumnX, y: secretY },
width: NODE_WIDTH,
height: SECRET_NODE_HEIGHT,
data: { secret } satisfies TSecretNodeData
@@ -238,18 +218,13 @@ export const buildAccessGraph = ({
// 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 firstGhostY = readersBottom + 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",
+ detail: "read it, but have no path to it now",
tone: "warning"
})
);
@@ -267,9 +242,11 @@ export const buildAccessGraph = ({
}
const contentHeight =
- (ghosts.length
- ? firstGhostY + columnHeight(ghosts.length, GHOST_NODE_HEIGHT)
- : COLUMN_TOP + tallestColumn) + MARGIN;
+ Math.max(
+ readersBottom,
+ secretY + SECRET_NODE_HEIGHT,
+ ghosts.length ? firstGhostY + columnHeight(ghosts.length, GHOST_NODE_HEIGHT) : 0
+ ) + MARGIN;
const contentWidth = secretColumnX + NODE_WIDTH + MARGIN;
return { nodes, edges, contentHeight, contentWidth };
diff --git a/frontend/src/components/secrets/SecretAccessGraph/nodes.tsx b/frontend/src/components/secrets/SecretAccessGraph/nodes.tsx
index 40d4b05487..eb7b21623b 100644
--- a/frontend/src/components/secrets/SecretAccessGraph/nodes.tsx
+++ b/frontend/src/components/secrets/SecretAccessGraph/nodes.tsx
@@ -1,19 +1,34 @@
-import { Handle, NodeProps, Position } from "@xyflow/react";
+import {
+ BaseEdge,
+ Edge,
+ EdgeProps,
+ getSmoothStepPath,
+ Handle,
+ NodeProps,
+ Position
+} from "@xyflow/react";
import { format } from "date-fns";
+import { HardDriveIcon, KeyIcon, UserIcon } from "lucide-react";
import { SecretExposureBadge } from "@app/components/secrets/SecretExposureScore";
import { formatReadDay } from "@app/components/secrets/SecretReadStatusBadge";
+import { Badge, Tooltip, TooltipContent, TooltipTrigger } from "@app/components/v3";
import { cn } from "@app/components/v3/utils";
import {
TAccessGraphActorType,
TBandLabelNodeData,
TGhostNodeData,
- TGroupNodeData,
+ TLaneEdgeData,
TReaderNodeData,
TSecretNodeData
} from "./buildAccessGraph";
+const TYPE_ICON: Record<TAccessGraphActorType, typeof UserIcon> = {
+ user: UserIcon,
+ identity: HardDriveIcon
+};
+
const TYPE_LABEL: Record<TAccessGraphActorType, string> = {
user: "user",
identity: "machine identity"
@@ -21,18 +36,36 @@ const TYPE_LABEL: Record<TAccessGraphActorType, string> = {
const hiddenHandle = "!opacity-0";
-const describeAccessPath = (isDirect: boolean, groupNames: string[]) => {
- if (!groupNames.length) return "Direct access";
- const groups = groupNames.join(", ");
- return isDirect ? `Direct · via ${groups}` : `Via ${groups}`;
+// How the reader has the value, on one line whatever the number of groups: the first group by name, the rest
+// as a count that stays visible however long that name is, and every group listed on hover.
+const AccessPath = ({ isDirect, groupNames }: { isDirect: boolean; groupNames: string[] }) => {
+ if (!groupNames.length) return <span className="truncate text-xs text-muted">Direct access</span>;
+ const [first, ...rest] = groupNames;
+ return (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <span className="flex min-w-0 items-center gap-1 text-xs text-muted">
+ <span className="truncate">
+ {isDirect ? "Direct · via" : "Via"} {first}
+ </span>
+ {rest.length > 0 && <span className="shrink-0">+{rest.length} more</span>}
+ </span>
+ </TooltipTrigger>
+ <TooltipContent className="max-w-72">
+ {isDirect ? "Direct access, and through " : "Through "}
+ {groupNames.length === 1 ? "the group" : "the groups"} {groupNames.join(", ")}
+ </TooltipContent>
+ </Tooltip>
+ );
};
export const ReaderNode = ({ data }: NodeProps & { data: TReaderNodeData }) => {
const { reader, groupNames, hasReadActivity } = data;
- // An admin is never counted as unused access, so their node stays solid whether or not they read.
- const hasReads = Boolean(reader.lastReadAt) || Boolean(reader.isAdmin);
+ const TypeIcon = TYPE_ICON[reader.type];
+ // A reader with no read is drawn dashed, like their line; an admin is never counted, so stays solid.
+ const isUnread = hasReadActivity && !reader.lastReadAt && !reader.isAdmin;
- // Three states once read activity is known: read, unused access, or too new to judge; admins are never judged.
+ // Read, unused access, or too new to judge; admins are never judged.
let status: { text: string; tone: string } | undefined;
if (hasReadActivity) {
if (reader.lastReadAt) {
@@ -55,47 +88,21 @@ export const ReaderNode = ({ data }: NodeProps & { data: TReaderNodeData }) => {
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"
+ "flex h-full w-full cursor-pointer flex-col justify-center gap-1 rounded-md border px-3",
+ isUnread ? "border-dashed border-border bg-container" : "border-border bg-card"
)}
>
- <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]}
- {reader.isAdmin && " · admin"}
- </span>
+ <div className="flex min-w-0 items-center gap-1.5">
+ <TypeIcon className="size-3.5 shrink-0 text-muted" aria-label={TYPE_LABEL[reader.type]} />
+ <p className="truncate text-xs font-medium text-foreground">{reader.name}</p>
+ {reader.isAdmin && (
+ <Badge variant="neutral" className="ml-auto shrink-0">
+ Admin
+ </Badge>
+ )}
</div>
{status && <span className={cn("truncate text-xs", status.tone)}>{status.text}</span>}
- <span className="mt-auto truncate text-xs text-muted">
- {describeAccessPath(reader.isDirect, groupNames)}
- </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} />
+ <AccessPath isDirect={reader.isDirect} groupNames={groupNames} />
<Handle type="source" position={Position.Right} className={hiddenHandle} />
</div>
);
@@ -104,14 +111,16 @@ export const GroupNode = ({ data }: NodeProps & { data: TGroupNodeData }) => {
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 text-accent">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}
+ <div className="flex h-full w-full flex-col justify-center gap-1 rounded-md border border-secret/50 bg-secret/10 px-3">
+ <div className="flex min-w-0 items-center gap-1.5">
+ <KeyIcon className="size-3.5 shrink-0 text-secret" aria-label="secret" />
+ <p className="truncate font-mono text-sm text-foreground">{secret.key}</p>
+ </div>
+ <p className="truncate text-xs text-muted">
+ {secret.environment} · {secret.secretPath}
</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">
+ <div className="mt-1 flex items-center gap-1.5 border-t border-secret/25 pt-1.5 text-xs text-muted">
Exposure <SecretExposureBadge exposure={secret.exposure} />
</div>
)}
@@ -124,23 +133,24 @@ export const SecretNode = ({ data }: NodeProps & { data: TSecretNodeData }) => {
// them to the secret, and an edge would say otherwise.
export const GhostNode = ({ data }: NodeProps & { data: TGhostNodeData }) => {
const { ghost } = data;
+ const TypeIcon = TYPE_ICON[ghost.type];
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">
+ <div className="flex h-full w-full flex-col justify-center gap-1 rounded-md border border-warning/40 bg-warning/5 px-3">
+ <div className="flex min-w-0 items-center gap-1.5">
+ <TypeIcon className="size-3.5 shrink-0 text-muted" aria-label={TYPE_LABEL[ghost.type]} />
<p
className={cn(
- "truncate font-mono text-xs",
+ "truncate text-xs font-medium",
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
+ {ghost.name ? "Access removed" : "Deleted"}, still knows the value
</span>
- <span className="mt-auto truncate text-xs text-accent">
+ <span className="truncate text-xs text-muted">
Read {formatReadDay(ghost.lastReadAt).toLowerCase()}
</span>
</div>
@@ -153,7 +163,7 @@ export const BandLabelNode = ({ data }: NodeProps & { data: TBandLabelNodeData }
<span
className={cn(
"text-xs font-medium",
- data.tone === "warning" ? "text-warning" : "text-accent"
+ data.tone === "warning" ? "text-warning" : "text-foreground"
)}
>
{data.label}
@@ -161,3 +171,28 @@ export const BandLabelNode = ({ data }: NodeProps & { data: TBandLabelNodeData }
<span className="text-xs text-muted">{data.detail}</span>
</div>
);
+
+// A right-angled line whose vertical run sits at the lane the layout gave it, so lines into the same node
+// run side by side instead of on top of each other or through the nodes in between.
+export const LaneEdge = ({
+ sourceX,
+ sourceY,
+ targetX,
+ targetY,
+ sourcePosition,
+ targetPosition,
+ style,
+ data
+}: EdgeProps<Edge<TLaneEdgeData>>) => {
+ const [path] = getSmoothStepPath({
+ sourceX,
+ sourceY,
+ sourcePosition,
+ targetX,
+ targetY,
+ targetPosition,
+ centerX: data?.centerX,
+ borderRadius: 8
+ });
+ return <BaseEdge path={path} style={style} />;
+};