diff --git a/apps/design-system/content/docs/components/combobox.mdx b/apps/design-system/content/docs/components/combobox.mdx index 3ad33b0124e8a..5b00f003667dc 100644 --- a/apps/design-system/content/docs/components/combobox.mdx +++ b/apps/design-system/content/docs/components/combobox.mdx @@ -132,3 +132,9 @@ You can create a responsive combobox by using the `` on desktop and t ### Form + +### Create from list + +When users can create an option while choosing one, give the action a clear verb label and place it at the bottom of the list, separated from the existing options. Keep the current selection in place while they create the new option. + + diff --git a/apps/design-system/registry/default/example/combobox-create-option.tsx b/apps/design-system/registry/default/example/combobox-create-option.tsx new file mode 100644 index 0000000000000..01fa6b5adc7a3 --- /dev/null +++ b/apps/design-system/registry/default/example/combobox-create-option.tsx @@ -0,0 +1,71 @@ +'use client' + +import { Check, Plus } from 'lucide-react' +import { useState } from 'react' +import { + ComboboxTrigger, + Command, + CommandGroup, + CommandItem, + CommandList, + CommandSeparator, + Popover, + PopoverContent, + PopoverTrigger, +} from 'ui' + +const buckets = ['Images', 'Exports'] + +export default function ComboboxCreateOption() { + const [selectedBucket, setSelectedBucket] = useState('') + const [isListOpen, setIsListOpen] = useState(false) + + return ( + + + + {selectedBucket || 'Select a bucket'} + + + + + + + {buckets.map((bucket) => ( + { + setSelectedBucket(bucket) + setIsListOpen(false) + }} + > + {bucket} + {selectedBucket === bucket && } + + ))} + + + + { + setIsListOpen(false) + // Open the creation flow here without changing the selected bucket. + }} + > + + New bucket + + + + + + + ) +} diff --git a/apps/design-system/registry/examples.ts b/apps/design-system/registry/examples.ts index 256eaa8f60fbf..0a47eeaa6c8e9 100644 --- a/apps/design-system/registry/examples.ts +++ b/apps/design-system/registry/examples.ts @@ -385,6 +385,12 @@ export const examples: Registry = [ registryDependencies: ['command'], files: ['example/combobox-demo.tsx'], }, + { + name: 'combobox-create-option', + type: 'components:example', + registryDependencies: ['command'], + files: ['example/combobox-create-option.tsx'], + }, { name: 'combobox-dropdown-menu', type: 'components:example', diff --git a/apps/docs/content/guides/self-hosting/docker.mdx b/apps/docs/content/guides/self-hosting/docker.mdx index d1ec5d98bd1b8..ca11c567ab906 100644 --- a/apps/docs/content/guides/self-hosting/docker.mdx +++ b/apps/docs/content/guides/self-hosting/docker.mdx @@ -326,10 +326,11 @@ To change the database password, read [Changing database password](#changing-dat ## Accessing Edge Functions -Edge Functions live in `volumes/functions`. The default setup includes a `hello` function you can invoke with `curl`: +Edge Functions live in `volumes/functions`. The default setup includes a `hello` function you can invoke with `curl`. It requires your publishable or secret key in the `apikey` header: ```sh -curl http://:8000/functions/v1/hello +curl http://:8000/functions/v1/hello \ + --header 'apikey: ' ``` Add new functions at `volumes/functions//index.ts`, then restart the service to pick them up: diff --git a/apps/docs/content/guides/self-hosting/self-hosted-envoy.mdx b/apps/docs/content/guides/self-hosting/self-hosted-envoy.mdx index 1772afdde013c..60a0d76065cef 100644 --- a/apps/docs/content/guides/self-hosting/self-hosted-envoy.mdx +++ b/apps/docs/content/guides/self-hosting/self-hosted-envoy.mdx @@ -113,7 +113,7 @@ Routes are matched in the order declared. The first matching prefix wins. Protec | `/.well-known/oauth-authorization-server` | auth | - | Open | OAuth 2.0 Authorization Server Metadata (RFC 8414) | | `/auth/v1/sso/saml/acs` | auth | `/sso/saml/acs` | Open | SAML assertion consumer | | `/auth/v1/sso/saml/metadata` | auth | `/sso/saml/metadata` | Open | SAML metadata | -| `/functions/v1/` | functions | `/` | Bypass | Edge Functions runtime performs its own JWT verification; 150s timeout | +| `/functions/v1/` | functions | `/` | `sb_` keys | Rejects invalid and conflicting `sb_` keys; others pass; timeout: 150s | | `/storage/v1/` | storage | `/` | Bypass | Storage performs its own authorization | | `/auth/v1/` | auth | `/` | API key | Protected Auth endpoints | | `/rest/v1/` | rest | `/` | API key | PostgREST Open API root (requires secret key) | @@ -154,7 +154,7 @@ A Lua filter rejects missing or invalid keys with HTTP `401 Unauthorized`. An RB ### Opaque key translation -When the new API keys (`sb_publishable_*`, `sb_secret_*`) are configured, a chain of Lua filters translates opaque keys into the corresponding pre-signed internal JWTs before the request reaches API key enforcement and upstream services. **The entire chain is skipped on `/functions/v1/`**: the Edge Runtime receives the original `apikey` and `Authorization` headers unchanged. +When the new API keys (`sb_publishable_*`, `sb_secret_*`) are configured, a chain of Lua filters translates opaque keys into the corresponding pre-signed internal JWTs before the request reaches API key enforcement and upstream services. **The chain is skipped on `/functions/v1/`**, which has its own filter. See [Edge Functions](#edge-functions). The chain operates in this order: @@ -166,6 +166,23 @@ The chain operates in this order: For background on opaque vs asymmetric keys, see [New API Keys and Asymmetric Authentication](/docs/guides/self-hosting/self-hosted-auth-keys). +### Edge Functions + +On `/functions/v1/`, a dedicated Lua filter handles API keys without changing the `apikey` or `Authorization` headers. When the new API keys are configured, it works as follows: + +| Request | Result | +| ------------------------------------------------------------------ | -------------------------------------------------------- | +| No `apikey` or `Authorization` | Passed through | +| `apikey` is `sb_publishable_*` or `sb_secret_*` | Passed through with `sb-api-key` set to the internal JWT | +| `Authorization: Bearer sb_...` and no `apikey` | Same as above, using the key from `Authorization` | +| Non-`sb_` value (legacy API key, user session token, any other) | Passed through | +| Unknown `sb_` key | Rejected with `401 Unauthorized` | +| `apikey` and `Authorization: Bearer sb_...` contain different keys | Rejected with `401 Unauthorized` | + +The filter always removes any `sb-api-key` header sent by the client. Without the new API keys configured, all other requests pass through unchanged. The `sb-api-key` value is the raw JWT, without a `Bearer` prefix. The `apikey` query parameter is not read on this route. + +When `FUNCTIONS_VERIFY_JWT` is `true`, the functions service verifies the JWT in `Authorization`. If `Authorization` is missing or contains an `sb_` key, it verifies `sb-api-key` instead. It removes `sb-api-key` before the request reaches your function. Functions can also check API keys themselves, for example with `withSupabase` from `@supabase/server`. See [Self-hosted Edge Functions](/docs/guides/self-hosting/self-hosted-functions). + ## Forwarded headers and CORS ### X-Forwarded headers diff --git a/apps/docs/content/guides/self-hosting/self-hosted-functions.mdx b/apps/docs/content/guides/self-hosting/self-hosted-functions.mdx index 00a2e74f641d3..5ef0d0625b2e7 100644 --- a/apps/docs/content/guides/self-hosting/self-hosted-functions.mdx +++ b/apps/docs/content/guides/self-hosting/self-hosted-functions.mdx @@ -42,7 +42,7 @@ Add the following code to `index.ts`: import { withSupabase } from '@supabase/server' export default { - fetch: withSupabase({ auth: 'none' }, async (req) => { + fetch: withSupabase({ auth: ['publishable', 'secret'] }, async (req) => { const { name } = await req.json() const message = `Hello, ${name}!` @@ -51,7 +51,7 @@ export default { } ``` -The `auth` option controls who can call the function: `'none'` accepts every request, `'user'` requires a valid user JWT, and `'publishable'` / `'secret'` require an API key. See the [Edge Functions auth guide](/docs/guides/functions/auth) for details. +The `auth` option controls who can call the function. This example matches the default `hello` function and requires a publishable or secret API key in the `apikey` header. `'none'` accepts every request, and `'user'` requires a valid user JWT. See the [Edge Functions auth guide](/docs/guides/functions/auth) for details. ### Step 2: Restart the functions service to pick up the new function @@ -63,6 +63,7 @@ sh run.sh restart functions ```sh curl -X POST http:///functions/v1/my-function \ + -H 'apikey: ' \ -H 'Content-Type: application/json' \ -d '{"name": "World"}' ``` @@ -226,7 +227,8 @@ Common causes: syntax errors in your function code, invalid imports, or missing ### 401 "invalid JWT" - Check that `FUNCTIONS_VERIFY_JWT` matches your intent (`true` or `false`) in `.env` -- If verification is enabled, ensure you're passing a valid token: `Authorization: Bearer ` +- If verification is enabled, pass either a valid JWT in `Authorization: Bearer ` (a user session token or a legacy API key), or an `sb_publishable_*` or `sb_secret_*` key in the `apikey` header. The API gateway translates `sb_` keys to an internal JWT, which the functions service then verifies. +- Verifying asymmetric JWTs, including translated `sb_` keys, requires `SUPABASE_JWKS` to be set for the `functions` service in `docker-compose.yml`. See [New API Keys and Asymmetric Authentication](/docs/guides/self-hosting/self-hosted-auth-keys). ### Changes to function code not reflected after editing diff --git a/apps/studio/components/interfaces/Integrations/VercelGithub/IntegrationPanels.test.tsx b/apps/studio/components/interfaces/Integrations/VercelGithub/IntegrationPanels.test.tsx new file mode 100644 index 0000000000000..e81bc75df9632 --- /dev/null +++ b/apps/studio/components/interfaces/Integrations/VercelGithub/IntegrationPanels.test.tsx @@ -0,0 +1,39 @@ +import { describe, expect, it, vi } from 'vitest' + +import { IntegrationConnection } from './IntegrationPanels' +import type { IntegrationProjectConnection } from '@/data/integrations/integrations.types' +import { render } from '@/tests/helpers' + +vi.mock('@/data/projects/project-detail-query', () => ({ + useProjectDetailQuery: () => ({ data: undefined, isPending: false }), +})) + +const connectionWithFramework = (framework: string) => + ({ + id: 'connection-1', + supabase_project_ref: 'project-ref', + foreign_project_id: 'vercel-project-1', + metadata: { id: 'vercel-project-1', name: 'my-app', framework }, + }) as IntegrationProjectConnection + +const frameworkIconSelector = 'img[src*="/img/icons/frameworks/"]' + +describe('IntegrationConnection', () => { + it('renders the fallback badge for a framework without a shipped icon', () => { + const { container } = render( + + ) + + expect(container.querySelector(frameworkIconSelector)).toBeNull() + }) + + it('renders the framework icon for a framework with a shipped icon', () => { + const { container } = render( + + ) + + expect(container.querySelector(frameworkIconSelector)?.getAttribute('src')).toMatch( + /\/img\/icons\/frameworks\/nextjs\.svg$/ + ) + }) +}) diff --git a/apps/studio/components/interfaces/Integrations/VercelGithub/IntegrationPanels.tsx b/apps/studio/components/interfaces/Integrations/VercelGithub/IntegrationPanels.tsx index 25c218a213449..1731a89d5d6c3 100644 --- a/apps/studio/components/interfaces/Integrations/VercelGithub/IntegrationPanels.tsx +++ b/apps/studio/components/interfaces/Integrations/VercelGithub/IntegrationPanels.tsx @@ -13,7 +13,7 @@ import type { } from '@/data/integrations/integrations.types' import { useProjectDetailQuery } from '@/data/projects/project-detail-query' import { BASE_PATH } from '@/lib/constants' -import { getIntegrationConfigurationUrl } from '@/lib/integration-utils' +import { getFrameworkIconUrl, getIntegrationConfigurationUrl } from '@/lib/integration-utils' const ICON_STROKE_WIDTH = 2 const ICON_SIZE = 14 @@ -150,6 +150,7 @@ export const IntegrationConnection = forwardRef { const { data: project } = useProjectDetailQuery({ ref: connection.supabase_project_ref }) + const frameworkIconUrl = getFrameworkIconUrl(connection?.metadata?.framework) return (
  • - {!connection?.metadata?.framework ? ( + {!frameworkIconUrl ? (
    ) : ( - {`icon`} + {`icon`} )} {type === 'GitHub' ? ( { {' '} Edit this server's credentials in{' '} Vault @@ -140,7 +140,7 @@ export const WrapperRow = ({ wrapper, isShared }: WrapperRowProps) => { {encryptedMetadata.map((metadata) => (
    { const getForeignProjectIcon = useCallback( (_project: ForeignProject) => { const project = vercelProjectsById[_project.id] + const frameworkIconUrl = getFrameworkIconUrl(project?.framework) - return !project?.framework ? ( + return !frameworkIconUrl ? ( vercelIcon ) : ( - {`icon`} + {`icon`} ) }, [vercelProjectsById] diff --git a/apps/studio/components/interfaces/Storage/StorageSettings/CreateCredentialModal.tsx b/apps/studio/components/interfaces/Storage/StorageSettings/CreateCredentialModal.tsx index e0a9ff4e8ecf7..90fe0ebb35391 100644 --- a/apps/studio/components/interfaces/Storage/StorageSettings/CreateCredentialModal.tsx +++ b/apps/studio/components/interfaces/Storage/StorageSettings/CreateCredentialModal.tsx @@ -16,6 +16,7 @@ import { DialogTitle, DialogTrigger, Form, + FormControl, FormField, Tooltip, TooltipContent, @@ -51,7 +52,7 @@ export const CreateCredentialModal = ({ visible, onOpenChange }: CreateCredentia const FormSchema = z.object({ description: z.string().min(3, { - message: 'Description must be at least 3 characters long', + message: 'Name must be at least 3 characters long', }), }) const form = useForm>({ @@ -110,6 +111,7 @@ export const CreateCredentialModal = ({ visible, onOpenChange }: CreateCredentia { if (showSuccess) e.preventDefault() }} @@ -117,10 +119,10 @@ export const CreateCredentialModal = ({ visible, onOpenChange }: CreateCredentia {showSuccess ? ( <> - Save your new S3 access keys + Save your new access key - You won't be able to see them again. If you lose these access keys, you'll need to - create a new ones. + Copy the access key ID and secret now. The secret won't be shown again. If you lose + it, create a new access key. @@ -128,7 +130,7 @@ export const CreateCredentialModal = ({ visible, onOpenChange }: CreateCredentia - + @@ -146,10 +148,9 @@ export const CreateCredentialModal = ({ visible, onOpenChange }: CreateCredentia ) : ( <> - Create new S3 access keys + Create new access key - S3 access keys provide full access to all S3 operations across all buckets and - bypass any existing RLS policies. + This access key grants full access to every bucket and bypasses RLS policies. @@ -159,20 +160,22 @@ export const CreateCredentialModal = ({ visible, onOpenChange }: CreateCredentia ( - - + + + + )} /> diff --git a/apps/studio/data/integrations/integrations.types.ts b/apps/studio/data/integrations/integrations.types.ts index 4e2d69fe60c4a..cc3344b1a4614 100644 --- a/apps/studio/data/integrations/integrations.types.ts +++ b/apps/studio/data/integrations/integrations.types.ts @@ -1,50 +1,3 @@ -export type VercelFramework = - | ( - | 'blitzjs' - | 'nextjs' - | 'gatsby' - | 'remix' - | 'astro' - | 'hexo' - | 'eleventy' - | 'docusaurus-2' - | 'docusaurus' - | 'preact' - | 'solidstart' - | 'dojo' - | 'ember' - | 'vue' - | 'scully' - | 'ionic-angular' - | 'angular' - | 'polymer' - | 'svelte' - | 'sveltekit' - | 'sveltekit-1' - | 'ionic-react' - | 'create-react-app' - | 'gridsome' - | 'umijs' - | 'sapper' - | 'saber' - | 'stencil' - | 'nuxtjs' - | 'redwoodjs' - | 'hugo' - | 'jekyll' - | 'brunch' - | 'middleman' - | 'zola' - | 'hydrogen' - | 'vite' - | 'vitepress' - | 'vuepress' - | 'parcel' - | 'sanity' - | 'storybook' - ) - | null - export type VercelGitLink = | { /** @@ -142,7 +95,7 @@ export type Imetadata = { } link?: VercelGitLink name: string - framework: VercelFramework + framework: string | null } export type IntegrationProjectConnection = { diff --git a/apps/studio/lib/integration-utils.test.ts b/apps/studio/lib/integration-utils.test.ts index 070ab28e47184..68767eba83a5f 100644 --- a/apps/studio/lib/integration-utils.test.ts +++ b/apps/studio/lib/integration-utils.test.ts @@ -1,6 +1,10 @@ +import { readdirSync } from 'node:fs' +import { join } from 'node:path' import { describe, expect, it, vi } from 'vitest' import { + FRAMEWORK_ICON_SLUGS, + getFrameworkIconUrl, getInitialMigrationSQLFromGitHubRepo, getIntegrationConfigurationUrl, } from './integration-utils' @@ -10,6 +14,7 @@ import type { VercelAccount, VercelTeamAccount, } from '@/data/integrations/integrations.types' +import { BASE_PATH } from '@/lib/constants' vi.mock('@/data/fetchers', () => ({ fetchHandler: vi.fn(), @@ -255,4 +260,23 @@ describe('integration-utils', () => { expect(result).toBe('') }) }) + + describe('getFrameworkIconUrl', () => { + it('returns undefined for missing or unshipped frameworks and a URL for shipped ones', () => { + expect(getFrameworkIconUrl('not-a-framework')).toBeUndefined() + expect(getFrameworkIconUrl(null)).toBeUndefined() + expect(getFrameworkIconUrl(undefined)).toBeUndefined() + expect(getFrameworkIconUrl('')).toBeUndefined() + expect(getFrameworkIconUrl('nextjs')).toBe(`${BASE_PATH}/img/icons/frameworks/nextjs.svg`) + }) + + it('stays in sync with public/img/icons/frameworks/*.svg', () => { + const slugsOnDisk = readdirSync(join(__dirname, '../public/img/icons/frameworks')) + .filter((file) => file.endsWith('.svg')) + .map((file) => file.replace(/\.svg$/, '')) + .sort() + + expect([...FRAMEWORK_ICON_SLUGS].sort()).toEqual(slugsOnDisk) + }) + }) }) diff --git a/apps/studio/lib/integration-utils.ts b/apps/studio/lib/integration-utils.ts index 3a17c7465807c..80e42858fee58 100644 --- a/apps/studio/lib/integration-utils.ts +++ b/apps/studio/lib/integration-utils.ts @@ -3,6 +3,7 @@ import { getCreateMigrationsTableSQL, getInsertMigrationSQL } from '@supabase/pg import { isResponseOk } from './api/apiWrapper' import { fetchHandler } from '@/data/fetchers' import type { Integration } from '@/data/integrations/integrations.types' +import { BASE_PATH } from '@/lib/constants' import { ResponseError, type SupaResponse } from '@/types' async function fetchGitHub(url: string, responseJson = true): Promise> { @@ -132,3 +133,53 @@ function getGitHubConfigurationUrl(integration: GitHubIntegration) { : '' }settings/installations/${integration.metadata?.installation_id}` } + +export const FRAMEWORK_ICON_SLUGS: ReadonlySet = new Set([ + 'angular', + 'astro', + 'blitzjs', + 'brunch', + 'create-react-app', + 'docusaurus', + 'docusaurus-2', + 'dojo', + 'eleventy', + 'ember', + 'gatsby', + 'gridsome', + 'hexo', + 'hugo', + 'hydrogen', + 'ionic-angular', + 'ionic-react', + 'jekyll', + 'middleman', + 'nextjs', + 'nuxtjs', + 'parcel', + 'polymer', + 'preact', + 'redwoodjs', + 'remix', + 'saber', + 'sanity', + 'sapper', + 'scully', + 'solidstart', + 'stencil', + 'storybook', + 'svelte', + 'sveltekit', + 'sveltekit-1', + 'umijs', + 'vite', + 'vitepress', + 'vue', + 'vuepress', + 'zola', +]) + +export function getFrameworkIconUrl(framework?: string | null): string | undefined { + if (!framework || !FRAMEWORK_ICON_SLUGS.has(framework)) return undefined + return `${BASE_PATH}/img/icons/frameworks/${framework}.svg` +} diff --git a/apps/studio/pages/integrations/vercel/[slug]/marketplace/choose-project.tsx b/apps/studio/pages/integrations/vercel/[slug]/marketplace/choose-project.tsx index ccd04468424b6..08c9592f422df 100644 --- a/apps/studio/pages/integrations/vercel/[slug]/marketplace/choose-project.tsx +++ b/apps/studio/pages/integrations/vercel/[slug]/marketplace/choose-project.tsx @@ -25,8 +25,8 @@ import { useIntegrationVercelConnectionsCreateMutation } from '@/data/integratio import { useVercelProjectsQuery } from '@/data/integrations/integrations-vercel-projects-query' import { useOrganizationsQuery } from '@/data/organizations/organizations-query' import { withAuth } from '@/hooks/misc/withAuth' -import { BASE_PATH } from '@/lib/constants' import { getErrorMessage } from '@/lib/get-error-message' +import { getFrameworkIconUrl } from '@/lib/integration-utils' import { hasVercelDeployButtonSignals } from '@/lib/integrations/vercel-install.utils' import { buildStudioPageTitle } from '@/lib/page-title' import { useProfileNameAndPicture } from '@/lib/profile' @@ -83,16 +83,12 @@ const VercelChooseProjectPage: NextPageWithLayout = () => { const getForeignProjectIcon = useCallback( (_project: ForeignProject) => { const project = vercelProjectsById[_project.id] + const frameworkIconUrl = getFrameworkIconUrl(project?.framework) - return !project?.framework ? ( + return !frameworkIconUrl ? ( vercelIcon ) : ( - Framework icon + Framework icon ) }, [vercelProjectsById] diff --git a/apps/ui-library/components/block-overview.tsx b/apps/ui-library/components/block-overview.tsx index 8c6cdba052b63..e966503672604 100644 --- a/apps/ui-library/components/block-overview.tsx +++ b/apps/ui-library/components/block-overview.tsx @@ -4,8 +4,6 @@ import type { ReactNode } from 'react' import { BlockItemCode } from './block-item-code' import { BlockOverviewTabs } from './block-overview-tabs' import { generateRegistryTree } from '@/lib/process-registry' -import { resolveRegistryItem } from '@/lib/registry-resolution' -import { registry } from '@/registry' export function BlockOverview({ name, @@ -16,40 +14,14 @@ export function BlockOverview({ children?: ReactNode showFiles?: boolean }) { - const resolved = registry.items.some((item) => item.name === name) - ? resolveRegistryItem((itemName) => registry.items.find((item) => item.name === itemName), name) - : undefined - return ( - {resolved && ( - // px-6 lines this up with the tab labels, which the list and trigger each inset by 12px. -

    - Supabase files - {resolved.firstPartyDependencies.length > 0 - ? ', including registry dependencies' - : ''} - . - {resolved.externalRegistryDependencies.length > 0 && ( - <> - {' '} - External UI dependencies: {resolved.externalRegistryDependencies.join(', ')}. - - )} -

    - )} -
    - -
    -
    + ) : undefined } > diff --git a/apps/www/_blog/2022-08-19-supabase-vault.mdx b/apps/www/_blog/2022-08-19-supabase-vault.mdx index 601b6c8c87ba3..947200a0562a0 100644 --- a/apps/www/_blog/2022-08-19-supabase-vault.mdx +++ b/apps/www/_blog/2022-08-19-supabase-vault.mdx @@ -19,7 +19,7 @@ Vault is a thin usability-layer on top of [pgsodium](https://github.com/michelp/ ❇️ UPDATE JUNE 2023 ❇️ -Vault is now available on every Supabase project. [Check it out](https://supabase.com/dashboard/project/_/settings/vault/secrets) +Vault is now available on every Supabase project. [Check it out](https://supabase.com/dashboard/project/_/integrations/vault/secrets)
    diff --git a/apps/www/_blog/2022-12-16-vault-now-in-beta.mdx b/apps/www/_blog/2022-12-16-vault-now-in-beta.mdx index ff06d533c94f9..9cf62ee3a8601 100644 --- a/apps/www/_blog/2022-12-16-vault-now-in-beta.mdx +++ b/apps/www/_blog/2022-12-16-vault-now-in-beta.mdx @@ -24,7 +24,7 @@ Vault is a new Postgres extension and accompanying Supabase UI that makes it saf ❇️ UPDATE JUNE 2023 ❇️ -Supabase Vault is now available on every Supabase project. [Check it out](https://supabase.com/dashboard/project/_/settings/vault/secrets) +Supabase Vault is now available on every Supabase project. [Check it out](https://supabase.com/dashboard/project/_/integrations/vault/secrets) @@ -91,7 +91,7 @@ Privacy is becoming one of the most important features in a modern product. Supa ### Using the Vault -To learn how to use Supabase Vault, check out the [docs](https://supabase.com/docs/guides/database/vault). Supabase Vault is now available on all [Supabase projects](https://supabase.com/dashboard/project/_/settings/vault/secrets) (some projects will have to enable via request). +To learn how to use Supabase Vault, check out the [docs](https://supabase.com/docs/guides/database/vault). Supabase Vault is now available on all [Supabase projects](https://supabase.com/dashboard/project/_/integrations/vault/secrets) (some projects will have to enable via request). ## More Launch Week 6 diff --git a/apps/www/_blog/2024-11-13-supabase-dynamic-functions.mdx b/apps/www/_blog/2024-11-13-supabase-dynamic-functions.mdx index 0bf986fa2bee2..d6e9a55df9a7c 100644 --- a/apps/www/_blog/2024-11-13-supabase-dynamic-functions.mdx +++ b/apps/www/_blog/2024-11-13-supabase-dynamic-functions.mdx @@ -226,7 +226,7 @@ END; $$; ``` -This function can retrieve the `service_role` secret from [Vault](https://supabase.com/dashboard/project/_/settings/vault/secrets), it also ensures that only authorized roles can access sensitive environment variables. +This function can retrieve the `service_role` secret from [Vault](https://supabase.com/dashboard/project/_/integrations/vault/secrets), it also ensures that only authorized roles can access sensitive environment variables. ## Setting Up the Edge Function diff --git a/docker/tests/test-auth-keys.sh b/docker/tests/test-auth-keys.sh index 1f58ae35a6968..e92905adffc90 100644 --- a/docker/tests/test-auth-keys.sh +++ b/docker/tests/test-auth-keys.sh @@ -59,6 +59,35 @@ http_status() { curl -s -o /dev/null -w "%{http_code}" "$@" "$url" } +# Like http_status, but appends " sdk" when the response carries the +# @supabase/server error header, i.e. the gateway passed the request through +# and the function itself rejected it. +fn_status() { + url="$1" + shift + out=$(curl -s -o /dev/null -D - -w '\n%{http_code}' "$@" "$url") + code=$(printf '%s\n' "$out" | tail -n 1) + if printf '%s\n' "$out" | grep -qi '^x-supabase-server-error:'; then + echo "$code sdk" + else + echo "$code" + fi +} + +# Detect which gateway is running so gateway-specific assertions can be gated. +detect_gateway() { + command -v docker >/dev/null 2>&1 || { echo unknown; return; } + running=$(docker ps --format '{{.Names}}' 2>/dev/null) + if printf '%s\n' "$running" | grep -q '^supabase-envoy$'; then + echo envoy + elif printf '%s\n' "$running" | grep -q '^supabase-kong$'; then + echo kong + else + echo unknown + fi +} +GATEWAY=$(detect_gateway) + echo "" echo "=== Testing against $BASE_URL ===" echo "" @@ -162,6 +191,44 @@ check "/api/tenants blocked -> 403" "403" \ check "/api/openapi blocked -> 403" "403" \ "$(http_status "$BASE_URL/realtime/v1/api/openapi" -H "apikey: $ANON_KEY")" +echo "" +echo "--- Edge Functions (/functions/v1/) ---" + +# hello uses withSupabase({ auth: ["publishable", "secret"] }), which requires +# an sb_ key in the apikey header. "401 sdk" means the gateway passed the +# request through and the function rejected it; a bare "401" is the gateway. +check "No auth -> passed to function, rejected by SDK" "401 sdk" \ + "$(fn_status "$BASE_URL/functions/v1/hello" -X POST -d '{}')" + +# Non-sb_ values (legacy JWT, typo, third-party JWT) are not validated at the gateway. +check "Legacy ANON_KEY -> passed to function, rejected by SDK" "401 sdk" \ + "$(fn_status "$BASE_URL/functions/v1/hello" -X POST -H "apikey: $ANON_KEY" -d '{}')" +check "Non-sb_ invalid apikey -> passed to function, rejected by SDK" "401 sdk" \ + "$(fn_status "$BASE_URL/functions/v1/hello" -X POST -H "apikey: invalid-key" -d '{}')" + +if [ -n "$SUPABASE_PUBLISHABLE_KEY" ]; then + check "PUBLISHABLE_KEY -> hello reachable" "200" \ + "$(fn_status "$BASE_URL/functions/v1/hello" -X POST -H "apikey: $SUPABASE_PUBLISHABLE_KEY" -d '{}')" + check "SECRET_KEY -> hello reachable" "200" \ + "$(fn_status "$BASE_URL/functions/v1/hello" -X POST -H "apikey: $SUPABASE_SECRET_KEY" -d '{}')" + # sb_ in Authorization only: the gateway translates it and passes it through, + # but the SDK only accepts sb_ keys in the apikey header. + check "sb_ in Authorization only -> passed to function, rejected by SDK" "401 sdk" \ + "$(fn_status "$BASE_URL/functions/v1/hello" -X POST -H "Authorization: Bearer $SUPABASE_PUBLISHABLE_KEY" -d '{}')" + + # Invalid sb_-prefixed key and apikey/bearer sb_ conflict are rejected at the + # gateway - but only by Envoy. Kong is permissive and passes them through. + if [ "$GATEWAY" = "envoy" ]; then + check "Invalid sb_ apikey -> 401 at gateway (Envoy)" "401" \ + "$(fn_status "$BASE_URL/functions/v1/hello" -X POST -H "apikey: sb_publishable_0000000000000000000000_00000000" -d '{}')" + check "Conflicting sb_ keys -> 401 at gateway (Envoy)" "401" \ + "$(fn_status "$BASE_URL/functions/v1/hello" -X POST -H "apikey: $SUPABASE_SECRET_KEY" -H "Authorization: Bearer $SUPABASE_PUBLISHABLE_KEY" -d '{}')" + else + check "Invalid sb_ apikey -> passed to function, rejected by SDK (Kong)" "401 sdk" \ + "$(fn_status "$BASE_URL/functions/v1/hello" -X POST -H "apikey: sb_publishable_0000000000000000000000_00000000" -d '{}')" + fi +fi + echo "" echo "--- supabase-js style requests (apikey + Authorization) ---" # supabase-js sends both apikey header AND Authorization: Bearer @@ -319,6 +386,13 @@ if [ -n "$access_token" ]; then "$(http_status "$BASE_URL/auth/v1/user" \ -H "apikey: $SUPABASE_PUBLISHABLE_KEY" \ -H "Authorization: Bearer $access_token")" + # Functions leaves Authorization (the user JWT) untouched and adds the + # translated sb-api-key alongside it; the request must reach the worker. + check "Opaque apikey + user JWT -> Functions reachable" "200" \ + "$(http_status "$BASE_URL/functions/v1/hello" -X POST \ + -H "apikey: $SUPABASE_PUBLISHABLE_KEY" \ + -H "Authorization: Bearer $access_token" \ + -d '{}')" fi else check "Sign in test user" "true" "false" diff --git a/docker/tests/test-self-hosted.sh b/docker/tests/test-self-hosted.sh index d842cc9dcfc11..775a853cdf4ab 100644 --- a/docker/tests/test-self-hosted.sh +++ b/docker/tests/test-self-hosted.sh @@ -457,6 +457,16 @@ fn_resp=$(http_body "$BASE_URL/functions/v1/hello" \ -d '{}') check "Call hello function" '{"message":"Hello from Edge Functions!"}' "$fn_resp" +# A non-sb_ value (typo / legacy / third-party JWT) is not rejected at the +# gateway - it passes to the function, where the Supabase Server SDK rejects it. +# (Detailed sb_-key translation/rejection is covered in test-auth-keys.sh.) +check "Functions reject non-sb_ apikey (Server SDK)" "401" \ + "$(http_status "$BASE_URL/functions/v1/hello" \ + -X POST \ + -H "apikey: invalid-key" \ + -H "Content-Type: application/json" \ + -d '{}')" + # --------------------------------------------- # 8. pg-meta (Studio backend) # --------------------------------------------- diff --git a/docker/volumes/api/envoy/lds.template.yaml b/docker/volumes/api/envoy/lds.template.yaml index 1a3c345188617..b13b7891bd680 100644 --- a/docker/volumes/api/envoy/lds.template.yaml +++ b/docker/volumes/api/envoy/lds.template.yaml @@ -1040,6 +1040,107 @@ resources: end end + # Functions: mirror the platform behavior. Translate opaque sb_ + # keys to the pre-signed internal asymmetric JWT and inject it as a + # raw `sb-api-key` header (no Bearer prefix), leaving Authorization + # untouched. The apikey is read from the header only (+ an + # Authorization `Bearer sb_` fallback) - no query-string source. + # Strips any client-supplied sb-api-key (anti-spoof). Returns 401 only + # for an sb_-prefixed key that is invalid/unregistered, or an + # apikey-vs-bearer sb_ conflict; any non-sb_ value (legacy/user/ + # third-party JWT, or anything else) passes through to the runtime. + - name: envoy.filters.http.lua + typed_config: + '@type': >- + type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua + inline_code: | + local FUNCTIONS_ROUTE = "functions-v1-all" + local FUNCTIONS_PREFIX = "/functions/v1/" + local PUBLISHABLE_KEY = "${SUPABASE_PUBLISHABLE_KEY}" + local SECRET_KEY = "${SUPABASE_SECRET_KEY}" + local ANON_JWT = "${ANON_KEY_ASYMMETRIC}" + local SERVICE_ROLE_JWT = "${SERVICE_ROLE_KEY_ASYMMETRIC}" + local TRANSLATION_ENABLED = SECRET_KEY ~= "" and PUBLISHABLE_KEY ~= "" and SERVICE_ROLE_JWT ~= "" and ANON_JWT ~= "" + + local function is_functions_request(request_handle, headers) + if request_handle:streamInfo():routeName() == FUNCTIONS_ROUTE then + return true + end + + local path = headers:get(":path") + if path == nil then + return false + end + + return string.sub(path, 1, string.len(FUNCTIONS_PREFIX)) == FUNCTIONS_PREFIX + end + + local function bearer_token(auth) + if auth == nil then + return nil + end + + return string.match(auth, "^[Bb]earer%s+(.+)$") + end + + local function unauthorized(request_handle, message) + request_handle:respond( + { [":status"] = "401", ["content-type"] = "text/plain" }, + message + ) + end + + function envoy_on_request(request_handle) + local headers = request_handle:headers() + if not is_functions_request(request_handle, headers) then + return + end + + -- Strip any client-supplied sb-api-key (anti-spoof). + headers:remove("sb-api-key") + + -- No opaque keys configured: nothing to translate, pass through. + if not TRANSLATION_ENABLED then + return + end + + local apikey = headers:get("apikey") + local bearer = bearer_token(headers:get("authorization")) + + -- No key at all: pass through (verify_jwt:false / unauthenticated). + if (apikey == nil or apikey == "") and (bearer == nil or bearer == "") then + return + end + + -- Conflict: bearer carries an sb_ key that disagrees with apikey. + if bearer ~= nil and string.sub(bearer, 1, 3) == "sb_" + and apikey ~= nil and apikey ~= "" and apikey ~= bearer then + unauthorized(request_handle, "Conflicting API keys") + return + end + + -- Resolve the key from apikey, else an Authorization `Bearer sb_` fallback. + local key = apikey + if (key == nil or key == "") and bearer ~= nil and string.sub(bearer, 1, 3) == "sb_" then + key = bearer + end + + -- Non-sb_ value (legacy/user/third-party JWT, or anything else): + -- pass through; the runtime verifies it. + if key == nil or key == "" or string.sub(key, 1, 3) ~= "sb_" then + return + end + + -- sb_ key: translate publishable/secret, otherwise reject. + if key == SECRET_KEY then + headers:replace("sb-api-key", SERVICE_ROLE_JWT) + elseif key == PUBLISHABLE_KEY then + headers:replace("sb-api-key", ANON_JWT) + else + unauthorized(request_handle, "Invalid API key") + end + end + - name: envoy.filters.http.rbac typed_config: '@type': >- diff --git a/docker/volumes/api/kong-entrypoint.sh b/docker/volumes/api/kong-entrypoint.sh index daf1d5e9a1a91..c5180dbbfaef6 100755 --- a/docker/volumes/api/kong-entrypoint.sh +++ b/docker/volumes/api/kong-entrypoint.sh @@ -19,10 +19,22 @@ if [ -n "$SUPABASE_SECRET_KEY" ] && [ -n "$SUPABASE_PUBLISHABLE_KEY" ]; then # Realtime WebSocket: reads from query_params.apikey (supabase-js sends apikey # via query string), outputs to x-api-key header which Realtime checks first. export LUA_RT_WS_EXPR="\$((query_params.apikey == '$SUPABASE_SECRET_KEY' and '$SERVICE_ROLE_KEY_ASYMMETRIC') or (query_params.apikey == '$SUPABASE_PUBLISHABLE_KEY' and '$ANON_KEY_ASYMMETRIC') or query_params.apikey)" + + # Functions: translate opaque sb_ keys to the pre-signed internal asymmetric + # JWT and emit it as a raw `sb-api-key` header (no Bearer prefix), leaving + # Authorization untouched. The key is read from the apikey header or an + # Authorization `Bearer sb_...` fallback (header only, matching platform + # behavior. On no match the expression yields nil (rendered as an empty + # header) which the route's post-function then strips. + export LUA_FUNCTIONS_EXPR="\$((headers.apikey == '$SUPABASE_SECRET_KEY' and '$SERVICE_ROLE_KEY_ASYMMETRIC') or (headers.apikey == '$SUPABASE_PUBLISHABLE_KEY' and '$ANON_KEY_ASYMMETRIC') or (headers.authorization == 'Bearer $SUPABASE_SECRET_KEY' and '$SERVICE_ROLE_KEY_ASYMMETRIC') or (headers.authorization == 'Bearer $SUPABASE_PUBLISHABLE_KEY' and '$ANON_KEY_ASYMMETRIC') or nil)" else # Legacy API keys, not sb_ API keys -> pass apikey through unchanged export LUA_AUTH_EXPR="\$((headers.authorization ~= nil and headers.authorization:sub(1, 10) ~= 'Bearer sb_' and headers.authorization) or headers.apikey)" export LUA_RT_WS_EXPR="\$(query_params.apikey)" + + # Functions: no opaque keys configured -> never set sb-api-key (the empty + # value is stripped by the route's post-function). + export LUA_FUNCTIONS_EXPR="\$(nil)" fi # Substitute environment variables in the Kong declarative config. diff --git a/docker/volumes/api/kong.yml b/docker/volumes/api/kong.yml index 84433c13657d4..d9608f04b8fda 100644 --- a/docker/volumes/api/kong.yml +++ b/docker/volumes/api/kong.yml @@ -341,6 +341,21 @@ services: end ## Edge Functions routes + ## + ## Functions header handling: opaque sb_ keys are translated to the pre-signed + ## internal asymmetric JWT and injected as a raw `sb-api-key` header (no + ## `Bearer` prefix), while `Authorization` is left untouched so user-session + ## JWTs and legacy bearers flow through to the runtime. + ## + ## No `key-auth`: Functions is a passthrough that does NOT validate keys. Kong + ## cannot reject an invalid key while still letting unauthenticated requests + ## through (key-auth's `anonymous` fallback accepts missing AND invalid keys + ## alike), so unknown/invalid keys simply pass to the runtime, which handles + ## verify_jwt itself. + ## + ## The request-transformer strips any client-supplied `sb-api-key` (anti-spoof) + ## and re-adds the translated value; on no match the Lua expression yields nil + ## (an empty header) which the post-function then removes. - name: functions-v1 _comment: 'Edge Functions: /functions/v1/* -> http://functions:9000/*' url: http://functions:9000/ @@ -352,6 +367,22 @@ services: - /functions/v1/ plugins: - name: cors + - name: request-transformer + config: + remove: + headers: + - "sb-api-key" + add: + headers: + - "sb-api-key:$LUA_FUNCTIONS_EXPR" + - name: post-function + config: + access: + - | + local v = kong.request.get_header("sb-api-key") + if v == nil or v == "" or v:find("^%s*$") then + kong.service.request.clear_header("sb-api-key") + end ## OAuth 2.0 Authorization Server Metadata (RFC 8414) - name: well-known-oauth diff --git a/docker/volumes/functions/main/index.ts b/docker/volumes/functions/main/index.ts index 6bfad388a8aaa..3eeb28375db16 100644 --- a/docker/volumes/functions/main/index.ts +++ b/docker/volumes/functions/main/index.ts @@ -36,7 +36,7 @@ export function parseJwks(raw: string | undefined): jose.JSONWebKeySet | null { } /** - * Extract JWT token from Authorization header + * Extract JWT token from 'Authorization' header or fallback to 'sb-api-key' compatibility * * Parses the Authorization header to extract the Bearer token. * Expects format: "Bearer " @@ -44,22 +44,41 @@ export function parseJwks(raw: string | undefined): jose.JSONWebKeySet | null { * @param req - The HTTP request object * @returns The JWT token string or an authentication failure */ +function extractBearerToken(authHeader: string | null): string | null { + const tokenParts = (authHeader ?? '').trim().split(/\s+/) + const [bearer, token] = tokenParts + if (bearer.toLowerCase() !== 'bearer' || tokenParts.length !== 2 || !token) { + return null + } + return token +} + function getAuthToken(req: Request): string | AuthFailure { const authHeader = req.headers.get('authorization') - if (!authHeader) { + const sbApiKeyCompatibilityToken = req.headers.get('sb-api-key') + + if (!authHeader && !sbApiKeyCompatibilityToken) { return { code: RequestErrors.MissingAuthHeader, message: 'Missing authorization header', } } - const tokenParts = authHeader.trim().split(/\s+/) - const [bearer, token] = tokenParts - if (bearer.toLowerCase() !== 'bearer' || tokenParts.length !== 2 || !token) { + + // NOTE:(kallebysantos) Compatibility mode is triggered when all conditions match: + // - API proxy mints a temp token + // - Original bearer is not present or is ApiKey + const bearerToken = extractBearerToken(authHeader) + const token = !bearerToken || bearerToken.startsWith('sb_') + ? sbApiKeyCompatibilityToken + : bearerToken + + if (!token) { return { code: RequestErrors.InvalidTokenFormat, message: 'Invalid JWT format', } } + return token } @@ -221,7 +240,11 @@ Deno.serve(async (req: Request) => { importMapPath, envVars, }) - return await worker.fetch(req) + // Gateway-minted internal JWT is for this router only; never expose it to user functions. + const userReq = new Request(req) + userReq.headers.delete('sb-api-key') + EdgeRuntime.applySupabaseTag(req, userReq) + return await worker.fetch(userReq) } catch (e) { const error = { msg: e.toString() } return new Response(JSON.stringify(error), { diff --git a/packages/shared-data/extensions.json b/packages/shared-data/extensions.json index c219fd1913ac8..203286a930e66 100644 --- a/packages/shared-data/extensions.json +++ b/packages/shared-data/extensions.json @@ -376,7 +376,7 @@ "link": "/guides/database/extensions/pgsodium", "github_url": "https://github.com/michelp/pgsodium", "product": "Supabase Vault", - "product_url": "/project/{ref}/settings/vault/secrets" + "product_url": "/project/{ref}/integrations/vault/secrets" }, { "name": "pgstattuple",