Skip to content

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

feat: add warning when a folder has RBAC policies and someone tries to move it

adilsoncd9432516d58
diff --git a/backend/src/server/routes/v1/dashboard-router.ts b/backend/src/server/routes/v1/dashboard-router.ts
index 6e60d693a4..313f292efd 100644
--- a/backend/src/server/routes/v1/dashboard-router.ts
+++ b/backend/src/server/routes/v1/dashboard-router.ts
@@ -2177,7 +2177,8 @@ export const registerDashboardRouter = async (server: FastifyZodProvider) => {
blockingPath: z.string().optional(),
destinationBlocked: z.boolean().optional(),
destinationBlockingPath: z.string().optional(),
- destinationPolicyName: z.string().optional()
+ destinationPolicyName: z.string().optional(),
+ hasRbacPolicies: z.boolean().optional()
})
}
},
diff --git a/backend/src/services/secret-folder/secret-folder-fns.test.ts b/backend/src/services/secret-folder/secret-folder-fns.test.ts
index 25f4cd3469..d0cf53c603 100644
--- a/backend/src/services/secret-folder/secret-folder-fns.test.ts
+++ b/backend/src/services/secret-folder/secret-folder-fns.test.ts
@@ -1,9 +1,14 @@
+import { Knex } from "knex";
+import { vi } from "vitest";
+
import { TSecretFolders } from "@app/db/schemas";
+import { TAdditionalPrivilegeDALFactory } from "../additional-privilege/additional-privilege-dal";
import {
buildChildrenMap,
buildFolderIdMap,
buildFolderPath,
+ checkFolderHasRbacPolicies,
resolveClosestFolder,
resolvePathToFolder
} from "./secret-folder-fns";
@@ -339,3 +344,43 @@ describe("edge cases", () => {
expect(resolveClosestFolder(childrenMap, ["nonexistent"])?.id).toBe("custom-root");
});
});
+
+describe("checkFolderHasRbacPolicies", () => {
+ const tx = {} as Knex;
+ const subtree = [{ id: "root-id" }, { id: "a-id" }, { id: "b-id" }];
+
+ const makeDAL = (rows: { id: string }[]) => {
+ const find = vi.fn().mockResolvedValue(rows);
+ return { dal: { find } as unknown as Pick<TAdditionalPrivilegeDALFactory, "find">, find };
+ };
+
+ test("returns true when a folder-scoped privilege exists in the subtree", async () => {
+ const { dal } = makeDAL([{ id: "privilege-1" }]);
+
+ await expect(checkFolderHasRbacPolicies({ subtree }, { additionalPrivilegeDAL: dal }, tx)).resolves.toBe(true);
+ });
+
+ test("returns false when no folder-scoped privilege exists", async () => {
+ const { dal } = makeDAL([]);
+
+ await expect(checkFolderHasRbacPolicies({ subtree }, { additionalPrivilegeDAL: dal }, tx)).resolves.toBe(false);
+ });
+
+ test("returns false without querying for an empty subtree", async () => {
+ const { dal, find } = makeDAL([{ id: "privilege-1" }]);
+
+ await expect(checkFolderHasRbacPolicies({ subtree: [] }, { additionalPrivilegeDAL: dal }, tx)).resolves.toBe(
+ false
+ );
+ expect(find).not.toHaveBeenCalled();
+ });
+
+ test("queries once with every subtree folder id, limit 1 and the provided transaction", async () => {
+ const { dal, find } = makeDAL([]);
+
+ await checkFolderHasRbacPolicies({ subtree }, { additionalPrivilegeDAL: dal }, tx);
+
+ expect(find).toHaveBeenCalledTimes(1);
+ expect(find).toHaveBeenCalledWith({ $in: { folderId: ["root-id", "a-id", "b-id"] } }, { limit: 1, tx });
+ });
+});
diff --git a/backend/src/services/secret-folder/secret-folder-fns.ts b/backend/src/services/secret-folder/secret-folder-fns.ts
index 89d1573a33..bc104358e7 100644
--- a/backend/src/services/secret-folder/secret-folder-fns.ts
+++ b/backend/src/services/secret-folder/secret-folder-fns.ts
@@ -16,6 +16,7 @@ import { TSecretApprovalPolicyServiceFactory } from "@app/ee/services/secret-app
import { TSecretRotationV2DALFactory } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-dal";
import { BadRequestError, InternalServerError } from "@app/lib/errors";
+import { TAdditionalPrivilegeDALFactory } from "../additional-privilege/additional-privilege-dal";
import { TSecretImportDALFactory } from "../secret-import/secret-import-dal";
import { TFolderMoveBlockingType } from "./secret-folder-types";
@@ -292,6 +293,22 @@ export const checkFolderMovePolicyBlock = async (
return null;
};
+type TCheckFolderRbacPoliciesDeps = {
+ additionalPrivilegeDAL: Pick<TAdditionalPrivilegeDALFactory, "find">;
+};
+
+export const checkFolderHasRbacPolicies = async (
+ { subtree }: { subtree: { id: string }[] },
+ { additionalPrivilegeDAL }: TCheckFolderRbacPoliciesDeps,
+ tx: Knex
+): Promise<boolean> => {
+ const folderIds = subtree.map((f) => f.id);
+ if (!folderIds.length) return false;
+
+ const [privilege] = await additionalPrivilegeDAL.find({ $in: { folderId: folderIds } }, { limit: 1, tx });
+ return Boolean(privilege);
+};
+
// throws the appropriate BadRequestError for a detected move block. the full subtree is always scanned to
// enforce correctness, but the message only reveals the offending path/type when the actor is allowed to read
// it; otherwise it stays generic so inaccessible subtree contents aren't disclosed.
diff --git a/backend/src/services/secret-folder/secret-folder-service.ts b/backend/src/services/secret-folder/secret-folder-service.ts
index ac7bd80a32..2e7ce0aee7 100644
--- a/backend/src/services/secret-folder/secret-folder-service.ts
+++ b/backend/src/services/secret-folder/secret-folder-service.ts
@@ -27,6 +27,7 @@ import {
buildChildrenMap,
buildFolderPath,
canActorReadBlock,
+ checkFolderHasRbacPolicies,
checkFolderMoveBlock,
checkFolderMovePolicyBlock,
TFolderMoveAccessScope
@@ -72,7 +73,7 @@ import { TSecretFolderVersionDALFactory } from "./secret-folder-version-dal";
type TSecretFolderServiceFactoryDep = {
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission" | "invalidateProjectFolderPermissionCache">;
- additionalPrivilegeDAL: Pick<TAdditionalPrivilegeDALFactory, "remapFolderIds">;
+ additionalPrivilegeDAL: Pick<TAdditionalPrivilegeDALFactory, "remapFolderIds" | "find">;
folderDAL: TSecretFolderDALFactory;
projectEnvDAL: Pick<TProjectEnvDALFactory, "findOne" | "findBySlugs" | "find">;
folderVersionDAL: Pick<TSecretFolderVersionDALFactory, "findLatestFolderVersions" | "create" | "insertMany" | "find">;
@@ -1496,7 +1497,8 @@ export const secretFolderServiceFactory = ({
// destination paths for a governing policy (`destinationBlock`); a folder cannot be moved INTO a path governed
// by a policy since the move would create its secrets there, bypassing the approval the policy requires. pass
// `accessScope` to limit reporting to paths the actor may read; omit it (the move path) to always detect a block
- // and gate only the resulting message.
+ // and gate only the resulting message. pass `checkRbacPolicies` to also report whether the subtree carries
+ // folder-scoped RBAC policies (`hasRbacPolicies`) — a warning, never a block.
const $getFolderMoveBlocks = async (
{
subtree,
@@ -1504,7 +1506,8 @@ export const secretFolderServiceFactory = ({
sourceEnvironment,
sourceFolderPath,
destination,
- accessScope
+ accessScope,
+ checkRbacPolicies
}: {
subtree: { id: string; path: string }[];
projectId: string;
@@ -1512,6 +1515,7 @@ export const secretFolderServiceFactory = ({
sourceFolderPath: string;
destination?: { environment: string; path: string };
accessScope?: TFolderMoveAccessScope;
+ checkRbacPolicies?: boolean;
},
tx: Knex
) => {
@@ -1535,7 +1539,11 @@ export const secretFolderServiceFactory = ({
)
: null;
- return { sourceBlock, destinationBlock };
+ const hasRbacPolicies = checkRbacPolicies
+ ? await checkFolderHasRbacPolicies({ subtree }, { additionalPrivilegeDAL }, tx)
+ : undefined;
+
+ return { sourceBlock, destinationBlock, hasRbacPolicies };
};
// checks whether a folder (and its entire recursive subtree) can be moved. when a destination is supplied, it
@@ -1552,8 +1560,6 @@ export const secretFolderServiceFactory = ({
}: TGetFolderMoveEligibilityDTO): Promise<TFolderMoveEligibility> => {
const folder = await getFolderById({ actor, actorId, actorOrgId, actorAuthMethod, id });
- // resolve the actor's ability so subtree disclosure is gated by per-path read permission. this is
- // request-memoized, so it reuses the lookup getFolderById already performed (no extra DB read).
const { permission } = await permissionService.getProjectPermission({
actor,
actorId,
@@ -1569,8 +1575,6 @@ export const secretFolderServiceFactory = ({
};
const destinationParentPath = destinationPath ?? "/";
- // a move only requires Create at the destination (the enforced move permission below). folder read is
- // implied-for-all (folder list/get is not gated by a Read permission), so it is not required here.
const canActorAccessDestination =
!!destinationEnvironment &&
permission.can(
@@ -1582,7 +1586,7 @@ export const secretFolderServiceFactory = ({
);
// run every read inside a transaction so it hits the primary database rather than a read replica
- const { sourceBlock, destinationBlock } = await folderDAL.transaction(async (tx) => {
+ const { sourceBlock, destinationBlock, hasRbacPolicies } = await folderDAL.transaction(async (tx) => {
// parent folder + full recursive subtree (with paths); reserved folders are already excluded.
const subtree = await folderDAL.findByEnvsDeep({ parentIds: [folder.id] }, tx);
@@ -1596,7 +1600,8 @@ export const secretFolderServiceFactory = ({
destinationEnvironment && canActorAccessDestination
? { environment: destinationEnvironment, path: path.join(destinationParentPath, folder.name) }
: undefined,
- accessScope
+ accessScope,
+ checkRbacPolicies: true
},
tx
);
@@ -1617,7 +1622,8 @@ export const secretFolderServiceFactory = ({
blockingPath: sourceBlock?.blockingAbsPath,
destinationBlocked: destinationEnvironment ? !canActorAccessDestination || Boolean(destinationBlock) : undefined,
destinationBlockingPath: readableDestinationBlock?.blockingPath,
- destinationPolicyName: readableDestinationBlock?.policyName
+ destinationPolicyName: readableDestinationBlock?.policyName,
+ hasRbacPolicies
};
};
diff --git a/backend/src/services/secret-folder/secret-folder-types.ts b/backend/src/services/secret-folder/secret-folder-types.ts
index d2b89110c8..9a19bfcf31 100644
--- a/backend/src/services/secret-folder/secret-folder-types.ts
+++ b/backend/src/services/secret-folder/secret-folder-types.ts
@@ -80,6 +80,8 @@ export type TFolderMoveEligibility = {
// the destination policy's path/name are disclosed only when the actor may read that path
destinationBlockingPath?: string;
destinationPolicyName?: string;
+ // warning, never a block: the subtree carries folder-scoped RBAC policies that will follow the move
+ hasRbacPolicies?: boolean;
};
export type TMoveFolderDTO = {
diff --git a/frontend/src/hooks/api/dashboard/queries.tsx b/frontend/src/hooks/api/dashboard/queries.tsx
index a0c123f1cd..fc9f517464 100644
--- a/frontend/src/hooks/api/dashboard/queries.tsx
+++ b/frontend/src/hooks/api/dashboard/queries.tsx
@@ -687,9 +687,13 @@ export const useGetFoldersMoveEligibility = (folderIds: string[], enabled = true
blockingType?: FolderMoveBlockingType;
blockingPath?: string;
}[] = [];
+ // non-blocking: folders whose subtree carries folder-scoped access policies, surfaced as a warning
+ const seenRbacWarnings = new Set<string>();
+ const foldersWithRbacPolicies: string[] = [];
results.forEach((result) => {
const { data } = result;
- if (data && !data.canMove && !seen.has(data.folderName)) {
+ if (!data) return;
+ if (!data.canMove && !seen.has(data.folderName)) {
seen.add(data.folderName);
blockedFolders.push({
folderName: data.folderName,
@@ -697,9 +701,13 @@ export const useGetFoldersMoveEligibility = (folderIds: string[], enabled = true
blockingPath: data.blockingPath
});
}
+ if (data.hasRbacPolicies && !seenRbacWarnings.has(data.folderName)) {
+ seenRbacWarnings.add(data.folderName);
+ foldersWithRbacPolicies.push(data.folderName);
+ }
});
- return { isChecking, canMove, blockedFolders };
+ return { isChecking, canMove, blockedFolders, foldersWithRbacPolicies };
}
});
diff --git a/frontend/src/hooks/api/dashboard/types.ts b/frontend/src/hooks/api/dashboard/types.ts
index 9ef2f15979..e7435626e3 100644
--- a/frontend/src/hooks/api/dashboard/types.ts
+++ b/frontend/src/hooks/api/dashboard/types.ts
@@ -259,6 +259,8 @@ export type FolderMoveEligibilityResponse = {
// the destination policy's path/name are disclosed only when the actor may read that path
destinationBlockingPath?: string;
destinationPolicyName?: string;
+ // warning, never a block: the subtree carries folder-scoped access policies that will follow the move
+ hasRbacPolicies?: boolean;
};
export type TFolderMoveDestinationCheck = {
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/MoveSecretsDialog/MoveSecretsDialog.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/MoveSecretsDialog/MoveSecretsDialog.tsx
index abdb6d69fe..219f443423 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/MoveSecretsDialog/MoveSecretsDialog.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/MoveSecretsDialog/MoveSecretsDialog.tsx
@@ -4,7 +4,13 @@ import { SingleValue } from "react-select";
import { subject } from "@casl/ability";
import { zodResolver } from "@hookform/resolvers/zod";
import axios from "axios";
-import { CheckCircleIcon, CircleAlertIcon, InfoIcon, LoaderCircleIcon } from "lucide-react";
+import {
+ CheckCircleIcon,
+ CircleAlertIcon,
+ InfoIcon,
+ LoaderCircleIcon,
+ TriangleAlertIcon
+} from "lucide-react";
import { twMerge } from "tailwind-merge";
import { z } from "zod";
@@ -73,6 +79,7 @@ type Props = {
type ContentProps = Omit<Props, "isOpen" | "onOpenChange"> & {
onClose: () => void;
+ foldersWithRbacPolicies: string[];
};
type OptionValue = { secretPath: string };
@@ -381,6 +388,27 @@ const MoveBlockAlerts = ({
);
};
+const FolderRbacPoliciesWarning = ({ folderNames }: { folderNames: string[] }) => {
+ if (!folderNames.length) return null;
+
+ const isSingle = folderNames.length === 1;
+
+ return (
+ <Alert variant="warning" className="mt-4">
+ <TriangleAlertIcon />
+ <AlertTitle>
+ Folder permissions will move with {isSingle ? "this folder" : "these folders"}
+ </AlertTitle>
+ <AlertDescription>
+ Folder-specific permissions are granted on{" "}
+ {folderNames.map((name) => `"${name}"`).join(", ")} or{" "}
+ {isSingle ? "one of its subfolders" : "their subfolders"}. Users and identities with this
+ access will keep it at the new location.
+ </AlertDescription>
+ </Alert>
+ );
+};
+
const SingleEnvContent = ({
onComplete,
onClose,
@@ -391,7 +419,8 @@ const SingleEnvContent = ({
visibleEnvs,
projectId,
projectSlug,
- sourceSecretPath
+ sourceSecretPath,
+ foldersWithRbacPolicies
}: ContentProps) => {
const sourceEnv = visibleEnvs[0];
const moveCopy = getMoveSelectionCopy({ secrets, rotations, folders });
@@ -661,6 +690,7 @@ const SingleEnvContent = ({
blockedDestinations={blockedDestinations}
environments={environments}
/>
+ <FolderRbacPoliciesWarning folderNames={foldersWithRbacPolicies} />
{showOverwriteOption && (
<Controller
control={control}
@@ -728,7 +758,8 @@ const MultiEnvContent = ({
environments,
projectId,
projectSlug,
- sourceSecretPath
+ sourceSecretPath,
+ foldersWithRbacPolicies
}: ContentProps) => {
const moveSecrets = useMoveSecrets();
const moveSecretRotation = useMoveSecretRotation();
@@ -1090,6 +1121,7 @@ const MultiEnvContent = ({
blockedDestinations={blockedDestinations}
environments={environments}
/>
+ <FolderRbacPoliciesWarning folderNames={foldersWithRbacPolicies} />
{showOverwriteOption && (
<Controller
control={control}
@@ -1227,7 +1259,8 @@ export const MoveSecretsModal = ({ isOpen, onOpenChange, visibleEnvs, ...props }
// gate the eligibility check on `isOpen` so selecting a folder never triggers the call, while the
// snapshot keeps `folderIds` populated so the rendered view stays stable through the close animation
- const { isChecking, canMove, blockedFolders } = useGetFoldersMoveEligibility(folderIds, isOpen);
+ const { isChecking, canMove, blockedFolders, foldersWithRbacPolicies } =
+ useGetFoldersMoveEligibility(folderIds, isOpen);
const renderContent = () => {
if (hasFolders && isChecking) {
@@ -1253,6 +1286,7 @@ export const MoveSecretsModal = ({ isOpen, onOpenChange, visibleEnvs, ...props }
<SingleEnvContent
{...contentProps}
visibleEnvs={visibleEnvs}
+ foldersWithRbacPolicies={foldersWithRbacPolicies}
onClose={() => onOpenChange(false)}
/>
);
@@ -1262,6 +1296,7 @@ export const MoveSecretsModal = ({ isOpen, onOpenChange, visibleEnvs, ...props }
<MultiEnvContent
{...contentProps}
visibleEnvs={visibleEnvs}
+ foldersWithRbacPolicies={foldersWithRbacPolicies}
onClose={() => onOpenChange(false)}
/>
);