Skip to content

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

feat: add bulk tag modal to overview page

Scott Wilson62e2f4c4d4ae
diff --git a/frontend/src/hooks/api/secrets/types.ts b/frontend/src/hooks/api/secrets/types.ts
index 381999f615..93f72c2d06 100644
--- a/frontend/src/hooks/api/secrets/types.ts
+++ b/frontend/src/hooks/api/secrets/types.ts
@@ -230,7 +230,7 @@ export type TUpdateSecretBatchDTO = {
secrets: Array<{
type: SecretType;
secretKey: string;
- secretValue: string;
+ secretValue?: string;
secretComment?: string;
skipMultilineEncoding?: boolean | null;
tagIds?: string[];
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/SelectionPanel.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/SelectionPanel.tsx
index 833b47b4c3..c841a7cd6d 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/SelectionPanel.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/SelectionPanel.tsx
@@ -1,6 +1,6 @@
import { useMemo } from "react";
import { subject } from "@casl/ability";
-import { FolderInputIcon, TrashIcon } from "lucide-react";
+import { FolderInputIcon, TagsIcon, TrashIcon } from "lucide-react";
import { twMerge } from "tailwind-merge";
import { createNotification } from "@app/components/notifications";
@@ -27,6 +27,7 @@ import {
} from "@app/hooks/api/types";
import {
BulkDeleteDialog,
+ BulkTagDialog,
MoveSecretsModal
} from "@app/pages/secret-manager/OverviewPage/components/SelectionPanel/components";
@@ -62,7 +63,8 @@ export const SelectionPanel = ({
const { handlePopUpOpen, handlePopUpToggle, handlePopUpClose, popUp } = usePopUp([
"bulkDeleteEntries",
- "bulkMoveSecrets"
+ "bulkMoveSecrets",
+ "bulkTagSecrets"
] as const);
const selectedFolderCount = Object.keys(selectedEntries.folder).length;
@@ -92,6 +94,20 @@ export const SelectionPanel = ({
)
);
+ const canEditSecretsInAnyEnv = userAvailableEnvs.some((env) =>
+ permission.can(
+ ProjectPermissionSecretActions.Edit,
+ subject(ProjectPermissionSub.Secrets, {
+ environment: env.slug,
+ secretPath,
+ secretName: "*",
+ secretTags: ["*"]
+ })
+ )
+ );
+ const canReadTags = permission.can(ProjectPermissionActions.Read, ProjectPermissionSub.Tags);
+ const isTagActionDisabled = !canEditSecretsInAnyEnv || !canReadTags;
+
const usedBySecretSyncsFiltered = useMemo(() => {
if (selectedKeysCount === 0 || usedBySecretSyncs.length === 0) return null;
const envs = Object.values(selectedEntries.secret).flatMap((entries) => Object.keys(entries));
@@ -289,9 +305,26 @@ export const SelectionPanel = ({
</button>
{isRotatedSecretSelected && (
<span className="text-xs text-accent">
- Rotated Secrets will not be affected by action.
+ Rotated Secrets will not be affected by move or delete action.
</span>
)}
+ {selectedKeysCount > 0 && (
+ <Tooltip open={isTagActionDisabled ? undefined : false}>
+ <TooltipTrigger>
+ <Button
+ isDisabled={isTagActionDisabled}
+ variant="project"
+ className="ml-2"
+ onClick={() => handlePopUpOpen("bulkTagSecrets")}
+ size="xs"
+ >
+ <TagsIcon />
+ Tags
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>Access denied</TooltipContent>
+ </Tooltip>
+ )}
{shouldShowDelete && (
<>
<Tooltip open={areFoldersSelected ? undefined : false}>
@@ -333,6 +366,16 @@ export const SelectionPanel = ({
secrets={selectedEntries[EntryType.SECRET]}
onComplete={resetSelectedEntries}
/>
+ <BulkTagDialog
+ isOpen={popUp.bulkTagSecrets.isOpen}
+ onOpenChange={(isOpen) => handlePopUpToggle("bulkTagSecrets", isOpen)}
+ projectId={projectId}
+ secretPath={secretPath}
+ secrets={selectedEntries[EntryType.SECRET]}
+ environments={userAvailableEnvs}
+ visibleEnvs={visibleEnvs}
+ onComplete={resetSelectedEntries}
+ />
<BulkDeleteDialog
isOpen={popUp.bulkDeleteEntries.isOpen}
onOpenChange={(isOpen) => handlePopUpToggle("bulkDeleteEntries", isOpen)}
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/BulkTagDialog/BulkTagDialog.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/BulkTagDialog/BulkTagDialog.tsx
new file mode 100644
index 0000000000..2517d92738
--- /dev/null
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/BulkTagDialog/BulkTagDialog.tsx
@@ -0,0 +1,400 @@
+import { useMemo, useState } from "react";
+import { Controller, useForm } from "react-hook-form";
+import { subject } from "@casl/ability";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { KeyIcon, TagsIcon } from "lucide-react";
+import { z } from "zod";
+
+import { createNotification } from "@app/components/notifications";
+import {
+ Button,
+ CreatableSelect,
+ Dialog,
+ DialogClose,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ Field,
+ FieldContent,
+ FieldDescription,
+ FieldLabel,
+ Switch,
+ UnstableTable,
+ UnstableTableBody,
+ UnstableTableCell,
+ UnstableTableHead,
+ UnstableTableHeader,
+ UnstableTableRow
+} from "@app/components/v3";
+import { ProjectPermissionActions, ProjectPermissionSub, useProjectPermission } from "@app/context";
+import { ProjectPermissionSecretActions } from "@app/context/ProjectPermissionContext/types";
+import { useCreateWsTag, useGetWsTags, useUpdateSecretBatch } from "@app/hooks/api";
+import { ProjectEnv } from "@app/hooks/api/projects/types";
+import { SecretType, SecretV3RawSanitized } from "@app/hooks/api/secrets/types";
+import { slugSchema } from "@app/lib/schemas";
+
+const formSchema = z.object({
+ tags: z
+ .array(z.object({ label: z.string(), value: z.string() }))
+ .min(1, "Select at least one tag"),
+ isReplaceMode: z.boolean().default(false)
+});
+
+type TFormSchema = z.infer<typeof formSchema>;
+
+type Props = {
+ isOpen: boolean;
+ onOpenChange: (isOpen: boolean) => void;
+ projectId: string;
+ secretPath: string;
+ secrets: Record<string, Record<string, SecretV3RawSanitized>>;
+ environments: ProjectEnv[];
+ visibleEnvs: ProjectEnv[];
+ onComplete: () => void;
+};
+
+type ContentProps = Omit<Props, "isOpen" | "onOpenChange"> & {
+ onClose: () => void;
+};
+
+const BulkTagDialogContent = ({
+ projectId,
+ secretPath,
+ secrets,
+ environments,
+ visibleEnvs,
+ onComplete,
+ onClose
+}: ContentProps) => {
+ const { permission } = useProjectPermission();
+ const { mutateAsync: updateSecretBatch } = useUpdateSecretBatch();
+ const { mutateAsync: createWsTag } = useCreateWsTag();
+
+ const canReadTags = permission.can(ProjectPermissionActions.Read, ProjectPermissionSub.Tags);
+ const canAddTags = permission.can(ProjectPermissionActions.Create, ProjectPermissionSub.Tags);
+
+ const { data: projectTags, isPending: isTagsLoading } = useGetWsTags(
+ canReadTags ? projectId : ""
+ );
+
+ const [isSubmitting, setIsSubmitting] = useState(false);
+
+ const {
+ handleSubmit,
+ control,
+ setValue,
+ getValues,
+ watch,
+ formState: { isValid }
+ } = useForm<TFormSchema>({
+ defaultValues: {
+ tags: [],
+ isReplaceMode: false
+ },
+ resolver: zodResolver(formSchema)
+ });
+
+ const isReplaceMode = watch("isReplaceMode");
+
+ const selectedResources = useMemo(
+ () =>
+ Object.entries(secrets).map(([name, envRecord]) => ({
+ name,
+ envSlugs: new Set(Object.keys(envRecord))
+ })),
+ [secrets]
+ );
+
+ const tagOptions = useMemo(
+ () => projectTags?.map((tag) => ({ label: tag.slug, value: tag.id })),
+ [projectTags]
+ );
+
+ const handleCreateTag = async (inputValue: string) => {
+ const parsedSlug = slugSchema().safeParse(inputValue);
+ if (!parsedSlug.success) return;
+
+ const newTag = await createWsTag({
+ projectId,
+ tagSlug: parsedSlug.data,
+ tagColor: ""
+ });
+ const currentTags = getValues("tags");
+ setValue("tags", [...currentTags, { label: newTag.slug, value: newTag.id }], {
+ shouldDirty: true,
+ shouldValidate: true
+ });
+ };
+
+ const onSubmit = async (data: TFormSchema) => {
+ setIsSubmitting(true);
+
+ const selectedTagIds = data.tags.map((t) => t.value);
+
+ // Group secrets by environment
+ const secretsByEnv = Object.values(secrets).reduce<Record<string, SecretV3RawSanitized[]>>(
+ (acc, secretRecord) => {
+ Object.entries(secretRecord).forEach(([envSlug, secret]) => {
+ const canEditSecret = permission.can(
+ ProjectPermissionSecretActions.Edit,
+ subject(ProjectPermissionSub.Secrets, {
+ environment: envSlug,
+ secretPath,
+ secretName: secret.key,
+ secretTags: (secret.tags || []).map((t) => t.slug)
+ })
+ );
+ if (!canEditSecret) return;
+
+ if (!acc[envSlug]) acc[envSlug] = [];
+ acc[envSlug].push(secret);
+ });
+ return acc;
+ },
+ {}
+ );
+
+ const envSlugs = Object.keys(secretsByEnv);
+
+ if (envSlugs.length === 0) {
+ createNotification({
+ type: "info",
+ text: "You don't have access to tag the selected secrets"
+ });
+ setIsSubmitting(false);
+ return;
+ }
+
+ let hasApprovalRequest = false;
+ let hasDirectUpdate = false;
+
+ const results = await Promise.allSettled(
+ envSlugs.map(async (envSlug) => {
+ const envSecrets = secretsByEnv[envSlug];
+
+ const secretUpdates = envSecrets.map((secret) => {
+ let tagIds: string[];
+ if (data.isReplaceMode) {
+ tagIds = selectedTagIds;
+ } else {
+ const existingTagIds = (secret.tags || []).map((t) => t.id);
+ tagIds = [...new Set([...existingTagIds, ...selectedTagIds])];
+ }
+
+ return {
+ secretKey: secret.key,
+ type: SecretType.Shared,
+ tagIds
+ };
+ });
+
+ const result = await updateSecretBatch({
+ projectId,
+ environment: envSlug,
+ secretPath,
+ secrets: secretUpdates
+ });
+
+ if (result && "approval" in result) {
+ hasApprovalRequest = true;
+ } else {
+ hasDirectUpdate = true;
+ }
+
+ return { environment: envSlug };
+ })
+ );
+
+ const allSucceeded = results.every((r) => r.status === "fulfilled");
+ const someSucceeded = results.some((r) => r.status === "fulfilled");
+
+ const failedEnvs = environments
+ .filter(
+ (env) => !results.some((r) => r.status === "fulfilled" && r.value.environment === env.slug)
+ )
+ .filter((env) => secretsByEnv[env.slug])
+ .map((env) => env.name);
+
+ if (allSucceeded) {
+ onClose();
+ onComplete();
+ if (hasDirectUpdate && hasApprovalRequest) {
+ createNotification({
+ type: "info",
+ text: "Tags updated and an approval request was generated for protected environments"
+ });
+ } else if (hasApprovalRequest) {
+ createNotification({
+ type: "info",
+ text: "An approval request has been generated for the tag changes"
+ });
+ } else {
+ createNotification({
+ type: "success",
+ text: "Successfully updated tags on selected secrets"
+ });
+ }
+ } else if (someSucceeded) {
+ createNotification({
+ type: "warning",
+ text: `Tag update partially completed. The following environments could not be processed: ${failedEnvs.join(", ")}.`
+ });
+ } else {
+ createNotification({
+ type: "error",
+ text: "Failed to update tags on selected secrets"
+ });
+ }
+
+ setIsSubmitting(false);
+ };
+
+ const selectedSecretCount = Object.keys(secrets).length;
+
+ return (
+ <form
+ onSubmit={handleSubmit(onSubmit)}
+ onKeyDown={(e) => {
+ if (e.key === "Enter") e.preventDefault();
+ }}
+ >
+ <DialogHeader>
+ <DialogTitle>Bulk Tag Secrets</DialogTitle>
+ <DialogDescription>
+ Apply tags to {selectedSecretCount} selected secret{selectedSecretCount !== 1 ? "s" : ""}{" "}
+ across all environments.
+ </DialogDescription>
+ </DialogHeader>
+ {selectedResources.length > 0 && (
+ <UnstableTable containerClassName="max-h-[40vh] mt-4 overflow-auto">
+ <UnstableTableHeader className="sticky -top-px z-20 bg-container [&_tr]:border-b-0">
+ <UnstableTableRow>
+ <UnstableTableHead className="sticky left-0 z-20 w-10 max-w-10 min-w-10 border-b-0 bg-container shadow-[inset_0_-1px_0_var(--color-border)]">
+ Type
+ </UnstableTableHead>
+ <UnstableTableHead className="sticky left-10 z-20 max-w-[30vw] min-w-[30vw] border-b-0 bg-container shadow-[inset_-1px_0_0_var(--color-border),inset_0_-1px_0_var(--color-border)]">
+ Name
+ </UnstableTableHead>
+ {visibleEnvs.map((env) => (
+ <UnstableTableHead
+ key={env.slug}
+ className="w-32 max-w-32 border-r border-b-0 text-center shadow-[inset_0_-1px_0_var(--color-border)] last:border-r-0"
+ isTruncatable
+ >
+ {env.name}
+ </UnstableTableHead>
+ ))}
+ </UnstableTableRow>
+ </UnstableTableHeader>
+ <UnstableTableBody>
+ {selectedResources.map((item) => (
+ <UnstableTableRow key={item.name} className="group">
+ <UnstableTableCell className="sticky left-0 z-10 bg-container transition-colors duration-75 group-hover:bg-container-hover">
+ <KeyIcon className="size-4 text-secret" />
+ </UnstableTableCell>
+ <UnstableTableCell
+ className="sticky left-10 z-10 max-w-80 bg-container shadow-[inset_-1px_0_0_var(--color-border)] transition-colors duration-75 group-hover:bg-container-hover"
+ isTruncatable
+ >
+ {item.name}
+ </UnstableTableCell>
+ {visibleEnvs.map((env) => (
+ <UnstableTableCell
+ key={env.slug}
+ className="border-r text-center last:border-r-0"
+ >
+ {item.envSlugs.has(env.slug) ? (
+ <TagsIcon className="inline-block size-4 text-project" />
+ ) : (
+ <span className="text-muted">&mdash;</span>
+ )}
+ </UnstableTableCell>
+ ))}
+ </UnstableTableRow>
+ ))}
+ </UnstableTableBody>
+ </UnstableTable>
+ )}
+
+ <div className="flex flex-col gap-4 py-4">
+ <Field>
+ <FieldLabel>Tags</FieldLabel>
+ <FieldContent>
+ <Controller
+ name="tags"
+ control={control}
+ render={({ field }) => (
+ <CreatableSelect
+ isMulti
+ noOptionsMessage={({ inputValue }) =>
+ inputValue && !slugSchema().safeParse(inputValue).success
+ ? "Tag must be slug-friendly"
+ : "No tags match search"
+ }
+ isLoading={isTagsLoading}
+ placeholder="Select or create tags..."
+ options={tagOptions}
+ value={field.value}
+ onChange={(newValue) => field.onChange(newValue)}
+ onCreateOption={handleCreateTag}
+ isValidNewOption={(inputValue) =>
+ !canAddTags
+ ? false
+ : slugSchema().safeParse(inputValue).success &&
+ !projectTags?.map((tag) => tag.slug).includes(inputValue)
+ }
+ />
+ )}
+ />
+ </FieldContent>
+ </Field>
+ <Field>
+ <div className="flex items-center gap-3">
+ <Controller
+ name="isReplaceMode"
+ control={control}
+ render={({ field }) => (
+ <Switch
+ variant="project"
+ id="replace-tags-toggle"
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ />
+ )}
+ />
+ <FieldLabel htmlFor="replace-tags-toggle" className="mb-0 cursor-pointer">
+ Replace existing tags
+ </FieldLabel>
+ </div>
+ <FieldDescription>
+ {isReplaceMode
+ ? "All existing tags on selected secrets will be removed and replaced with the tags selected above."
+ : "Selected tags will be added to each secret, keeping any existing tags."}
+ </FieldDescription>
+ </Field>
+ </div>
+ <DialogFooter>
+ <DialogClose asChild>
+ <Button variant="outline">Cancel</Button>
+ </DialogClose>
+ <Button type="submit" variant="project" isPending={isSubmitting} isDisabled={!isValid}>
+ Apply Tags
+ </Button>
+ </DialogFooter>
+ </form>
+ );
+};
+
+export const BulkTagDialog = ({ isOpen, onOpenChange, ...contentProps }: Props) => {
+ return (
+ <Dialog open={isOpen} onOpenChange={onOpenChange}>
+ {isOpen && (
+ <DialogContent className="max-w-7xl">
+ <BulkTagDialogContent {...contentProps} onClose={() => onOpenChange(false)} />
+ </DialogContent>
+ )}
+ </Dialog>
+ );
+};
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/BulkTagDialog/index.ts b/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/BulkTagDialog/index.ts
new file mode 100644
index 0000000000..638fe9d824
--- /dev/null
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/BulkTagDialog/index.ts
@@ -0,0 +1 @@
+export * from "./BulkTagDialog";
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/index.ts b/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/index.ts
index 2189b40e8e..433ba042f0 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/index.ts
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/index.ts
@@ -1,2 +1,3 @@
export * from "./BulkDeleteDialog";
+export * from "./BulkTagDialog";
export * from "./MoveSecretsDialog";