Skip to content

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

feat(ui): confirm before disabling or narrowing cross-project secret sharing

Claude229c08cf2b76
diff --git a/frontend/src/hooks/api/projectFolderGrants/queries.tsx b/frontend/src/hooks/api/projectFolderGrants/queries.tsx
index f948148dfe..80fef91580 100644
--- a/frontend/src/hooks/api/projectFolderGrants/queries.tsx
+++ b/frontend/src/hooks/api/projectFolderGrants/queries.tsx
@@ -47,6 +47,14 @@ export const useListProjectFolderGrantsReceived = (targetProjectId: string) =>
enabled: Boolean(targetProjectId)
});
+export const fetchProjectFolderGrantUsage = async (grantId: string, sourceProjectId: string) => {
+ const { data } = await apiRequest.get<TProjectFolderGrantUsage>(
+ `/api/v1/project-folder-grants/${grantId}/usage`,
+ { params: { sourceProjectId } }
+ );
+ return data;
+};
+
export const useGetProjectFolderGrantUsage = (
grantId: string,
sourceProjectId: string,
@@ -54,12 +62,6 @@ export const useGetProjectFolderGrantUsage = (
) =>
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;
- },
+ queryFn: () => fetchProjectFolderGrantUsage(grantId, sourceProjectId),
enabled: Boolean(grantId) && Boolean(sourceProjectId) && enabled
});
diff --git a/frontend/src/pages/organization/ProductSettingsPage/SecretsManagement/ProductSettingsPage.tsx b/frontend/src/pages/organization/ProductSettingsPage/SecretsManagement/ProductSettingsPage.tsx
index 580de9a848..4a0401ccfe 100644
--- a/frontend/src/pages/organization/ProductSettingsPage/SecretsManagement/ProductSettingsPage.tsx
+++ b/frontend/src/pages/organization/ProductSettingsPage/SecretsManagement/ProductSettingsPage.tsx
@@ -1,4 +1,5 @@
-import { KeyRound } from "lucide-react";
+import { useState } from "react";
+import { KeyRound, Unlink } from "lucide-react";
import {
CrossProjectSecretSharingUpgradeIntent,
@@ -8,6 +9,15 @@ import { createNotification } from "@app/components/notifications";
import { PageTitle } from "@app/components/PageTitle";
import { OrgPermissionCan } from "@app/components/permissions";
import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogMedia,
+ AlertDialogTitle,
Card,
CardContent,
CardDescription,
@@ -38,6 +48,7 @@ export const ProductSettingsPage = () => {
const { mutateAsync: updateOrg, isPending } = useUpdateOrg();
const { subscription } = useSubscription();
const { openUpgradeGate, upgradeGate } = useUpgradeGate();
+ const [isDisableSharingConfirmOpen, setIsDisableSharingConfirmOpen] = useState(false);
const handleToggle = async (state: boolean) => {
if (!currentOrg?.id) return;
@@ -139,7 +150,13 @@ export const ProductSettingsPage = () => {
id="allow-cross-project-secret-sharing"
variant="project"
checked={currentOrg?.allowCrossProjectSecretSharing ?? false}
- onCheckedChange={(value) => handleCrossProjectSharingToggle(value)}
+ onCheckedChange={(value) => {
+ if (!value) {
+ setIsDisableSharingConfirmOpen(true);
+ return;
+ }
+ handleCrossProjectSharingToggle(value);
+ }}
disabled={!isAllowed || isPending}
/>
)}
@@ -158,6 +175,30 @@ export const ProductSettingsPage = () => {
</div>
</div>
</div>
+ <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.
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel>Cancel</AlertDialogCancel>
+ <AlertDialogAction
+ variant="danger"
+ onClick={() => handleCrossProjectSharingToggle(false)}
+ >
+ Disable
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
{upgradeGate}
</>
);
diff --git a/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/ShareSecretsSheet.tsx b/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/ShareSecretsSheet.tsx
index 48871e790c..3862d5dcd8 100644
--- a/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/ShareSecretsSheet.tsx
+++ b/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/ShareSecretsSheet.tsx
@@ -1,8 +1,18 @@
import { useEffect, useState } from "react";
-import { ArrowDown, Box, FolderIcon, Layers, Plus, Trash2, X } from "lucide-react";
+import { useQueries } from "@tanstack/react-query";
+import { ArrowDown, Box, FolderIcon, Layers, Plus, Trash2, Unlink, X } from "lucide-react";
import { createNotification } from "@app/components/notifications";
import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogMedia,
+ AlertDialogTitle,
Button,
Combobox,
Field,
@@ -28,6 +38,10 @@ import {
useCreateProjectFolderGrant,
useDeleteProjectFolderGrant
} 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";
@@ -239,6 +253,7 @@ export const ShareSecretsSheet = ({
const [targetProjects, setTargetProjects] = useState<Project[]>([]);
const [isSubmitting, setIsSubmitting] = useState(false);
+ const [isConfirmUpdateOpen, setIsConfirmUpdateOpen] = useState(false);
const createGrant = useCreateProjectFolderGrant();
const deleteGrant = useDeleteProjectFolderGrant();
const { data: projects = [], isPending: isProjectsLoading } = useGetUserProjectsByType(
@@ -281,6 +296,29 @@ export const ShareSecretsSheet = ({
const usedEnvironments = new Set(groups.map((g) => g.environment).filter(Boolean));
+ const remainingKeys = new Set(
+ flattenGroups(groups).map((e) => entryKey(e.environment, e.secretPath))
+ );
+ const revokedGrants = (editData?.grants ?? []).filter(
+ (g) =>
+ !remainingKeys.has(entryKey(g.environmentSlug, g.secretPath)) &&
+ 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 hasValidEntry =
groups.length > 0 && groups.every((g) => g.environment && g.secretPaths.length > 0);
@@ -489,12 +527,51 @@ export const ShareSecretsSheet = ({
variant="project"
disabled={!hasValidEntry || (!isEditMode && targetProjects.length === 0)}
isPending={isSubmitting}
- onClick={handleSubmit}
+ onClick={() => {
+ if (revokedGrants.length > 0) {
+ setIsConfirmUpdateOpen(true);
+ return;
+ }
+ handleSubmit();
+ }}
>
{isEditMode ? "Save" : "Share"}
</Button>
</SheetFooter>
</SheetContent>
+ <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>
+ <AlertDialogFooter>
+ <AlertDialogCancel>Cancel</AlertDialogCancel>
+ <AlertDialogAction variant="danger" onClick={handleSubmit}>
+ Save
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
</Sheet>
);
};