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
allow multiple envs to be selected
Matheus Nogueira5e23343916f6
diff --git a/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/ShareSecretsSheet.tsx b/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/ShareSecretsSheet.tsxindex 503b6f6fef..61ef874a93 100644--- a/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/ShareSecretsSheet.tsx+++ b/frontend/src/pages/project/SettingsPage/components/CrossProjectSharingSection/ShareSecretsSheet.tsx@@ -1,17 +1,22 @@import { useState } from "react";import { MultiValue } from "react-select";-import { TriangleAlert } from "lucide-react";+import { useQueryClient } from "@tanstack/react-query";+import axios from "axios";+import { ArrowRight, FolderIcon, Layers, Pencil, Plus, Trash2, TriangleAlert } from "lucide-react";import { createNotification } from "@app/components/notifications";import {Alert,AlertDescription,+ Badge,Button,+ Card,Field,FieldDescription,FieldGroup,FieldLabel,FilterableSelect,+ IconButton,SecretPathInput,Select,SelectContent,@@ -26,16 +31,117 @@ import {SheetHeader,SheetTitle} from "@app/components/v3";+import { apiRequest } from "@app/config/request";import { useProject } from "@app/context";-import {- useCreateProjectFolderGrant,- useListProjectFolderGrants-} from "@app/hooks/api/projectFolderGrants";+import { projectFolderGrantKeys } from "@app/hooks/api/projectFolderGrants/queries";+import { TCreateProjectFolderGrantDTO } from "@app/hooks/api/projectFolderGrants/types";import { useGetUserProjectsByType } from "@app/hooks/api/projects";import { Project, ProjectType } from "@app/hooks/api/projects/types";-import { useGetProjectFolders } from "@app/hooks/api/secretFolders";import { useGetSecretImports } from "@app/hooks/api/secretImports";+type SourceEntry = {+ environment: string;+ secretPath: string;+};++const EMPTY_ENTRY: SourceEntry = { environment: "", secretPath: "/" };++type SourceEntryRowProps = {+ entry: SourceEntry;+ index: number;+ environments: { id: string; slug: string; name: string }[];+ onChange: (index: number, updated: Partial<SourceEntry>) => void;+};++const SourceEntryRow = ({ entry, index, environments, onChange }: SourceEntryRowProps) => {+ const { currentProject } = useProject();+ const { data: secretImports = [] } = useGetSecretImports({+ projectId: currentProject.id,+ environment: entry.environment,+ path: entry.secretPath,+ options: { enabled: Boolean(entry.environment) && Boolean(entry.secretPath) }+ });++ return (+ <div className="flex flex-col gap-3">+ <Field>+ <FieldLabel>Environment</FieldLabel>+ <Select+ value={entry.environment}+ onValueChange={(val) => onChange(index, { environment: val, secretPath: "/" })}+ >+ <SelectTrigger className="w-full">+ <SelectValue placeholder="Select environment" />+ </SelectTrigger>+ <SelectContent position="popper">+ {environments.map((env) => (+ <SelectItem key={env.id} value={env.slug}>+ {env.name}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ </Field>++ <Field>+ <FieldLabel>Folder path</FieldLabel>+ <SecretPathInput+ value={entry.secretPath}+ onChange={(val) => onChange(index, { secretPath: val })}+ environment={entry.environment}+ placeholder="/"+ />+ <FieldDescription>+ Secrets at this path become available to the target project.+ </FieldDescription>+ </Field>++ {secretImports.length > 0 && (+ <Alert variant="warning">+ <TriangleAlert />+ <AlertDescription>+ This folder contains secret imports. Imports aren't re-shared across projects, so+ only the folder's own static secrets will be shared with the target project.+ </AlertDescription>+ </Alert>+ )}+ </div>+ );+};++type CompactEntryRowProps = {+ entry: SourceEntry;+ envName: string;+ onEdit: () => void;+ onRemove: () => void;+};++const CompactEntryRow = ({ entry, envName, onEdit, onRemove }: CompactEntryRowProps) => (+ <div className="flex items-center gap-2 px-3 py-2">+ <div className="flex flex-1 items-center gap-2">+ <Badge variant="neutral" className="gap-1.5">+ <Layers className="size-3" />+ {envName}+ </Badge>+ <ArrowRight className="size-3.5 shrink-0 text-muted" />+ <div className="flex items-center gap-1.5">+ <FolderIcon className="size-3.5 text-muted" />+ <span className="text-sm text-muted">+ {entry.secretPath === "/" ? "/" : entry.secretPath}+ </span>+ </div>+ </div>+ <div className="flex items-center gap-1">+ <IconButton variant="ghost-muted" size="xs" onClick={onEdit}>+ <Pencil />+ </IconButton>+ <IconButton variant="ghost-muted" size="xs" onClick={onRemove}>+ <Trash2 />+ </IconButton>+ </div>+ </div>+);+type Props = {isOpen: boolean;onOpenChange: (isOpen: boolean) => void;@@ -43,71 +149,105 @@ type Props = {export const ShareSecretsSheet = ({ isOpen, onOpenChange }: Props) => {const { currentProject } = useProject();- const [environment, setEnvironment] = useState("");- const [folderPath, setFolderPath] = useState("/");+ const [entries, setEntries] = useState<SourceEntry[]>([{ ...EMPTY_ENTRY }]);+ const [editingIndex, setEditingIndex] = useState<number | null>(0);const [targetProjects, setTargetProjects] = useState<Project[]>([]);+ const queryClient = useQueryClient();+ const [isSubmitting, setIsSubmitting] = useState(false);const { data: projects = [], isPending: isProjectsLoading } = useGetUserProjectsByType(ProjectType.SecretManager);- const { data: secretImports = [] } = useGetSecretImports({- projectId: currentProject.id,- environment,- path: folderPath,- options: { enabled: Boolean(environment) && Boolean(folderPath) }- });- const { data: existingGrants = [] } = useListProjectFolderGrants(currentProject.id);- const createGrant = useCreateProjectFolderGrant();- const pathSegments = folderPath.split("/").filter(Boolean);- const parentPath = pathSegments.length <= 1 ? "/" : `/${pathSegments.slice(0, -1).join("/")}`;- const leafName = pathSegments.at(-1) ?? "";+ const availableProjects = projects.filter((p) => p.id !== currentProject.id);- const { data: parentFolders = [] } = useGetProjectFolders({- projectId: currentProject.id,- environment,- path: parentPath,- options: { enabled: Boolean(environment) && folderPath !== "/" }- });+ const hasValidEntry = entries.some((e) => e.environment && e.secretPath);- const selectedFolderId = parentFolders.find((f) => f.name === leafName)?.id;+ const envNameBySlug = new Map(currentProject.environments.map((e) => [e.slug, e.name]));+ const isEntryFilled = (entry: SourceEntry) => Boolean(entry.environment);- const grantedProjectIds = new Set(- existingGrants- .filter((g) =>- selectedFolderId- ? g.sourceFolderId === selectedFolderId- : g.environmentSlug === environment && g.folderName === "root"- )- .map((g) => g.targetProjectId)- );+ const compactEntries = entries+ .map((entry, originalIndex) => ({ entry, originalIndex }))+ .filter(({ entry, originalIndex }) => originalIndex !== editingIndex && isEntryFilled(entry));- const availableProjects = projects.filter(- (p) => p.id !== currentProject.id && !grantedProjectIds.has(p.id)- );+ const handleEntryChange = (index: number, updated: Partial<SourceEntry>) => {+ setEntries((prev) => prev.map((e, i) => (i === index ? { ...e, ...updated } : e)));+ };++ const handleEntryRemove = (index: number) => {+ setEntries((prev) => {+ const next = prev.filter((_, i) => i !== index);+ if (next.length === 0) return [{ ...EMPTY_ENTRY }];+ return next;+ });+ setEditingIndex((prev) => {+ if (prev === null) return null;+ if (index < prev) return prev - 1;+ if (index === prev) return null;+ return prev;+ });+ };++ const handleAddEntry = () => {+ setEntries((prev) => [...prev, { ...EMPTY_ENTRY }]);+ setEditingIndex(entries.length);+ };++ const createGrant = async (dto: TCreateProjectFolderGrantDTO) => {+ try {+ await apiRequest.post("/api/v1/project-folder-grants", dto);+ } catch (err) {+ if (+ axios.isAxiosError(err) &&+ typeof err.response?.data?.message === "string" &&+ (err.response.data.message as string).includes("already exists")+ ) {+ return;+ }+ throw err;+ }+ };const handleSubmit = async () => {- if (!environment || targetProjects.length === 0 || !folderPath) return;+ const validEntries = entries.filter((e) => e.environment && e.secretPath);+ if (validEntries.length === 0 || targetProjects.length === 0) return;+ setIsSubmitting(true);try {await Promise.all(- targetProjects.map((project) =>- createGrant.mutateAsync({- sourceProjectId: currentProject.id,- environment,- secretPath: folderPath,- targetProjectId: project.id+ validEntries.flatMap((entry) =>+ targetProjects.map((project) =>+ createGrant({+ sourceProjectId: currentProject.id,+ environment: entry.environment,+ secretPath: entry.secretPath,+ targetProjectId: project.id+ })+ )+ )+ );++ await queryClient.invalidateQueries({+ queryKey: projectFolderGrantKeys.listByProject(currentProject.id)+ });+ await Promise.all(+ targetProjects.map((p) =>+ queryClient.invalidateQueries({+ queryKey: projectFolderGrantKeys.listReceived(p.id)})));+createNotification({ text: "Access granted successfully", type: "success" });onOpenChange(false);- setEnvironment("");- setFolderPath("/");+ setEntries([{ ...EMPTY_ENTRY }]);+ setEditingIndex(0);setTargetProjects([]);} catch (err) {console.error(err);createNotification({ text: "Failed to create grant", type: "error" });+ } finally {+ setIsSubmitting(false);}};@@ -127,55 +267,34 @@ export const ShareSecretsSheet = ({ isOpen, onOpenChange }: Props) => {From This Project</p>- <Field>- <FieldLabel>Environment</FieldLabel>- <Select- value={environment}- onValueChange={(val) => {- setEnvironment(val);- setTargetProjects([]);- }}- >- <SelectTrigger className="w-full">- <SelectValue placeholder="Select environment" />- </SelectTrigger>- <SelectContent position="popper">- {currentProject.environments.map((env) => (- <SelectItem key={env.id} value={env.slug}>- {env.name}- </SelectItem>- ))}- </SelectContent>- </Select>- </Field>-- <Field>- <FieldLabel>Folder path</FieldLabel>- <SecretPathInput- value={folderPath}- onChange={(val) => {- setFolderPath(val);- setTargetProjects([]);- }}- environment={environment}- placeholder="/"+ {compactEntries.length > 0 && (+ <Card className="gap-0 divide-y divide-border p-0">+ {compactEntries.map(({ entry, originalIndex }) => (+ <CompactEntryRow+ key={originalIndex}+ entry={entry}+ envName={envNameBySlug.get(entry.environment) ?? entry.environment}+ onEdit={() => setEditingIndex(originalIndex)}+ onRemove={() => handleEntryRemove(originalIndex)}+ />+ ))}+ </Card>+ )}++ {editingIndex !== null && entries[editingIndex] && (+ <SourceEntryRow+ entry={entries[editingIndex]}+ index={editingIndex}+ environments={currentProject.environments}+ onChange={handleEntryChange}/>- <FieldDescription>- Secrets at this path become available to the target project.- </FieldDescription>- </Field>-- {secretImports.length > 0 && (- <Alert variant="warning">- <TriangleAlert />- <AlertDescription>- This folder contains secret imports. Imports aren't re-shared across- projects, so only the folder's own static secrets will be shared with the- target project.- </AlertDescription>- </Alert>)}+ <Button variant="outline" size="sm" className="w-fit" onClick={handleAddEntry}>+ <Plus className="size-3.5" />+ Add another path+ </Button>+<div className="rounded-md border border-border p-4"><p className="mb-4 text-xs font-semibold tracking-widest text-muted uppercase">To Another Project@@ -204,8 +323,8 @@ export const ShareSecretsSheet = ({ isOpen, onOpenChange }: Props) => {</SheetClose><Buttonvariant="project"- disabled={!environment || targetProjects.length === 0 || !folderPath}- isPending={createGrant.isPending}+ disabled={!hasValidEntry || targetProjects.length === 0}+ isPending={isSubmitting}onClick={handleSubmit}>Share