feat: ui removed all private key except secret rotation to raw endpoints version

This commit is contained in:
=
2024-07-23 00:55:18 +05:30
parent d4747abba8
commit b7b0e60b1d
12 changed files with 66 additions and 200 deletions

View File

@@ -13,15 +13,13 @@ import {
import { apiRequest } from "@app/config/request";
import { UserWsKeyPair } from "../keys/types";
import { EncryptedSecret, SecretType,SecretV3RawSanitized } from "../secrets/types";
import { EncryptedSecret, SecretType, SecretV3RawSanitized } from "../secrets/types";
import {
CommitType,
TGetSecretApprovalRequestCount,
TGetSecretApprovalRequestDetails,
TGetSecretApprovalRequestList,
TSecretApprovalRequest,
TSecretApprovalRequestCount,
TSecretApprovalSecChangeData
TSecretApprovalRequestCount
} from "./types";
export const secretApprovalRequestKeys = {
@@ -117,48 +115,6 @@ export const decryptSecrets = (
return secrets;
};
export const decryptSecretApprovalSecret = (
encSecret: TSecretApprovalSecChangeData,
decryptFileKey: UserWsKeyPair
) => {
const PRIVATE_KEY = localStorage.getItem("PRIVATE_KEY") as string;
const key = decryptAssymmetric({
ciphertext: decryptFileKey.encryptedKey,
nonce: decryptFileKey.nonce,
publicKey: decryptFileKey.sender.publicKey,
privateKey: PRIVATE_KEY
});
const secretKey = decryptSymmetric({
ciphertext: encSecret.secretKeyCiphertext,
iv: encSecret.secretKeyIV,
tag: encSecret.secretKeyTag,
key
});
const secretValue = decryptSymmetric({
ciphertext: encSecret.secretValueCiphertext,
iv: encSecret.secretValueIV,
tag: encSecret.secretValueTag,
key
});
const secretComment = decryptSymmetric({
ciphertext: encSecret.secretCommentCiphertext,
iv: encSecret.secretCommentIV,
tag: encSecret.secretCommentTag,
key
});
return {
id: encSecret.id,
version: encSecret.version,
secretKey,
secretValue,
secretComment,
tags: encSecret.tags
};
};
const fetchSecretApprovalRequestList = async ({
workspaceId,
environment,
@@ -245,7 +201,7 @@ export const useGetSecretApprovalRequestDetails = ({
UseQueryOptions<
TSecretApprovalRequest,
unknown,
TSecretApprovalRequest<SecretV3RawSanitized>,
TSecretApprovalRequest,
ReturnType<typeof secretApprovalRequestKeys.detail>
>,
"queryKey" | "queryFn"
@@ -254,16 +210,6 @@ export const useGetSecretApprovalRequestDetails = ({
useQuery({
queryKey: secretApprovalRequestKeys.detail({ id }),
queryFn: () => fetchSecretApprovalRequestDetails({ id }),
select: (data) => ({
...data,
commits: data.commits.map(({ secretVersion, op, secret, ...newVersion }) => ({
op,
secret,
secretVersion: secretVersion ? decryptSecrets([secretVersion], decryptKey)[0] : undefined,
newVersion:
op !== CommitType.DELETE ? decryptSecretApprovalSecret(newVersion, decryptKey) : undefined
}))
}),
enabled: Boolean(id && decryptKey) && (options?.enabled ?? true)
});

View File

@@ -1,6 +1,6 @@
import { UserWsKeyPair } from "../keys/types";
import { TSecretApprovalPolicy } from "../secretApproval/types";
import { EncryptedSecret } from "../secrets/types";
import { SecretV3Raw } from "../secrets/types";
import { WsTag } from "../tags/types";
export enum ApprovalStatus {
@@ -17,15 +17,9 @@ export enum CommitType {
export type TSecretApprovalSecChangeData = {
id: string;
secretKeyCiphertext: string;
secretKeyIV: string;
secretKeyTag: string;
secretValueCiphertext: string;
secretValueIV: string;
secretValueTag: string;
secretCommentIV: string;
secretCommentTag: string;
secretCommentCiphertext: string;
secretKey: string;
secretValue?: string;
secretComment?: string;
skipMultilineEncoding?: boolean;
algorithm: "aes-256-gcm";
keyEncoding: "utf8" | "base64";
@@ -37,12 +31,12 @@ export type TSecretApprovalSecChange = {
id: string;
version: number;
secretKey: string;
secretValue: string;
secretComment: string;
secretValue?: string;
secretComment?: string;
tags?: string[];
};
export type TSecretApprovalRequest<J extends unknown = EncryptedSecret> = {
export type TSecretApprovalRequest = {
id: string;
isReplicated?: boolean;
slug: string;
@@ -90,7 +84,7 @@ export type TSecretApprovalRequest<J extends unknown = EncryptedSecret> = {
commits: ({
// if there is no secret means it was creation
secret?: { version: number };
secretVersion: J;
secretVersion: SecretV3Raw;
// if there is no new version its for Delete
op: CommitType;
} & TSecretApprovalSecChangeData)[];

View File

@@ -1,13 +1,9 @@
/* eslint-disable no-param-reassign */
import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import {
decryptAssymmetric,
decryptSymmetric
} from "@app/components/utilities/cryptography/crypto";
import { apiRequest } from "@app/config/request";
import { SecretType,SecretV3RawSanitized } from "../secrets/types";
import { SecretType, SecretV3RawSanitized } from "../secrets/types";
import {
TGetSecretSnapshotsDTO,
TSecretRollbackDTO,
@@ -65,55 +61,33 @@ const fetchSnapshotEncSecrets = async (snapshotId: string) => {
return res.data.secretSnapshot;
};
export const useGetSnapshotSecrets = ({ decryptFileKey, snapshotId }: TSnapshotDataProps) =>
export const useGetSnapshotSecrets = ({ snapshotId }: TSnapshotDataProps) =>
useQuery({
queryKey: secretSnapshotKeys.snapshotData(snapshotId),
enabled: Boolean(snapshotId && decryptFileKey),
enabled: Boolean(snapshotId),
queryFn: () => fetchSnapshotEncSecrets(snapshotId),
select: (data) => {
const PRIVATE_KEY = localStorage.getItem("PRIVATE_KEY") as string;
const latestKey = decryptFileKey;
const key = decryptAssymmetric({
ciphertext: latestKey.encryptedKey,
nonce: latestKey.nonce,
publicKey: latestKey.sender.publicKey,
privateKey: PRIVATE_KEY
});
const sharedSecrets: SecretV3RawSanitized[] = [];
const personalSecrets: Record<string, { id: string; value: string }> = {};
data.secretVersions.forEach((encSecret) => {
const secretKey = decryptSymmetric({
ciphertext: encSecret.secretKeyCiphertext,
iv: encSecret.secretKeyIV,
tag: encSecret.secretKeyTag,
key
});
const secretValue = decryptSymmetric({
ciphertext: encSecret.secretValueCiphertext,
iv: encSecret.secretValueIV,
tag: encSecret.secretValueTag,
key
});
const secretComment = "";
data.secretVersions.forEach((secretVersion) => {
const decryptedSecret = {
id: encSecret.secretId,
id: secretVersion.secretId,
env: data.environment.slug,
key: secretKey,
value: secretValue,
tags: encSecret.tags,
comment: secretComment,
createdAt: encSecret.createdAt,
updatedAt: encSecret.updatedAt,
key: secretVersion.secretKey,
value: secretVersion.secretValue || "",
tags: secretVersion.tags,
comment: secretVersion.secretComment,
createdAt: secretVersion.createdAt,
updatedAt: secretVersion.updatedAt,
type: "modified",
version: encSecret.version
version: secretVersion.version
};
if (encSecret.type === SecretType.Personal) {
personalSecrets[decryptedSecret.key] = { id: encSecret.secretId, value: secretValue };
if (secretVersion.type === SecretType.Personal) {
personalSecrets[decryptedSecret.key] = {
id: secretVersion.secretId,
value: secretVersion.secretValue || ""
};
} else {
sharedSecrets.push(decryptedSecret);
}

View File

@@ -1,5 +1,4 @@
import { UserWsKeyPair } from "../keys/types";
import { EncryptedSecretVersion } from "../secrets/types";
import { SecretVersions } from "../secrets/types";
import { WorkspaceEnv } from "../types";
export type TSecretSnapshot = {
@@ -12,7 +11,7 @@ export type TSecretSnapshot = {
export type TSnapshotData = Omit<TSecretSnapshot, "secretVersions"> & {
id: string;
secretVersions: EncryptedSecretVersion[];
secretVersions: SecretVersions[];
folderVersion: Array<{ name: string; id: string }>;
environment: WorkspaceEnv;
};
@@ -20,7 +19,6 @@ export type TSnapshotData = Omit<TSecretSnapshot, "secretVersions"> & {
export type TSnapshotDataProps = {
snapshotId: string;
env: string;
decryptFileKey: UserWsKeyPair;
};
export type TGetSecretSnapshotsDTO = {

View File

@@ -2,19 +2,15 @@
import { useCallback, useMemo } from "react";
import { useQueries, useQuery, UseQueryOptions } from "@tanstack/react-query";
import {
decryptAssymmetric,
decryptSymmetric
} from "@app/components/utilities/cryptography/crypto";
import { apiRequest } from "@app/config/request";
import {
EncryptedSecretVersion,
GetSecretVersionsDTO,
SecretType,
SecretV3Raw,
SecretV3RawResponse,
SecretV3RawSanitized,
SecretVersions,
TGetProjectSecretsAllEnvDTO,
TGetProjectSecretsDTO,
TGetProjectSecretsKey
@@ -166,7 +162,7 @@ export const useGetProjectSecretsAllEnv = ({
};
const fetchEncryptedSecretVersion = async (secretId: string, offset: number, limit: number) => {
const { data } = await apiRequest.get<{ secretVersions: EncryptedSecretVersion[] }>(
const { data } = await apiRequest.get<{ secretVersions: SecretVersions[] }>(
`/api/v1/secret/${secretId}/secret-versions`,
{
params: {
@@ -180,33 +176,10 @@ const fetchEncryptedSecretVersion = async (secretId: string, offset: number, lim
export const useGetSecretVersion = (dto: GetSecretVersionsDTO) =>
useQuery({
enabled: Boolean(dto.secretId && dto.decryptFileKey),
enabled: Boolean(dto.secretId),
queryKey: secretKeys.getSecretVersion(dto.secretId),
queryFn: () => fetchEncryptedSecretVersion(dto.secretId, dto.offset, dto.limit),
select: useCallback(
(data: EncryptedSecretVersion[]) => {
const PRIVATE_KEY = localStorage.getItem("PRIVATE_KEY") as string;
const latestKey = dto.decryptFileKey;
const key = decryptAssymmetric({
ciphertext: latestKey.encryptedKey,
nonce: latestKey.nonce,
publicKey: latestKey.sender.publicKey,
privateKey: PRIVATE_KEY
});
return data
.map((el) => ({
createdAt: el.createdAt,
id: el.id,
value: decryptSymmetric({
ciphertext: el.secretValueCiphertext,
iv: el.secretValueIV,
tag: el.secretValueTag,
key
})
}))
.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
},
[dto.decryptFileKey]
)
select: useCallback((data: SecretVersions[]) => {
return data.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
}, [])
});

View File

@@ -1,4 +1,3 @@
import type { UserWsKeyPair } from "../keys/types";
import type { WsTag } from "../tags/types";
export enum SecretType {
@@ -79,7 +78,7 @@ export type SecretV3RawResponse = {
}[];
};
export type EncryptedSecretVersion = {
export type SecretVersions = {
id: string;
secretId: string;
version: number;
@@ -87,12 +86,9 @@ export type EncryptedSecretVersion = {
type: SecretType;
isDeleted: boolean;
envId: string;
secretKeyCiphertext: string;
secretKeyIV: string;
secretKeyTag: string;
secretValueCiphertext: string;
secretValueIV: string;
secretValueTag: string;
secretKey: string;
secretValue?: string;
secretComment?: string;
tags: WsTag[];
__v: number;
skipMultilineEncoding?: boolean;
@@ -123,7 +119,6 @@ export type GetSecretVersionsDTO = {
secretId: string;
limit: number;
offset: number;
decryptFileKey: UserWsKeyPair;
};
export type TCreateSecretsV3DTO = {

View File

@@ -13,16 +13,11 @@ import {
Tooltip,
Tr
} from "@app/components/v2";
import {
CommitType,
SecretV3RawSanitized,
TSecretApprovalSecChange,
WsTag
} from "@app/hooks/api/types";
import { CommitType, SecretV3Raw, TSecretApprovalSecChange, WsTag } from "@app/hooks/api/types";
export type Props = {
op: CommitType;
secretVersion?: SecretV3RawSanitized;
secretVersion?: SecretV3Raw;
newVersion?: Omit<TSecretApprovalSecChange, "tags"> & { tags?: WsTag[] };
presentSecretVersionNumber: number;
hasMerged?: Boolean;
@@ -96,11 +91,11 @@ export const SecretApprovalRequestChangeItem = ({
<TBody>
<Tr>
<Td className="text-red-600">OLD</Td>
<Td>{secretVersion?.key}</Td>
<Td>{secretVersion?.secretKey}</Td>
<Td>
<SecretInput isReadOnly value={secretVersion?.value} />
<SecretInput isReadOnly value={secretVersion?.secretValue} />
</Td>
<Td>{secretVersion?.comment}</Td>
<Td>{secretVersion?.secretComment}</Td>
<Td>
{secretVersion?.tags?.map(({ name, id: tagId, color }) => (
<Tag
@@ -142,17 +137,23 @@ export const SecretApprovalRequestChangeItem = ({
) : (
<TBody>
<Tr>
<Td>{op === CommitType.CREATE ? newVersion?.secretKey : secretVersion?.key}</Td>
<Td>
{op === CommitType.CREATE ? newVersion?.secretKey : secretVersion?.secretKey}
</Td>
<Td>
<SecretInput
isReadOnly
value={
op === CommitType.CREATE ? newVersion?.secretValue : secretVersion?.value
op === CommitType.CREATE
? newVersion?.secretValue
: secretVersion?.secretValue
}
/>
</Td>
<Td>
{op === CommitType.CREATE ? newVersion?.secretComment : secretVersion?.comment}
{op === CommitType.CREATE
? newVersion?.secretComment
: secretVersion?.secretComment}
</Td>
<Td>
{(op === CommitType.CREATE ? newVersion?.tags : secretVersion?.tags)?.map(

View File

@@ -230,7 +230,7 @@ export const SecretApprovalRequestChanges = ({
</div>
<div className="flex flex-col space-y-4">
{secretApprovalRequestDetails.commits.map(
({ op, secretVersion, secret, newVersion }, index) => (
({ op, secretVersion, secret, ...newVersion }, index) => (
<SecretApprovalRequestChangeItem
op={op}
conflicts={secretApprovalRequestDetails.conflicts}
@@ -269,8 +269,9 @@ export const SecretApprovalRequestChanges = ({
>
<div className="flex-grow text-sm">
<Tooltip
content={`${requiredApprover.firstName || ""} ${requiredApprover.lastName || ""
}`}
content={`${requiredApprover.firstName || ""} ${
requiredApprover.lastName || ""
}`}
>
<span>{requiredApprover?.email} </span>
</Tooltip>

View File

@@ -23,13 +23,11 @@ import {
useGetProjectSecrets,
useGetSecretApprovalPolicyOfABoard,
useGetSecretImports,
useGetUserWsKey,
useGetWorkspaceSnapshotList,
useGetWsSnapshotCount,
useGetWsTags
} from "@app/hooks/api";
import { ProjectIndexSecretsSection } from "../SecretOverviewPage/components/ProjectIndexSecretsSection";
import { ActionBar } from "./components/ActionBar";
import { CreateSecretForm } from "./components/CreateSecretForm";
import { DynamicSecretListView } from "./components/DynamicSecretListView";
@@ -93,8 +91,6 @@ export const SecretMainPage = () => {
}
}, [isWorkspaceLoading, currentWorkspace, environment, router.isReady]);
const { data: decryptFileKey } = useGetUserWsKey(workspaceId);
// fetch secrets
const { data: secrets, isLoading: isSecretsLoading } = useGetProjectSecrets({
environment,
@@ -248,7 +244,6 @@ export const SecretMainPage = () => {
protectionPolicyName={boardPolicy?.name}
/>
</div>
<ProjectIndexSecretsSection decryptFileKey={decryptFileKey!} />
{!isRollbackMode ? (
<>
<ActionBar
@@ -330,7 +325,6 @@ export const SecretMainPage = () => {
environment={environment}
workspaceId={workspaceId}
secretPath={secretPath}
decryptFileKey={decryptFileKey!}
isProtectedBranch={isProtectedBranch}
/>
)}
@@ -367,7 +361,6 @@ export const SecretMainPage = () => {
) : (
<SnapshotView
snapshotId={snapshotId || ""}
decryptFileKey={decryptFileKey!}
environment={environment}
workspaceId={workspaceId}
secretPath={secretPath}

View File

@@ -37,7 +37,7 @@ import { InfisicalSecretInput } from "@app/components/v2/InfisicalSecretInput";
import { ProjectPermissionActions, ProjectPermissionSub, useProjectPermission } from "@app/context";
import { useToggle } from "@app/hooks";
import { useGetSecretVersion } from "@app/hooks/api";
import { SecretV3RawSanitized, UserWsKeyPair, WsTag } from "@app/hooks/api/types";
import { SecretV3RawSanitized, WsTag } from "@app/hooks/api/types";
import { CreateReminderForm } from "./CreateReminderForm";
import { formSchema, SecretActionType, TFormSchema } from "./SecretListView.utils";
@@ -49,7 +49,6 @@ type Props = {
onToggle: (isOpen: boolean) => void;
onClose: () => void;
secret: SecretV3RawSanitized;
decryptFileKey: UserWsKeyPair;
onDeleteSecret: () => void;
onSaveSecret: (
orgSec: SecretV3RawSanitized,
@@ -64,7 +63,6 @@ type Props = {
export const SecretDetailSidebar = ({
isOpen,
onToggle,
decryptFileKey,
secret,
onDeleteSecret,
onSaveSecret,
@@ -114,8 +112,7 @@ export const SecretDetailSidebar = ({
const { data: secretVersion } = useGetSecretVersion({
limit: 10,
offset: 0,
secretId: secret?.id,
decryptFileKey
secretId: secret?.id
});
const handleOverrideClick = () => {
@@ -428,7 +425,7 @@ export const SecretDetailSidebar = ({
<div className="dark mt-4 mb-4 flex-grow text-sm text-bunker-300">
<div className="mb-2">Version History</div>
<div className="flex h-48 flex-col space-y-2 overflow-y-auto overflow-x-hidden rounded-md border border-mineshaft-600 bg-bunker-800 p-2 dark:[color-scheme:dark]">
{secretVersion?.map(({ createdAt, value, id }, i) => (
{secretVersion?.map(({ createdAt, secretValue, id }, i) => (
<div key={id} className="flex flex-col space-y-1">
<div className="flex items-center space-x-2">
<div>
@@ -438,7 +435,7 @@ export const SecretDetailSidebar = ({
</div>
<div className="ml-1.5 flex items-center space-x-2 border-l border-bunker-300 pl-4">
<div className="self-start rounded-sm bg-primary-500/30 px-1">Value:</div>
<div className="break-all font-mono">{value}</div>
<div className="break-all font-mono">{secretValue}</div>
</div>
</div>
))}

View File

@@ -10,9 +10,9 @@ import { usePopUp } from "@app/hooks";
import { useCreateSecretV3, useDeleteSecretV3, useUpdateSecretV3 } from "@app/hooks/api";
import { secretApprovalRequestKeys } from "@app/hooks/api/secretApprovalRequest/queries";
import { secretKeys } from "@app/hooks/api/secrets/queries";
import { SecretType,SecretV3RawSanitized } from "@app/hooks/api/secrets/types";
import { SecretType, SecretV3RawSanitized } from "@app/hooks/api/secrets/types";
import { secretSnapshotKeys } from "@app/hooks/api/secretSnapshots/queries";
import { UserWsKeyPair, WsTag } from "@app/hooks/api/types";
import { WsTag } from "@app/hooks/api/types";
import { AddShareSecretModal } from "@app/views/ShareSecretPage/components/AddShareSecretModal";
import { useSelectedSecretActions, useSelectedSecrets } from "../../SecretMainPage.store";
@@ -25,7 +25,6 @@ type Props = {
secrets?: SecretV3RawSanitized[];
environment: string;
workspaceId: string;
decryptFileKey: UserWsKeyPair;
secretPath?: string;
filter: Filter;
sortDir?: SortDir;
@@ -88,7 +87,6 @@ export const SecretListView = ({
secrets = [],
environment,
workspaceId,
decryptFileKey,
secretPath = "/",
filter,
sortDir = SortDir.ASC,
@@ -392,7 +390,6 @@ export const SecretListView = ({
secretPath={secretPath}
isOpen={popUp.secretDetail.isOpen}
onToggle={(isOpen) => handlePopUpToggle("secretDetail", isOpen)}
decryptFileKey={decryptFileKey}
secret={popUp.secretDetail.data as SecretV3RawSanitized}
onDeleteSecret={() => handlePopUpOpen("deleteSecret", popUp.secretDetail.data)}
onClose={() => handlePopUpClose("secretDetail")}

View File

@@ -14,7 +14,7 @@ import { ProjectPermissionCan } from "@app/components/permissions";
import { Button, ContentLoader, Input, Tag, Tooltip } from "@app/components/v2";
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/context";
import { useGetSnapshotSecrets, usePerformSecretRollback } from "@app/hooks/api";
import { SecretV3RawSanitized, TSecretFolder, UserWsKeyPair } from "@app/hooks/api/types";
import { SecretV3RawSanitized, TSecretFolder } from "@app/hooks/api/types";
import { renderIcon, SecretItem, TDiffModes, TDiffView } from "./SecretItem";
@@ -23,7 +23,6 @@ type Props = {
environment: string;
workspaceId: string;
secretPath?: string;
decryptFileKey: UserWsKeyPair;
secrets?: SecretV3RawSanitized[];
folders?: TSecretFolder[];
snapshotCount?: number;
@@ -45,7 +44,6 @@ export const SnapshotView = ({
environment,
workspaceId,
secretPath,
decryptFileKey,
secrets = [],
folders = [],
onGoBack,
@@ -57,8 +55,7 @@ export const SnapshotView = ({
const { data: snapshotData, isLoading: isSnapshotLoading } = useGetSnapshotSecrets({
snapshotId,
env: environment,
decryptFileKey
env: environment
});
const rollingFolder = snapshotData?.folders || [];