Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat(insights): draw admins and every group path on the secret access graph
Dimitris Staratzis443eaf61f03f
diff --git a/frontend/src/components/secrets/SecretAccessGraph/buildAccessGraph.test.ts b/frontend/src/components/secrets/SecretAccessGraph/buildAccessGraph.test.tsindex eec51a4bcb..b2469a1a0a 100644--- a/frontend/src/components/secrets/SecretAccessGraph/buildAccessGraph.test.ts+++ b/frontend/src/components/secrets/SecretAccessGraph/buildAccessGraph.test.ts@@ -70,13 +70,14 @@ describe("buildAccessGraph", () => {expect(sorted).toEqual(["ci", "newcomer", "alice", "bob"]);});- test("connects direct readers to the secret and group-only readers through their group", () => {+ 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+ SECRET_NODE_ID,+ groupNodeId({ id: "devs" })]);expect(edgeOf(readerNodeId({ type: "identity", id: "ci" })).map((edge) => edge.target)).toEqual([groupNodeId({ id: "devs" })]@@ -99,6 +100,33 @@ describe("buildAccessGraph", () => {expect(unknown.edges.every((edge) => edge.style?.strokeDasharray === undefined)).toBe(true);});+ test("draws admins last, with a plain edge whether or not they read", () => {+ const withAdmin = buildAccessGraph({+ ...input,+ readers: [+ ...input.readers,+ {+ id: "root",+ name: "[email protected]",+ type: "user",+ isDirect: true,+ groupIds: [],+ isAdmin: true+ }+ ]+ });+ 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();+ });+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);diff --git a/frontend/src/components/secrets/SecretAccessGraph/buildAccessGraph.ts b/frontend/src/components/secrets/SecretAccessGraph/buildAccessGraph.tsindex bc8715e86d..61f6a09856 100644--- a/frontend/src/components/secrets/SecretAccessGraph/buildAccessGraph.ts+++ b/frontend/src/components/secrets/SecretAccessGraph/buildAccessGraph.ts@@ -8,9 +8,11 @@ export type TAccessGraphReader = {id: string;name: string;type: TAccessGraphActorType;- // Granted on their own, as opposed to only through a group.+ // Granted on their own; a reader can also have the value through groups at the same time.isDirect: boolean;groupIds: string[];+ // Project admins can read everything by design, so they are drawn but never count as unused access.+ isAdmin?: boolean;lastReadAt?: string;// Set when the reader counts as unused access: no read since this date, with the secret and their access// both older than the judged period. A reader with neither this nor a read is too new to judge.@@ -106,12 +108,15 @@ const bandLabelNode = (});// 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.+// neutral, because unknown is not the same as unused, and so is an admin's, who is never counted.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 };+ if (reader.lastReadAt && hasReadActivity) {+ return { stroke: "var(--color-foreground)", strokeWidth: 1.5, opacity: 0.55 };+ }+ if (!hasReadActivity || reader.isAdmin) {+ return { stroke: "var(--color-muted)", strokeWidth: 1, opacity: 0.5 };+ }+ return { stroke: "var(--color-muted)", strokeWidth: 1, strokeDasharray: "5 5", opacity: 0.45 };};export const buildAccessGraph = ({@@ -125,9 +130,10 @@ export const buildAccessGraph = ({const nodes: Node[] = [];const edges: Edge[] = [];- // Unused access first, then readers too new to judge, then the ones who have read: 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;if (reader.lastReadAt) return 2;return reader.unreadSince ? 0 : 1;@@ -172,9 +178,7 @@ export const buildAccessGraph = ({orderedReaders.forEach((reader, index) => {const nodeId = readerNodeId(reader);- const viaGroups = reader.isDirect- ? []- : reader.groupIds.flatMap((groupId) => groupById.get(groupId) ?? []);+ const viaGroups = reader.groupIds.flatMap((groupId) => groupById.get(groupId) ?? []);nodes.push({id: nodeId,type: "reader",@@ -190,20 +194,19 @@ export const buildAccessGraph = ({});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.+ // 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 });- } else {- viaGroups.forEach((group) => {- edges.push({- id: `edge-${nodeId}-${groupNodeId(group)}`,- source: nodeId,- target: groupNodeId(group),- style- });- });}+ viaGroups.forEach((group) => {+ edges.push({+ id: `edge-${nodeId}-${groupNodeId(group)}`,+ source: nodeId,+ target: groupNodeId(group),+ style+ });+ });});groups.forEach((group, index) => {diff --git a/frontend/src/components/secrets/SecretAccessGraph/nodes.tsx b/frontend/src/components/secrets/SecretAccessGraph/nodes.tsxindex af4212b73d..40d4b05487 100644--- a/frontend/src/components/secrets/SecretAccessGraph/nodes.tsx+++ b/frontend/src/components/secrets/SecretAccessGraph/nodes.tsx@@ -21,11 +21,18 @@ 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}`;+};+export const ReaderNode = ({ data }: NodeProps & { data: TReaderNodeData }) => {const { reader, groupNames, hasReadActivity } = data;- const hasReads = Boolean(reader.lastReadAt);+ // 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);- // Three states once read activity is known: read, unused access, or too new to judge.+ // Three states once read activity is known: read, unused access, or too new to judge; admins are never judged.let status: { text: string; tone: string } | undefined;if (hasReadActivity) {if (reader.lastReadAt) {@@ -33,6 +40,8 @@ export const ReaderNode = ({ data }: NodeProps & { data: TReaderNodeData }) => {text: `Read ${formatReadDay(reader.lastReadAt).toLowerCase()}`,tone: "text-accent"};+ } else if (reader.isAdmin) {+ status = { text: "No reads, admins are not counted", tone: "text-muted" };} else if (reader.unreadSince) {status = {text: `No reads since ${format(new Date(reader.unreadSince), "MMM d")}`,@@ -61,11 +70,14 @@ export const ReaderNode = ({ data }: NodeProps & { data: TReaderNodeData }) => {>{reader.name}</p>- <span className="shrink-0 text-xs text-muted">{TYPE_LABEL[reader.type]}</span>+ <span className="shrink-0 text-xs text-muted">+ {TYPE_LABEL[reader.type]}+ {reader.isAdmin && " · admin"}+ </span></div>{status && <span className={cn("truncate text-xs", status.tone)}>{status.text}</span>}<span className="mt-auto truncate text-xs text-muted">- {groupNames.length ? `Via ${groupNames.join(", ")}` : "Direct access"}+ {describeAccessPath(reader.isDirect, groupNames)}</span><Handle type="source" position={Position.Right} className={hiddenHandle} /></div>diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretAccessInsights.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretAccessInsights.tsxindex f67f8e8347..c87a073b09 100644--- a/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretAccessInsights.tsx+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretAccessInsights.tsx@@ -573,8 +573,6 @@ export function SecretAccessInsights({.filter((group) => group[memberField].includes(entry.id)).map((group) => group.id);if (!isDirect && !groupIds.length) return [];- // Admins can read everything by design, so the secret is not exposed to them and they stay off the graph.- if (entitledReaders.get(`${type}:${entry.id}`)?.isAdmin) return [];const status = readStatusOf(type, entry.id);return [{@@ -583,6 +581,7 @@ export function SecretAccessInsights({type,isDirect,groupIds,+ isAdmin: entitledReaders.get(`${type}:${entry.id}`)?.isAdmin ?? false,lastReadAt: status?.kind === "read" ? status.lastReadAt : undefined,unreadSince: status?.kind === "unread" ? status.since : undefined}@@ -601,7 +600,7 @@ export function SecretAccessInsights({...secretAccessList.identities.map((identity) => `identity:${identity.id}`)]);const groupOnlyReaders = (readActivity?.entitled ?? []).flatMap((reader) => {- if (reader.isAdmin || listed.has(`${reader.actorType}:${reader.actorId}`)) return [];+ if (listed.has(`${reader.actorType}:${reader.actorId}`)) return [];const memberField = reader.actorType === "user" ? "userIds" : "identityIds";const groupIds = groups.filter((group) => group[memberField].includes(reader.actorId))@@ -614,25 +613,22 @@ export function SecretAccessInsights({type: reader.actorType,isDirect: false,groupIds,+ isAdmin: reader.isAdmin,lastReadAt: status?.kind === "read" ? status.lastReadAt : undefined,unreadSince: status?.kind === "unread" ? status.since : undefined}];});const readers = [...directReaders, ...groupOnlyReaders];- 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- })),+ // Every group that grants the value is drawn, including one whose members also have it directly.+ groups: groups.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,