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 support to select secret rotation
adilson0f456a11a0b5
diff --git a/frontend/src/hooks/api/secretRotationsV2/mutations.tsx b/frontend/src/hooks/api/secretRotationsV2/mutations.tsxindex 25ca4f2664..131529e8cf 100644--- a/frontend/src/hooks/api/secretRotationsV2/mutations.tsx+++ b/frontend/src/hooks/api/secretRotationsV2/mutations.tsx@@ -5,6 +5,7 @@ import { dashboardKeys } from "@app/hooks/api/dashboard/queries";import {TCreateSecretRotationV2DTO,TDeleteSecretRotationV2DTO,+ TMoveSecretRotationV2DTO,TReconcileLocalAccountRotationDTO,TReconcileLocalAccountRotationResponse,TRotateSecretRotationV2DTO,@@ -92,6 +93,29 @@ export const useDeleteSecretRotationV2 = () => {});};+export const useMoveSecretRotation = () => {+ const queryClient = useQueryClient();+ return useMutation({+ mutationFn: async ({+ type,+ rotationId,+ destinationEnvironment,+ destinationSecretPath+ }: TMoveSecretRotationV2DTO) => {+ const { data } = await apiRequest.post<TSecretRotationV2Response>(+ `/api/v2/secret-rotations/${type}/move/${rotationId}`,+ { destinationEnvironment, destinationSecretPath }+ );++ return data.secretRotation;+ },+ onSuccess: (_, { projectId, secretPath }) =>+ queryClient.invalidateQueries({+ queryKey: dashboardKeys.getDashboardSecrets({ projectId, secretPath })+ })+ });+};+export const useReconcileLocalAccountRotation = () => {const queryClient = useQueryClient();return useMutation({diff --git a/frontend/src/hooks/api/secretRotationsV2/types/index.ts b/frontend/src/hooks/api/secretRotationsV2/types/index.tsindex 60569f66dd..004a33a4fc 100644--- a/frontend/src/hooks/api/secretRotationsV2/types/index.ts+++ b/frontend/src/hooks/api/secretRotationsV2/types/index.ts@@ -190,6 +190,16 @@ export type TDeleteSecretRotationV2DTO = TRotateSecretRotationV2DTO & {deleteSecrets: boolean;};+export type TMoveSecretRotationV2DTO = {+ type: SecretRotation;+ rotationId: string;+ destinationEnvironment: string;+ destinationSecretPath: string;+ // required for query invalidation+ projectId: string;+ secretPath: string;+};+export type TViewSecretRotationV2GeneratedCredentialsDTO = {rotationId: string;type: SecretRotation;diff --git a/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx b/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsxindex 0455e2d23a..5d0d833948 100644--- a/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx+++ b/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx@@ -231,7 +231,8 @@ type TSecOverwriteOpt = { update: TParsedEnv; create: TParsedEnv };export enum EntryType {FOLDER = "folder",- SECRET = "secret"+ SECRET = "secret",+ SECRET_ROTATION = "secretRotation"}export enum RowType {@@ -336,9 +337,11 @@ const OverviewPageContent = () => {// selectedEntries[name/key][envSlug][resource][EntryType.FOLDER]: Record<string, Record<string, TSecretFolder>>;[EntryType.SECRET]: Record<string, Record<string, SecretV3RawSanitized>>;+ [EntryType.SECRET_ROTATION]: Record<string, Record<string, TSecretRotationV2>>;}>({[EntryType.FOLDER]: {},- [EntryType.SECRET]: {}+ [EntryType.SECRET]: {},+ [EntryType.SECRET_ROTATION]: {}});const {@@ -363,7 +366,8 @@ const OverviewPageContent = () => {const resetSelectedEntries = useCallback(() => {setSelectedEntries({[EntryType.FOLDER]: {},- [EntryType.SECRET]: {}+ [EntryType.SECRET]: {},+ [EntryType.SECRET_ROTATION]: {}});}, []);@@ -2082,24 +2086,28 @@ const OverviewPageContent = () => {}, []);const allRowsSelectedOnPage = useMemo(() => {- if (!secrets?.length && !folders?.length) return { isChecked: false, isIndeterminate: false };+ if (!secrets?.length && !folders?.length && !secretRotationNames?.length)+ return { isChecked: false, isIndeterminate: false };if ((!secrets?.length ||secrets?.every((secret) => selectedEntries[EntryType.SECRET][secret.key])) &&(!folders?.length ||- folders?.every((folder) => selectedEntries[EntryType.FOLDER][folder.name]))+ folders?.every((folder) => selectedEntries[EntryType.FOLDER][folder.name])) &&+ (!secretRotationNames?.length ||+ secretRotationNames?.every((name) => selectedEntries[EntryType.SECRET_ROTATION][name])))return { isChecked: true, isIndeterminate: false };if (secrets?.some((secret) => selectedEntries[EntryType.SECRET][secret.key]) ||- folders?.some((folder) => selectedEntries[EntryType.FOLDER][folder.name])+ folders?.some((folder) => selectedEntries[EntryType.FOLDER][folder.name]) ||+ secretRotationNames?.some((name) => selectedEntries[EntryType.SECRET_ROTATION][name]))return { isChecked: true, isIndeterminate: true };return { isChecked: false, isIndeterminate: false };- }, [selectedEntries, secrets, folders]);+ }, [selectedEntries, secrets, folders, secretRotationNames]);const toggleSelectedEntry = useCallback((type: EntryType, key: string) => {@@ -2112,10 +2120,14 @@ const OverviewPageContent = () => {} else {newChecks[type][key] = {};userAvailableEnvs.forEach((env) => {- const resource =- type === EntryType.SECRET- ? getSecretByKey(env.slug, key)- : getFolderByNameAndEnv(key, env.slug);+ let resource;+ if (type === EntryType.SECRET) {+ resource = getSecretByKey(env.slug, key);+ } else if (type === EntryType.FOLDER) {+ resource = getFolderByNameAndEnv(key, env.slug);+ } else {+ resource = getSecretRotationByName(env.slug, key);+ }if (resource) newChecks[type][key][env.slug] = resource;});@@ -2123,7 +2135,7 @@ const OverviewPageContent = () => {setSelectedEntries(newChecks);},- [selectedEntries, getFolderByNameAndEnv, getSecretByKey]+ [selectedEntries, getFolderByNameAndEnv, getSecretByKey, getSecretRotationByName]);const toggleSelectAllRows = () => {@@ -2155,6 +2167,19 @@ const OverviewPageContent = () => {if (resource) newChecks[EntryType.FOLDER][folder.name][env.slug] = resource;}});++ secretRotationNames?.forEach((rotationName) => {+ if (allRowsSelectedOnPage.isChecked) {+ delete newChecks[EntryType.SECRET_ROTATION][rotationName];+ } else {+ if (!newChecks[EntryType.SECRET_ROTATION][rotationName])+ newChecks[EntryType.SECRET_ROTATION][rotationName] = {};++ const resource = getSecretRotationByName(env.slug, rotationName);++ if (resource) newChecks[EntryType.SECRET_ROTATION][rotationName][env.slug] = resource;+ }+ });});setSelectedEntries(newChecks);@@ -2999,6 +3024,12 @@ const OverviewPageContent = () => {getSecretRotationStatusesByName={getSecretRotationStatusesByName}key={`overview-${secretRotationName}-${index + 1}`}tableWidth={tableWidth}+ isSelected={Boolean(+ selectedEntries.secretRotation[secretRotationName]+ )}+ onToggleRotationSelect={() =>+ toggleSelectedEntry(EntryType.SECRET_ROTATION, secretRotationName)+ }onEdit={(secretRotation) =>handlePopUpOpen("editSecretRotation", secretRotation)}diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SecretRotationTableRow/SecretRotationTableRow.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SecretRotationTableRow/SecretRotationTableRow.tsxindex 2d0c70bdb5..ae58f0d960 100644--- a/frontend/src/pages/secret-manager/OverviewPage/components/SecretRotationTableRow/SecretRotationTableRow.tsx+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SecretRotationTableRow/SecretRotationTableRow.tsx@@ -15,6 +15,7 @@ import { ProjectPermissionCan } from "@app/components/permissions";import { SecretRotationV2StatusBadge } from "@app/components/secret-rotations-v2/SecretRotationV2StatusBadge";import {Badge,+ Checkbox,IconButton,Table,TableBody,@@ -50,6 +51,8 @@ type Props = {getSecretRotationByName: (slug: string, name: string) => TSecretRotationV2 | undefined;getSecretRotationStatusesByName: (name: string) => (SecretRotationStatus | null)[] | undefined;tableWidth: number;+ isSelected: boolean;+ onToggleRotationSelect: (name: string) => void;onEdit: (secretRotation: TSecretRotationV2) => void;onRotate: (secretRotation: TSecretRotationV2) => void;onReconcile: (secretRotation: TSecretRotationV2) => void;@@ -73,6 +76,8 @@ export const SecretRotationTableRow = ({tableWidth,getSecretRotationByName,getSecretRotationStatusesByName,+ isSelected,+ onToggleRotationSelect,onEdit,onRotate,onViewGeneratedCredentials,@@ -261,10 +266,30 @@ export const SecretRotationTableRow = ({!isSingleEnvView && isExpanded && "border-b-0 bg-container-hover")}>+ <Checkbox+ variant="project"+ id={`checkbox-${secretRotationName}`}+ isChecked={isSelected}+ onCheckedChange={() => {+ onToggleRotationSelect(secretRotationName);+ }}+ onClick={(e) => {+ e.stopPropagation();+ }}+ className={twMerge("hidden group-hover:flex", isSelected && "flex")}+ />{!isSingleEnvView && isExpanded ? (- <ChevronDownIcon />+ <ChevronDownIcon+ className={twMerge("block", "group-hover:!hidden", isSelected && "!hidden")}+ />) : (- <RefreshCwIcon className="text-secret-rotation" />+ <RefreshCwIcon+ className={twMerge(+ "block text-secret-rotation",+ "group-hover:!hidden",+ isSelected && "!hidden"+ )}+ />)}</TableCell><TableCelldiff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/SelectionPanel.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/SelectionPanel.tsxindex 19956fc002..5faa352d9f 100644--- a/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/SelectionPanel.tsx+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/SelectionPanel.tsx@@ -18,6 +18,7 @@ import { useDeleteSecretBatch } from "@app/hooks/api";import { ProjectSecretsImportedBy, UsedBySecretSyncs } from "@app/hooks/api/dashboard/types";import { ProjectEnv } from "@app/hooks/api/projects/types";import { PendingAction } from "@app/hooks/api/secretFolders/types";+import { TSecretRotationV2 } from "@app/hooks/api/secretRotationsV2";import { useCreateCommit } from "@app/hooks/api/secrets/mutations";import {SecretType,@@ -33,7 +34,8 @@ import {export enum EntryType {FOLDER = "folder",- SECRET = "secret"+ SECRET = "secret",+ SECRET_ROTATION = "secretRotation"}type Props = {@@ -42,6 +44,7 @@ type Props = {selectedEntries: {[EntryType.FOLDER]: Record<string, Record<string, TSecretFolder>>;[EntryType.SECRET]: Record<string, Record<string, SecretV3RawSanitized>>;+ [EntryType.SECRET_ROTATION]: Record<string, Record<string, TSecretRotationV2>>;};importedBy?: ProjectSecretsImportedBy[] | null;usedBySecretSyncs?: UsedBySecretSyncs[];@@ -69,10 +72,11 @@ export const SelectionPanel = ({const selectedFolderCount = Object.keys(selectedEntries.folder).length;const selectedKeysCount = Object.keys(selectedEntries.secret).length;+ const selectedRotationCount = Object.keys(selectedEntries.secretRotation).length;const isRotatedSecretSelected = Object.values(selectedEntries.secret).some((record) =>Object.values(record).some((secret) => secret.isRotatedSecret));- const selectedCount = selectedFolderCount + selectedKeysCount;+ const selectedCount = selectedFolderCount + selectedKeysCount + selectedRotationCount;const { currentProject, projectId } = useProject();const userAvailableEnvs = currentProject?.environments || [];@@ -364,6 +368,7 @@ export const SelectionPanel = ({projectSlug={currentProject.slug}sourceSecretPath={secretPath}secrets={selectedEntries[EntryType.SECRET]}+ rotations={selectedEntries[EntryType.SECRET_ROTATION]}onComplete={resetSelectedEntries}/><BulkTagDialogdiff --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.tsxindex f87b4f8646..67e714caf2 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@@ -40,6 +40,7 @@ import { useDebounce } from "@app/hooks";import { useMoveSecrets } from "@app/hooks/api";import { useGetProjectSecretsQuickSearch } from "@app/hooks/api/dashboard";import { ProjectEnv } from "@app/hooks/api/projects/types";+import { TSecretRotationV2, useMoveSecretRotation } from "@app/hooks/api/secretRotationsV2";import { SecretV3RawSanitized } from "@app/hooks/api/secrets/types";type Props = {@@ -51,6 +52,7 @@ type Props = {projectSlug: string;sourceSecretPath: string;secrets: Record<string, Record<string, SecretV3RawSanitized>>;+ rotations: Record<string, Record<string, TSecretRotationV2>>;onComplete: () => void;};@@ -187,6 +189,7 @@ const SingleEnvContent = ({onComplete,onClose,secrets,+ rotations,environments,visibleEnvs,projectId,@@ -195,6 +198,7 @@ const SingleEnvContent = ({}: ContentProps) => {const sourceEnv = visibleEnvs[0];const moveSecrets = useMoveSecrets();+ const moveSecretRotation = useMoveSecretRotation();const [selectedPath, setSelectedPath] = useState<OptionValue | null>({secretPath: "/"});@@ -237,44 +241,100 @@ const SingleEnvContent = ({(secret): secret is SecretV3RawSanitized => Boolean(secret) && !secret.isRotatedSecret);- if (!secretsToMove.length) {+ const rotationsToMove = Object.values(rotations)+ .map((rotationRecord) => rotationRecord[sourceEnv.slug])+ .filter((rotation): rotation is TSecretRotationV2 => Boolean(rotation));++ if (!secretsToMove.length && !rotationsToMove.length) {createNotification({type: "info",- text: "No secrets to move in this environment"+ text: "No secrets or rotations to move in this environment"});return;}- const { isDestinationUpdated, isSourceUpdated } = await moveSecrets.mutateAsync({- shouldOverwrite: data.shouldOverwrite,- sourceEnvironment: sourceEnv.slug,- sourceSecretPath,- destinationEnvironment: data.environment,- destinationSecretPath: selectedPath.secretPath,- projectId,- projectSlug,- secretIds: secretsToMove.map((sec) => sec.id)- });+ let isDestinationUpdated = true;+ let isSourceUpdated = true;++ if (secretsToMove.length) {+ const result = await moveSecrets.mutateAsync({+ shouldOverwrite: data.shouldOverwrite,+ sourceEnvironment: sourceEnv.slug,+ sourceSecretPath,+ destinationEnvironment: data.environment,+ destinationSecretPath: selectedPath.secretPath,+ projectId,+ projectSlug,+ secretIds: secretsToMove.map((sec) => sec.id)+ });+ isDestinationUpdated = result.isDestinationUpdated;+ isSourceUpdated = result.isSourceUpdated;+ }++ const rotationFailures: { name: string; message: string }[] = [];+ let rotationSuccessCount = 0;++ // eslint-disable-next-line no-restricted-syntax+ for await (const rotation of rotationsToMove) {+ try {+ await moveSecretRotation.mutateAsync({+ type: rotation.type,+ rotationId: rotation.id,+ destinationEnvironment: data.environment,+ destinationSecretPath: selectedPath.secretPath,+ projectId,+ secretPath: sourceSecretPath+ });+ rotationSuccessCount += 1;+ } catch (error) {+ let message = (error as Error)?.message ?? "Failed to move rotation";+ if (axios.isAxiosError(error)) {+ const responseMessage = (error?.response?.data as { message?: string })?.message;+ if (responseMessage) message = responseMessage;+ }+ rotationFailures.push({ name: rotation.name, message });+ }+ }++ if (secretsToMove.length) {+ if (isDestinationUpdated && isSourceUpdated) {+ createNotification({+ type: "success",+ text: "Successfully moved selected secrets"+ });+ } else if (isDestinationUpdated) {+ createNotification({+ type: "info",+ text: "Successfully created secrets in destination. A secret approval request has been generated for the source."+ });+ } else if (isSourceUpdated) {+ createNotification({+ type: "info",+ text: "A secret approval request has been generated in the destination"+ });+ } else {+ createNotification({+ type: "info",+ text: "A secret approval request has been generated in both the source and the destination."+ });+ }+ }- if (isDestinationUpdated && isSourceUpdated) {+ if (rotationSuccessCount > 0) {createNotification({type: "success",- text: "Successfully moved selected secrets"+ text: `Successfully moved ${rotationSuccessCount} secret rotation${+ rotationSuccessCount === 1 ? "" : "s"+ }`});- } else if (isDestinationUpdated) {- createNotification({- type: "info",- text: "Successfully created secrets in destination. A secret approval request has been generated for the source."- });- } else if (isSourceUpdated) {- createNotification({- type: "info",- text: "A secret approval request has been generated in the destination"- });- } else {+ }++ if (rotationFailures.length > 0) {createNotification({- type: "info",- text: "A secret approval request has been generated in both the source and the destination."+ type: "error",+ text: `Failed to move ${rotationFailures.length} secret rotation${+ rotationFailures.length === 1 ? "" : "s"+ }: ${rotationFailures.map((f) => `${f.name} (${f.message})`).join("; ")}`});}@@ -380,12 +440,14 @@ const MultiEnvContent = ({onComplete,onClose,secrets,+ rotations,environments,projectId,projectSlug,sourceSecretPath}: ContentProps) => {const moveSecrets = useMoveSecrets();+ const moveSecretRotation = useMoveSecretRotation();const { permission } = useProjectPermission();const [moveResults, setMoveResults] = useState<MoveResults | null>(null);const [selectedPath, setSelectedPath] = useState<OptionValue | null>({@@ -466,21 +528,32 @@ const MultiEnvContent = ({}));+ const rotationsByEnv: Record<string, TSecretRotationV2[]> = Object.fromEntries(+ environments.map((env) => [env.slug, []])+ );++ Object.values(rotations).forEach((rotationRecord) =>+ Object.entries(rotationRecord).forEach(([env, rotation]) => {+ rotationsByEnv[env].push(rotation);+ })+ );+// eslint-disable-next-line no-restricted-syntaxfor await (const environment of environments) {const envSlug = environment.slug;const secretsToMove = secretsByEnv[envSlug];+ const rotationsToMove = rotationsByEnv[envSlug];if (moveSecretsEligibility[envSlug].missingPermissions) {// eslint-disable-next-line no-continuecontinue;}- if (!secretsToMove.length) {+ if (!secretsToMove.length && !rotationsToMove.length) {results.push({name: environment.name,- message: "No secrets selected in environment",+ message: "No secrets or rotations selected in environment",status: MoveResult.Info,id: environment.id});@@ -488,53 +561,89 @@ const MultiEnvContent = ({continue;}- try {- const { isDestinationUpdated, isSourceUpdated } = await moveSecrets.mutateAsync({- shouldOverwrite: data.shouldOverwrite,- sourceEnvironment: environment.slug,- sourceSecretPath,- destinationEnvironment: environment.slug,- destinationSecretPath: selectedPath.secretPath,- projectId,- projectSlug,- secretIds: secretsToMove.map((sec) => sec.id)- });+ if (secretsToMove.length) {+ try {+ const { isDestinationUpdated, isSourceUpdated } = await moveSecrets.mutateAsync({+ shouldOverwrite: data.shouldOverwrite,+ sourceEnvironment: environment.slug,+ sourceSecretPath,+ destinationEnvironment: environment.slug,+ destinationSecretPath: selectedPath.secretPath,+ projectId,+ projectSlug,+ secretIds: secretsToMove.map((sec) => sec.id)+ });++ let message = "";+ let status: MoveResult = MoveResult.Info;++ if (isDestinationUpdated && isSourceUpdated) {+ message = "Successfully moved selected secrets";+ status = MoveResult.Success;+ } else if (isDestinationUpdated) {+ message =+ "Successfully created secrets in destination. A secret approval request has been generated for the source.";+ } else if (isSourceUpdated) {+ message = "A secret approval request has been generated in the destination";+ } else {+ message =+ "A secret approval request has been generated in both the source and the destination.";+ }- let message = "";- let status: MoveResult = MoveResult.Info;-- if (isDestinationUpdated && isSourceUpdated) {- message = "Successfully moved selected secrets";- status = MoveResult.Success;- } else if (isDestinationUpdated) {- message =- "Successfully created secrets in destination. A secret approval request has been generated for the source.";- } else if (isSourceUpdated) {- message = "A secret approval request has been generated in the destination";- } else {- message =- "A secret approval request has been generated in both the source and the destination.";- }+ results.push({+ name: environment.name,+ message,+ status,+ id: environment.id+ });+ } catch (error) {+ let errorMessage = (error as Error)?.message ?? "Failed to move secrets";+ if (axios.isAxiosError(error)) {+ const { message } = error?.response?.data as { message: string };+ if (message) errorMessage = message;+ }- results.push({- name: environment.name,- message,- status,- id: environment.id- });- } catch (error) {- let errorMessage = (error as Error)?.message ?? "Failed to move secrets";- if (axios.isAxiosError(error)) {- const { message } = error?.response?.data as { message: string };- if (message) errorMessage = message;+ results.push({+ name: environment.name,+ message: errorMessage,+ status: MoveResult.Error,+ id: environment.id+ });}+ }- results.push({- name: environment.name,- message: errorMessage,- status: MoveResult.Error,- id: environment.id- });+ // eslint-disable-next-line no-restricted-syntax+ for await (const rotation of rotationsToMove) {+ try {+ await moveSecretRotation.mutateAsync({+ type: rotation.type,+ rotationId: rotation.id,+ destinationEnvironment: environment.slug,+ destinationSecretPath: selectedPath.secretPath,+ projectId,+ secretPath: sourceSecretPath+ });++ results.push({+ name: `${environment.name} / ${rotation.name}`,+ message: "Successfully moved secret rotation",+ status: MoveResult.Success,+ id: `${environment.id}-${rotation.id}`+ });+ } catch (error) {+ let errorMessage = (error as Error)?.message ?? "Failed to move secret rotation";+ if (axios.isAxiosError(error)) {+ const responseMessage = (error?.response?.data as { message?: string })?.message;+ if (responseMessage) errorMessage = responseMessage;+ }++ results.push({+ name: `${environment.name} / ${rotation.name}`,+ message: errorMessage,+ status: MoveResult.Error,+ id: `${environment.id}-${rotation.id}`+ });+ }}}@@ -551,7 +660,7 @@ const MultiEnvContent = ({return <MoveResultsView moveResults={moveResults} onComplete={onComplete} />;}- if (moveSecrets.isPending) {+ if (moveSecrets.isPending || moveSecretRotation.isPending) {return (<div className="flex h-full flex-col items-center justify-center py-2.5"><LoaderCircleIcon className="size-8 animate-spin text-accent" />