From bc6cca73bbe46a1a4dd2abe94dc0721400b450af Mon Sep 17 00:00:00 2001
From: Bobbie Soedirgo <31685197+soedirgo@users.noreply.github.com>
Date: Tue, 22 Apr 2025 20:49:18 +0800
Subject: [PATCH] fix: remove refs to pgsodium keys from vault & wrappers
(#35168)
---
.../Landing/Integrations.constants.tsx | 10 -
.../Vault/Keys/EncryptionKeySelector.tsx | 98 ------
.../Vault/Keys/EncryptionKeysManagement.tsx | 310 ------------------
.../Vault/Secrets/AddNewSecretModal.tsx | 73 +----
.../Vault/Secrets/DeleteSecretModal.tsx | 2 +-
.../Vault/Secrets/EditSecretModal.tsx | 33 --
.../Integrations/Vault/Secrets/SecretRow.tsx | 16 +-
.../Vault/Secrets/SecretsManagement.tsx | 14 +-
apps/studio/data/fdw/fdw-create-mutation.ts | 2 -
apps/studio/data/fdw/fdw-delete-mutation.ts | 2 -
apps/studio/data/fdw/fdw-update-mutation.ts | 2 -
apps/studio/data/pg-sodium-keys/keys.ts | 3 -
.../pg-sodium-key-create-mutation.ts | 64 ----
.../pg-sodium-key-delete-mutation.ts | 60 ----
.../pg-sodium-keys/pg-sodium-keys-query.ts | 64 ----
.../vault/vault-secret-create-mutation.ts | 3 +-
.../vault/vault-secret-update-mutation.ts | 3 +-
apps/studio/data/vault/vault-secrets-query.ts | 2 +-
apps/studio/types/ui.ts | 1 -
19 files changed, 15 insertions(+), 747 deletions(-)
delete mode 100644 apps/studio/components/interfaces/Integrations/Vault/Keys/EncryptionKeySelector.tsx
delete mode 100644 apps/studio/components/interfaces/Integrations/Vault/Keys/EncryptionKeysManagement.tsx
delete mode 100644 apps/studio/data/pg-sodium-keys/keys.ts
delete mode 100644 apps/studio/data/pg-sodium-keys/pg-sodium-key-create-mutation.ts
delete mode 100644 apps/studio/data/pg-sodium-keys/pg-sodium-key-delete-mutation.ts
delete mode 100644 apps/studio/data/pg-sodium-keys/pg-sodium-keys-query.ts
diff --git a/apps/studio/components/interfaces/Integrations/Landing/Integrations.constants.tsx b/apps/studio/components/interfaces/Integrations/Landing/Integrations.constants.tsx
index a642e87976d..528a6438755 100644
--- a/apps/studio/components/interfaces/Integrations/Landing/Integrations.constants.tsx
+++ b/apps/studio/components/interfaces/Integrations/Landing/Integrations.constants.tsx
@@ -204,16 +204,6 @@ const supabaseIntegrations: IntegrationDefinition[] = [
loading: Loading,
}
)
- case 'keys':
- return dynamic(
- () =>
- import('../Vault/Keys/EncryptionKeysManagement').then(
- (mod) => mod.EncryptionKeysManagement
- ),
- {
- loading: Loading,
- }
- )
case 'secrets':
return dynamic(
() => import('../Vault/Secrets/SecretsManagement').then((mod) => mod.SecretsManagement),
diff --git a/apps/studio/components/interfaces/Integrations/Vault/Keys/EncryptionKeySelector.tsx b/apps/studio/components/interfaces/Integrations/Vault/Keys/EncryptionKeySelector.tsx
deleted file mode 100644
index 071eae7ef06..00000000000
--- a/apps/studio/components/interfaces/Integrations/Vault/Keys/EncryptionKeySelector.tsx
+++ /dev/null
@@ -1,98 +0,0 @@
-import { noop } from 'lodash'
-import { Plus } from 'lucide-react'
-import {
- Input,
- SelectContent_Shadcn_,
- SelectGroup_Shadcn_,
- SelectItem_Shadcn_,
- SelectTrigger_Shadcn_,
- Select_Shadcn_,
-} from 'ui'
-
-import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
-import { usePgSodiumKeysQuery } from 'data/pg-sodium-keys/pg-sodium-keys-query'
-
-interface EncryptionKeySelectorProps {
- nameId?: string
- label?: string
- labelOptional?: string
- selectedKeyId?: any
- error?: string
- onSelectKey: (keyId: string) => void
- onUpdateDescription?: (desc: string) => void
-}
-
-const EncryptionKeySelector = ({
- nameId = 'keyName',
- label = 'Encryption key',
- labelOptional,
- selectedKeyId,
- error,
- onSelectKey = noop,
- onUpdateDescription = noop,
-}: EncryptionKeySelectorProps) => {
- const { project } = useProjectContext()
-
- const { data } = usePgSodiumKeysQuery({
- projectRef: project?.ref,
- connectionString: project?.connectionString,
- })
-
- const keys = data || []
-
- return (
- <>
-
- {label && (
-
-
- {labelOptional && (
- {labelOptional}
- )}
-
- )}
-
-
- {keys.find((key) => key.id === selectedKeyId)?.name || 'Select an encryption key'}
-
-
-
-
-
-
- Create a new Encryption Key
-
-
- {keys.length > 0 && (
- <>
-
- {keys.map((key) => (
-
-
-
{key.name || 'No name provided'}
-
- ID: {key.id}
-
-
-
- ))}
- >
- )}
-
-
-
-
- {selectedKeyId === 'create-new' && (
- onUpdateDescription(event.target.value)}
- descriptionText="Provide a name for your key for easier identification"
- />
- )}
- >
- )
-}
-
-export default EncryptionKeySelector
diff --git a/apps/studio/components/interfaces/Integrations/Vault/Keys/EncryptionKeysManagement.tsx b/apps/studio/components/interfaces/Integrations/Vault/Keys/EncryptionKeysManagement.tsx
deleted file mode 100644
index ef7a070cb40..00000000000
--- a/apps/studio/components/interfaces/Integrations/Vault/Keys/EncryptionKeysManagement.tsx
+++ /dev/null
@@ -1,310 +0,0 @@
-import { PermissionAction } from '@supabase/shared-types/out/constants'
-import dayjs from 'dayjs'
-import { sortBy } from 'lodash'
-import { Fragment, useEffect, useState } from 'react'
-import { toast } from 'sonner'
-
-import { useParams } from 'common'
-import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
-import { ButtonTooltip } from 'components/ui/ButtonTooltip'
-import { DocsButton } from 'components/ui/DocsButton'
-import { usePgSodiumKeyCreateMutation } from 'data/pg-sodium-keys/pg-sodium-key-create-mutation'
-import { usePgSodiumKeyDeleteMutation } from 'data/pg-sodium-keys/pg-sodium-key-delete-mutation'
-import { usePgSodiumKeysQuery } from 'data/pg-sodium-keys/pg-sodium-keys-query'
-import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
-import { Key, Loader, Search, Trash, X } from 'lucide-react'
-import { Button, Form, Input, Listbox, Modal, Separator } from 'ui'
-import { Admonition } from 'ui-patterns'
-
-const DEFAULT_KEY_NAME = 'No description provided'
-
-export const EncryptionKeysManagement = () => {
- const { search } = useParams()
- const { project } = useProjectContext()
-
- const [searchValue, setSearchValue] = useState('')
- const [selectedSort, setSelectedSort] = useState<'name' | 'created'>('created')
- const [showAddKeyModal, setShowAddKeyModal] = useState(false)
- const [selectedKeyToRemove, setSelectedKeyToRemove] = useState()
- const canManageKeys = useCheckPermissions(PermissionAction.TENANT_SQL_ADMIN_WRITE, 'tables')
-
- useEffect(() => {
- if (search !== undefined) setSearchValue(search)
- }, [search])
-
- const { data, isLoading } = usePgSodiumKeysQuery({
- projectRef: project?.ref,
- connectionString: project?.connectionString,
- })
- const { mutate: addKeyMutation, isLoading: isCreating } = usePgSodiumKeyCreateMutation({
- onSuccess: () => {
- toast.success('Successfully added new key')
- setShowAddKeyModal(false)
- },
- })
- const { mutate: deleteKeyMutation, isLoading: isDeleting } = usePgSodiumKeyDeleteMutation({
- onSuccess: () => {
- toast.success(`Successfully deleted encryption key`)
- setSelectedKeyToRemove(undefined)
- },
- })
-
- const allKeys = data || []
- const keys = sortBy(
- searchValue
- ? allKeys.filter(
- (key) =>
- (key?.name ?? '').toLowerCase().includes(searchValue.toLowerCase()) ||
- key.id.toLowerCase().includes(searchValue.toLowerCase())
- )
- : allKeys,
- (k) => {
- if (selectedSort === 'created') {
- return Number(new Date(k.created))
- } else {
- return k[selectedSort]
- }
- }
- )
-
- const addKey = async (values: any, { setSubmitting }: any) => {
- if (!project) return console.error('Project is required')
-
- addKeyMutation({
- projectRef: project.ref,
- connectionString: project.connectionString,
- name: values.name,
- })
- }
-
- const confirmDeleteKey = async () => {
- if (!selectedKeyToRemove) return
- if (!project) return console.error('Project is required')
-
- deleteKeyMutation({
- projectRef: project.ref,
- connectionString: project.connectionString,
- id: selectedKeyToRemove.id,
- })
- }
-
- return (
- <>
-
-
-
-
setSearchValue(event.target.value)}
- icon={
}
- actions={
- searchValue.length > 0
- ? [
-
}
- className="px-1"
- onClick={() => setSearchValue('')}
- />,
- ]
- : []
- }
- />
-
-
-
- Created at
-
-
- Name
-
-
-
-
-
-
- setShowAddKeyModal(true)}
- tooltip={{
- content: {
- side: 'bottom',
- text: !canManageKeys ? 'You need additional permissions to add keys' : undefined,
- },
- }}
- >
- Add new key
-
-
-
-
- {/* Table of keys */}
-
- {isLoading ? (
-
-
-
Loading keys from the Vault
-
- ) : (
- <>
- {keys.map((key, idx) => {
- return (
-
-
-
-
-
- {key.name || DEFAULT_KEY_NAME}
-
-
- ID: {key.id}
-
-
-
-
- Added on {dayjs(key.created).format('MMM D, YYYY')}
-
-
}
- disabled={!canManageKeys}
- onClick={() => setSelectedKeyToRemove(key)}
- tooltip={{
- content: {
- side: 'bottom',
- text: !canManageKeys
- ? 'You need additional permissions to delete keys'
- : undefined,
- },
- }}
- />
-
-
- {idx !== keys.length - 1 && }
-
- )
- })}
- {keys.length === 0 && (
- <>
- {searchValue.length === 0 ? (
-
-
No encryption keys added yet
-
- Encryption keys are created by the pgsodium extension and can be used to
- encrypt your columns and secrets
-
-
- ) : (
-
-
No results found
-
- Your search for "{searchValue}" did not return any results
-
-
- )}
- >
- )}
- >
- )}
-
-
-
- setSelectedKeyToRemove(undefined)}
- onConfirm={confirmDeleteKey}
- loading={isDeleting}
- header="Confirm to delete key"
- >
-
-
-
- The following key will be permanently removed and cannot be recovered.
-
-
-
- {selectedKeyToRemove?.name ?? DEFAULT_KEY_NAME}
-
-
- ID: {selectedKeyToRemove?.id}
-
-
-
-
-
- setShowAddKeyModal(false)}
- header="Add a new key"
- >
-
-
- >
- )
-}
diff --git a/apps/studio/components/interfaces/Integrations/Vault/Secrets/AddNewSecretModal.tsx b/apps/studio/components/interfaces/Integrations/Vault/Secrets/AddNewSecretModal.tsx
index 2337b5b9ffb..0f9996d60da 100644
--- a/apps/studio/components/interfaces/Integrations/Vault/Secrets/AddNewSecretModal.tsx
+++ b/apps/studio/components/interfaces/Integrations/Vault/Secrets/AddNewSecretModal.tsx
@@ -4,12 +4,9 @@ import { toast } from 'sonner'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import InformationBox from 'components/ui/InformationBox'
import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
-import { usePgSodiumKeyCreateMutation } from 'data/pg-sodium-keys/pg-sodium-key-create-mutation'
-import { usePgSodiumKeysQuery } from 'data/pg-sodium-keys/pg-sodium-keys-query'
import { useVaultSecretCreateMutation } from 'data/vault/vault-secret-create-mutation'
import { Eye, EyeOff, HelpCircle } from 'lucide-react'
import { Button, Form, Input, Modal } from 'ui'
-import EncryptionKeySelector from '../Keys/EncryptionKeySelector'
interface AddNewSecretModalProps {
visible: boolean
@@ -18,35 +15,20 @@ interface AddNewSecretModalProps {
const AddNewSecretModal = ({ visible, onClose }: AddNewSecretModalProps) => {
const [showSecretValue, setShowSecretValue] = useState(false)
- const [selectedKeyId, setSelectedKeyId] = useState()
const { project } = useProjectContext()
- const { mutateAsync: addKeyMutation } = usePgSodiumKeyCreateMutation()
const { mutateAsync: addSecret } = useVaultSecretCreateMutation()
- // const { data: keys, isLoading } = usePgSodiumKeysQuery(
- // {
- // projectRef: project?.ref,
- // connectionString: project?.connectionString,
- // },
- // {
- // enabled: visible,
- // }
- // )
-
- // useEffect(() => {
- // if (visible && keys) {
- // setShowSecretValue(false)
- // setSelectedKeyId(keys[0]?.id ?? 'create-new')
- // }
- // }, [visible, keys])
+ useEffect(() => {
+ if (visible) {
+ setShowSecretValue(false)
+ }
+ }, [visible])
const validate = (values: any) => {
const errors: any = {}
if (values.name.length === 0) errors.name = 'Please provide a name for your secret'
if (values.secret.length === 0) errors.secret = 'Please enter your secret value'
- if (selectedKeyId === 'create-new' && values.keyName.length === 0)
- errors.keyName = 'Please provide a name for your new key'
return errors
}
@@ -54,18 +36,9 @@ const AddNewSecretModal = ({ visible, onClose }: AddNewSecretModalProps) => {
if (!project) return console.error('Project is required')
setSubmitting(true)
- let encryptionKeyId = selectedKeyId
try {
setSubmitting(true)
- if (selectedKeyId === 'create-new') {
- const addKeyRes = await addKeyMutation({
- projectRef: project?.ref!,
- connectionString: project?.connectionString,
- name: values.keyName || undefined,
- })
- encryptionKeyId = addKeyRes[0].id
- }
await addSecret({
projectRef: project.ref,
@@ -73,7 +46,6 @@ const AddNewSecretModal = ({ visible, onClose }: AddNewSecretModalProps) => {
name: values.name,
description: values.description,
secret: values.secret,
- key_id: encryptionKeyId,
})
toast.success(`Successfully added new secret ${values.name}`)
onClose()
@@ -86,11 +58,6 @@ const AddNewSecretModal = ({ visible, onClose }: AddNewSecretModalProps) => {
return (
- {/* {isLoading ? (
-
-
-
- ) : ( */}
- {/* )} */}
)
}
diff --git a/apps/studio/components/interfaces/Integrations/Vault/Secrets/DeleteSecretModal.tsx b/apps/studio/components/interfaces/Integrations/Vault/Secrets/DeleteSecretModal.tsx
index 45643cb06ec..c918cc9c8e2 100644
--- a/apps/studio/components/interfaces/Integrations/Vault/Secrets/DeleteSecretModal.tsx
+++ b/apps/studio/components/interfaces/Integrations/Vault/Secrets/DeleteSecretModal.tsx
@@ -50,7 +50,7 @@ const DeleteSecretModal = ({ selectedSecret, onClose }: DeleteSecretModalProps)
{selectedSecret?.description}
- ID: {selectedSecret?.key_id}
+ ID: {selectedSecret?.id}
diff --git a/apps/studio/components/interfaces/Integrations/Vault/Secrets/EditSecretModal.tsx b/apps/studio/components/interfaces/Integrations/Vault/Secrets/EditSecretModal.tsx
index aa3104c5e4b..5c19268657a 100644
--- a/apps/studio/components/interfaces/Integrations/Vault/Secrets/EditSecretModal.tsx
+++ b/apps/studio/components/interfaces/Integrations/Vault/Secrets/EditSecretModal.tsx
@@ -4,12 +4,10 @@ import { toast } from 'sonner'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
-import { usePgSodiumKeyCreateMutation } from 'data/pg-sodium-keys/pg-sodium-key-create-mutation'
import { useVaultSecretDecryptedValueQuery } from 'data/vault/vault-secret-decrypted-value-query'
import { useVaultSecretUpdateMutation } from 'data/vault/vault-secret-update-mutation'
import type { VaultSecret } from 'types'
import { Button, Form, Input, Modal } from 'ui'
-import EncryptionKeySelector from '../Keys/EncryptionKeySelector'
import { EyeOff, Eye } from 'lucide-react'
interface EditSecretModalProps {
@@ -18,11 +16,9 @@ interface EditSecretModalProps {
}
const EditSecretModal = ({ selectedSecret, onClose }: EditSecretModalProps) => {
- const [selectedKeyId, setSelectedKeyId] = useState()
const [showSecretValue, setShowSecretValue] = useState(false)
const { project } = useProjectContext()
- const { mutateAsync: addKeyMutation } = usePgSodiumKeyCreateMutation()
const { mutateAsync: updateSecret } = useVaultSecretUpdateMutation()
let INITIAL_VALUES = {
@@ -34,7 +30,6 @@ const EditSecretModal = ({ selectedSecret, onClose }: EditSecretModalProps) => {
useEffect(() => {
if (selectedSecret !== undefined) {
setShowSecretValue(false)
- setSelectedKeyId(selectedSecret.key_id)
}
}, [selectedSecret])
@@ -53,23 +48,6 @@ const EditSecretModal = ({ selectedSecret, onClose }: EditSecretModalProps) => {
if (values.name !== selectedSecret?.name) payload.name = values.name
if (values.description !== selectedSecret?.description)
payload.description = values.description
- if (selectedKeyId !== selectedSecret?.key_id) {
- let encryptionKeyId = selectedKeyId
- if (encryptionKeyId === 'create-new') {
- const addKeyRes = await addKeyMutation({
- projectRef: project?.ref!,
- connectionString: project?.connectionString,
- name: values.keyName || undefined,
- })
- if (addKeyRes.error) {
- return toast.error(`Failed to create new key: ${addKeyRes.error.message}`)
- } else {
- encryptionKeyId = addKeyRes[0].id
- }
- }
-
- payload.key_id = encryptionKeyId
- }
payload.secret = values.secret
if (!isEmpty(payload) && selectedSecret) {
@@ -161,17 +139,6 @@ const EditSecretModal = ({ selectedSecret, onClose }: EditSecretModalProps) => {
}
/>
- {/*
-
-
-
- */}