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
add new sheet to add folder access for a specific user/identity
adilson2ccbb3c6a658
diff --git a/frontend/src/lib/analytics/events.ts b/frontend/src/lib/analytics/events.tsindex 1773bf0562..d7109d12b7 100644--- a/frontend/src/lib/analytics/events.ts+++ b/frontend/src/lib/analytics/events.ts@@ -2,7 +2,8 @@ export const AnalyticsEvent = {PaywallViewed: "Paywall Viewed",PaywallUpgradeClicked: "Paywall Upgrade Clicked",FolderAccessSheetOpened: "Folder Access Sheet Opened",- FolderAccessAddSheetOpened: "Folder Access Add Sheet Opened"+ FolderAccessAddSheetOpened: "Folder Access Add Sheet Opened",+ FolderAccessGrantSheetOpened: "Folder Access Grant Sheet Opened"} as const;type PaywallProperties = {@@ -23,11 +24,20 @@ type FolderAccessAddSheetOpenedProperties = {projectId: string;};+export type FolderAccessGrantSheetSource = "card_header" | "empty_state";++type FolderAccessGrantSheetOpenedProperties = {+ source: FolderAccessGrantSheetSource;+ actorType: "user" | "identity";+ projectId: string;+};+export type OrganizationAnalyticsEventMap = {[AnalyticsEvent.PaywallViewed]: PaywallProperties;[AnalyticsEvent.PaywallUpgradeClicked]: PaywallProperties;[AnalyticsEvent.FolderAccessSheetOpened]: FolderAccessSheetOpenedProperties;[AnalyticsEvent.FolderAccessAddSheetOpened]: FolderAccessAddSheetOpenedProperties;+ [AnalyticsEvent.FolderAccessGrantSheetOpened]: FolderAccessGrantSheetOpenedProperties;};export type OrganizationAnalyticsEvent = keyof OrganizationAnalyticsEventMap;diff --git a/frontend/src/lib/analytics/index.ts b/frontend/src/lib/analytics/index.tsindex 53cba9f758..1a1ed9f414 100644--- a/frontend/src/lib/analytics/index.ts+++ b/frontend/src/lib/analytics/index.ts@@ -22,3 +22,4 @@ export const analytics = {};export { AnalyticsEvent };+export type { FolderAccessGrantSheetSource } from "./events";diff --git a/frontend/src/pages/project/components/FolderAccessSection/FolderAccessSection.tsx b/frontend/src/pages/project/components/FolderAccessSection/FolderAccessSection.tsxindex e4418a384a..406c5a4eb2 100644--- a/frontend/src/pages/project/components/FolderAccessSection/FolderAccessSection.tsx+++ b/frontend/src/pages/project/components/FolderAccessSection/FolderAccessSection.tsx@@ -6,6 +6,7 @@ import {ClockAlertIcon,ClockIcon,FolderIcon,+ PlusIcon,RefreshCwIcon,Trash2Icon,UsersIcon@@ -19,12 +20,14 @@ import {Badge,Button,Card,+ CardAction,CardContent,CardDescription,CardHeader,CardTitle,DocumentationLinkBadge,Empty,+ EmptyContent,EmptyDescription,EmptyHeader,EmptyTitle,@@ -43,6 +46,7 @@ import {import {ProjectPermissionSecretFolderActions,ProjectPermissionSub,+ useOrganization,useProject,useProjectPermission} from "@app/context";@@ -53,6 +57,7 @@ import {useListIdentityFolderAccess,useListUserFolderAccess} from "@app/hooks/api/folderAccess";+import { analytics, AnalyticsEvent, FolderAccessGrantSheetSource } from "@app/lib/analytics";import { FOLDER_ROLE_TIER_LABELS } from "@app/pages/secret-manager/OverviewPage/components/FolderAccessSheet/folder-access.const";import {formatExpirationTime,@@ -62,6 +67,7 @@ import {import { RemoveFolderAccessDialog } from "@app/pages/secret-manager/OverviewPage/components/FolderAccessSheet/RemoveFolderAccessDialog";import { EditFolderAccessSheet } from "./EditFolderAccessSheet";+import { GrantFolderAccessSheet } from "./GrantFolderAccessSheet";import { TFolderAccessSectionActor } from "./types";const FOLDER_ACCESS_DOCS_URL =@@ -74,8 +80,10 @@ type Props = {export const FolderAccessSection = ({ actor, hideActions = false }: Props) => {const { projectId, currentProject } = useProject();+ const { currentOrg } = useOrganization();const { permission } = useProjectPermission();+ const [isGrantOpen, setIsGrantOpen] = useState(false);const [editTarget, setEditTarget] = useState<TFolderAccess | null>(null);const [deleteTarget, setDeleteTarget] = useState<TFolderAccess | null>(null);@@ -111,6 +119,15 @@ export const FolderAccessSection = ({ actor, hideActions = false }: Props) => {const actorNoun = actor.type === "user" ? "user" : "machine identity";+ const openGrantSheet = (source: FolderAccessGrantSheetSource) => {+ setIsGrantOpen(true);+ analytics.captureForOrganization(AnalyticsEvent.FolderAccessGrantSheetOpened, currentOrg.id, {+ source,+ actorType: actor.type,+ projectId+ });+ };+const dialogActor = (() => {if (!deleteTarget) return null;if (actor.type === "user") {@@ -172,6 +189,14 @@ export const FolderAccessSection = ({ actor, hideActions = false }: Props) => {Folder-level access for this {actorNoun}. Overrides{" "}{actor.type === "user" ? "their" : "its"} project roles within each folder.</CardDescription>+ {!hideActions && (+ <CardAction>+ <Button size="xs" variant="outline" onClick={() => openGrantSheet("card_header")}>+ <PlusIcon />+ Grant Access+ </Button>+ </CardAction>+ )}</CardHeader><CardContent>{isError && (@@ -307,14 +332,32 @@ export const FolderAccessSection = ({ actor, hideActions = false }: Props) => {<EmptyHeader><EmptyTitle>This {actorNoun} has no folder access</EmptyTitle><EmptyDescription>- Grant folder-level access from the Secrets overview using a folder's Manage- Access action+ Grant access to a folder to override{" "}+ {actor.type === "user" ? "their" : "its"} project roles within it</EmptyDescription></EmptyHeader>+ {!hideActions && (+ <EmptyContent>+ <Button+ size="xs"+ variant="outline"+ onClick={() => openGrantSheet("empty_state")}+ >+ <PlusIcon />+ Grant Access+ </Button>+ </EmptyContent>+ )}</Empty>))}</CardContent></Card>+ <GrantFolderAccessSheet+ isOpen={isGrantOpen}+ onOpenChange={setIsGrantOpen}+ actor={actor}+ existingAccess={folderAccess ?? []}+ /><EditFolderAccessSheetaccess={editTarget}actor={actor}diff --git a/frontend/src/pages/project/components/FolderAccessSection/GrantFolderAccessSheet.tsx b/frontend/src/pages/project/components/FolderAccessSection/GrantFolderAccessSheet.tsxnew file mode 100644index 0000000000..91a308b604--- /dev/null+++ b/frontend/src/pages/project/components/FolderAccessSection/GrantFolderAccessSheet.tsx@@ -0,0 +1,255 @@+import { useState } from "react";+import { subject } from "@casl/ability";++import { createNotification } from "@app/components/notifications";+import {+ Button,+ DocumentationLinkBadge,+ Label,+ SecretPathInput,+ Select,+ SelectContent,+ SelectItem,+ SelectTrigger,+ SelectValue,+ Sheet,+ SheetContent,+ SheetFooter,+ SheetHeader,+ SheetTitle+} from "@app/components/v3";+import {+ ProjectPermissionSecretFolderActions,+ ProjectPermissionSub,+ useProject,+ useProjectPermission+} from "@app/context";+import {+ SecretFolderRole,+ TFolderAccess,+ useCreateIdentityFolderAccess,+ useCreateUserFolderAccess+} from "@app/hooks/api/folderAccess";+import { useGetProjectFolders } from "@app/hooks/api/secretFolders/queries";+import { DEFAULT_TEMPORARY_RANGE } from "@app/pages/secret-manager/OverviewPage/components/FolderAccessSheet/folder-access.const";+import {+ isValidTemporaryRange,+ normalizeFolderPath+} from "@app/pages/secret-manager/OverviewPage/components/FolderAccessSheet/folder-access.utils";+import { FolderTierRadioGroup } from "@app/pages/secret-manager/OverviewPage/components/FolderAccessSheet/FolderTierRadioGroup";+import { TemporaryAccessPopover } from "@app/pages/secret-manager/OverviewPage/components/FolderAccessSheet/TemporaryAccessPopover";++import { TFolderAccessSectionActor } from "./types";++type Props = {+ isOpen: boolean;+ onOpenChange: (isOpen: boolean) => void;+ actor: TFolderAccessSectionActor;+ existingAccess: TFolderAccess[];+};++type FormProps = {+ actor: TFolderAccessSectionActor;+ existingAccess: TFolderAccess[];+ onClose: () => void;+};++const actorNameOf = (actor: TFolderAccessSectionActor) => {+ if (actor.type === "identity") return actor.name;+ const fullName = [actor.firstName, actor.lastName].filter(Boolean).join(" ").trim();+ return fullName || actor.username;+};++const GrantFolderAccessForm = ({ actor, existingAccess, onClose }: FormProps) => {+ const { projectId, currentProject } = useProject();+ const { permission } = useProjectPermission();++ const environments = currentProject?.environments ?? [];++ const [environmentSlug, setEnvironmentSlug] = useState(environments[0]?.slug ?? "");+ const [secretPath, setSecretPath] = useState("/");+ const [tier, setTier] = useState(SecretFolderRole.Read);+ const [isTemporary, setIsTemporary] = useState(false);+ const [range, setRange] = useState(DEFAULT_TEMPORARY_RANGE);++ const createUserAccess = useCreateUserFolderAccess();+ const createIdentityAccess = useCreateIdentityFolderAccess();++ const normalizedPath = normalizeFolderPath(secretPath);+ const isRoot = normalizedPath === "/";+ const parentPath = isRoot ? "/" : normalizedPath.slice(0, normalizedPath.lastIndexOf("/")) || "/";+ const folderName = isRoot ? "" : (normalizedPath.split("/").filter(Boolean).pop() ?? "");++ const { data: siblingFolders = [], isLoading: isCheckingFolder } = useGetProjectFolders({+ projectId,+ environment: environmentSlug,+ path: parentPath,+ options: { enabled: Boolean(environmentSlug) && !isRoot }+ });++ const actorNoun = actor.type === "user" ? "user" : "machine identity";+ const folderExists = isRoot || siblingFolders.some((folder) => folder.name === folderName);+ const isDuplicate = existingAccess.some(+ (row) =>+ row.environment === environmentSlug && normalizeFolderPath(row.secretPath) === normalizedPath+ );+ const isFullAccessTemporary = tier === SecretFolderRole.FullAccess && isTemporary;+ const isRangeValid = !isTemporary || isValidTemporaryRange(range);++ const targetError = (() => {+ if (!environmentSlug) return "Select an environment.";+ if (isCheckingFolder) return null;+ if (!folderExists) return `No folder at ${normalizedPath} in this environment.`;+ if (isDuplicate)+ return `This ${actorNoun} already has access to ${normalizedPath}. Edit the existing access from the table instead.`;+ // the backend authorizes a grant against the target folder's own path, not its parent+ if (+ !permission.can(+ ProjectPermissionSecretFolderActions.ManageAccess,+ subject(ProjectPermissionSub.SecretFolders, {+ environment: environmentSlug,+ secretPath: normalizedPath+ })+ )+ )+ return "You do not have permission to manage access on this folder.";+ return null;+ })();++ const isSubmitDisabled =+ isCheckingFolder || Boolean(targetError) || isFullAccessTemporary || !isRangeValid;++ const handleSubmit = async () => {+ const type = isTemporary+ ? ({+ isTemporary: true,+ temporaryMode: "relative",+ temporaryRange: range,+ temporaryAccessStartTime: new Date().toISOString()+ } as const)+ : undefined;++ const payload = {+ projectId,+ environmentSlug,+ secretPath: normalizedPath,+ permission: tier,+ type+ };++ if (actor.type === "user") {+ await createUserAccess.mutateAsync({ ...payload, userId: actor.id });+ } else {+ await createIdentityAccess.mutateAsync({ ...payload, identityId: actor.id });+ }+ createNotification({ type: "success", text: "Folder access granted" });+ onClose();+ };++ return (+ <>+ <SheetHeader>+ <SheetTitle className="flex items-center gap-2">+ Grant Folder Access+ <DocumentationLinkBadge href="https://infisical.com/docs/documentation/platform/access-controls/folder-rbac" />+ </SheetTitle>+ <div className="mt-2 flex min-w-0 items-center gap-2 text-xs">+ <span className="truncate text-accent">{actorNameOf(actor)}</span>+ </div>+ </SheetHeader>++ <div className="thin-scrollbar flex-1 space-y-5 overflow-y-auto p-4">+ <div className="space-y-2">+ <Label>Folder</Label>+ <div className="grid grid-cols-[minmax(8rem,0.8fr)_minmax(0,1.2fr)] gap-2">+ <Select+ value={environmentSlug}+ onValueChange={(value) => {+ setEnvironmentSlug(value);+ // folder suggestions and path existence are per environment, so a path carried+ // across a switch would point at a folder that need not exist in the new one+ setSecretPath("/");+ }}+ >+ <SelectTrigger className="w-full" aria-label="Environment">+ <SelectValue placeholder="Select environment" />+ </SelectTrigger>+ <SelectContent position="popper">+ {environments.map((env) => (+ <SelectItem key={env.id} value={env.slug}>+ {env.name}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ <SecretPathInput+ aria-label="Folder path"+ projectId={projectId}+ environment={environmentSlug}+ value={secretPath}+ isError={Boolean(targetError)}+ onChange={setSecretPath}+ />+ </div>+ {targetError && <p className="text-xs text-danger">{targetError}</p>}+ </div>++ <div className="space-y-2">+ <Label>Permission</Label>+ <FolderTierRadioGroup value={tier} onValueChange={setTier} />+ {isFullAccessTemporary && (+ <p className="text-xs text-danger">+ Full Access cannot be temporary. Remove the expiration or choose a lower tier.+ </p>+ )}+ </div>++ <div className="space-y-2">+ <Label>Temporary access</Label>+ <TemporaryAccessPopover+ isTemporary={isTemporary}+ range={range}+ label={isTemporary ? `Expires in ${range}` : "No expiration"}+ description="Access is revoked automatically once the duration elapses."+ onApply={(nextRange) => {+ setRange(nextRange);+ setIsTemporary(true);+ }}+ onRemove={() => setIsTemporary(false)}+ />+ </div>+ </div>++ <SheetFooter className="border-t">+ <Button+ variant="project"+ isFullWidth+ isDisabled={isSubmitDisabled}+ isPending={createUserAccess.isPending || createIdentityAccess.isPending}+ onClick={() => handleSubmit().catch(() => undefined)}+ >+ Grant Access+ </Button>+ </SheetFooter>+ </>+ );+};++export const GrantFolderAccessSheet = ({+ isOpen,+ onOpenChange,+ actor,+ existingAccess+}: Props) => (+ <Sheet open={isOpen} onOpenChange={onOpenChange}>+ <SheetContent className="gap-y-0 sm:max-w-[600px]">+ {isOpen && (+ <GrantFolderAccessForm+ actor={actor}+ existingAccess={existingAccess}+ onClose={() => onOpenChange(false)}+ />+ )}+ </SheetContent>+ </Sheet>+);diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/FolderAccessSheet/folder-access.utils.ts b/frontend/src/pages/secret-manager/OverviewPage/components/FolderAccessSheet/folder-access.utils.tsindex 611d9a230e..0158b92c5a 100644--- a/frontend/src/pages/secret-manager/OverviewPage/components/FolderAccessSheet/folder-access.utils.ts+++ b/frontend/src/pages/secret-manager/OverviewPage/components/FolderAccessSheet/folder-access.utils.ts@@ -116,3 +116,10 @@ export const formatExpirationTime = (expiresAt: string, now: number, suffix?: stvalue: `${minutes}m ${seconds}s${suffix ? ` ${suffix}` : ""}`};};++// SecretPathInput emits a trailing slash when a suggestion is picked, so `/foo/` and `/foo` both+// reach a form that has to compare the path against stored grants+export const normalizeFolderPath = (path: string) => {+ const segments = path.trim().split("/").filter(Boolean);+ return segments.length ? `/${segments.join("/")}` : "/";+};