mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 23:47:06 +00:00
feat: secret v2 architecture for secret rotation
This commit is contained in:
@@ -1,14 +1,9 @@
|
||||
import { useCallback } from "react";
|
||||
import { useQuery, UseQueryOptions } from "@tanstack/react-query";
|
||||
|
||||
import {
|
||||
decryptAssymmetric,
|
||||
decryptSymmetric
|
||||
} from "@app/components/utilities/cryptography/crypto";
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import {
|
||||
TGetSecretRotationList,
|
||||
TGetSecretRotationListDTO,
|
||||
TGetSecretRotationProviders,
|
||||
TSecretRotation,
|
||||
TSecretRotationProviderList
|
||||
@@ -19,7 +14,7 @@ export const secretRotationKeys = {
|
||||
{ workspaceId },
|
||||
"secret-rotation-providers"
|
||||
],
|
||||
list: ({ workspaceId }: Omit<TGetSecretRotationList, "decryptFileKey">) =>
|
||||
list: ({ workspaceId }: Omit<TGetSecretRotationListDTO, "decryptFileKey">) =>
|
||||
[{ workspaceId }, "secret-rotations"] as const
|
||||
};
|
||||
|
||||
@@ -53,7 +48,7 @@ export const useGetSecretRotationProviders = ({
|
||||
|
||||
const fetchSecretRotations = async ({
|
||||
workspaceId
|
||||
}: Omit<TGetSecretRotationList, "decryptFileKey">) => {
|
||||
}: Omit<TGetSecretRotationListDTO, "decryptFileKey">) => {
|
||||
const { data } = await apiRequest.get<{ secretRotations: TSecretRotation[] }>(
|
||||
"/api/v1/secret-rotations",
|
||||
{ params: { workspaceId } }
|
||||
@@ -63,14 +58,13 @@ const fetchSecretRotations = async ({
|
||||
|
||||
export const useGetSecretRotations = ({
|
||||
workspaceId,
|
||||
decryptFileKey,
|
||||
options = {}
|
||||
}: TGetSecretRotationList & {
|
||||
}: TGetSecretRotationListDTO & {
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
TSecretRotation[],
|
||||
unknown,
|
||||
TSecretRotation<{ key: string }>[],
|
||||
TSecretRotation[],
|
||||
ReturnType<typeof secretRotationKeys.list>
|
||||
>,
|
||||
"queryKey" | "queryFn"
|
||||
@@ -80,31 +74,5 @@ export const useGetSecretRotations = ({
|
||||
...options,
|
||||
queryKey: secretRotationKeys.list({ workspaceId }),
|
||||
enabled: Boolean(workspaceId) && (options?.enabled ?? true),
|
||||
queryFn: async () => fetchSecretRotations({ workspaceId }),
|
||||
select: useCallback(
|
||||
(data: TSecretRotation[]) => {
|
||||
const PRIVATE_KEY = localStorage.getItem("PRIVATE_KEY") as string;
|
||||
const decryptKey = decryptAssymmetric({
|
||||
ciphertext: decryptFileKey.encryptedKey,
|
||||
nonce: decryptFileKey.nonce,
|
||||
publicKey: decryptFileKey.sender.publicKey,
|
||||
privateKey: PRIVATE_KEY
|
||||
});
|
||||
return data.map((el) => ({
|
||||
...el,
|
||||
outputs: el.outputs.map(({ key, secret }) => ({
|
||||
key,
|
||||
secret: {
|
||||
key: decryptSymmetric({
|
||||
ciphertext: secret.secretValueCiphertext,
|
||||
iv: secret.secretValueIV,
|
||||
tag: secret.secretValueTag,
|
||||
key: decryptKey
|
||||
})
|
||||
}
|
||||
}))
|
||||
}));
|
||||
},
|
||||
[decryptFileKey]
|
||||
)
|
||||
queryFn: async () => fetchSecretRotations({ workspaceId })
|
||||
});
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { UserWsKeyPair } from "../keys/types";
|
||||
import { EncryptedSecret } from "../secrets/types";
|
||||
import { WorkspaceEnv } from "../workspace/types";
|
||||
|
||||
export enum TProviderFunctionTypes {
|
||||
@@ -74,7 +72,7 @@ export type TDbProviderTemplate = {
|
||||
outputs: Record<string, unknown>;
|
||||
};
|
||||
|
||||
export type TSecretRotation<T extends unknown = EncryptedSecret> = {
|
||||
export type TSecretRotation = {
|
||||
id: string;
|
||||
interval: number;
|
||||
provider: string;
|
||||
@@ -85,7 +83,11 @@ export type TSecretRotation<T extends unknown = EncryptedSecret> = {
|
||||
secretPath: string;
|
||||
outputs: Array<{
|
||||
key: string;
|
||||
secret: T;
|
||||
secret: {
|
||||
version: number;
|
||||
id: string;
|
||||
secretKey: string;
|
||||
};
|
||||
}>;
|
||||
status?: "success" | "failed";
|
||||
lastRotatedAt?: string;
|
||||
@@ -103,9 +105,8 @@ export type TGetSecretRotationProviders = {
|
||||
workspaceId: string;
|
||||
};
|
||||
|
||||
export type TGetSecretRotationList = {
|
||||
export type TGetSecretRotationListDTO = {
|
||||
workspaceId: string;
|
||||
decryptFileKey: UserWsKeyPair;
|
||||
};
|
||||
|
||||
export type TCreateSecretRotationDTO = {
|
||||
|
||||
Reference in New Issue
Block a user