Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Secrets management UI flow

Joshen Limfdeb3aca21e9
diff --git a/package-lock.json b/package-lock.json
index fe00dc0278c..b8f3c88e71f 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -48613,7 +48613,7 @@
"next-themes": "0.0.15",
"next-transpile-modules": "9.0.0",
"npm-run-all": "^4.1.5",
- "octokit": "*",
+ "octokit": "^2.0.10",
"openapi-types": "^12.0.2",
"react": "17.0.2",
"react-copy-to-clipboard": "^5.0.2",
diff --git a/packages/ui/src/components/Modal/Modal.tsx b/packages/ui/src/components/Modal/Modal.tsx
index 9cf8a159a47..4c536622e39 100644
--- a/packages/ui/src/components/Modal/Modal.tsx
+++ b/packages/ui/src/components/Modal/Modal.tsx
@@ -115,13 +115,14 @@ const Modal = ({
customFooter
) : (
<Space
+ className="flex w-full space-x-2"
style={{
width: '100%',
justifyContent:
layout === 'vertical' ? 'center' : alignFooter === 'right' ? 'flex-end' : 'flex-start',
}}
>
- <Button type="secondary" onClick={onCancel} disabled={loading}>
+ <Button type="default" onClick={onCancel} disabled={loading}>
{cancelText}
</Button>
<Button onClick={onConfirm} loading={loading} danger={variant === 'danger'}>
diff --git a/packages/ui/src/components/Space/Space.tsx b/packages/ui/src/components/Space/Space.tsx
index c5c75cefa1b..45fc2fb5748 100644
--- a/packages/ui/src/components/Space/Space.tsx
+++ b/packages/ui/src/components/Space/Space.tsx
@@ -2,15 +2,7 @@ import React from 'react'
// @ts-ignore
// import SpaceStyles from './Space.module.css'
-function Space({
- direction,
- size = 2,
- className,
- block,
- style,
- minus,
- children,
-}: any) {
+function Space({ direction, size = 2, className, block, style, minus, children }: any) {
// const classes = []
// classes.push(direction === 'vertical' ? 'sbui-space-col' : 'sbui-space-row')
// classes.push(
@@ -33,6 +25,7 @@ function Space({
return (
<div
// className={classes.join(' ')}
+ className={className}
style={style}
>
{children}
diff --git a/studio/components/interfaces/Settings/General/index.ts b/studio/components/interfaces/Settings/General/index.ts
index 8502444ce42..108fd79d1a7 100644
--- a/studio/components/interfaces/Settings/General/index.ts
+++ b/studio/components/interfaces/Settings/General/index.ts
@@ -1,7 +1,6 @@
import General from './General'
-import Vault from './Vault'
import Infrastructure from './Infrastructure/Infrastructure'
import DeleteProjectPanel from './DeleteProjectPanel/DeleteProjectPanel'
import DeleteProjectButton from './DeleteProjectPanel/DeleteProjectButton'
-export { General, Vault, Infrastructure, DeleteProjectPanel, DeleteProjectButton }
+export { General, Infrastructure, DeleteProjectPanel, DeleteProjectButton }
diff --git a/studio/components/interfaces/Settings/Vault/SecretRow.tsx b/studio/components/interfaces/Settings/Vault/SecretRow.tsx
new file mode 100644
index 00000000000..4dd76d06d38
--- /dev/null
+++ b/studio/components/interfaces/Settings/Vault/SecretRow.tsx
@@ -0,0 +1,69 @@
+import dayjs from 'dayjs'
+import { FC, useState } from 'react'
+import { Button, IconEye, IconEyeOff, IconTrash, Input } from 'ui'
+
+interface Props {
+ secret: any
+ onSelectRemove: (secret: any) => void
+}
+
+const SecretRow: FC<Props> = ({ secret, onSelectRemove }) => {
+ const [revealedValue, setRevealedValue] = useState<string>()
+
+ const revealSecret = async () => {
+ if (revealedValue === undefined) {
+ // Some DB call
+ setRevealedValue(secret.secret)
+ } else {
+ setRevealedValue(undefined)
+ }
+ }
+
+ return (
+ <div className="px-6 py-4 flex items-center space-x-4">
+ <div className="space-y-1 min-w-[37%] max-w-[37%]">
+ <p className="text-sm truncate" title={secret.description}>
+ {secret.description}
+ </p>
+ <p className="text-sm text-scale-1000 font-mono font-bold truncate" title={secret.secret}>
+ {secret.key_id}
+ </p>
+ </div>
+ <div className="flex items-center space-x-2 w-[38%]">
+ <Button
+ type="text"
+ className="px-1.5"
+ icon={
+ revealedValue === undefined ? (
+ <IconEye size={16} strokeWidth={1.5} />
+ ) : (
+ <IconEyeOff size={16} strokeWidth={1.5} />
+ )
+ }
+ onClick={() => revealSecret()}
+ />
+ <div className="flex-grow">
+ {revealedValue === undefined ? (
+ <p className="text-sm font-mono">••••••••••••••••••</p>
+ ) : (
+ // <p className="text-sm font-mono">{revealedValue}</p>
+ <Input copy className="font-mono" value={revealedValue} />
+ )}
+ </div>
+ </div>
+ <div className="flex items-center justify-end w-[25%] space-x-4">
+ <p className="text-sm text-scale-1100">
+ Added on {dayjs(secret.created_at).format('MMM D, YYYY')}.
+ </p>
+ <Button
+ type="default"
+ className="py-2"
+ icon={<IconTrash />}
+ onClick={() => onSelectRemove(secret)}
+ />
+ </div>
+ </div>
+ )
+}
+
+export default SecretRow
diff --git a/studio/components/interfaces/Settings/Vault/SecretsManagement.tsx b/studio/components/interfaces/Settings/Vault/SecretsManagement.tsx
new file mode 100644
index 00000000000..dff9f404152
--- /dev/null
+++ b/studio/components/interfaces/Settings/Vault/SecretsManagement.tsx
@@ -0,0 +1,218 @@
+import { FC, Fragment, useState } from 'react'
+import Divider from 'components/ui/Divider'
+import { IconSearch, Input, Button, Listbox, Modal, Form, IconHelpCircle } from 'ui'
+import SecretRow from './SecretRow'
+import InformationBox from 'components/ui/InformationBox'
+
+interface Props {}
+
+const SecretsManagement: FC<Props> = ({}) => {
+ const [searchValue, setSearchValue] = useState<string>('')
+ const [selectedSort, setSelectedSort] = useState<string>('name')
+ const [showAddSecretModal, setShowAddSecretModal] = useState(false)
+ const [selectedSecretToRemove, setSelectedSecretToRemove] = useState<any>()
+
+ const mockSecrets = [
+ {
+ key_id: '74d97ba2-f9e3-4a64-a032-8427cd6bd686',
+ description: 'NEXT_PUBLIC_CLIENT_ACCESS_KEY',
+ created_at: Number(new Date()),
+ secret: '74d97ba2-f9e3-4a64-a032-8427cd6bd686',
+ },
+ {
+ key_id: '74d97ba2-f9e3-4a64-a032-8427cd6bd686',
+ description: 'SUPABASE_SUPA_SECRET_SERVER_SIDE_KEY',
+ created_at: Number(new Date()),
+ secret: '74d97ba2-f9e3-4a64-a032-8427cd6bd686',
+ },
+ {
+ key_id: '74d97ba2-f9e3-4a64-a032-8427cd6bd686',
+ description: 'This is a bit more of a secret key',
+ created_at: Number(new Date()),
+ secret: '74d97ba2-f9e3-4a64-a032-8427cd6bd686',
+ },
+ ]
+
+ const secrets =
+ searchValue.length > 0
+ ? mockSecrets.filter(
+ (secret) =>
+ secret.key_id.toLowerCase().includes(searchValue.toLowerCase()) ||
+ secret.description.toLowerCase().includes(searchValue.toLowerCase())
+ )
+ : mockSecrets
+
+ const validate = (values: any) => {
+ const errors: any = {}
+
+ if (values.secret.length === 0) errors.secret = 'Please enter your secret value'
+ if (values.keyId.length > 0 && false) errors.keyId = ''
+
+ return errors
+ }
+
+ const onAddNewSecret = async (values: any, { setSubmitting }: any) => {
+ console.log('onAddNewSecret', values)
+ }
+
+ return (
+ <>
+ <div className="space-y-4">
+ <h3 className="text-scale-1200 mb-2 text-xl">Secrets Management</h3>
+ <div className="flex items-center justify-between">
+ <div className="flex items-center space-x-2">
+ <Input
+ className="w-64"
+ size="small"
+ placeholder="Search"
+ value={searchValue}
+ onChange={(event) => setSearchValue(event.target.value)}
+ icon={<IconSearch strokeWidth={2} size={16} />}
+ />
+ <div className="w-32">
+ <Listbox size="small" value={selectedSort} onChange={setSelectedSort}>
+ <Listbox.Option id="name" value="name" label="Sort by name">
+ Name
+ </Listbox.Option>
+ <Listbox.Option id="createdAt" value="createdAt" label="Sort by created at">
+ Created at
+ </Listbox.Option>
+ </Listbox>
+ </div>
+ </div>
+ <Button type="primary" onClick={() => setShowAddSecretModal(true)}>
+ Add new secret
+ </Button>
+ </div>
+
+ {/* Table of secrets */}
+ <div className="border border-scale-500 rounded">
+ {secrets.map((secret, idx) => {
+ return (
+ <Fragment key={secret.key_id}>
+ <SecretRow secret={secret} onSelectRemove={setSelectedSecretToRemove} />
+ {idx !== mockSecrets.length - 1 && <Divider light />}
+ </Fragment>
+ )
+ })}
+ {secrets.length === 0 && (
+ <>
+ {searchValue.length === 0 ? (
+ <div className="px-6 py-6 space-y-1 flex flex-col items-center justify-center">
+ <p className="text-sm text-scale-1200">No secrets added yet</p>
+ <p className="text-sm text-scale-1100">
+ The Vault allows you to store sensitive information like API keys
+ </p>
+ </div>
+ ) : (
+ <div className="px-6 py-4 space-y-1">
+ <p className="text-sm text-scale-1200">No results found</p>
+ <p className="text-sm text-scale-1100">
+ Your search for "{searchValue}" did not return any results
+ </p>
+ </div>
+ )}
+ </>
+ )}
+ </div>
+ </div>
+
+ <Modal
+ closable
+ size="small"
+ alignFooter="right"
+ visible={selectedSecretToRemove !== undefined}
+ onCancel={() => setSelectedSecretToRemove(undefined)}
+ onConfirm={() => setSelectedSecretToRemove(undefined)}
+ header={<h5 className="text-sm text-scale-1200">Confirm to delete secret</h5>}
+ >
+ <div className="py-4">
+ <Modal.Content>
+ <div className="space-y-4">
+ <p className="text-sm">
+ The following secret will be permanently removed and cannot be recovered. Are you
+ sure?
+ </p>
+ <div className="space-y-1">
+ <p className="text-sm">{selectedSecretToRemove?.description}</p>
+ <p className="text-sm text-scale-1100">
+ ID: <span className="font-mono">{selectedSecretToRemove?.key_id}</span>
+ </p>
+ </div>
+ </div>
+ </Modal.Content>
+ </div>
+ </Modal>
+
+ <Modal
+ closable
+ hideFooter
+ visible={showAddSecretModal}
+ onCancel={() => setShowAddSecretModal(false)}
+ header={<h5 className="text-sm text-scale-1200">Add new secret</h5>}
+ >
+ <Form
+ id="add-new-secret-form"
+ initialValues={{ secret: '', description: '', keyId: '' }}
+ validate={validate}
+ onSubmit={onAddNewSecret}
+ >
+ {({ isSubmitting }: any) => {
+ return (
+ <div className="py-4">
+ <Modal.Content>
+ <div className="space-y-4 pb-4">
+ <Input id="secret" label="Secret value" />
+ <Input id="description" label="Description" labelOptional="Optional" />
+ </div>
+ </Modal.Content>
+ <Modal.Separator />
+ <Modal.Content>
+ <div className="py-4 space-y-2">
+ <Input id="keyId" label="Key ID" labelOptional="Optional" />
+ <InformationBox
+ icon={<IconHelpCircle size={18} strokeWidth={2} />}
+ url="asd"
+ urlLabel="Vault documentation"
+ title="What is a Key ID?"
+ description={
+ <div className="space-y-2">
+ <p>
+ Every secret in the Vault is encrypted with a Key ID. The Vault comes
+ with a default value for this Key ID which is sufficient for simple
+ purposes.
+ </p>
+ <p>
+ However, you may also use a custom Key ID for more advanced use cases,
+ such as having different secrets visible to different users
+ </p>
+ </div>
+ }
+ />
+ </div>
+ </Modal.Content>
+ <Modal.Separator />
+ <Modal.Content>
+ <div className="flex items-center justify-end space-x-2">
+ <Button
+ type="default"
+ disabled={isSubmitting}
+ onClick={() => setShowAddSecretModal(false)}
+ >
+ Cancel
+ </Button>
+ <Button htmlType="submit" disabled={isSubmitting} loading={isSubmitting}>
+ Add secret
+ </Button>
+ </div>
+ </Modal.Content>
+ </div>
+ )
+ }}
+ </Form>
+ </Modal>
+ </>
+ )
+}
+
+export default SecretsManagement
diff --git a/studio/components/interfaces/Settings/General/Vault.tsx b/studio/components/interfaces/Settings/Vault/VaultToggle.tsx
similarity index 64%
rename from studio/components/interfaces/Settings/General/Vault.tsx
rename to studio/components/interfaces/Settings/Vault/VaultToggle.tsx
index fec266b5773..5f0c2b3529d 100644
--- a/studio/components/interfaces/Settings/General/Vault.tsx
+++ b/studio/components/interfaces/Settings/Vault/VaultToggle.tsx
@@ -10,11 +10,10 @@ import {
} from 'components/ui/Forms'
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { checkPermissions } from 'hooks'
-import InformationBox from 'components/ui/InformationBox'
interface Props {}
-const Vault: FC<Props> = () => {
+const VaultToggle: FC<Props> = () => {
const formId = 'project-vault-settings'
const canToggleVault = checkPermissions(PermissionAction.TENANT_SQL_ADMIN_WRITE, 'extensions')
@@ -60,34 +59,20 @@ const Vault: FC<Props> = () => {
id="enabled"
size="small"
layout="flex"
- label="Enable Supabase Vault"
+ label="Enable Vault"
descriptionText="Vault provides secret management and data encryption for your project"
disabled={!canToggleVault}
/>
- {hasChanges && (
- <>
- {values.enabled ? (
- <InformationBox
- defaultVisibility
- hideCollapse
- icon={<IconAlertCircle strokeWidth={2} />}
- title="Enabling Vault for your project"
- description={
- <div>
- <p className="text-sm">
- A new schema <code>vault</code> will be created in your database,
- where you will be able to manage your secrets.
- </p>
- </div>
- }
- />
- ) : (
- <Alert withIcon variant="warning" title="Disabling Vault for your project">
- The schema <code>vault</code> will be removed from your database and
- [highlight other side effects]
- </Alert>
- )}
- </>
+ {hasChanges && !values.enabled && (
+ <Alert
+ withIcon
+ variant="warning"
+ title="Warning: Disabling Vault for your project"
+ >
+ All of your current secrets that are stored in the Vault will be removed from
+ and cannot be recovered. If you have tables which are currently using any
+ secrets, you may not be able to decrypt them. This action cannot be undone.
+ </Alert>
)}
</FormSectionContent>
</FormSection>
@@ -99,4 +84,4 @@ const Vault: FC<Props> = () => {
)
}
-export default Vault
+export default VaultToggle
diff --git a/studio/components/interfaces/Settings/Vault/index.ts b/studio/components/interfaces/Settings/Vault/index.ts
new file mode 100644
index 00000000000..065adfdaec3
--- /dev/null
+++ b/studio/components/interfaces/Settings/Vault/index.ts
@@ -0,0 +1,4 @@
+import VaultToggle from './VaultToggle'
+import SecretsManagement from './SecretsManagement'
+
+export { VaultToggle, SecretsManagement }
diff --git a/studio/components/layouts/SettingsLayout/SettingsMenu.utils.ts b/studio/components/layouts/SettingsLayout/SettingsMenu.utils.ts
index 72aace81800..b2220cb126b 100644
--- a/studio/components/layouts/SettingsLayout/SettingsMenu.utils.ts
+++ b/studio/components/layouts/SettingsLayout/SettingsMenu.utils.ts
@@ -58,6 +58,12 @@ export const generateSettingsMenu = (ref: string, project?: ProjectBase): Produc
},
]
: []),
+ {
+ name: 'Vault',
+ key: 'vault',
+ url: isProjectBuilding ? buildingUrl : `/project/${ref}/settings/vault`,
+ items: [],
+ },
],
},
...(IS_PLATFORM
diff --git a/studio/components/ui/InformationBox.tsx b/studio/components/ui/InformationBox.tsx
index d5e824a1e86..3d560569866 100644
--- a/studio/components/ui/InformationBox.tsx
+++ b/studio/components/ui/InformationBox.tsx
@@ -1,5 +1,6 @@
+import Link from 'next/link'
import { FC, ReactNode, useState } from 'react'
-import { IconMaximize2, IconMinimize2 } from 'ui'
+import { Button, IconExternalLink, IconMaximize2, IconMinimize2 } from 'ui'
interface Props {
icon?: ReactNode
@@ -64,13 +65,13 @@ const InformationBox: FC<Props> = ({
<div className="text-scale-1100 text-sm">{description}</div>
{url && (
- <a
- href={url}
- target="_blank"
- className="text-scale-1100 hover:text-scale-1200 text-sm underline transition-colors"
- >
- {urlLabel}
- </a>
+ <Link href={url}>
+ <a target="_blank" className="pt-2">
+ <Button type="default" icon={<IconExternalLink />}>
+ {urlLabel}
+ </Button>
+ </a>
+ </Link>
)}
{button && <div>{button}</div>}
diff --git a/studio/pages/project/[ref]/settings/vault.tsx b/studio/pages/project/[ref]/settings/vault.tsx
new file mode 100644
index 00000000000..05b99784dc3
--- /dev/null
+++ b/studio/pages/project/[ref]/settings/vault.tsx
@@ -0,0 +1,18 @@
+import { observer } from 'mobx-react-lite'
+import { NextPageWithLayout } from 'types'
+import { SettingsLayout } from 'components/layouts'
+import { VaultToggle, SecretsManagement } from 'components/interfaces/Settings/Vault'
+
+const VaultSettings: NextPageWithLayout = () => {
+ return (
+ <div className="1xl:px-28 mx-auto flex flex-col gap-8 px-5 py-6 lg:px-16 xl:px-24 2xl:px-32 ">
+ <VaultToggle />
+
+ {/* Show secrets table if vault extension is enabled */}
+ <SecretsManagement />
+ </div>
+ )
+}
+
+VaultSettings.getLayout = (page) => <SettingsLayout title="Vault">{page}</SettingsLayout>
+export default observer(VaultSettings)