Skip to content

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

feat: final ui/ux updates for jwt signing keys (#36889)

Stojan Dimitrovski4eeac16a25b4
diff --git a/apps/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionDetails.tsx b/apps/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionDetails.tsx
index cea81239bac..fdcbd0ed0e4 100644
--- a/apps/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionDetails.tsx
+++ b/apps/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionDetails.tsx
@@ -173,9 +173,18 @@ export const EdgeFunctionDetails = () => {
name="verify_jwt"
render={({ field }) => (
<FormItemLayout
- label="Enforce JWT Verification"
+ label="Verify JWT with legacy secret"
layout="flex-row-reverse"
- description="Require a valid JWT in the authorization header when invoking the function"
+ description={
+ <>
+ Requires that a JWT signed{' '}
+ <em className="text-brand not-italic">only by the legacy JWT secret</em>{' '}
+ is present in the <code>Authorization</code> header. The easy to obtain{' '}
+ <code>anon</code> key can be used to satisfy this requirement.
+ Recommendation: OFF with JWT and additional authorization logic
+ implemented inside your function's code.
+ </>
+ }
>
<FormControl_Shadcn_>
<Switch
diff --git a/apps/studio/components/interfaces/JwtSecrets/algorithm-details.ts b/apps/studio/components/interfaces/JwtSecrets/algorithm-details.ts
index 66b1f589697..60c1db5f286 100644
--- a/apps/studio/components/interfaces/JwtSecrets/algorithm-details.ts
+++ b/apps/studio/components/interfaces/JwtSecrets/algorithm-details.ts
@@ -10,71 +10,62 @@ export interface AlgorithmDetail {
export const algorithmDetails: Record<string, AlgorithmDetail> = {
HS256: {
- label: 'HS256 (Symmetric)',
+ label: 'HS256 (Shared Secret)',
name: 'HMAC with SHA-256',
- description: 'Symmetric algorithm using a shared secret key',
- pros: [
- 'Fast and simple to use',
- 'Requires less computational power',
- 'Suitable for server-to-server communication',
- ],
+ description: 'JWT signatures are produced by a shared secret.',
+ pros: ['Simple to use', 'Verifying and creating JWTs is very fast and not resource intensive'],
cons: [
+ 'Usually not compatible with SOC2 and other security compliance frameworks',
'Requires secure key exchange',
"Not suitable when the verifier shouldn't be able to sign tokens",
'Key needs to be kept secret on both sides',
],
shortDescription: 'HMAC with SHA-256: Fast, simple, requires secure key exchange',
links: [
- { url: 'https://jwt.io/introduction', label: 'JWT.io Introduction' },
{
url: 'https://datatracker.ietf.org/doc/html/rfc7518#section-3.2',
- label: 'RFC 7518 Specification',
+ label: 'RFC 7518 Specification Section 3.2',
},
],
},
RS256: {
label: 'RSA 2048',
name: 'RSA with SHA-256',
- description: 'Asymmetric algorithm using a public/private key pair',
+ description: 'JWT is signed with a private and verified with a public RSA key.',
pros: [
- 'Allows public key to be distributed freely',
- 'Private key can be kept secret on the signing side',
- "Suitable for scenarios where the verifier shouldn't be able to sign tokens",
+ 'Compatible with SOC2 and other security compliance frameworks',
+ 'RSA is widely adopted and easier to work with',
+ 'Public key does not need to be kept secret',
],
cons: [
- 'Slower than HS256',
- 'Requires more computational power',
- 'Keys are larger than ECDSA keys',
+ 'Larger JWT sizes than other choices',
+ 'Slower to create and verify JWT than other choices',
],
- shortDescription: 'RSA with SHA-256: Allows public key distribution, slower',
+ shortDescription: 'RSA with SHA-256: Widely adopted, has public key, slower',
links: [
- { url: 'https://jwt.io/introduction', label: 'JWT.io Introduction' },
{
url: 'https://datatracker.ietf.org/doc/html/rfc7518#section-3.3',
- label: 'RFC 7518 Specification',
+ label: 'RFC 7518 Specification Section 3.3',
},
],
},
ES256: {
label: 'ECC (P-256)',
name: 'ECDSA with SHA-256',
- description: 'Asymmetric algorithm using elliptic curve cryptography',
+ description:
+ 'JWT is signed with a private and verified with a public ECC key using the NIST P-256 curve.',
pros: [
- 'Faster than RSA',
- 'Smaller key and signature sizes compared to RSA',
- 'Provides forward secrecy',
- ],
- cons: [
- 'Less widely supported than RSA',
- 'More complex to implement correctly',
- 'Requires careful implementation to avoid timing attacks',
+ 'Compatible with SOC2 and other security compliance frameworks',
+ 'Faster to create and verify signatures than RSA',
+ 'Ideal tradeoff between JWT size and efficiency',
+ 'Public key does not need to be kept secret',
],
- shortDescription: 'ECDSA with SHA-256: Compact keys, fast, modern alternative to RSA',
+ cons: ['Wide support but some libraries might make it harder to work with than RSA'],
+ shortDescription: 'ECDSA with SHA-256: Faster, more efficient alternative to RSA',
links: [
- { url: 'https://jwt.io/introduction', label: 'JWT.io Introduction' },
{
url: 'https://datatracker.ietf.org/doc/html/rfc7518#section-3.4',
- label: 'RFC 7518 Specification',
+ label: 'RFC 7518 Specification Section 3.4',
},
],
},
diff --git a/apps/studio/components/interfaces/JwtSecrets/algorithm-hover-card.tsx b/apps/studio/components/interfaces/JwtSecrets/algorithm-hover-card.tsx
index 79d9cf31777..e546c0900e3 100644
--- a/apps/studio/components/interfaces/JwtSecrets/algorithm-hover-card.tsx
+++ b/apps/studio/components/interfaces/JwtSecrets/algorithm-hover-card.tsx
@@ -1,7 +1,7 @@
-import { GlobeLock } from 'lucide-react'
+import { LockKeyholeOpen, RectangleEllipsis } from 'lucide-react'
import React from 'react'
-import { InfoPill } from '../../ui/InfoPill'
+import { InfoPill } from 'components/ui/InfoPill'
import { AlgorithmDetail, algorithmDetails } from './algorithm-details'
interface AlgorithmHoverCardProps {
@@ -14,10 +14,37 @@ export const AlgorithmHoverCard: React.FC<AlgorithmHoverCardProps> = ({ algorith
return (
<InfoPill
- label={legacy ? `Legacy JWT Secret ${details.label}` : details.label}
- icon={<GlobeLock className="w-4" strokeWidth={1} />}
+ label={<span className="pt-1 h-6">{legacy ? `Legacy ${details.label}` : details.label}</span>}
+ icon={
+ algorithm === 'HS256' ? (
+ <RectangleEllipsis className="size-4" />
+ ) : (
+ <LockKeyholeOpen className="size-4" />
+ )
+ }
title={details.name}
- description={details.description}
+ description={
+ <div className="flex flex-col gap-2">
+ <p>{details.description}</p>
+ <p>
+ Pros:
+ <ul className="list-disc">
+ {details.pros.map((pro, i) => (
+ <li key={i}>{pro}</li>
+ ))}
+ </ul>
+ </p>
+ <p>
+ Cons:{' '}
+ <ul className="list-disc">
+ {details.cons.map((con, i) => (
+ <li key={i}>{con}</li>
+ ))}
+ </ul>
+ <br />
+ </p>
+ </div>
+ }
links={details.links}
/>
)
diff --git a/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/action-panel.tsx b/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/action-panel.tsx
index cfebd69aa98..b00802a8285 100644
--- a/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/action-panel.tsx
+++ b/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/action-panel.tsx
@@ -15,12 +15,12 @@ export const ActionPanel = forwardRef<HTMLDivElement, ActionPanelProps>(
({ title, description, buttonLabel, onClick, loading, icon, type, ...props }, ref) => {
return (
<Card
- className="bg-surface-100 first:rounded-b-none last:rounded-t-none shadow-none only:rounded-lg"
+ className="first:rounded-b-none last:rounded-t-none shadow-none only:rounded-lg"
ref={ref}
{...props}
>
<CardHeader className="lg:flex-row lg:items-center gap-3 lg:gap-10 py-4 border-0">
- <div className="flex flex-col gap-0 flex-1 grow">
+ <div className="flex flex-col gap-2 flex-1 grow">
<CardTitle className="text-sm">{title}</CardTitle>
<CardDescription className="max-w-xl">{description}</CardDescription>
</div>
diff --git a/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/create-key-dialog.tsx b/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/create-key-dialog.tsx
index 08c7495de9e..639fbec9886 100644
--- a/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/create-key-dialog.tsx
+++ b/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/create-key-dialog.tsx
@@ -165,9 +165,11 @@ export const CreateKeyDialog = ({
<DialogSectionSeparator />
<DialogSection className="space-y-4">
<p className="text-sm text-foreground-light">
- This will create a new JWT signing key in standby mode. The key will be available for your
- application to use, but won't be used for signing new JWTs until you activate it. Once
- you've updated your application to trust this key, you can switch to it for new JWTs.
+ Adds a new JSON Web Token signing key. Once all of your application's components have
+ picked it up you can rotate the current key with it.
+ <br />
+ <br />
+ This action does not invalidate existing tokens, so your users remain signed in.
</p>
</DialogSection>
<DialogSectionSeparator />
@@ -183,14 +185,14 @@ export const CreateKeyDialog = ({
<SelectValue_Shadcn_ placeholder="Select algorithm" />
</SelectTrigger_Shadcn_>
<SelectContent_Shadcn_>
- <SelectItem_Shadcn_ value="HS256">HS256 (Symmetric)</SelectItem_Shadcn_>
- <SelectItem_Shadcn_ value="RS256">RS256 (RSA)</SelectItem_Shadcn_>
<SelectItem_Shadcn_ value="ES256">
<span>ES256 (ECC)</span>
<Badge variant="brand" className="ml-2">
Recommended
</Badge>
</SelectItem_Shadcn_>
+ <SelectItem_Shadcn_ value="RS256">RS256 (RSA)</SelectItem_Shadcn_>
+ <SelectItem_Shadcn_ value="HS256">HS256 (Shared Secret)</SelectItem_Shadcn_>
</SelectContent_Shadcn_>
</Select_Shadcn_>
</div>
diff --git a/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/index.tsx b/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/index.tsx
index e6691f6da4e..026a25cba57 100644
--- a/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/index.tsx
+++ b/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/index.tsx
@@ -13,6 +13,7 @@ import {
import { useMemo, useState } from 'react'
import { useParams } from 'common'
+import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
import { useLegacyAPIKeysStatusQuery } from 'data/api-keys/legacy-api-keys-status-query'
import { useJWTSigningKeyDeleteMutation } from 'data/jwt-signing-keys/jwt-signing-key-delete-mutation'
@@ -64,17 +65,20 @@ import { StartUsingJwtSigningKeysBanner } from '../start-using-keys-banner'
import { ActionPanel } from './action-panel'
import { CreateKeyDialog } from './create-key-dialog'
import { RotateKeyDialog } from './rotate-key-dialog'
+import { KeyDetailsDialog } from './key-details-dialog'
import { SigningKeyRow } from './signing-key-row'
const MotionTableRow = motion(TableRow)
export default function JWTSecretKeysTable() {
const { ref: projectRef } = useParams()
+ const { project, isLoading: isProjectLoading } = useProjectContext()
+
const newJwtSecrets = useFlag('newJwtSecrets')
const [selectedKey, setSelectedKey] = useState<JWTSigningKey | null>(null)
const [shownDialog, setShownDialog] = useState<
- 'legacy' | 'create' | 'rotate' | 'confirm-rotate' | 'key-details' | 'revoke' | 'delete' | null
+ 'legacy' | 'create' | 'rotate' | 'key-details' | 'revoke' | 'delete' | null
>(null)
const resetDialog = () => {
@@ -100,7 +104,8 @@ export default function JWTSecretKeysTable() {
const isLoadingMutation =
updateMutation.isLoading || deleteMutation.isLoading || legacyMutation.isLoading
- const isLoading = isLoadingSigningKeys || isLoadingLegacyKey || isLoadingLegacyAPIKeysStatus
+ const isLoading =
+ isProjectLoading || isLoadingSigningKeys || isLoadingLegacyKey || isLoadingLegacyAPIKeysStatus
const sortedKeys = useMemo(() => {
if (!signingKeys || !Array.isArray(signingKeys.keys)) return []
@@ -141,42 +146,50 @@ export default function JWTSecretKeysTable() {
}
const handlePreviouslyUsedKey = async (keyId: string) => {
- if (!projectRef) {
- return
- }
- try {
- await updateMutation.mutateAsync({ projectRef, keyId, status: 'previously_used' })
- resetDialog()
- } catch (error) {
- console.error('Failed to move key to previously used', error)
- }
+ updateMutation.mutate(
+ { projectRef, keyId, status: 'previously_used' },
+ {
+ onSuccess: () => {
+ resetDialog()
+ },
+ }
+ )
}
- const handleStandbyKey = async (keyId: string) => {
- try {
- await updateMutation.mutateAsync({ projectRef: projectRef!, keyId, status: 'standby' })
- resetDialog()
- } catch (error) {
- console.error('Failed to move key to standby', error)
- }
+ const handleStandbyKey = (keyId: string) => {
+ updateMutation.mutate(
+ { projectRef: projectRef!, keyId, status: 'standby' },
+ {
+ onSuccess: () => {
+ resetDialog()
+ },
+ }
+ )
}
- const handleRevokeKey = async (keyId: string) => {
- try {
- await updateMutation.mutateAsync({ projectRef: projectRef!, keyId, status: 'revoked' })
- resetDialog()
- } catch (error) {
- console.error('Failed to revoke key', error)
- }
+ const handleRevokeKey = (keyId: string) => {
+ updateMutation.mutate(
+ { projectRef: projectRef!, keyId, status: 'revoked' },
+ {
+ onSuccess: () => {
+ resetDialog()
+ },
+ }
+ )
}
- const handleDeleteKey = async (keyId: string) => {
- try {
- await deleteMutation.mutateAsync({ projectRef: projectRef!, keyId })
- resetDialog()
- } catch (error) {
- console.error('Failed to delete key', error)
- }
+ const handleDeleteKey = (keyId: string) => {
+ deleteMutation.mutate(
+ { projectRef: projectRef!, keyId },
+ {
+ onSuccess: () => {
+ resetDialog()
+ },
+ onError: () => {
+ resetDialog()
+ },
+ }
+ )
}
if (isLoading) {
@@ -195,24 +208,24 @@ export default function JWTSecretKeysTable() {
{standbyKey && (
<ActionPanel
title="Rotate Signing Key"
- description="Promote the standby key to in use. All new JWTs will be signed with this key. Make sure the standby key has been received by all of your application's components to avoid downtime."
+ description="Switch the standby key to in use. All new JSON Web Tokens issued by Supabase Auth will be signed with this key."
buttonLabel="Rotate keys"
onClick={() => setShownDialog('rotate')}
loading={isLoadingMutation}
- icon={<RotateCw />}
- type="warning"
+ icon={<RotateCw className="size-4" />}
+ type="primary"
/>
)}
{!standbyKey && (
<ActionPanel
title="Create standby key"
- description="Create a standby key for the next rotation which will be used on next key rotation."
+ description="Set up a new key which you can switch to once it has been picked up by all components of your application."
buttonLabel="Create Standby Key"
onClick={() => setShownDialog('create')}
loading={isLoadingMutation}
type="primary"
- icon={<Timer />}
+ icon={<Timer className="size-4" />}
/>
)}
</>
@@ -254,8 +267,10 @@ export default function JWTSecretKeysTable() {
signingKey={standbyKey}
setSelectedKey={setSelectedKey}
setShownDialog={setShownDialog}
+ handleStandbyKey={handleStandbyKey}
handlePreviouslyUsedKey={handlePreviouslyUsedKey}
legacyKey={legacyKey}
+ standbyKey={standbyKey}
/>
)}
{inUseKey && (
@@ -264,8 +279,10 @@ export default function JWTSecretKeysTable() {
signingKey={inUseKey}
setSelectedKey={setSelectedKey}
setShownDialog={setShownDialog}
+ handleStandbyKey={handleStandbyKey}
handlePreviouslyUsedKey={handlePreviouslyUsedKey}
legacyKey={legacyKey}
+ standbyKey={standbyKey}
/>
)}
</AnimatePresence>
@@ -275,12 +292,13 @@ export default function JWTSecretKeysTable() {
</Card>
</div>
- <div className="flex flex-col space-y-2">
- <div>
+ <div className="flex flex-col gap-4">
+ <div className="flex flex-col gap-2">
<h2 className="text-xl">Previously used keys</h2>
<p className="text-sm text-foreground-lighter">
- These JWT signing keys are still used to <strong>verify</strong> JWTs already
- issued. Revoke them once all JWTs have expired.
+ These JWT signing keys are still used to{' '}
+ <em className="text-brand not-italic">verify tokens</em> that are yet to expire.
+ Revoke once all tokens have expired.
</p>
</div>
<Card className="overflow-hidden">
@@ -306,97 +324,16 @@ export default function JWTSecretKeysTable() {
<TableBody>
<AnimatePresence>
{previouslyUsedKeys.map((key) => (
- <MotionTableRow
+ <SigningKeyRow
key={key.id}
- layout
- initial={{ opacity: 0, height: 0 }}
- animate={{
- opacity: 1,
- height: 'auto',
- transition: { duration: 0.2 },
- }}
- exit={{ opacity: 0, height: 0 }}
- className="border-b border-dashed border-border"
- >
- <TableCell className="w-[150px] pr-0 py-2">
- <div className="flex -space-x-px items-center">
- <Badge
- className={cn(
- statusColors[key.status],
- 'rounded-r-none',
- 'gap-2 w-full h-6',
- 'uppercase font-mono',
- 'border-r-0'
- )}
- >
- <Key size={13} />
- {statusLabels[key.status]}
- </Badge>
- </div>
- </TableCell>
- <TableCell className="font-mono truncate max-w-[100px] pl-0 py-2">
- <div className="">
- <Badge
- className={cn(
- 'bg-opacity-100 bg-200 border-foreground-muted',
- 'rounded-l-none',
- 'gap-2 py-2 h-6'
- )}
- >
- <span className="truncate">{key.id}</span>
- <button
- onClick={() => {
- setSelectedKey(key)
- setShownDialog('key-details')
- }}
- >
- <Eye size={13} strokeWidth={1.5} />
- </button>
- </Badge>
- </div>
- </TableCell>
- <TableCell className="truncate max-w-[100px] py-2">
- <AlgorithmHoverCard
- algorithm={key.algorithm}
- legacy={key.id === legacyKey?.id}
- />
- </TableCell>
- <TableCell className="text-right py-2">
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button type="text" className="px-2" icon={<MoreVertical />} />
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- <DropdownMenuItem
- onSelect={() => {
- setSelectedKey(key)
- setShownDialog('key-details')
- }}
- >
- <Eye className="mr-2 h-4 w-4" />
- View key details
- </DropdownMenuItem>
- <DropdownMenuItem
- disabled={!!standbyKey}
- onSelect={() => handleStandbyKey(key.id)}
- >
- <CircleArrowUp className="mr-2 h-4 w-4" />
- Set as standby key
- </DropdownMenuItem>
- <DropdownMenuItem
- onSelect={() => {
- setSelectedKey(key)
- setShownDialog('revoke')
- }}
- className="text-destructive"
- >
- <ShieldOff className="mr-2 h-4 w-4" />
- Revoke key
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- </TableCell>
- </MotionTableRow>
+ signingKey={key}
+ setSelectedKey={setSelectedKey}
+ setShownDialog={setShownDialog}
+ handleStandbyKey={handleStandbyKey}
+ handlePreviouslyUsedKey={handlePreviouslyUsedKey}
+ legacyKey={legacyKey}
+ standbyKey={standbyKey}
+ />
))}
</AnimatePresence>
</TableBody>
@@ -413,8 +350,8 @@ export default function JWTSecretKeysTable() {
)}
{revokedKeys.length > 0 && (
- <div className="flex flex-col space-y-2">
- <div>
+ <div className="flex flex-col gap-4">
+ <div className="flex flex-col gap-2">
<h2 className="text-xl">Revoked keys</h2>
<p className="text-sm text-foreground-lighter">
These keys are no longer used to verify or sign JWTs.
@@ -442,98 +379,16 @@ export default function JWTSecretKeysTable() {
<TableBody>
<AnimatePresence>
{revokedKeys.map((key) => (
- <MotionTableRow
+ <SigningKeyRow
key={key.id}
- layout
- initial={{ opacity: 0, height: 0 }}
- animate={{
- opacity: 1,
- height: 'auto',
- transition: { duration: 0.2 },
- }}
- exit={{ opacity: 0, height: 0 }}
- className="border-b border-dashed border-border"
- >
- <TableCell className="w-[150px] pr-0 py-2">
- <div className="flex -space-x-px items-center">
- <Badge
- className={cn(
- statusColors[key.status],
- 'rounded-r-none',
- 'gap-2 w-full h-6',
- 'uppercase font-mono',
- 'border-r-0'
- )}
- >
- <Key size={13} />
- {statusLabels[key.status]}
- </Badge>
- </div>
- </TableCell>
- <TableCell className="font-mono truncate max-w-[100px] pl-0 py-2">
- <div className="">
- <Badge
- className={cn(
- 'bg-opacity-100 bg-200 border-foreground-muted',
- 'rounded-l-none',
- 'gap-2 py-2 h-6'
- )}
- >
- <span className="truncate">{key.id}</span>
- <button
- onClick={() => {
- setSelectedKey(key)
- setShownDialog('key-details')
- }}
- >
- <Eye size={13} strokeWidth={1.5} />
- </button>
- </Badge>
- </div>
- </TableCell>
- <TableCell className="truncate max-w-[100px] py-2">
- <AlgorithmHoverCard
- algorithm={key.algorithm}
- legacy={key.id === legacyKey?.id}
- />
- </TableCell>
- <TableCell className="text-right py-2">
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button type="text" className="px-2" icon={<MoreVertical />} />
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- <DropdownMenuItem
- onSelect={() => {
- setSelectedKey(key)
- setShownDialog('key-details')
- }}
- >
- <Eye className="mr-2 h-4 w-4" />
- View key details
- </DropdownMenuItem>
- <DropdownMenuItem
- disabled={!!standbyKey}
- onSelect={() => handleStandbyKey(key.id)}
- >
- <CircleArrowUp className="mr-2 h-4 w-4" />
- Set as standby key
- </DropdownMenuItem>
- <DropdownMenuItem
- disabled={key.id === legacyKey?.id}
- onSelect={() => {
- setSelectedKey(key)
- setShownDialog('delete')
- }}
- className="text-destructive"
- >
- <Trash2 className="mr-2 h-4 w-4" />
- Permanently delete key
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- </TableCell>
- </MotionTableRow>
+ signingKey={key}
+ setSelectedKey={setSelectedKey}
+ setShownDialog={setShownDialog}
+ handleStandbyKey={handleStandbyKey}
+ handlePreviouslyUsedKey={handlePreviouslyUsedKey}
+ legacyKey={legacyKey}
+ standbyKey={standbyKey}
+ />
))}
</AnimatePresence>
</TableBody>
@@ -629,37 +484,17 @@ export default function JWTSecretKeysTable() {
</Dialog>
)}
- <Dialog open={shownDialog === 'key-details'} onOpenChange={resetDialog}>
- <DialogContent className="sm:max-w-lg">
- <DialogHeader>
- <DialogTitle className="text-lg font-medium">Key Details</DialogTitle>
- </DialogHeader>
- <DialogSectionSeparator />
- <DialogSection className="flex flex-col gap-6">
- {selectedKey && (
- <>
- <div className="bg-surface-100/50 border rounded-md">
- <div className="flex items-center gap-2 px-3 py-2 border-b">
- <FileKey strokeWidth={1.5} size={15} className="text-foreground-light" />
- <h4 className="text-xs font-mono">Public Key (PEM format)</h4>
- </div>
- <pre className="bg-surface-100 p-3 text-xs overflow-x-auto whitespace-pre-wrap break-all max-h-40">
- {typeof selectedKey.public_jwk === 'string'
- ? selectedKey.public_jwk
- : JSON.stringify(selectedKey.public_jwk ?? '', null, 2)}
- </pre>
- </div>
- <div>
- <h4 className="text-sm mb-2">JWKS URL</h4>
- <pre className="bg-surface-100 border p-3 rounded-md text-xs overflow-x-auto break-all">
- {`${window.location.origin}/jwt/v1/jwks.json`}
- </pre>
- </div>
- </>
- )}
- </DialogSection>
- </DialogContent>
- </Dialog>
+ {selectedKey && project && (
+ <Dialog open={shownDialog === 'key-details'} onOpenChange={resetDialog}>
+ <DialogContent className="sm:max-w-lg">
+ <KeyDetailsDialog
+ selectedKey={selectedKey}
+ restURL={project.restUrl}
+ onClose={resetDialog}
+ />
+ </DialogContent>
+ </Dialog>
+ )}
{selectedKey &&
selectedKey.status === 'previously_used' &&
diff --git a/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/key-details-dialog.tsx b/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/key-details-dialog.tsx
new file mode 100644
index 00000000000..3a12789a6c9
--- /dev/null
+++ b/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/key-details-dialog.tsx
@@ -0,0 +1,58 @@
+import { useMemo } from 'react'
+import { FileKey } from 'lucide-react'
+import {
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogSection,
+ DialogSectionSeparator,
+ DialogTitle,
+ Input,
+ Textarea,
+ Label_Shadcn_,
+ Button,
+} from 'ui'
+import { JWTSigningKey } from 'data/jwt-signing-keys/jwt-signing-keys-query'
+
+export function KeyDetailsDialog({
+ selectedKey,
+ restURL,
+ onClose,
+}: {
+ selectedKey: JWTSigningKey
+ restURL: string
+ onClose: () => void
+}) {
+ const jwksURL = useMemo(() => new URL('/auth/v1/.well-known/jwks.json', restURL), [restURL])
+ const jwk = useMemo(() => JSON.stringify(selectedKey.public_jwk, null, 2), [selectedKey])
+
+ return (
+ <>
+ <DialogHeader>
+ <DialogTitle>Key Details</DialogTitle>
+ </DialogHeader>
+ <DialogSectionSeparator />
+ <DialogSection className="flex flex-col gap-6">
+ <div className="flex flex-col gap-2">
+ <Label_Shadcn_ htmlFor="key-id">Key ID</Label_Shadcn_>
+ <Input id="key-id" value={selectedKey.id} readOnly />
+ </div>
+ <div className="flex flex-col gap-2">
+ <Label_Shadcn_ htmlFor="discovery-url">Discovery URL</Label_Shadcn_>
+ <Input id="discovery-url" value={jwksURL.href} readOnly />
+ </div>
+ <div className="flex flex-col gap-2">
+ <Label_Shadcn_ htmlFor="jwk" className="flex flex-row gap-2 items-center">
+ <FileKey className="size-4 text-foreground-light" />
+ Public Key (JSON Web Key format)
+ </Label_Shadcn_>
+ <Textarea className="font-mono text-sm" rows={8} value={jwk} readOnly />
+ </div>
+ </DialogSection>
+ <DialogFooter>
+ <Button onClick={() => onClose()}>OK</Button>
+ </DialogFooter>
+ </>
+ )
+}
diff --git a/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/rotate-key-dialog.tsx b/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/rotate-key-dialog.tsx
index 38bedabcb14..ebff98a2202 100644
--- a/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/rotate-key-dialog.tsx
+++ b/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/rotate-key-dialog.tsx
@@ -2,7 +2,7 @@ import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import { useEdgeFunctionsQuery } from 'data/edge-functions/edge-functions-query'
import { useJWTSigningKeyUpdateMutation } from 'data/jwt-signing-keys/jwt-signing-key-update-mutation'
import { JWTSigningKey } from 'data/jwt-signing-keys/jwt-signing-keys-query'
-import { ArrowRight, Info, Key, Timer } from 'lucide-react'
+import { ArrowRight, Info, Key, Timer, ExternalLink } from 'lucide-react'
import { useState } from 'react'
import { toast } from 'sonner'
import {
@@ -10,6 +10,7 @@ import {
Button,
Checkbox_Shadcn_,
cn,
+ DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
@@ -196,10 +197,7 @@ export function RotateKeyDialog({
text: (
<p>
Rotating the signing key only changes what key is used by Supabase Auth to
- issue{' '}
- <strong>
- <em>new tokens</em>
- </strong>
+ issue <em className="text-brand not-italic">new tokens</em>
.<br />
<br />
To prevent users from being prematurely signed out, you have to manually
@@ -224,14 +222,23 @@ export function RotateKeyDialog({
onCheckedChange={(value) => setEdgeFunctionsVerifyJWTUnderstood(!!value)}
/>
<p className="text-sm text-foreground-light">
- The following Edge Functions may stop funtioning as they verify the legacy JWT
- secret:{' '}
+ The following Edge Functions may stop funtioning for signed-in users as they
+ verify the legacy JWT secret:{' '}
{verifyJWTEdgeFunctions
- .map(({ name }) => <code>{name}</code>)
- .reduce<
- React.ReactNode[]
- >((arr, v) => (arr.length > 0 ? [...arr, ', ', v] : [v]), [])}
- .
+ .map(({ name }) => (
+ <a
+ className=""
+ href={`../../functions/${name}/details`}
+ target="_blank"
+ title={name}
+ >
+ <ExternalLink className="size-3 inline-block" /> <code>{name}</code>
+ </a>
+ ))
+ .reduce<React.ReactNode[]>(
+ (arr, v) => (arr.length > 0 ? [...arr, ', ', v] : [v]),
+ []
+ )}
</p>
<ButtonTooltip
type="default"
@@ -242,14 +249,19 @@ export function RotateKeyDialog({
className: 'max-w-[320px] p-4',
text: (
<p>
- Edge Functions can verify only the legacy JWT secret. Since rotation will
- change they key that signs JWTs if your Edge Function is set up to reject
- JWTs not signed by the legacy JWT secret they might stop functioning.
+ Some of your Edge Functions are set up to require a JWT in the{' '}
+ <code>Authorization</code> header signed with the{' '}
+ <em className="text-brand not-italic">legacy JWT secret</em>. Rotation
+ causes{' '}
+ <em className="text-brand not-italic">invocations by signed-in users</em>{' '}
+ to fail with HTTP 401 Unauthorized, as the JWT no longer meets this
+ requirement.
<br />
<br />
- Recommendation: Change all of your Edge Functions to use the{' '}
- <code>--no-verify-jwt</code> option and implement JWT verification logic
- within the function's body.
+ Recommendation: Change all of your Edge Functions to no longer verify JWT
+ and implement the verification logic in the function's code yourself by
+ using the Supabase client library or any other library for working with
+ JWT.
</p>
),
},
diff --git a/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/signing-key-row.tsx b/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/signing-key-row.tsx
index e8395ed57b0..6e6075b0532 100644
--- a/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/signing-key-row.tsx
+++ b/apps/studio/components/interfaces/JwtSecrets/jwt-secret-keys-table/signing-key-row.tsx
@@ -1,5 +1,14 @@
import { motion } from 'framer-motion'
-import { CircleArrowDown, Eye, Key, MoreVertical, ShieldOff, Timer } from 'lucide-react'
+import {
+ CircleArrowDown,
+ CircleArrowUp,
+ Trash2,
+ Eye,
+ Key,
+ MoreVertical,
+ ShieldOff,
+ Timer,
+} from 'lucide-react'
import { components } from 'api-types'
import { JWTSigningKey } from 'data/jwt-signing-keys/jwt-signing-keys-query'
@@ -20,19 +29,11 @@ import { statusColors, statusLabels } from '../jwt.constants'
interface SigningKeyRowProps {
signingKey: components['schemas']['SigningKeyResponse']
setSelectedKey: (key: JWTSigningKey | null) => void
- setShownDialog: (
- dialog:
- | 'legacy'
- | 'create'
- | 'rotate'
- | 'confirm-rotate'
- | 'key-details'
- | 'revoke'
- | 'delete'
- | null
- ) => void
+ setShownDialog: (dialog: 'key-details' | 'revoke' | 'delete' | null) => void
handlePreviouslyUsedKey: (keyId: string) => void
- legacyKey?: components['schemas']['SigningKeyResponse'] | null
+ handleStandbyKey: (keyId: string) => void
+ legacyKey?: JWTSigningKey | null
+ standbyKey?: JWTSigningKey | null
}
const MotionTableRow = motion(TableRow)
@@ -42,7 +43,9 @@ export const SigningKeyRow = ({
setSelectedKey,
setShownDialog,
handlePreviouslyUsedKey,
+ handleStandbyKey,
legacyKey,
+ standbyKey,
}: SigningKeyRowProps) => (
<MotionTableRow
key={signingKey.id}
@@ -69,7 +72,11 @@ export const SigningKeyRow = ({
'border-r-0'
)}
>
- {signingKey.status === 'standby' ? <Timer size={13} /> : <Key size={13} />}
+ {signingKey.status === 'standby' ? (
+ <Timer className="size-4" />
+ ) : (
+ <Key className="size-4" />
+ )}
{statusLabels[signingKey.status]}
</Badge>
</div>
@@ -83,15 +90,7 @@ export const SigningKeyRow = ({
'gap-2 py-2 h-6'
)}
>
- <span className="truncate">{signingKey.id}</span>
- <button
- onClick={() => {
- setSelectedKey(signingKey)
- setShownDialog('key-details')
- }}
- >
- <Eye size={13} strokeWidth={1.5} />
- </button>
+ {signingKey.id}
</Badge>
</div>
</TableCell>
@@ -102,46 +101,84 @@ export const SigningKeyRow = ({
/>
</TableCell>
<TableCell className="text-right py-2">
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button type="text" className="px-2" icon={<MoreVertical />} />
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- <DropdownMenuItem
- onSelect={() => {
- setSelectedKey(signingKey)
- setShownDialog('key-details')
- }}
- >
- <Eye className="mr-2 h-4 w-4" />
- View key details
- </DropdownMenuItem>
- {signingKey.status === 'standby' && (
- <>
+ {(signingKey.status !== 'in_use' || signingKey.algorithm !== 'HS256') && (
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button type="text" className="px-2" icon={<MoreVertical className="size-4" />} />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ {signingKey.algorithm !== 'HS256' && (
<DropdownMenuItem
- onSelect={() => handlePreviouslyUsedKey(signingKey.id)}
- className="text-destructive"
+ onSelect={() => {
+ setSelectedKey(signingKey)
+ setShownDialog('key-details')
+ }}
>
- <CircleArrowDown className="mr-2 h-4 w-4" />
- Move to previously used
+ <Eye className="mr-2 size-4" />
+ View key details
</DropdownMenuItem>
- </>
- )}
- {signingKey.status === 'previously_used' && (
- <DropdownMenuItem
- onSelect={() => {
- setSelectedKey(signingKey)
- setShownDialog('revoke')
- }}
- className="text-destructive"
- >
- <ShieldOff className="mr-2 h-4 w-4" />
- Revoke key
- <span className="text-xs text-foreground-light ml-2">(after 30 days)</span>
- </DropdownMenuItem>
- )}
- </DropdownMenuContent>
- </DropdownMenu>
+ )}
+ {signingKey.status === 'standby' && (
+ <>
+ <DropdownMenuItem
+ onSelect={() => handlePreviouslyUsedKey(signingKey.id)}
+ className="text-destructive"
+ >
+ <CircleArrowDown className="mr-2 size-4" />
+ Move to previously used
+ </DropdownMenuItem>
+ </>
+ )}
+ {signingKey.status === 'previously_used' && (
+ <>
+ <DropdownMenuItem
+ onSelect={() => {
+ handleStandbyKey(signingKey.id)
+ }}
+ disabled={!!standbyKey}
+ >
+ <CircleArrowUp className="mr-2 size-4" />
+ Move to standby key
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ onSelect={() => {
+ setSelectedKey(signingKey)
+ setShownDialog('revoke')
+ }}
+ className="text-destructive"
+ >
+ <ShieldOff className="mr-2 size-4" />
+ Revoke key
+ </DropdownMenuItem>
+ </>
+ )}
+ {signingKey.status === 'revoked' && (
+ <>
+ <DropdownMenuItem
+ onSelect={() => {
+ handleStandbyKey(signingKey.id)
+ }}
+ disabled={!!standbyKey}
+ >
+ <CircleArrowUp className="mr-2 size-4" />
+ Move to standby key
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ onSelect={() => {
+ setSelectedKey(signingKey)
+ setShownDialog('delete')
+ }}
+ className="text-destructive"
+ disabled={legacyKey?.id === signingKey.id}
+ >
+ <Trash2 className="mr-2 size-4" />
+ Delete permanently
+ </DropdownMenuItem>
+ </>
+ )}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ )}
</TableCell>
</MotionTableRow>
)
diff --git a/apps/studio/components/interfaces/JwtSecrets/jwt-settings.tsx b/apps/studio/components/interfaces/JwtSecrets/jwt-settings.tsx
index a4163c21798..8ef4fe5bc16 100644
--- a/apps/studio/components/interfaces/JwtSecrets/jwt-settings.tsx
+++ b/apps/studio/components/interfaces/JwtSecrets/jwt-settings.tsx
@@ -11,17 +11,19 @@ import {
EyeOff,
Hourglass,
Key,
- KeyRound,
+ CloudOff,
Loader2,
PenTool,
Power,
RefreshCw,
- Undo,
+ TriangleAlert,
+ ExternalLink,
+ Lightbulb,
} from 'lucide-react'
import { Dispatch, SetStateAction, useState } from 'react'
import { toast } from 'sonner'
import { number, object } from 'yup'
-
+import Link from 'next/link'
import { useParams } from 'common'
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import { FormActions } from 'components/ui/Forms/FormActions'
@@ -31,6 +33,8 @@ import { useAuthConfigUpdateMutation } from 'data/auth/auth-config-update-mutati
import { useJwtSecretUpdateMutation } from 'data/config/jwt-secret-update-mutation'
import { useJwtSecretUpdatingStatusQuery } from 'data/config/jwt-secret-updating-status-query'
import { useProjectPostgrestConfigQuery } from 'data/config/project-postgrest-config-query'
+import { useLegacyJWTSigningKeyQuery } from 'data/jwt-signing-keys/legacy-jwt-signing-key-query'
+import { useLegacyAPIKeysStatusQuery } from 'data/api-keys/legacy-api-keys-status-query'
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { uuidv4 } from 'lib/helpers'
import {
@@ -51,6 +55,8 @@ import {
} from 'ui'
import { Admonition } from 'ui-patterns/admonition'
import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
+import TextConfirmModal from 'ui-patterns/Dialogs/TextConfirmModal'
+import { useFlag } from 'hooks/ui/useFlag'
import {
JWT_SECRET_UPDATE_ERROR_MESSAGES,
JWT_SECRET_UPDATE_PROGRESS_MESSAGES,
@@ -65,6 +71,8 @@ const schema = object({
const JWTSettings = () => {
const { ref: projectRef } = useParams()
+ const newJwtSecrets = useFlag('newJwtSecrets')
+
const [customToken, setCustomToken] = useState<string>('')
const [showCustomTokenInput, setShowCustomTokenInput] = useState(false)
const [isCreatingKey, setIsCreatingKey] = useState<boolean>(false)
@@ -82,6 +90,11 @@ const JWTSettings = () => {
const { mutateAsync: updateJwt, isLoading: isSubmittingJwtSecretUpdateRequest } =
useJwtSecretUpdateMutation()
+ const { data: legacyKey } = useLegacyJWTSigningKeyQuery({
+ projectRef,
+ })
+ const { data: legacyAPIKeysStatus } = useLegacyAPIKeysStatusQuery({ projectRef })
+
const {
data: authConfig,
error: authConfigError,
@@ -135,9 +148,8 @@ const JWTSettings = () => {
toast(
'Successfully submitted JWT secret update request. Please wait while your project is updated.'
)
- } catch (error) {
- toast.error('Failed to update JWT secret. Please try again.')
- console.error('Failed to update JWT secret:', error)
+ } catch (error: any) {
+ toast.error(`Failed to update JWT secret: ${error.message}`)
}
}
@@ -180,8 +192,47 @@ const JWTSettings = () => {
</div>
) : (
<>
+ {legacyKey && legacyKey.status !== 'revoked' && (
+ <Admonition type="warning">
+ You've successfully migrated your legacy JWT secret to the new JWT Signing
+ Keys feature. Changing the legacy JWT secret now can only be done by
+ rotating to a standby key and finally revoking it. Now used to{' '}
+ <em className="text-brand not-italic">
+ {legacyKey.status === 'in_use' ? 'sign and verify' : 'only verify'}
+ </em>{' '}
+ JSON Web Tokens by Supabase products.{' '}
+ {legacyAPIKeysStatus && legacyAPIKeysStatus.enabled && (
+ <>
+ <em className="text-warning not-italic">
+ This includes the <code>anon</code> and <code>service_role</code> JWT
+ based API keys.
+ </em>{' '}
+ Consider switching to publishable and secret API keys to disable them.
+ </>
+ )}
+ <br />
+ <br />
+ <Button type="default" asChild icon={<ExternalLink className="size-4" />}>
+ <Link href={`/project/${projectRef}/settings/api-keys`}>
+ Go to API keys
+ </Link>
+ </Button>
+ </Admonition>
+ )}
+ {legacyKey && legacyKey.status === 'revoked' && (
+ <Admonition type="note">
+ Your project has revoked the legacy JWT secret. No new JSON Web Tokens are
+ issued nor verified with it by Supabase products.
+ </Admonition>
+ )}
<Input
- label="JWT Secret"
+ label={
+ legacyKey?.status === 'revoked'
+ ? 'Revoked legacy JWT secret'
+ : legacyKey
+ ? 'Legacy JWT secret (still used)'
+ : 'Legacy JWT secret'
+ }
readOnly
copy={canReadJWTSecret && isNotUpdatingJwtSecret}
reveal={canReadJWTSecret && isNotUpdatingJwtSecret}
@@ -197,7 +248,11 @@ const JWTSettings = () => {
}
className="input-mono"
descriptionText={
- 'Used to decode your JWTs. You can also use this to mint your own JWTs.'
+ legacyKey?.status === 'revoked'
+ ? 'No longer used to sign JWTs by Supabase Auth.'
+ : !legacyKey || legacyKey.status === 'in_use'
+ ? 'Used to sign and verify JWTs issued by Supabase Auth.'
+ : 'Used only to verify JWTs.'
}
layout="horizontal"
/>
@@ -213,83 +268,201 @@ const JWTSettings = () => {
disabled={!canUpdateConfig || isLoadingAuthConfig}
/>
- <div className="space-y-3">
- <div className="p-3 px-6 border rounded-md shadow-sm bg-studio">
- {isUpdatingJwtSecret ? (
+ {newJwtSecrets && !legacyKey && (
+ <>
+ {isUpdatingJwtSecret && (
<div className="flex items-center space-x-2">
<Loader2 className="animate-spin" size={14} />
<p className="text-sm">
Updating JWT secret: {jwtSecretUpdateProgressMessage}
</p>
</div>
- ) : (
- <div className="w-full space-y-2">
- <div className="flex items-center justify-between w-full">
- <div className="flex flex-col space-y-1">
- <p className="text-sm">Generate a new JWT secret</p>
- <p className="text-sm opacity-50">
- A random secret will be created, or you can create your own.
- </p>
- </div>
- <div className="flex flex-col items-end">
- {isUpdatingJwtSecret ? (
- <Button loading type="secondary">
- Updating JWT secret...
- </Button>
- ) : !canGenerateNewJWTSecret ? (
- <ButtonTooltip
- disabled
- type="default"
- iconRight={<ChevronDown size={14} />}
- tooltip={{
- content: {
- side: 'bottom',
- text: 'You need additional permissions to generate a new JWT secret',
- },
- }}
- >
- Generate a new secret
- </ButtonTooltip>
- ) : (
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button type="default" iconRight={<ChevronDown size={14} />}>
- <span>Generate a new secret</span>
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end" side="bottom">
- <DropdownMenuItem
- className="space-x-2"
- onClick={() => setIsGeneratingKey(true)}
- >
- <RefreshCw size={16} />
- <p>Generate a random secret</p>
- </DropdownMenuItem>
- <DropdownMenuSeparator />
- <DropdownMenuItem
- className="space-x-2"
- onClick={() => setIsCreatingKey(true)}
- >
- <PenTool size={16} />
- <p>Create my own secret</p>
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- )}
+ )}
+
+ {isJwtSecretUpdateFailed && (
+ <Admonition type="warning" title="Failed to update JWT secret">
+ Please try again. If the failures persist, please contact Supabase
+ support with the following details: <br />
+ Change tracking ID: {data?.changeTrackingId} <br />
+ Error message: {jwtSecretUpdateErrorMessage}
+ </Admonition>
+ )}
+
+ <div className="flex flex-col gap-6 border rounded-md bg p-6">
+ <div className="flex flex-col gap-2">
+ <h4 className="text-sm">How to change your JWT secret?</h4>
+ <p className="text-sm text-foreground-light">
+ Instead of changing the legacy JWT secret use a combination of the JWT
+ Signing Keys and API keys features. Consider these advantages:
+ </p>
+ <ul className="text-sm text-foreground-light list-disc list-inside">
+ <li>Zero-downtime, reversible change.</li>
+ <li>Users remain signed in and bad actors out.</li>
+ <li>
+ Create multiple secret API keys that are immediately revocable and
+ fully covered by audit logs.
+ </li>
+ <li>
+ Private keys and shared secrets are no longer visible by
+ organization members, so they can't leak.
+ </li>
+ <li>
+ Maintain tighter alignment with SOC2 and other security compliance
+ frameworks.
+ </li>
+ <li>
+ Improve app's performance by using public keys to verify JWTs
+ instead of calling <code>getUser()</code>.
+ </li>
+ </ul>
+ </div>
+
+ <div className="flex flex-row gap-4">
+ <Button
+ type="default"
+ icon={<ExternalLink className="size-4" />}
+ asChild
+ >
+ <Link href={`/project/${projectRef}/settings/api-keys/new`}>
+ Go to API Keys
+ </Link>
+ </Button>
+ <Button
+ type="default"
+ icon={<ExternalLink className="size-4" />}
+ asChild
+ >
+ <Link href={`/project/${projectRef}/settings/jwt/signing-keys`}>
+ Go to JWT Signing Keys
+ </Link>
+ </Button>
+
+ <div className="grow" />
+
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <ButtonTooltip
+ disabled={!canGenerateNewJWTSecret}
+ type="default"
+ iconRight={<ChevronDown size={14} />}
+ loading={isUpdatingJwtSecret}
+ tooltip={{
+ content: {
+ side: 'bottom',
+ text: !canGenerateNewJWTSecret
+ ? 'You need additional permissions to generate a new JWT secret'
+ : undefined,
+ },
+ }}
+ >
+ Change legacy JWT secret
+ </ButtonTooltip>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end" side="bottom">
+ <DropdownMenuItem
+ className="space-x-2"
+ onClick={() => setIsGeneratingKey(true)}
+ >
+ <RefreshCw size={16} />
+ <p>Generate a random secret</p>
+ </DropdownMenuItem>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem
+ className="space-x-2"
+ onClick={() => setIsCreatingKey(true)}
+ >
+ <PenTool size={16} />
+ <p>Create my own secret</p>
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
+ </div>
+ </>
+ )}
+
+ {!newJwtSecrets && (
+ <div className="space-y-3">
+ <div className="p-3 px-6 border rounded-md shadow-sm bg-studio">
+ {isUpdatingJwtSecret ? (
+ <div className="flex items-center space-x-2">
+ <Loader2 className="animate-spin" size={14} />
+ <p className="text-sm">
+ Updating JWT secret: {jwtSecretUpdateProgressMessage}
+ </p>
+ </div>
+ ) : (
+ <div className="w-full space-y-2">
+ <div className="flex items-center justify-between w-full">
+ <div className="flex flex-col space-y-1">
+ <p className="text-sm">Generate a new JWT secret</p>
+ <p className="text-sm opacity-50">
+ A random secret will be created, or you can create your own.
+ </p>
+ </div>
+ <div className="flex flex-col items-end">
+ {isUpdatingJwtSecret ? (
+ <Button loading type="secondary">
+ Updating JWT secret...
+ </Button>
+ ) : !canGenerateNewJWTSecret ? (
+ <ButtonTooltip
+ disabled
+ type="default"
+ iconRight={<ChevronDown size={14} />}
+ tooltip={{
+ content: {
+ side: 'bottom',
+ text: 'You need additional permissions to generate a new JWT secret',
+ },
+ }}
+ >
+ Generate a new secret
+ </ButtonTooltip>
+ ) : (
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button
+ type="default"
+ iconRight={<ChevronDown size={14} />}
+ >
+ <span>Generate a new secret</span>
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end" side="bottom">
+ <DropdownMenuItem
+ className="space-x-2"
+ onClick={() => setIsGeneratingKey(true)}
+ >
+ <RefreshCw size={16} />
+ <p>Generate a random secret</p>
+ </DropdownMenuItem>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem
+ className="space-x-2"
+ onClick={() => setIsCreatingKey(true)}
+ >
+ <PenTool size={16} />
+ <p>Create my own secret</p>
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ )}
+ </div>
</div>
</div>
- </div>
- )}
+ )}
+ </div>
+ {isJwtSecretUpdateFailed ? (
+ <Admonition type="warning" title="Failed to update JWT secret">
+ Please try again. If the failures persist, please contact Supabase
+ support with the following details: <br />
+ Change tracking ID: {data?.changeTrackingId} <br />
+ Error message: {jwtSecretUpdateErrorMessage}
+ </Admonition>
+ ) : null}
</div>
- {isJwtSecretUpdateFailed ? (
- <Admonition type="warning" title="Failed to update JWT secret">
- Please try again. If the failures persist, please contact Supabase support
- with the following details: <br />
- Change tracking ID: {data?.changeTrackingId} <br />
- Error message: {jwtSecretUpdateErrorMessage}
- </Admonition>
- ) : null}
- </div>
+ )}
</>
)}
</Panel.Content>
@@ -298,80 +471,118 @@ const JWTSettings = () => {
}}
</Form>
- <ConfirmationModal
- variant={'destructive'}
+ <TextConfirmModal
+ variant="destructive"
size="large"
visible={isRegeneratingKey}
- title="Generate a new JWT secret"
- confirmLabel="Generate new secret"
- confirmLabelLoading="Generating"
- onCancel={() => setIsGeneratingKey(false)}
- onConfirm={() => handleJwtSecretUpdate('ROLL', setIsGeneratingKey)}
+ title="Confirm legacy JWT secret change"
+ confirmString="I understand and wish to proceed"
+ confirmLabel={customToken ? 'Apply custom secret' : 'Generate random secret'}
+ confirmPlaceholder=""
+ loading={isSubmittingJwtSecretUpdateRequest}
+ onCancel={() => {
+ setIsGeneratingKey(false)
+ setCustomToken('')
+ }}
+ onConfirm={() => handleJwtSecretUpdate(customToken || 'ROLL', setIsGeneratingKey)}
>
- <ul className="mt-4 space-y-5 text-sm">
- <li className="flex gap-4">
- <span className="shrink-0 mt-1">
- <KeyRound size={24} className="flex-shrink-0" />
- </span>
- <div>
- <p className="font-bold">This will invalidate all API keys</p>
- <p>
- Generating a new JWT secret will invalidate <u className="text-foreground">all</u>{' '}
- existing keys, including <code className="text-xs text-code">service_role</code>{' '}
- <code className="text-xs text-code !bg-destructive !text-white !border-destructive">
- secret
- </code>{' '}
- and <code className="text-xs text-code">anon</code>{' '}
- <code className="text-xs text-code">public</code>.
+ <ul className="space-y-4 text-sm">
+ <li className="flex gap-2 bg border rounded-md p-4">
+ <Lightbulb size={24} className="flex-shrink-0 text-brand" />
+
+ <div className="flex flex-col gap-2">
+ <p>Use new JWT Signing Keys and API Keys instead</p>
+ <p className="text-foreground-light">
+ Consider using a combination of the JWT Signing Keys and API Keys features to
+ achieve the same effect.{' '}
+ <em className="text-brand not-italic">
+ Some or all of the warnings listed below might not apply when using these features
+ </em>
+ .
+ </p>
+ </div>
+ </li>
+ <li className="flex gap-2 px-4">
+ <CloudOff size={24} className="text-foreground-light flex-shrink-0" />
+
+ <div className="flex flex-col gap-2">
+ <p>Your application will experience significant downtime</p>
+ <p className="text-foreground-light">
+ As new <code>anon</code> and <code>service_role</code> keys will be created and the
+ existing ones permanently destroyed, your application will stop functioning for the
+ duration it takes you to swap them.{' '}
+ <em className="text-warning not-italic">
+ If you have a mobile, desktop, CLI or any offline-capable application the downtime
+ may be more significant and dependent on app store reviews or user-initiated
+ upgrades or downloads!
+ </em>
+ </p>
+ <p className="text-foreground-light">
+ Currently active users will be forcefully signed out (inactive users will keep their
+ sessions).
+ </p>
+ <p className="text-foreground-light">
+ All long-lived Storage pre-signed URLs will be permanently invalidated.
</p>
</div>
</li>
- <li className="flex gap-4">
- <span className="shrink-0 mt-1">
- <Power size={24} className="flex-shrink-0" />
- </span>
- <div>
- <p className="font-bold">Your project will be restarted</p>
- <p>
- This process restarts your project, terminating existing connections. You may see
- API errors for up to 2 minutes while the new secret is deployed.
+ <li className="flex gap-2 px-4">
+ <Power size={24} className="text-foreground-light flex-shrink-0" />
+ <div className="flex flex-col gap-2">
+ <p>Your project and database will be restarted</p>
+ <p className="text-foreground-light">
+ This process restarts your project, terminating existing connections to your
+ database. You may see API or other unusual errors for{' '}
+ <em className="text-warning not-italic">up to 2 minutes</em> while the new secret is
+ deployed.
</p>
</div>
</li>
- <li className="flex gap-4">
- <span className="shrink-0 mt-1">
- <Hourglass size={24} className="flex-shrink-0" />
- </span>
- <div>
- <p className="font-bold">20-minute cooldown</p>
- <p>Keys can only be regenerated every 20 minutes.</p>
+ <li className="flex gap-2 px-4">
+ <Hourglass size={24} className="text-foreground-light flex-shrink-0" />
+ <div className="flex flex-col gap-2">
+ <p>20-minute cooldown period</p>
+ <p className="text-foreground-light">
+ Should you need to revert or repeat this operation, it will take at least 20 minutes
+ before you're able to do so again.
+ </p>
</div>
</li>
- <li className="flex gap-4">
- <span className="shrink-0 mt-1">
- <Undo size={24} className="flex-shrink-0" />
- </span>
- <div>
- <p className="font-bold">This cannot be undone</p>
- <p>
- The old JWT secret will be lost, all API keys invalidated, and open connections
- terminated.
+ <li className="flex gap-2 px-4">
+ <TriangleAlert size={24} className="text-foreground-light flex-shrink-0" />
+ <div className="flex flex-col gap-2">
+ <p>Irreversible change! This cannot be undone!</p>
+ <p className="text-foreground-light">
+ The old JWT secret will be permanently lost (unless you've saved it prior). Even if
+ you use it again the <code>anon</code> and <code>service_role</code> API keys{' '}
+ <em className="text-warning not-italic">will not be restorable</em> to their exact
+ values.
</p>
</div>
</li>
</ul>
- </ConfirmationModal>
+ </TextConfirmModal>
<Modal
- header="Create a custom JWT secret"
+ header="Pick a new JWT secret"
visible={isCreatingKey}
size="medium"
variant="danger"
+ onCancel={() => {
+ setIsCreatingKey(false)
+ setCustomToken('')
+ }}
loading={isSubmittingJwtSecretUpdateRequest}
customFooter={
<div className="space-x-2">
- <Button type="default" onClick={() => setIsCreatingKey(false)}>
+ <Button
+ type="default"
+ onClick={() => {
+ setIsCreatingKey(false)
+ setCustomToken('')
+ }}
+ >
Cancel
</Button>
<Button
@@ -380,28 +591,21 @@ const JWTSettings = () => {
customToken.length < 32 || customToken.includes('@') || customToken.includes('$')
}
loading={isSubmittingJwtSecretUpdateRequest}
- onClick={() => handleJwtSecretUpdate(customToken, setIsCreatingKey)}
+ onClick={() => {
+ setIsGeneratingKey(true)
+ setIsCreatingKey(false)
+ }}
>
- Apply new JWT secret
+ Proceed to final confirmation
</Button>
</div>
}
>
<Modal.Content className="space-y-2">
<p className="text-sm text-foreground-light">
- Create a custom JWT secret. Make sure it is a strong combination of characters that
+ Pick a new custom JWT secret. Make sure it is a strong combination of characters that
cannot be guessed easily.
</p>
- <Alert_Shadcn_ variant="warning">
- <WarningIcon />
- <AlertTitle_Shadcn_>This will invalidate all existing API keys</AlertTitle_Shadcn_>
- <AlertDescription_Shadcn_>
- Generating a new JWT secret will invalidate <u className="text-foreground">all</u> of
- your API keys, including your <code className="text-xs">service_role</code> and{' '}
- <code className="text-xs">anon</code> keys. Your project will also be restarted during
- this process, which will terminate any existing connections.
- </AlertDescription_Shadcn_>
- </Alert_Shadcn_>
<Input
onChange={(e: any) => setCustomToken(e.target.value)}
value={customToken}
diff --git a/apps/studio/components/layouts/JWTKeys/JWTKeysLayout.tsx b/apps/studio/components/layouts/JWTKeys/JWTKeysLayout.tsx
index 9b3825af558..acebf3386e5 100644
--- a/apps/studio/components/layouts/JWTKeys/JWTKeysLayout.tsx
+++ b/apps/studio/components/layouts/JWTKeys/JWTKeysLayout.tsx
@@ -9,12 +9,12 @@ const JWTKeysLayout = ({ children }: PropsWithChildren) => {
const navigationItems = [
{
- label: 'JWT Secret',
+ label: 'Legacy JWT Secret',
href: `/project/${projectRef}/settings/jwt`,
id: 'legacy-jwt-keys',
},
{
- label: 'JWT Signing Keys (Coming Soon)',
+ label: 'JWT Signing Keys',
href: `/project/${projectRef}/settings/jwt/signing-keys`,
id: 'signing-keys',
},
@@ -23,7 +23,7 @@ const JWTKeysLayout = ({ children }: PropsWithChildren) => {
return (
<PageLayout
title="JWT Keys"
- subtitle="Control the keys used to sign JWTs for your project"
+ subtitle="Control the keys used to sign JSON Web Tokens for your project"
navigationItems={navigationItems}
>
<ScaffoldContainer className="flex flex-col py-8 gap-8" bottomPadding>
diff --git a/apps/studio/components/ui/InfoPill.tsx b/apps/studio/components/ui/InfoPill.tsx
index be2b35973bc..a1287d2a693 100644
--- a/apps/studio/components/ui/InfoPill.tsx
+++ b/apps/studio/components/ui/InfoPill.tsx
@@ -13,10 +13,10 @@ interface Link {
}
interface InfoPillProps {
- label: string
+ label: string | React.ReactNode
icon: React.ReactNode
title: string
- description: string
+ description: string | React.ReactNode
links?: Link[]
}
diff --git a/apps/studio/components/ui/ProjectSettings/ToggleLegacyApiKeys.tsx b/apps/studio/components/ui/ProjectSettings/ToggleLegacyApiKeys.tsx
index a24bc09ef89..66463764cf3 100644
--- a/apps/studio/components/ui/ProjectSettings/ToggleLegacyApiKeys.tsx
+++ b/apps/studio/components/ui/ProjectSettings/ToggleLegacyApiKeys.tsx
@@ -6,6 +6,7 @@ import { useParams } from 'common'
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import { useToggleLegacyAPIKeysMutation } from 'data/api-keys/legacy-api-key-toggle-mutation'
import { useLegacyAPIKeysStatusQuery } from 'data/api-keys/legacy-api-keys-status-query'
+import { useLegacyJWTSigningKeyQuery } from 'data/jwt-signing-keys/legacy-jwt-signing-key-query'
import { useAsyncCheckProjectPermissions } from 'hooks/misc/useCheckPermissions'
import TextConfirmModal from 'ui-patterns/Dialogs/TextConfirmModal'
import Panel from '../Panel'
@@ -17,6 +18,8 @@ export const ToggleLegacyApiKeysPanel = () => {
const { data: legacyAPIKeysStatusData, isSuccess: isLegacyAPIKeysStatusSuccess } =
useLegacyAPIKeysStatusQuery({ projectRef })
+ const { data: legacyJWTSecret } = useLegacyJWTSigningKeyQuery({ projectRef })
+
const { can: canUpdateAPIKeys, isSuccess: isPermissionsSuccess } =
useAsyncCheckProjectPermissions(PermissionAction.SECRETS_WRITE, '*')
@@ -31,27 +34,32 @@ export const ToggleLegacyApiKeysPanel = () => {
<Panel>
<Panel.Content>
<div className="flex justify-between">
- <div>
+ <div className="flex flex-col gap-2">
<p className="text-sm">
{isLegacyKeysEnabled ? 'Disable legacy API keys' : 'Re-enabling legacy API keys'}
</p>
<p className="text-foreground-light text-sm">
{isLegacyKeysEnabled
? 'Make sure you are no longer using your legacy API keys before proceeding.'
- : 'Ensure that your RLS policies are in place prior to re-enabling legacy keys.'}
+ : 'We recommend you use the new API keys whenever possible, but re-enabling is an option.'}
</p>
</div>
<div className="flex items-center">
<ButtonTooltip
type="default"
onClick={() => setIsConfirmOpen(true)}
- disabled={!canUpdateAPIKeys}
+ disabled={
+ !canUpdateAPIKeys ||
+ (!isLegacyKeysEnabled && legacyJWTSecret?.status === 'revoked')
+ }
tooltip={{
content: {
side: 'bottom',
text: !canUpdateAPIKeys
? 'You need additional permissions to enable or disable JWT-based API keys'
- : undefined,
+ : !isLegacyKeysEnabled && legacyJWTSecret?.status === 'revoked'
+ ? 'The legacy JWT secret is revoked. Re-enabling is not possible until it is at least moved to previously used.'
+ : undefined,
},
}}
>
@@ -126,7 +134,8 @@ const ToggleApiKeysModal = ({
<span className="prose text-sm">
Disabling <code>anon</code> and <code>service_role</code> keys while they are in
use will cause downtime for your application. Ensure they are no longer in use
- before proceeding.
+ before proceeding. If you have not created a publishable and at least one secret
+ API key, some dashboard functionality may become unavailable.
</span>
),
}
@@ -136,7 +145,7 @@ const ToggleApiKeysModal = ({
<span className="prose text-sm">
Re-enabling <code>anon</code> and <code>service_role</code> keys may be
appropriate in certain cases, but using a publishable and secret key is more
- secure. We recommend against re-enabling legacy API keys
+ secure. We recommend against re-enabling legacy API keys.
</span>
),
}
diff --git a/apps/studio/data/config/jwt-secret-update-mutation.ts b/apps/studio/data/config/jwt-secret-update-mutation.ts
index 0abd8aeca65..672ce8d9ab6 100644
--- a/apps/studio/data/config/jwt-secret-update-mutation.ts
+++ b/apps/studio/data/config/jwt-secret-update-mutation.ts
@@ -52,11 +52,7 @@ export const useJwtSecretUpdateMutation = ({
await onSuccess?.(data, variables, context)
},
async onError(data, variables, context) {
- if (onError === undefined) {
- toast.error(`Failed to submit JWT secret update request: ${data.message}`)
- } else {
- onError(data, variables, context)
- }
+ await onError?.(data, variables, context)
},
...options,
}