Skip to content
Database

保护你的数据

Supabase 帮助你控制数据访问。通过访问策略,你可以保护敏感数据,并确保用户只能访问他们被允许看到的内容。

🌐 Supabase helps you control access to your data. With access policies, you can protect sensitive data and make sure users only access what they're allowed to see.

安全地连接你的应用 #

🌐 Connecting your app securely

Supabase 给你几种方式来访问你的数据。每种选项都有不同的安全模型:

🌐 Supabase gives you several ways to access your data. Each option has a different security model:

数据 API #

🌐 Data API

使用 Supabase 客户端库、REST 或 GraphQL,并配合可发布的密钥。通过 行级安全 (RLS) 保护公开的表,并仅授予每个角色所需的权限。

🌐 Use Supabase client libraries, REST, or GraphQL with a publishable key. Protect exposed tables with Row Level Security (RLS) and grant only the privileges each role needs.

边缘函数 #

🌐 Edge Functions

通过 Edge Functions 在你的客户端和数据库之间放置自定义的服务器端逻辑。你可以在函数中使用密钥、API 密钥或数据库连接字符串,如果你的应用只通过这种方式访问数据,还可以 禁用数据 API

🌐 Put custom server-side logic between your client and database with Edge Functions. You can use secrets, API keys, or database connection strings inside the function, and you can disable the Data API if your app only accesses data this way.

直接数据库连接 #

🌐 Direct database connections

通过受信任的服务器、工作节点或工具使用连接字符串连接到 Postgres。保持数据库凭据的私密,并为你的环境使用正确的连接方式。如果你的应用只使用直接连接,也可以禁用数据 API

🌐 Connect to Postgres with a connection string from trusted servers, workers, or tools. Keep database credentials secret and use the right connection method for your environment. You can disable the Data API if your app only uses direct connections.

前端访问 #

🌐 Frontend access

对于前端应用,数据 API 是常用的选择。只要你做到以下几点,就可以在从前端访问数据的同时保持数据安全:

🌐 For frontend apps, the Data API is the usual choice. You can keep your data secure while accessing it from the frontend, so long as you:

  • 为你的表启用行级安全(RLS),并正确配置访问策略,以授予你的应用运行所需的最少权限
  • 创建 Supabase 客户端时使用你的 Supabase 可发布密钥

启用 RLS 后,你的可发布密钥可以安全公开,因为行访问权限会根据你的访问策略和用户的 JSON Web Token (JWT) 进行检查。如果用户通过 Supabase Auth 登录,Supabase 客户端库会自动发送 JWT。

🌐 Your publishable key is safe to expose with RLS enabled, because row access permission is checked against your access policies and the user's JSON Web Token (JWT). The JWT is automatically sent by the Supabase client libraries if the user is logged in using Supabase Auth.

较老的项目可能也会显示一个 anon 密钥。把它当作可发布的密钥来处理:它可以识别你的项目,但不是秘密,并且必须与 RLS 和最小权限授权配合使用。

🌐 Older projects may also show an anon key. Treat it like a publishable key: it can identify your project, but it is not a secret and must be paired with RLS and least-privilege grants.

更多信息 #

🌐 More information

Supabase 和 Postgres 提供多种方式来管理安全性,包括但不限于行级安全性。更多信息请查看访问和安全页面:

🌐 Supabase and Postgres provide you with multiple ways to manage security, including but not limited to Row Level Security. See the Access and Security pages for more information: