Skip to content

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

feat: enhance project folder grant management with usage tracking

Victor Hugo dos Santos6a9694b5a854
diff --git a/frontend/src/hooks/api/projectFolderGrants/index.ts b/frontend/src/hooks/api/projectFolderGrants/index.ts
index 638c5d3d64..b785e159ae 100644
--- a/frontend/src/hooks/api/projectFolderGrants/index.ts
+++ b/frontend/src/hooks/api/projectFolderGrants/index.ts
@@ -1,5 +1,6 @@
export { useCreateProjectFolderGrant, useDeleteProjectFolderGrant } from "./mutations";
export {
+ useGetProjectFolderGrantsUsageTotal,
useGetProjectFolderGrantUsage,
useListProjectFolderGrants,
useListProjectFolderGrantsReceived
diff --git a/frontend/src/hooks/api/projectFolderGrants/queries.tsx b/frontend/src/hooks/api/projectFolderGrants/queries.tsx
index 80fef91580..6f7fdc89d6 100644
--- a/frontend/src/hooks/api/projectFolderGrants/queries.tsx
+++ b/frontend/src/hooks/api/projectFolderGrants/queries.tsx
@@ -1,4 +1,4 @@
-import { useQuery } from "@tanstack/react-query";
+import { useQueries, useQuery } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
@@ -47,7 +47,7 @@ export const useListProjectFolderGrantsReceived = (targetProjectId: string) =>
enabled: Boolean(targetProjectId)
});
-export const fetchProjectFolderGrantUsage = async (grantId: string, sourceProjectId: string) => {
+const fetchProjectFolderGrantUsage = async (grantId: string, sourceProjectId: string) => {
const { data } = await apiRequest.get<TProjectFolderGrantUsage>(
`/api/v1/project-folder-grants/${grantId}/usage`,
{ params: { sourceProjectId } }
@@ -65,3 +65,24 @@ export const useGetProjectFolderGrantUsage = (
queryFn: () => fetchProjectFolderGrantUsage(grantId, sourceProjectId),
enabled: Boolean(grantId) && Boolean(sourceProjectId) && enabled
});
+
+export const useGetProjectFolderGrantsUsageTotal = (
+ grantIds: string[],
+ sourceProjectId: string,
+ enabled = true
+) =>
+ useQueries({
+ queries: grantIds.map((grantId) => ({
+ queryKey: projectFolderGrantKeys.usage(grantId, sourceProjectId),
+ queryFn: () => fetchProjectFolderGrantUsage(grantId, sourceProjectId),
+ enabled: Boolean(sourceProjectId) && enabled
+ })),
+ combine: (results) => ({
+ isPending: results.some((r) => r.isPending),
+ isError: results.some((r) => r.isError),
+ total: results.reduce(
+ (sum, r) => sum + (r.data?.importCount ?? 0) + (r.data?.referenceCount ?? 0),
+ 0
+ )
+ })
+ });
diff --git a/frontend/src/pages/organization/ProductSettingsPage/SecretsManagement/ProductSettingsPage.tsx b/frontend/src/pages/organization/ProductSettingsPage/SecretsManagement/ProductSettingsPage.tsx
index 4a0401ccfe..abfd059678 100644
--- a/frontend/src/pages/organization/ProductSettingsPage/SecretsManagement/ProductSettingsPage.tsx
+++ b/frontend/src/pages/organization/ProductSettingsPage/SecretsManagement/ProductSettingsPage.tsx
@@ -1,5 +1,5 @@
import { useState } from "react";
-import { KeyRound, Unlink } from "lucide-react";
+import { KeyRound, TriangleAlertIcon } from "lucide-react";
import {
CrossProjectSecretSharingUpgradeIntent,
@@ -9,6 +9,8 @@ import { createNotification } from "@app/components/notifications";
import { PageTitle } from "@app/components/PageTitle";
import { OrgPermissionCan } from "@app/components/permissions";
import {
+ Alert,
+ AlertDescription,
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
@@ -16,7 +18,6 @@ import {
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
- AlertDialogMedia,
AlertDialogTitle,
Card,
CardContent,
@@ -178,16 +179,18 @@ export const ProductSettingsPage = () => {
<AlertDialog open={isDisableSharingConfirmOpen} onOpenChange={setIsDisableSharingConfirmOpen}>
<AlertDialogContent>
<AlertDialogHeader>
- <AlertDialogMedia>
- <Unlink />
- </AlertDialogMedia>
<AlertDialogTitle>Disable cross-project secret sharing?</AlertDialogTitle>
<AlertDialogDescription>
- Existing secret imports and secret references that point to other projects will stop
- resolving, which can break secret syncs and other integrations that depend on them.
- You can turn sharing back on later.
+ Projects in this organization will no longer be able to share secrets with each other.
</AlertDialogDescription>
</AlertDialogHeader>
+ <Alert variant="warning">
+ <TriangleAlertIcon />
+ <AlertDescription>
+ Existing secret imports and secret references that point to other projects will stop
+ resolving, which can break secret syncs and other integrations that depend on them.
+ </AlertDescription>
+ </Alert>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
diff --git a/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/CrossProjectSharingSection.tsx b/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/CrossProjectSharingSection.tsx
index 5fa817605d..124711dcef 100644
--- a/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/CrossProjectSharingSection.tsx
+++ b/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/CrossProjectSharingSection.tsx
@@ -65,10 +65,12 @@ import {
} from "@app/context";
import {
TProjectFolderGrant,
+ useGetProjectFolderGrantsUsageTotal,
useListProjectFolderGrants
} from "@app/hooks/api/projectFolderGrants";
import { projectFolderGrantKeys } from "@app/hooks/api/projectFolderGrants/queries";
+import { GrantRevocationImpact } from "./GrantRevocationImpact";
import { ShareSecretsEditData, ShareSecretsSheet } from "./ShareSecretsSheet";
type ProjectGroup = {
@@ -117,6 +119,11 @@ const DeleteProjectGrantsDialog = ({
const [confirmation, setConfirmation] = useState("");
const [isDeleting, setIsDeleting] = useState(false);
const queryClient = useQueryClient();
+ const usage = useGetProjectFolderGrantsUsageTotal(
+ grants.map((g) => g.id),
+ sourceProjectId,
+ isOpen
+ );
const isConfirmed = confirmation === CONFIRMATION_KEYWORD;
@@ -171,6 +178,11 @@ const DeleteProjectGrantsDialog = ({
shared {grants.length === 1 ? "grant" : "grants"}. This action cannot be undone.
</AlertDialogDescription>
</AlertDialogHeader>
+ <GrantRevocationImpact
+ usage={usage}
+ targetProjectName={projectName}
+ folderCount={grants.length}
+ />
<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
@@ -189,7 +201,7 @@ const DeleteProjectGrantsDialog = ({
variant="danger"
onClick={handleConfirmDelete}
isPending={isDeleting}
- disabled={!isConfirmed}
+ disabled={!isConfirmed || usage.isPending}
>
Remove
</AlertDialogAction>
diff --git a/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/GrantRevocationImpact.tsx b/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/GrantRevocationImpact.tsx
new file mode 100644
index 0000000000..f0648d70dd
--- /dev/null
+++ b/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/GrantRevocationImpact.tsx
@@ -0,0 +1,51 @@
+import { TriangleAlertIcon } from "lucide-react";
+
+import { Alert, AlertDescription } from "@app/components/v3";
+
+type Props = {
+ usage: { isPending: boolean; isError: boolean; total: number };
+ targetProjectName?: string;
+ folderCount: number;
+};
+
+export const GrantRevocationImpact = ({ usage, targetProjectName, folderCount }: Props) => {
+ const folders = folderCount === 1 ? "this folder" : "these folders";
+ const projectName = targetProjectName ?? "the other project";
+
+ if (usage.isPending) {
+ return (
+ <p className="text-sm text-label">
+ Checking for secret imports and references that use {folders}...
+ </p>
+ );
+ }
+
+ if (!usage.isError && usage.total === 0) {
+ return (
+ <p className="text-sm text-label">
+ No secret imports or references in {projectName} use {folders}.
+ </p>
+ );
+ }
+
+ return (
+ <Alert variant="warning">
+ <TriangleAlertIcon />
+ <AlertDescription>
+ {usage.isError ? (
+ <>
+ Usage could not be checked. Secret imports and references in {projectName} that use{" "}
+ {folders} will stop resolving
+ </>
+ ) : (
+ <>
+ {usage.total}{" "}
+ {usage.total === 1 ? "secret import or reference" : "secret imports and references"} in{" "}
+ {projectName} {usage.total === 1 ? "uses" : "use"} {folders} and will stop resolving
+ </>
+ )}
+ , which can break secret syncs and other integrations that depend on them.
+ </AlertDescription>
+ </Alert>
+ );
+};
diff --git a/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/ShareSecretsSheet.tsx b/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/ShareSecretsSheet.tsx
index 3862d5dcd8..7c7d74e00b 100644
--- a/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/ShareSecretsSheet.tsx
+++ b/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/ShareSecretsSheet.tsx
@@ -1,6 +1,5 @@
import { useEffect, useState } from "react";
-import { useQueries } from "@tanstack/react-query";
-import { ArrowDown, Box, FolderIcon, Layers, Plus, Trash2, Unlink, X } from "lucide-react";
+import { ArrowDown, Box, FolderIcon, Layers, Plus, Trash2, X } from "lucide-react";
import { createNotification } from "@app/components/notifications";
import {
@@ -11,7 +10,6 @@ import {
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
- AlertDialogMedia,
AlertDialogTitle,
Button,
Combobox,
@@ -36,16 +34,15 @@ import { useProject } from "@app/context";
import {
TProjectFolderGrant,
useCreateProjectFolderGrant,
- useDeleteProjectFolderGrant
+ useDeleteProjectFolderGrant,
+ useGetProjectFolderGrantsUsageTotal
} from "@app/hooks/api/projectFolderGrants";
-import {
- fetchProjectFolderGrantUsage,
- projectFolderGrantKeys
-} from "@app/hooks/api/projectFolderGrants/queries";
import { useGetUserProjectsByType } from "@app/hooks/api/projects";
import { Project, ProjectType } from "@app/hooks/api/projects/types";
import { useGetProjectFolders } from "@app/hooks/api/secretFolders/queries";
+import { GrantRevocationImpact } from "./GrantRevocationImpact";
+
type EnvironmentGroup = {
environment: string;
secretPaths: string[];
@@ -305,19 +302,11 @@ export const ShareSecretsSheet = ({
canRevokeGrant(g.environmentSlug, g.secretPath)
);
- const revokedGrantUsage = useQueries({
- queries: revokedGrants.map((g) => ({
- queryKey: projectFolderGrantKeys.usage(g.id, currentProject.id),
- queryFn: () => fetchProjectFolderGrantUsage(g.id, currentProject.id),
- enabled: isConfirmUpdateOpen
- }))
- });
- const affectedUsageCount = revokedGrantUsage.every((q) => q.isSuccess)
- ? revokedGrantUsage.reduce(
- (sum, q) => sum + (q.data?.importCount ?? 0) + (q.data?.referenceCount ?? 0),
- 0
- )
- : null;
+ const revokedGrantUsage = useGetProjectFolderGrantsUsageTotal(
+ revokedGrants.map((g) => g.id),
+ currentProject.id,
+ isConfirmUpdateOpen
+ );
const hasValidEntry =
groups.length > 0 && groups.every((g) => g.environment && g.secretPaths.length > 0);
@@ -542,31 +531,24 @@ export const ShareSecretsSheet = ({
<AlertDialog open={isConfirmUpdateOpen} onOpenChange={setIsConfirmUpdateOpen}>
<AlertDialogContent>
<AlertDialogHeader>
- <AlertDialogMedia>
- <Unlink />
- </AlertDialogMedia>
<AlertDialogTitle>Remove access to shared folders?</AlertDialogTitle>
<AlertDialogDescription>
<strong>{editData?.targetProjectName}</strong> will lose access to{" "}
{revokedGrants.length} shared {revokedGrants.length === 1 ? "folder" : "folders"}.
- Secret imports and secret references in that project that point to{" "}
- {revokedGrants.length === 1 ? "it" : "them"} will stop resolving, which can break
- secret syncs and other integrations that depend on them.
- {affectedUsageCount !== null && (
- <>
- {" "}
- <strong>
- {affectedUsageCount}{" "}
- {affectedUsageCount === 1 ? "import or reference" : "imports and references"}
- </strong>{" "}
- currently {affectedUsageCount === 1 ? "depends" : "depend"} on this access.
- </>
- )}
</AlertDialogDescription>
</AlertDialogHeader>
+ <GrantRevocationImpact
+ usage={revokedGrantUsage}
+ targetProjectName={editData?.targetProjectName}
+ folderCount={revokedGrants.length}
+ />
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
- <AlertDialogAction variant="danger" onClick={handleSubmit}>
+ <AlertDialogAction
+ variant="danger"
+ onClick={handleSubmit}
+ isDisabled={revokedGrantUsage.isPending}
+ >
Save
</AlertDialogAction>
</AlertDialogFooter>