Sync secrets from Vault to Vercel Project
The Vercel Project sync destination allows Vault to safely synchronize secrets as Vercel environment variables. This is a low footprint option that enables your applications to benefit from Vault-managed secrets without requiring them to connect directly with Vault. This guide walks you through the configuration process.
Prerequisites:
- Ability to read or create KVv2 secrets
- Ability to create Vercel tokens with access to modify project environment variables
- Ability to create sync destinations and associations on your Vault server
Setup
If you do not already have a Vercel token, navigate your account settings to generate credentials with the necessary permissions to manage your project's environment variables.
Next you need to locate your project ID. It can be found under the
Settings
tab in your project's overview page.Configure a sync destination with the access token and project ID obtained in the previous steps.
Output:
Usage
If you do not already have a KVv2 secret to sync, mount a new KVv2 secrets engine.
Output:
Create secrets you wish to sync with a target Vercel project.
Output:
Create an association between the destination and a secret to synchronize.
Output:
Navigate to your project's settings under the
Environment Variables
section to confirm your secret was successfully created in your Vercel project.
Moving forward, any modification on the Vault secret will be propagated in near real time to its Vercel environment variable counterpart. Creating a new secret version in Vault will overwrite the value in your Vercel Project. Deleting the secret or the association in Vault will delete the secret on Vercel as well.
Note
Vault syncs secrets differently depending on whether you have configured
secret-key
or secret-path
granularity:
secret-key
granularity splits KVv2 secrets from Vault into key-value pairs and stores the pairs as distinct entries in Vercel. For example,secrets.key1="val1"
andsecrets.key2="val2"
.secret-path
granularity stores secrets as a single JSON string that contains all the associated key-value pairs. For example,{"key1":"val1", "key2":"val2"}
.
Since Vercel projects limit environment variables to single-value secrets, the
sync granularity defaults to secret-key
.
API
Please see the secrets sync API for more details.