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
show cross-project references in Secret references graph
Matheus Nogueira2efdf7792121
diff --git a/backend/src/server/routes/v3/deprecated-secret-router.ts b/backend/src/server/routes/v3/deprecated-secret-router.tsindex 3aebc5bee0..ea7a13d37f 100644--- a/backend/src/server/routes/v3/deprecated-secret-router.ts+++ b/backend/src/server/routes/v3/deprecated-secret-router.ts@@ -29,7 +29,14 @@ const SecretReferenceNode = z.object({key: z.string(),value: z.string().optional(),environment: z.string(),- secretPath: z.string()+ secretPath: z.string(),+ project: z+ .object({+ id: z.string(),+ slug: z.string(),+ name: z.string()+ })+ .optional()});const convertStringBoolean = (defaultValue: boolean = false) => {diff --git a/backend/src/server/routes/v4/secret-router.ts b/backend/src/server/routes/v4/secret-router.tsindex d7552a86e2..96703d277a 100644--- a/backend/src/server/routes/v4/secret-router.ts+++ b/backend/src/server/routes/v4/secret-router.ts@@ -28,7 +28,14 @@ const SecretReferenceNode = z.object({key: z.string(),value: z.string().optional(),environment: z.string(),- secretPath: z.string()+ secretPath: z.string(),+ project: z+ .object({+ id: z.string(),+ slug: z.string(),+ name: z.string()+ })+ .optional()});const DuplicateSecretAttributesSchema = zdiff --git a/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts b/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.tsindex 110947ae93..9095dcf1d3 100644--- a/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts+++ b/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts@@ -1004,6 +1004,41 @@ export const secretV2BridgeDALFactory = ({ db, keyStore }: TSecretV2DalArg) => {}};+ const findCrossProjectSecretReferencesByTargetSecretKey = async (+ targetProjectSlug: string,+ envSlug: string,+ secretPath: string,+ secretKey: string,+ tx?: Knex+ ) => {+ try {+ const docs = await (tx || db.replicaNode())(TableName.SecretReferenceV2)+ .where({+ [`${TableName.SecretReferenceV2}.secretPath` as "secretPath"]: secretPath,+ [`${TableName.SecretReferenceV2}.environment` as "environment"]: envSlug,+ [`${TableName.SecretReferenceV2}.secretKey` as "secretKey"]: secretKey,+ [`${TableName.SecretReferenceV2}.targetProjectSlug` as "targetProjectSlug"]: targetProjectSlug+ })+ .join(TableName.SecretV2, `${TableName.SecretV2}.id`, `${TableName.SecretReferenceV2}.secretId`)+ .join(TableName.SecretFolder, `${TableName.SecretV2}.folderId`, `${TableName.SecretFolder}.id`)+ .join(TableName.Environment, `${TableName.SecretFolder}.envId`, `${TableName.Environment}.id`)+ .where({+ [`${TableName.SecretFolder}.isReserved` as "isReserved"]: false+ })+ .whereNull(`${TableName.Environment}.deleteAfter`)+ .select(+ selectAllTableCols(TableName.SecretReferenceV2),+ db.ref("folderId").withSchema(TableName.SecretV2),+ db.ref("key").withSchema(TableName.SecretV2).as("secretVKey"),+ db.ref("projectId").withSchema(TableName.Environment).as("referencingProjectId")+ );++ return docs;+ } catch (error) {+ throw new DatabaseError({ error, name: "FindCrossProjectSecretReferencesByTargetSecretKey" });+ }+ };+const updateSecretReferenceEnvAndPath = async (projectId: string,oldEnvSlug: string,@@ -1449,6 +1484,7 @@ export const secretV2BridgeDALFactory = ({ db, keyStore }: TSecretV2DalArg) => {findSecretsWithReminderRecipients,findSecretsWithReminderRecipientsOld,findReferencedSecretReferencesBySecretKey,+ findCrossProjectSecretReferencesByTargetSecretKey,updateSecretReferenceSecretKey,updateSecretReferenceEnvAndPath};diff --git a/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts b/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.tsindex 67299d0aad..5ae105ca0e 100644--- a/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts+++ b/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts@@ -3128,8 +3128,7 @@ export const secretV2BridgeServiceFactory = ({});const folder = await folderDAL.findBySecretPath(projectId, environment, secretPath);- if (!folder)- throw new NotFoundError({ message: `Secret with name '${secretName}' not found` });+ if (!folder) throw new NotFoundError({ message: `Secret with name '${secretName}' not found` });const folderId = folder.id;const { decryptor: secretManagerDecryptor } = await kmsService.createCipherPairWithDataKey({@@ -3242,6 +3241,11 @@ export const secretV2BridgeServiceFactory = ({secretTags: (secret?.tags || []).map((el) => el.slug)});+ const project = await projectDAL.findById(projectId);+ if (!project) {+ throw new NotFoundError({ message: "Project not found" });+ }+const { decryptor: secretManagerDecryptor } = await kmsService.createCipherPairWithDataKey({type: KmsDataKey.SecretManager,projectId@@ -3320,6 +3324,63 @@ export const secretV2BridgeServiceFactory = ({return results;};+ const findCrossProjectSecretsReferencingSecret = async (env: string, path: string, key: string) => {+ const crossProjectRefs = await secretDAL.findCrossProjectSecretReferencesByTargetSecretKey(+ project.slug,+ env,+ path,+ key+ );++ if (!crossProjectRefs.length) return [];++ const refsByProject = new Map<string, typeof crossProjectRefs>();+ for (const ref of crossProjectRefs) {+ const refProjectId = ref.referencingProjectId;+ const existing = refsByProject.get(refProjectId) || [];+ existing.push(ref);+ refsByProject.set(refProjectId, existing);+ }++ const results: Array<{+ key: string;+ environment: string;+ secretPath: string;+ project: { id: string; slug: string; name: string };+ }> = [];++ const refProjectIds = [...refsByProject.keys()];+ const refProjects = refProjectIds.length > 0 ? await projectDAL.find({ $in: { id: refProjectIds } }) : [];+ const projectInfoMap = new Map(refProjects.map((p) => [p.id, { id: p.id, slug: p.slug, name: p.name }]));++ for (const [refProjectId, refs] of refsByProject) {+ const projectInfo = projectInfoMap.get(refProjectId);+ if (!projectInfo) {+ // eslint-disable-next-line no-continue+ continue;+ }++ const folderIds = [...new Set(refs.map((r) => r.folderId))];+ // eslint-disable-next-line no-await-in-loop+ const folderPaths = await folderDAL.findSecretPathByFolderIds(refProjectId, folderIds);+ const folderPathMap = new Map(folderPaths.filter(Boolean).map((fp) => [fp!.id, fp]));++ for (const ref of refs) {+ const folderPath = folderPathMap.get(ref.folderId);+ if (folderPath) {+ results.push({+ key: ref.secretVKey,+ environment: folderPath.environmentSlug,+ secretPath: folderPath.path,+ project: projectInfo+ });+ }+ }+ }++ return results;+ };+const createSecretId = (env: string, path: string, key: string) => `${env}:${path}:${key}`;const visitedSecrets = new Set<string>();const MAX_DEPTH = 10;@@ -3328,6 +3389,7 @@ export const secretV2BridgeServiceFactory = ({key: string;environment: string;secretPath: string;+ project?: { id: string; slug: string; name: string };children: DependencyNode[];};@@ -3377,6 +3439,17 @@ export const secretV2BridgeServiceFactory = ({}}+ const crossProjectRefs = await findCrossProjectSecretsReferencingSecret(env, path, key);+ for (const crossRef of crossProjectRefs) {+ node.children.push({+ key: crossRef.key,+ environment: crossRef.environment,+ secretPath: crossRef.secretPath,+ project: crossRef.project,+ children: []+ });+ }+return node;};diff --git a/frontend/src/components/secrets/SecretReferenceDetails/SecretReferenceDetails.tsx b/frontend/src/components/secrets/SecretReferenceDetails/SecretReferenceDetails.tsxindex a71f09afd3..bc36b4b875 100644--- a/frontend/src/components/secrets/SecretReferenceDetails/SecretReferenceDetails.tsx+++ b/frontend/src/components/secrets/SecretReferenceDetails/SecretReferenceDetails.tsx@@ -27,6 +27,7 @@ import { useGetSecretReferences, useGetSecretReferenceTree } from "@app/hooks/apimport { ApiErrorTypes, TApiErrors, TSecretReferenceTraceNode } from "@app/hooks/api/types";import { SecretReferenceEdge } from "./edges/SecretReferenceEdge";+import { ProjectGroupNode } from "./nodes/ProjectGroupNode";import { SecretNode } from "./nodes/SecretNode";import { convertDependencyTreeToFlow } from "./utils/convertToFlowElements";import { SecretReferenceCloseContext } from "./SecretReferenceContext";@@ -194,7 +195,7 @@ const SecretTree = ({);};-const NODE_TYPES = { secretNode: SecretNode };+const NODE_TYPES = { secretNode: SecretNode, projectGroupNode: ProjectGroupNode };const EDGE_TYPES = { secretEdge: SecretReferenceEdge };const SecretDependencyTree = ({ secretPath, environment, secretKey }: Props) => {diff --git a/frontend/src/components/secrets/SecretReferenceDetails/nodes/ProjectGroupNode.tsx b/frontend/src/components/secrets/SecretReferenceDetails/nodes/ProjectGroupNode.tsxnew file mode 100644index 0000000000..d1361b6ea3--- /dev/null+++ b/frontend/src/components/secrets/SecretReferenceDetails/nodes/ProjectGroupNode.tsx@@ -0,0 +1,19 @@+import { NodeProps } from "@xyflow/react";+import { BoxIcon } from "lucide-react";++export type ProjectGroupNodeData = {+ projectName: string;+};++export const ProjectGroupNode = ({ data }: NodeProps & { data: ProjectGroupNodeData }) => {+ const { projectName } = data;++ return (+ <div className="h-full w-full rounded-md border border-info/30 bg-info/5 p-2 pt-0">+ <div className="mb-1 flex items-center gap-1 rounded-b-sm bg-info/10 px-2 py-0.5 text-[10px] text-info">+ <BoxIcon className="size-3" />+ <span className="font-medium">{projectName}</span>+ </div>+ </div>+ );+};diff --git a/frontend/src/components/secrets/SecretReferenceDetails/nodes/SecretNode.tsx b/frontend/src/components/secrets/SecretReferenceDetails/nodes/SecretNode.tsxindex 8749f8aef2..94f5fce7ba 100644--- a/frontend/src/components/secrets/SecretReferenceDetails/nodes/SecretNode.tsx+++ b/frontend/src/components/secrets/SecretReferenceDetails/nodes/SecretNode.tsx@@ -16,7 +16,14 @@ import { SecretReferenceCloseContext } from "../SecretReferenceContext";import { SecretNodeData } from "../utils/convertToFlowElements";export const SecretNode = ({ data }: NodeProps & { data: SecretNodeData }) => {- const { secretKey, environment, secretPath, isRoot, isCircular } = data;+ const {+ secretKey,+ environment,+ secretPath,+ projectId: crossProjectId,+ isRoot,+ isCircular+ } = data;const capitalizedEnv = environment.charAt(0).toUpperCase() + environment.slice(1);@@ -51,7 +58,7 @@ export const SecretNode = ({ data }: NodeProps & { data: SecretNodeData }) => {to: ROUTE_PATHS.SecretManager.OverviewPage.path,params: {orgId: routeParams.orgId as string,- projectId: currentProject?.id || ""+ projectId: crossProjectId || currentProject?.id || ""},search: {secretPath,@@ -63,6 +70,7 @@ export const SecretNode = ({ data }: NodeProps & { data: SecretNodeData }) => {navigate,routeParams.orgId,currentProject,+ crossProjectId,environment,secretPath,secretKey,diff --git a/frontend/src/components/secrets/SecretReferenceDetails/utils/convertToFlowElements.ts b/frontend/src/components/secrets/SecretReferenceDetails/utils/convertToFlowElements.tsindex 9bef814c7d..03ede3ab54 100644--- a/frontend/src/components/secrets/SecretReferenceDetails/utils/convertToFlowElements.ts+++ b/frontend/src/components/secrets/SecretReferenceDetails/utils/convertToFlowElements.ts@@ -2,6 +2,7 @@ import { Edge, MarkerType, Node } from "@xyflow/react";import { TSecretDependencyTreeNode } from "@app/hooks/api/secrets/types";+import { ProjectGroupNodeData } from "../nodes/ProjectGroupNode";import { positionElements } from "./positionElements";const NODE_WIDTH = 260;@@ -11,16 +12,23 @@ export type SecretNodeData = {secretKey: string;environment: string;secretPath: string;+ projectId?: string;isRoot: boolean;isCircular: boolean;};const makeNodeKey = (env: string, path: string, key: string) => `${env}:${path}:${key}`;-// Walk the dependency tree and produce React Flow elements with root at the top+type GroupInfo = {+ groupId: string;+ projectName: string;+ childNodeIds: string[];+};+export const convertDependencyTreeToFlow = (tree: TSecretDependencyTreeNode) => {- const nodes: Node<SecretNodeData>[] = [];+ const nodes: Node<SecretNodeData | ProjectGroupNodeData>[] = [];const edges: Edge[] = [];+ const groups: GroupInfo[] = [];const walk = (node: TSecretDependencyTreeNode,@@ -43,6 +51,7 @@ export const convertDependencyTreeToFlow = (tree: TSecretDependencyTreeNode) =>secretKey: node.key,environment: node.environment,secretPath: node.secretPath,+ projectId: node.project?.id,isRoot,isCircular}@@ -66,11 +75,40 @@ export const convertDependencyTreeToFlow = (tree: TSecretDependencyTreeNode) =>if (!isCircular) {const newVisited = new Set([...visited, nodeKey]);- node.children.forEach((child) => walk(child, nodeId, depth + 1, newVisited));++ const crossProjectBySlug = new Map<string, TSecretDependencyTreeNode[]>();+ const sameProjectChildren: TSecretDependencyTreeNode[] = [];++ node.children.forEach((child) => {+ if (child.project) {+ const existing = crossProjectBySlug.get(child.project.slug) || [];+ existing.push(child);+ crossProjectBySlug.set(child.project.slug, existing);+ } else {+ sameProjectChildren.push(child);+ }+ });++ sameProjectChildren.forEach((child) => walk(child, nodeId, depth + 1, newVisited));++ Array.from(crossProjectBySlug.entries()).forEach(([slug, children]) => {+ const groupId = `group-${nodeId}-${slug}`;+ const childNodeIds = children.map((child) => {+ walk(child, nodeId, depth + 1, newVisited);+ const childKey = makeNodeKey(child.environment, child.secretPath, child.key);+ return `${nodeId}>${childKey}`;+ });++ groups.push({+ groupId,+ projectName: children[0].project?.name || slug,+ childNodeIds+ });+ });}};walk(tree, undefined, 0, new Set());- return positionElements(nodes, edges);+ return positionElements(nodes, edges, groups);};diff --git a/frontend/src/components/secrets/SecretReferenceDetails/utils/positionElements.ts b/frontend/src/components/secrets/SecretReferenceDetails/utils/positionElements.tsindex 4547ff9ca1..97d306314a 100644--- a/frontend/src/components/secrets/SecretReferenceDetails/utils/positionElements.ts+++ b/frontend/src/components/secrets/SecretReferenceDetails/utils/positionElements.ts@@ -1,8 +1,19 @@import Dagre from "@dagrejs/dagre";import { Edge, Node } from "@xyflow/react";-export const positionElements = (nodes: Node[], edges: Edge[]) => {- const dagre = new Dagre.graphlib.Graph({ directed: true })+import { ProjectGroupNodeData } from "../nodes/ProjectGroupNode";++type GroupInfo = {+ groupId: string;+ projectName: string;+ childNodeIds: string[];+};++const GROUP_PADDING = 12;+const GROUP_HEADER_HEIGHT = 24;++export const positionElements = (nodes: Node[], edges: Edge[], groups: GroupInfo[] = []) => {+ const dagre = new Dagre.graphlib.Graph({ directed: true, compound: true }).setDefaultEdgeLabel(() => ({})).setGraph({rankdir: "TB",@@ -17,11 +28,18 @@ export const positionElements = (nodes: Node[], edges: Edge[]) => {});});+ groups.forEach((group) => {+ dagre.setNode(group.groupId, {});+ group.childNodeIds.forEach((childId) => {+ dagre.setParent(childId, group.groupId);+ });+ });+edges.forEach((edge) => dagre.setEdge(edge.source, edge.target));Dagre.layout(dagre, {});- const positionedNodes = nodes.map((node) => {+ const positionedNodes: Node[] = nodes.map((node) => {const { x, y } = dagre.node(node.id);return {@@ -33,8 +51,50 @@ export const positionElements = (nodes: Node[], edges: Edge[]) => {};});+ const groupNodes: Node<ProjectGroupNodeData>[] = groups+ .map((group) => {+ const childPositions = group.childNodeIds+ .map((id) => positionedNodes.find((n) => n.id === id))+ .filter(Boolean) as Node[];++ if (childPositions.length === 0) return null;++ let minX = Infinity;+ let minY = Infinity;+ let maxX = -Infinity;+ let maxY = -Infinity;++ childPositions.forEach((child) => {+ const w = child.width || 150;+ const h = child.height || 40;+ minX = Math.min(minX, child.position.x);+ minY = Math.min(minY, child.position.y);+ maxX = Math.max(maxX, child.position.x + w);+ maxY = Math.max(maxY, child.position.y + h);+ });++ const groupX = minX - GROUP_PADDING;+ const groupY = minY - GROUP_PADDING - GROUP_HEADER_HEIGHT;+ const groupWidth = maxX - minX + GROUP_PADDING * 2;+ const groupHeight = maxY - minY + GROUP_PADDING * 2 + GROUP_HEADER_HEIGHT;++ return {+ id: group.groupId,+ type: "projectGroupNode",+ position: { x: groupX, y: groupY },+ width: groupWidth,+ height: groupHeight,+ style: { width: groupWidth, height: groupHeight },+ zIndex: -1,+ data: { projectName: group.projectName },+ selectable: false,+ draggable: false+ };+ })+ .filter(Boolean) as Node<ProjectGroupNodeData>[];+return {- nodes: positionedNodes,+ nodes: [...groupNodes, ...positionedNodes],edges};};diff --git a/frontend/src/hooks/api/secrets/types.ts b/frontend/src/hooks/api/secrets/types.tsindex 9fe9cbf2fd..4fc968eff7 100644--- a/frontend/src/hooks/api/secrets/types.ts+++ b/frontend/src/hooks/api/secrets/types.ts@@ -333,6 +333,7 @@ export type TSecretDependencyTreeNode = {key: string;environment: string;secretPath: string;+ project?: { id: string; slug: string; name: string };children: TSecretDependencyTreeNode[];};