Skip to content

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

feedback changes

Matheus Nogueirac610abebc994
diff --git a/backend/src/server/routes/v1/project-folder-grant-router.ts b/backend/src/server/routes/v1/project-folder-grant-router.ts
index a0c59fdbc9..3c15a6e466 100644
--- a/backend/src/server/routes/v1/project-folder-grant-router.ts
+++ b/backend/src/server/routes/v1/project-folder-grant-router.ts
@@ -118,6 +118,37 @@ export const registerProjectFolderGrantRouter = async (server: FastifyZodProvide
}
});
+ server.route({
+ method: "GET",
+ url: "/:grantId/usage",
+ config: { rateLimit: readLimit },
+ schema: {
+ params: z.object({
+ grantId: z.string().uuid()
+ }),
+ querystring: z.object({
+ sourceProjectId: z.string()
+ }),
+ response: {
+ 200: z.object({
+ importCount: z.number(),
+ referenceCount: z.number()
+ })
+ }
+ },
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
+ handler: async (req) => {
+ return server.services.projectFolderGrant.getGrantUsage({
+ actorId: req.permission.id,
+ actor: req.permission.type,
+ actorAuthMethod: req.permission.authMethod,
+ actorOrgId: req.permission.orgId,
+ grantId: req.params.grantId,
+ sourceProjectId: req.query.sourceProjectId
+ });
+ }
+ });
+
server.route({
method: "DELETE",
url: "/:grantId",
diff --git a/backend/src/services/project-folder-grant/project-folder-grant-dal.ts b/backend/src/services/project-folder-grant/project-folder-grant-dal.ts
index cfe7e5db2c..e83eedf49b 100644
--- a/backend/src/services/project-folder-grant/project-folder-grant-dal.ts
+++ b/backend/src/services/project-folder-grant/project-folder-grant-dal.ts
@@ -2,6 +2,7 @@ import { Knex } from "knex";
import { TDbClient } from "@app/db";
import { TableName, TProjectFolderGrants } from "@app/db/schemas";
+import { DatabaseError } from "@app/lib/errors";
import { ormify } from "@app/lib/knex";
export type TProjectFolderGrantDALFactory = ReturnType<typeof projectFolderGrantDALFactory>;
@@ -71,5 +72,51 @@ export const projectFolderGrantDALFactory = (db: TDbClient) => {
})[];
};
- return { ...orm, listBySourceProject, listByTargetProject };
+ const countUsageByGrant = async (
+ {
+ targetProjectId,
+ sourceEnvId,
+ sourcePath,
+ sourceProjectSlug,
+ sourceEnvSlug
+ }: {
+ targetProjectId: string;
+ sourceEnvId: string;
+ sourcePath: string;
+ sourceProjectSlug: string;
+ sourceEnvSlug: string;
+ },
+ tx?: Knex
+ ) => {
+ try {
+ const importResult = await (tx || db.replicaNode())(TableName.SecretImport)
+ .join(TableName.SecretFolder, `${TableName.SecretImport}.folderId`, `${TableName.SecretFolder}.id`)
+ .join(TableName.Environment, `${TableName.SecretFolder}.envId`, `${TableName.Environment}.id`)
+ .whereNull(`${TableName.Environment}.deleteAfter`)
+ .where(`${TableName.Environment}.projectId`, targetProjectId)
+ .where(`${TableName.SecretImport}.importEnv`, sourceEnvId)
+ .where(`${TableName.SecretImport}.importPath`, sourcePath)
+ .count();
+
+ const referenceResult = await (tx || db.replicaNode())(TableName.SecretReferenceV2)
+ .join(TableName.SecretV2, `${TableName.SecretReferenceV2}.secretId`, `${TableName.SecretV2}.id`)
+ .join(TableName.SecretFolder, `${TableName.SecretV2}.folderId`, `${TableName.SecretFolder}.id`)
+ .join(TableName.Environment, `${TableName.SecretFolder}.envId`, `${TableName.Environment}.id`)
+ .whereNull(`${TableName.Environment}.deleteAfter`)
+ .where(`${TableName.Environment}.projectId`, targetProjectId)
+ .where(`${TableName.SecretReferenceV2}.targetProjectSlug`, sourceProjectSlug)
+ .where(`${TableName.SecretReferenceV2}.environment`, sourceEnvSlug)
+ .where(`${TableName.SecretReferenceV2}.secretPath`, sourcePath)
+ .count();
+
+ return {
+ importCount: Number(importResult[0]?.count ?? 0),
+ referenceCount: Number(referenceResult[0]?.count ?? 0)
+ };
+ } catch (error) {
+ throw new DatabaseError({ error, name: "Count grant usage" });
+ }
+ };
+
+ return { ...orm, listBySourceProject, listByTargetProject, countUsageByGrant };
};
diff --git a/backend/src/services/project-folder-grant/project-folder-grant-service.ts b/backend/src/services/project-folder-grant/project-folder-grant-service.ts
index acd3022f8a..1090cc78a0 100644
--- a/backend/src/services/project-folder-grant/project-folder-grant-service.ts
+++ b/backend/src/services/project-folder-grant/project-folder-grant-service.ts
@@ -18,6 +18,7 @@ import { isCrossProjectEnabled } from "./project-folder-grant-fns";
import {
TCreateProjectFolderGrantDTO,
TDeleteProjectFolderGrantDTO,
+ TGetGrantUsageDTO,
TListProjectFolderGrantsDTO,
TListProjectFolderGrantsForTargetDTO
} from "./project-folder-grant-types";
@@ -197,5 +198,50 @@ export const projectFolderGrantServiceFactory = ({
return projectFolderGrantDAL.listByTargetProject(targetProjectId);
};
- return { createGrant, deleteGrant, listGrantsByProject, listGrantsForTargetProject };
+ const getGrantUsage = async ({
+ actorId,
+ actor,
+ actorAuthMethod,
+ actorOrgId,
+ grantId,
+ sourceProjectId
+ }: TGetGrantUsageDTO) => {
+ const grant = await projectFolderGrantDAL.findById(grantId);
+ if (!grant || grant.sourceProjectId !== sourceProjectId) {
+ throw new NotFoundError({ message: "Grant not found" });
+ }
+
+ const { permission } = await permissionService.getProjectPermission({
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId,
+ projectId: sourceProjectId,
+ actionProjectType: ActionProjectType.SecretManager
+ });
+ ForbiddenError.from(permission).throwUnlessCan(
+ ProjectPermissionProjectFolderGrantActions.ReadGrant,
+ ProjectPermissionSub.ProjectFolderGrant
+ );
+
+ const [folderInfo] = await folderDAL.findSecretPathByFolderIds(sourceProjectId, [grant.sourceFolderId]);
+ if (!folderInfo) {
+ return { importCount: 0, referenceCount: 0 };
+ }
+
+ const sourceProject = await projectDAL.findById(sourceProjectId);
+ if (!sourceProject) {
+ return { importCount: 0, referenceCount: 0 };
+ }
+
+ return projectFolderGrantDAL.countUsageByGrant({
+ targetProjectId: grant.targetProjectId,
+ sourceEnvId: folderInfo.envId,
+ sourcePath: folderInfo.path,
+ sourceProjectSlug: sourceProject.slug,
+ sourceEnvSlug: folderInfo.environmentSlug
+ });
+ };
+
+ return { createGrant, deleteGrant, listGrantsByProject, listGrantsForTargetProject, getGrantUsage };
};
diff --git a/backend/src/services/project-folder-grant/project-folder-grant-types.ts b/backend/src/services/project-folder-grant/project-folder-grant-types.ts
index 556f7e421c..34a34d3430 100644
--- a/backend/src/services/project-folder-grant/project-folder-grant-types.ts
+++ b/backend/src/services/project-folder-grant/project-folder-grant-types.ts
@@ -27,6 +27,11 @@ export type TListProjectFolderGrantsForTargetDTO = TBaseActor & {
targetProjectId: string;
};
+export type TGetGrantUsageDTO = TBaseActor & {
+ grantId: string;
+ sourceProjectId: string;
+};
+
export type TCheckRevokedGrantsDTO = {
targetProjectId: string;
actorOrgId: string;
diff --git a/backend/src/services/secret-import/secret-import-dal.ts b/backend/src/services/secret-import/secret-import-dal.ts
index 27d11da147..c664177cd1 100644
--- a/backend/src/services/secret-import/secret-import-dal.ts
+++ b/backend/src/services/secret-import/secret-import-dal.ts
@@ -524,6 +524,41 @@ export const secretImportDALFactory = (db: TDbClient) => {
}
};
+ const findCrossProjectImportsBySourceFolder = async (
+ sourceEnvId: string,
+ sourceSecretPath: string,
+ sourceProjectId: string,
+ tx?: Knex
+ ) => {
+ try {
+ const docs = await (tx || db.replicaNode())(TableName.SecretImport)
+ .where({
+ [`${TableName.SecretImport}.importEnv` as "importEnv"]: sourceEnvId,
+ [`${TableName.SecretImport}.importPath` as "importPath"]: sourceSecretPath
+ })
+ .where((qb) => {
+ void qb
+ .where(`${TableName.SecretImport}.isReplication`, false)
+ .orWhereNull(`${TableName.SecretImport}.isReplication`);
+ })
+ .join(TableName.SecretFolder, `${TableName.SecretImport}.folderId`, `${TableName.SecretFolder}.id`)
+ .join(TableName.Environment, `${TableName.SecretFolder}.envId`, `${TableName.Environment}.id`)
+ .join(TableName.Project, `${TableName.Environment}.projectId`, `${TableName.Project}.id`)
+ .whereNot(`${TableName.Environment}.projectId`, sourceProjectId)
+ .whereNull(`${TableName.Environment}.deleteAfter`)
+ .whereNull(`${TableName.Project}.deleteAfter`)
+ .select(
+ db.ref("folderId").withSchema(TableName.SecretImport),
+ db.ref("projectId").withSchema(TableName.Environment).as("targetProjectId"),
+ db.ref("orgId").withSchema(TableName.Project).as("targetOrgId")
+ );
+
+ return docs;
+ } catch (error) {
+ throw new DatabaseError({ error, name: "FindCrossProjectImportsBySourceFolder" });
+ }
+ };
+
return {
...secretImportOrm,
find,
@@ -537,6 +572,7 @@ export const secretImportDALFactory = (db: TDbClient) => {
getProjectImportCount,
getUniqueImportCountByFolderIds,
getFolderIsImportedBy,
- getFolderImports
+ getFolderImports,
+ findCrossProjectImportsBySourceFolder
};
};
diff --git a/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts b/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts
index 9095dcf1d3..293ca80a5d 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
@@ -1039,6 +1039,40 @@ export const secretV2BridgeDALFactory = ({ db, keyStore }: TSecretV2DalArg) => {
}
};
+ const findCrossProjectSecretReferencesByTargetFolder = async (
+ targetProjectSlug: string,
+ envSlug: string,
+ secretPath: 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}.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`)
+ .join(TableName.Project, `${TableName.Environment}.projectId`, `${TableName.Project}.id`)
+ .where({
+ [`${TableName.SecretFolder}.isReserved` as "isReserved"]: false
+ })
+ .whereNull(`${TableName.Environment}.deleteAfter`)
+ .whereNull(`${TableName.Project}.deleteAfter`)
+ .select(
+ db.ref("folderId").withSchema(TableName.SecretV2),
+ db.ref("projectId").withSchema(TableName.Environment).as("referencingProjectId"),
+ db.ref("orgId").withSchema(TableName.Project).as("referencingOrgId")
+ );
+
+ return docs;
+ } catch (error) {
+ throw new DatabaseError({ error, name: "FindCrossProjectSecretReferencesByTargetFolder" });
+ }
+ };
+
const updateSecretReferenceEnvAndPath = async (
projectId: string,
oldEnvSlug: string,
@@ -1485,6 +1519,7 @@ export const secretV2BridgeDALFactory = ({ db, keyStore }: TSecretV2DalArg) => {
findSecretsWithReminderRecipientsOld,
findReferencedSecretReferencesBySecretKey,
findCrossProjectSecretReferencesByTargetSecretKey,
+ findCrossProjectSecretReferencesByTargetFolder,
updateSecretReferenceSecretKey,
updateSecretReferenceEnvAndPath
};
diff --git a/backend/src/services/secret/secret-queue.ts b/backend/src/services/secret/secret-queue.ts
index c3d2c0ea4a..78ae26547e 100644
--- a/backend/src/services/secret/secret-queue.ts
+++ b/backend/src/services/secret/secret-queue.ts
@@ -95,7 +95,10 @@ type TSecretQueueFactoryDep = {
integrationAuthService: Pick<TIntegrationAuthServiceFactory, "getIntegrationAccessToken">;
folderDAL: TSecretFolderDALFactory;
secretDAL: TSecretDALFactory;
- secretImportDAL: Pick<TSecretImportDALFactory, "find" | "findByFolderIds" | "findByIds">;
+ secretImportDAL: Pick<
+ TSecretImportDALFactory,
+ "find" | "findByFolderIds" | "findByIds" | "findCrossProjectImportsBySourceFolder"
+ >;
webhookDAL: Pick<TWebhookDALFactory, "findAllWebhooks" | "transaction" | "update" | "bulkUpdate">;
projectEnvDAL: Pick<TProjectEnvDALFactory, "findOne" | "find">;
projectDAL: TProjectDALFactory;
@@ -904,6 +907,78 @@ export const secretQueueFactory = ({
);
}
+ // Cross-project imports: find imports from other projects that import from this folder
+ const crossProjectImports = await secretImportDAL.findCrossProjectImportsBySourceFolder(
+ folder.environment.id,
+ secretPath,
+ projectId
+ );
+ if (crossProjectImports.length) {
+ logger.info(
+ `getIntegrationSecrets: Syncing cross-project imports [jobId=${job.id}] [sourceProjectId=${projectId}] [environment=${environment}] [secretPath=${secretPath}] [targetCount=${crossProjectImports.length}]`
+ );
+ const crossProjectGroups = groupBy(crossProjectImports, (i) => i.targetProjectId);
+ for await (const [targetProjectId, groupImports] of Object.entries(crossProjectGroups)) {
+ const targetFolderIds = unique(groupImports, (i) => i.folderId).map(({ folderId }) => folderId);
+ const targetFolders = await folderDAL.findSecretPathByFolderIds(targetProjectId, targetFolderIds);
+ const targetFoldersGroupedById = groupBy(targetFolders.filter(Boolean), (i) => i?.id as string);
+ const { targetOrgId } = groupImports[0];
+
+ await Promise.all(
+ targetFolderIds
+ .filter((folderId) => Boolean(targetFoldersGroupedById[folderId]?.[0]?.path))
+ .map((folderId) =>
+ syncSecrets({
+ projectId: targetProjectId,
+ orgId: targetOrgId,
+ secretPath: targetFoldersGroupedById[folderId][0]?.path as string,
+ environmentSlug: targetFoldersGroupedById[folderId][0]?.environmentSlug as string,
+ environmentName: targetFoldersGroupedById[folderId][0]?.environmentName as string,
+ _depth: depth + 1,
+ excludeReplication: true
+ })
+ )
+ );
+ }
+ }
+
+ // Cross-project references: find secrets in other projects that reference secrets in this folder
+ if (shouldUseSecretV2Bridge) {
+ const crossProjectRefs = await secretV2BridgeDAL.findCrossProjectSecretReferencesByTargetFolder(
+ project.slug,
+ environment,
+ secretPath
+ );
+ if (crossProjectRefs.length) {
+ logger.info(
+ `getIntegrationSecrets: Syncing cross-project references [jobId=${job.id}] [sourceProjectId=${projectId}] [environment=${environment}] [secretPath=${secretPath}] [refCount=${crossProjectRefs.length}]`
+ );
+ const crossRefProjectGroups = groupBy(crossProjectRefs, (i) => i.referencingProjectId);
+ for await (const [referencingProjectId, groupRefs] of Object.entries(crossRefProjectGroups)) {
+ const refFolderIds = unique(groupRefs, (i) => i.folderId).map(({ folderId }) => folderId);
+ const refFolders = await folderDAL.findSecretPathByFolderIds(referencingProjectId, refFolderIds);
+ const refFoldersGroupedById = groupBy(refFolders.filter(Boolean), (i) => i?.id as string);
+ const { referencingOrgId } = groupRefs[0];
+
+ await Promise.all(
+ refFolderIds
+ .filter((folderId) => Boolean(refFoldersGroupedById[folderId]?.[0]?.path))
+ .map((folderId) =>
+ syncSecrets({
+ projectId: referencingProjectId,
+ orgId: referencingOrgId,
+ secretPath: refFoldersGroupedById[folderId][0]?.path as string,
+ environmentSlug: refFoldersGroupedById[folderId][0]?.environmentSlug as string,
+ environmentName: refFoldersGroupedById[folderId][0]?.environmentName as string,
+ _depth: depth + 1,
+ excludeReplication: true
+ })
+ )
+ );
+ }
+ }
+ }
+
const lock = await keyStore.acquireLock(
[KeyStorePrefixes.SyncSecretIntegrationLock(projectId, environment, secretPath)],
60000,
diff --git a/frontend/src/components/v2/InfisicalSecretInput/InfisicalSecretInput.tsx b/frontend/src/components/v2/InfisicalSecretInput/InfisicalSecretInput.tsx
index 56121512f3..31c4d95f02 100644
--- a/frontend/src/components/v2/InfisicalSecretInput/InfisicalSecretInput.tsx
+++ b/frontend/src/components/v2/InfisicalSecretInput/InfisicalSecretInput.tsx
@@ -360,6 +360,8 @@ export const InfisicalSecretInput = forwardRef<HTMLTextAreaElement, Props>(
return;
}
+ if (allSegments[0]?.startsWith("@")) return;
+
if (allSegments.length === 1) {
const canReadSecretValue = hasSecretReadValueOrDescribePermission(
permission,
diff --git a/frontend/src/components/v2/SecretInput/SecretInput.tsx b/frontend/src/components/v2/SecretInput/SecretInput.tsx
index cfc4fdb840..07c4399fcb 100644
--- a/frontend/src/components/v2/SecretInput/SecretInput.tsx
+++ b/frontend/src/components/v2/SecretInput/SecretInput.tsx
@@ -36,6 +36,7 @@ const syntaxHighlight = (
const part = el;
const innerContent = el.slice(2, -1); // Remove ${ and }
const parts = innerContent.split(".");
+ const isCrossProjectRef = parts[0]?.startsWith("@");
return (
<span className="ph-no-capture relative z-10 text-yellow" key={`secret-value-${i + 1}`}>
@@ -43,33 +44,34 @@ const syntaxHighlight = (
{parts.map((segment, segmentIndex) => {
const segmentKey = `${part}-segment-${segmentIndex}`;
const isHovered = hoveredPart === segmentKey;
- const shouldShowHoverStyle = isHovered && isCmdOrCtrlPressed;
+ const isInteractive = isCmdOrCtrlPressed && !isCrossProjectRef;
+ const shouldShowHoverStyle = isHovered && isInteractive;
return (
<span key={segmentKey}>
<span
role="button"
- tabIndex={isCmdOrCtrlPressed ? 0 : -1}
+ tabIndex={isInteractive ? 0 : -1}
className={`ph-no-capture text-yellow-200/80 ${
- isCmdOrCtrlPressed ? "pointer-events-auto" : "pointer-events-none"
+ isInteractive ? "pointer-events-auto" : "pointer-events-none"
} ${shouldShowHoverStyle ? "cursor-pointer underline decoration-yellow-400" : ""}`}
onMouseEnter={() => onHoverPart?.(segmentKey)}
onMouseLeave={() => onHoverPart?.("")}
onMouseDown={(e) => {
- if (isCmdOrCtrlPressed) {
+ if (isInteractive) {
e.preventDefault();
e.stopPropagation();
}
}}
onClick={(e) => {
e.stopPropagation();
- if (isCmdOrCtrlPressed) {
+ if (isInteractive) {
e.preventDefault();
onClickSegment?.(segment, parts);
}
}}
onKeyDown={(e) => {
- if (isCmdOrCtrlPressed && (e.key === "Enter" || e.key === " ")) {
+ if (isInteractive && (e.key === "Enter" || e.key === " ")) {
e.preventDefault();
e.stopPropagation();
onClickSegment?.(segment, parts);
diff --git a/frontend/src/components/v3/platform/SecretInput/SecretInput.tsx b/frontend/src/components/v3/platform/SecretInput/SecretInput.tsx
index f0dd79b112..20f7fa0ccb 100644
--- a/frontend/src/components/v3/platform/SecretInput/SecretInput.tsx
+++ b/frontend/src/components/v3/platform/SecretInput/SecretInput.tsx
@@ -37,6 +37,7 @@ const syntaxHighlight = (
const part = el;
const innerContent = el.slice(2, -1);
const parts = innerContent.split(".");
+ const isCrossProjectRef = parts[0]?.startsWith("@");
return (
<span className="ph-no-capture relative z-10 text-yellow" key={`secret-value-${i + 1}`}>
@@ -44,35 +45,36 @@ const syntaxHighlight = (
{parts.map((segment, segmentIndex) => {
const segmentKey = `${part}-segment-${segmentIndex}`;
const isHovered = hoveredPart === segmentKey;
- const shouldShowHoverStyle = isHovered && isCmdOrCtrlPressed;
+ const isInteractive = isCmdOrCtrlPressed && !isCrossProjectRef;
+ const shouldShowHoverStyle = isHovered && isInteractive;
return (
<span key={segmentKey}>
<span
role="button"
- tabIndex={isCmdOrCtrlPressed ? 0 : -1}
+ tabIndex={isInteractive ? 0 : -1}
className={cn(
"ph-no-capture text-yellow-200/80",
- isCmdOrCtrlPressed ? "pointer-events-auto" : "pointer-events-none",
+ isInteractive ? "pointer-events-auto" : "pointer-events-none",
shouldShowHoverStyle && "cursor-pointer underline decoration-yellow-400"
)}
onMouseEnter={() => onHoverPart?.(segmentKey)}
onMouseLeave={() => onHoverPart?.("")}
onMouseDown={(e) => {
- if (isCmdOrCtrlPressed) {
+ if (isInteractive) {
e.preventDefault();
e.stopPropagation();
}
}}
onClick={(e) => {
e.stopPropagation();
- if (isCmdOrCtrlPressed) {
+ if (isInteractive) {
e.preventDefault();
onClickSegment?.(segment, parts);
}
}}
onKeyDown={(e) => {
- if (isCmdOrCtrlPressed && (e.key === "Enter" || e.key === " ")) {
+ if (isInteractive && (e.key === "Enter" || e.key === " ")) {
e.preventDefault();
e.stopPropagation();
onClickSegment?.(segment, parts);
diff --git a/frontend/src/hooks/api/projectFolderGrants/index.ts b/frontend/src/hooks/api/projectFolderGrants/index.ts
index 70991d7c18..638c5d3d64 100644
--- a/frontend/src/hooks/api/projectFolderGrants/index.ts
+++ b/frontend/src/hooks/api/projectFolderGrants/index.ts
@@ -1,8 +1,13 @@
export { useCreateProjectFolderGrant, useDeleteProjectFolderGrant } from "./mutations";
-export { useListProjectFolderGrants, useListProjectFolderGrantsReceived } from "./queries";
+export {
+ useGetProjectFolderGrantUsage,
+ useListProjectFolderGrants,
+ useListProjectFolderGrantsReceived
+} from "./queries";
export type {
TCreateProjectFolderGrantDTO,
TDeleteProjectFolderGrantDTO,
TProjectFolderGrant,
- TProjectFolderGrantReceived
+ TProjectFolderGrantReceived,
+ TProjectFolderGrantUsage
} from "./types";
diff --git a/frontend/src/hooks/api/projectFolderGrants/queries.tsx b/frontend/src/hooks/api/projectFolderGrants/queries.tsx
index 9f76a77167..a2e7c86638 100644
--- a/frontend/src/hooks/api/projectFolderGrants/queries.tsx
+++ b/frontend/src/hooks/api/projectFolderGrants/queries.tsx
@@ -2,13 +2,19 @@ import { useQuery } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
-import { TProjectFolderGrant, TProjectFolderGrantReceived } from "./types";
+import {
+ TProjectFolderGrant,
+ TProjectFolderGrantReceived,
+ TProjectFolderGrantUsage
+} from "./types";
export const projectFolderGrantKeys = {
listByProject: (sourceProjectId: string) =>
[{ sourceProjectId }, "project-folder-grants"] as const,
listReceived: (targetProjectId: string) =>
- [{ targetProjectId }, "project-folder-grants-received"] as const
+ [{ targetProjectId }, "project-folder-grants-received"] as const,
+ usage: (grantId: string, sourceProjectId: string) =>
+ [{ grantId, sourceProjectId }, "project-folder-grant-usage"] as const
};
export const useListProjectFolderGrants = (sourceProjectId: string) =>
@@ -40,3 +46,20 @@ export const useListProjectFolderGrantsReceived = (targetProjectId: string) =>
},
enabled: Boolean(targetProjectId)
});
+
+export const useGetProjectFolderGrantUsage = (
+ grantId: string,
+ sourceProjectId: string,
+ enabled = true
+) =>
+ useQuery({
+ queryKey: projectFolderGrantKeys.usage(grantId, sourceProjectId),
+ queryFn: async () => {
+ const { data } = await apiRequest.get<TProjectFolderGrantUsage>(
+ `/api/v1/project-folder-grants/${grantId}/usage`,
+ { params: { sourceProjectId } }
+ );
+ return data;
+ },
+ enabled: Boolean(grantId) && Boolean(sourceProjectId) && enabled
+ });
diff --git a/frontend/src/hooks/api/projectFolderGrants/types.ts b/frontend/src/hooks/api/projectFolderGrants/types.ts
index 510fb758d6..a88b1b2c4b 100644
--- a/frontend/src/hooks/api/projectFolderGrants/types.ts
+++ b/frontend/src/hooks/api/projectFolderGrants/types.ts
@@ -38,3 +38,8 @@ export type TDeleteProjectFolderGrantDTO = {
grantId: string;
sourceProjectId: string;
};
+
+export type TProjectFolderGrantUsage = {
+ importCount: number;
+ referenceCount: number;
+};
diff --git a/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/CrossProjectSharingSection.tsx b/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/CrossProjectSharingSection.tsx
index 0c56ded843..f323bd5783 100644
--- a/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/CrossProjectSharingSection.tsx
+++ b/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/CrossProjectSharingSection.tsx
@@ -12,6 +12,14 @@ import {
import { createNotification } from "@app/components/notifications";
import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
Badge,
Breadcrumb,
BreadcrumbItem,
@@ -20,11 +28,14 @@ import {
BreadcrumbSeparator,
Button,
DocumentationLinkBadge,
- IconButton
+ IconButton,
+ Input
} from "@app/components/v3";
import { useProject } from "@app/context";
import {
+ TProjectFolderGrant,
useDeleteProjectFolderGrant,
+ useGetProjectFolderGrantUsage,
useListProjectFolderGrants
} from "@app/hooks/api/projectFolderGrants";
@@ -53,23 +64,120 @@ const FolderPath = ({ folderName }: FolderPathProps) => {
);
};
-export const CrossProjectSharingSection = () => {
- const [isShareSheetOpen, setIsShareSheetOpen] = useState(false);
- const { currentProject } = useProject();
+type DeleteGrantDialogProps = {
+ grant: TProjectFolderGrant | null;
+ onOpenChange: (open: boolean) => void;
+ sourceProjectId: string;
+};
- const { data: grants = [] } = useListProjectFolderGrants(currentProject.id);
+const CONFIRMATION_KEYWORD = "confirm";
+
+const DeleteGrantDialog = ({ grant, onOpenChange, sourceProjectId }: DeleteGrantDialogProps) => {
+ const [confirmation, setConfirmation] = useState("");
const deleteGrant = useDeleteProjectFolderGrant();
+ const { data: usage, isLoading: isLoadingUsage } = useGetProjectFolderGrantUsage(
+ grant?.id ?? "",
+ sourceProjectId,
+ Boolean(grant)
+ );
- const handleDelete = async (grantId: string) => {
+ const totalUsage = (usage?.importCount ?? 0) + (usage?.referenceCount ?? 0);
+ const isConfirmed = confirmation === CONFIRMATION_KEYWORD;
+
+ const handleConfirmDelete = async () => {
+ if (!grant || !isConfirmed) return;
try {
- await deleteGrant.mutateAsync({ grantId, sourceProjectId: currentProject.id });
+ await deleteGrant.mutateAsync({ grantId: grant.id, sourceProjectId });
createNotification({ text: "Grant removed", type: "success" });
+ onOpenChange(false);
} catch (err) {
console.error(err);
createNotification({ text: "Failed to remove grant", type: "error" });
}
};
+ const renderDescription = () => {
+ if (isLoadingUsage) {
+ return "Checking for active usage...";
+ }
+
+ if (totalUsage > 0) {
+ const parts: string[] = [];
+ if (usage!.importCount > 0) {
+ parts.push(
+ `${usage!.importCount} secret ${usage!.importCount === 1 ? "import" : "imports"}`
+ );
+ }
+ if (usage!.referenceCount > 0) {
+ parts.push(
+ `${usage!.referenceCount} secret ${usage!.referenceCount === 1 ? "reference" : "references"}`
+ );
+ }
+ return (
+ <>
+ This grant is actively used by {parts.join(" and ")} in{" "}
+ <strong>{grant?.targetProjectName}</strong>. Removing it will break{" "}
+ {totalUsage === 1 ? "that link" : "those links"}.
+ </>
+ );
+ }
+
+ return (
+ <>
+ This will revoke <strong>{grant?.targetProjectName}</strong>&apos;s access to the shared
+ secrets. This action cannot be undone.
+ </>
+ );
+ };
+
+ return (
+ <AlertDialog
+ open={Boolean(grant)}
+ onOpenChange={(open) => {
+ if (!open) setConfirmation("");
+ onOpenChange(open);
+ }}
+ >
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>Remove Grant</AlertDialogTitle>
+ <AlertDialogDescription>{renderDescription()}</AlertDialogDescription>
+ </AlertDialogHeader>
+ <div className="w-full pb-4">
+ <p className="mb-2 text-sm text-muted">
+ Type <span className="font-medium text-foreground">{CONFIRMATION_KEYWORD}</span> to
+ proceed
+ </p>
+ <Input
+ value={confirmation}
+ onChange={(e) => setConfirmation(e.target.value)}
+ placeholder={CONFIRMATION_KEYWORD}
+ autoComplete="off"
+ />
+ </div>
+ <AlertDialogFooter>
+ <AlertDialogCancel>Cancel</AlertDialogCancel>
+ <AlertDialogAction
+ variant="danger"
+ onClick={handleConfirmDelete}
+ isPending={deleteGrant.isPending}
+ disabled={!isConfirmed || isLoadingUsage}
+ >
+ Remove
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
+ );
+};
+
+export const CrossProjectSharingSection = () => {
+ const [isShareSheetOpen, setIsShareSheetOpen] = useState(false);
+ const [grantToDelete, setGrantToDelete] = useState<TProjectFolderGrant | null>(null);
+ const { currentProject } = useProject();
+
+ const { data: grants = [] } = useListProjectFolderGrants(currentProject.id);
+
return (
<div className="mb-6 rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-4">
<div className="flex w-full items-center justify-between">
@@ -137,18 +245,20 @@ export const CrossProjectSharingSection = () => {
</div>
{/* delete */}
- <IconButton
- variant="ghost-muted"
- size="xs"
- isPending={deleteGrant.isPending}
- onClick={() => handleDelete(grant.id)}
- >
+ <IconButton variant="ghost-muted" size="xs" onClick={() => setGrantToDelete(grant)}>
<Trash2 />
</IconButton>
</div>
))}
</div>
)}
+ <DeleteGrantDialog
+ grant={grantToDelete}
+ onOpenChange={(open) => {
+ if (!open) setGrantToDelete(null);
+ }}
+ sourceProjectId={currentProject.id}
+ />
</div>
);
};
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SecretImportTableRow/SecretImportTableRow.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SecretImportTableRow/SecretImportTableRow.tsx
index 34b17f947b..eb56c57603 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/SecretImportTableRow/SecretImportTableRow.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SecretImportTableRow/SecretImportTableRow.tsx
@@ -482,8 +482,8 @@ export const SecretImportTableRow = ({
</EmptyTitle>
</div>
<EmptyDescription>
- Imported values can no longer be resolved and any reference to them will fail at build
- time. Re-request access from the source project, or remove this import.
+ Import can no longer be resolved. Re-request access from the source project or remove
+ this import.
</EmptyDescription>
</EmptyHeader>
</Empty>
@@ -729,7 +729,7 @@ export const SecretImportTableRow = ({
>
<Badge variant="danger">
<BanIcon />
- Access revoked
+ Secret share revoked
</Badge>
</div>
)}
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretEditTableRow.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretEditTableRow.tsx
index 02fc30471e..5b9ac98820 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretEditTableRow.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretEditTableRow.tsx
@@ -1124,7 +1124,7 @@ export const SecretEditTableRow = ({
>
<Badge variant="danger">
<BanIcon className="size-3.5" />
- Access Revoked
+ Secret share revoked
</Badge>
</div>
)}
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretTableRow.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretTableRow.tsx
index 0a152ae2f5..5b2682907f 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretTableRow.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretTableRow.tsx
@@ -356,7 +356,7 @@ export const SecretTableRow = ({
) && (
<Badge variant="danger">
<BanIcon className="size-3.5" />
- Access Revoked
+ Secret share revoked
</Badge>
)}
</div>
diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateSecretImportForm.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateSecretImportForm.tsx
index dae6846ab4..3e50253a5c 100644
--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateSecretImportForm.tsx
+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateSecretImportForm.tsx
@@ -443,8 +443,10 @@ export const CreateSecretImportForm = ({
<TabsTrigger value="another-project">Another Project</TabsTrigger>
</TabsList>
<Tooltip>
- <TooltipTrigger>
- <InfoIcon size={16} className="text-mineshaft-400" />
+ <TooltipTrigger asChild>
+ <span className="flex cursor-default items-center">
+ <InfoIcon size={16} className="text-mineshaft-400" />
+ </span>
</TooltipTrigger>
<TooltipContent side="right" align="start" className="max-w-sm">
<p className="mb-2 text-mineshaft-300">
diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretImportListView/SecretImportItem.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretImportListView/SecretImportItem.tsx
index 70a2d78b43..52ba47a69c 100644
--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretImportListView/SecretImportItem.tsx
+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretImportListView/SecretImportItem.tsx
@@ -182,7 +182,7 @@ export const SecretImportItem = ({
<div className="flex items-center space-x-4 py-2 pr-4">
{isAccessRevoked && (
<span className="rounded border border-red-700/40 bg-red-900/20 px-1.5 py-0.5 text-xs text-red-400">
- Access revoked
+ Secret share revoked
</span>
)}
{lastReplicated && (
@@ -316,8 +316,8 @@ export const SecretImportItem = ({
</EmptyTitle>
</div>
<EmptyDescription className="text-danger/70">
- Imported values can no longer be resolved and any reference to them will fail at
- build time. Re-request access from the source project, or remove this import.
+ Import can no longer be resolved. Re-request access from the source project or
+ remove this import.
</EmptyDescription>
</EmptyHeader>
</Empty>