Skip to content

Issues with rotating pgsodium and Vault root encryption keys

Last edited: 10/14/2026

如果在尝试密钥轮换后你仍然可以解密现有的 Vault 秘密,那么项目仍在使用传统的根密钥。Supabase 管理 API 的 /pgsodium 端点是进行密钥轮换的正确方式,但它需要特定格式才能触发整个数据库实例的更新。

🌐 If you can still decrypt existing Vault secrets after an attempted key rotation, the project is still using the legacy root key. The Supabase Management API /pgsodium endpoint is the correct mechanism for key rotation, but it requires a specific format to trigger the update across the database instance.

如何轮换根密钥 #

🌐 How to rotate the root key

  1. 生成一个新的64位十六进制字符串作为根密钥。
  2. 使用有效的个人访问令牌,对项目的 /pgsodium 管理 API 端点发起 PUT 请求。
  3. 在请求体中传递新的64位十六进制密钥。
  4. 通过尝试解密使用之前的密钥加密的数据来验证密钥轮换。轮换后,你将无法再解密旧数据。
  5. 使用新的密钥配置手动重新加密或重新存储你的 Vault 密钥。