Rotating environment variables
When you need to rotate API keys, tokens, or other credentials stored in your environment variables, you'll need to update both your third-party service and your Vercel projects. This ensures your applications continue to work without downtime.
Secret rotation is a security best practice that limits the exposure window if a credential is compromised. You might rotate secrets when:
- A team member with access to credentials leaves
- You suspect a credential has been exposed
- Your security policy requires periodic rotation
- A third-party service forces a credential update
The key to safe rotation is updating Vercel before you invalidate the old credential. This prevents your deployments from breaking when the old key stops working.
If your secret is configured at the project level, only that project uses it. You'll only need to redeploy that one project.
- Go to your third-party service (like a database provider, API service, or integration) and generate a new credential. Don't delete or invalidate the old one yet.
- From your Vercel dashboard, select the project that uses this credential.
- Select Environment Variables in the sidebar.
- Find the environment variable that stores the credential. Click the three dots to the right and select Edit.
- Replace the old value with your new credential.
- Make sure the correct environments are selected (Production, Preview, and/or Development).
- Click Save.
- Redeploy your project to apply the new credential:
- Open Deployments in the sidebar.
- Find your latest production deployment.
- Click the three dots and select Redeploy.
- Once the new deployment succeeds and you've verified it works, go back to your third-party service and invalidate the old credential.
If your secret is configured at the team level, multiple projects might use it. You'll need to redeploy all projects that depend on this credential.
- Go to your third-party service and generate a new credential. Keep the old one active for now.
- From your Vercel dashboard, select your team from the team switcher.
- Select Environment Variables in the sidebar.
- Find the environment variable that stores the credential. Click the three dots to the right and select Edit.
- Replace the old value with your new credential.
- Make sure the correct environments are selected (Production, Preview, and/or Development).
- Click Save.
- Identify which projects use this credential. You can check the Link to Projects field in the environment variable form to see which projects have access.
- Redeploy each project that uses this credential:
- Go to each project's Deployments section in the sidebar.
- Find the latest production deployment.
- Click the three dots and select Redeploy.
- Once all deployments succeed and you've verified they work, go back to your third-party service and invalidate the old credential.
When rotating credentials for integrations (like database providers or third-party services installed from the Vercel Marketplace):
- From the Vercel dashboard, select Integrations in the sidebar, then open the provider whose credentials you want to rotate.
- Under Installed Products, select the product for the resource whose credentials you want to rotate.
- In the sidebar, select Settings, then scroll to Secure This Resource.
- Click Rotate Secrets, enter the Rotation reason and confirm by typing the project name.
- Redeploy the linked project to use the new secrets.
Alternatively, rotate secrets from the provider's dashboard:
- Navigate to the integration from the Integrations section in the sidebar and then by selecting the provider you want to rotate credentials for
- Click Log into provider (if the integration has multiple resources, repeat this for each resource).
- Manually reset the credentials in the provider's dashboard (this will synchronize the new secrets to your Vercel team and stage them to be applied to linked projects when the projects are redeployed)
- Redeploy the projects that use this integration or resource.
- Test your application to confirm the new credential works.
- Return to your integration's dashboard and revoke or delete the old credential (if the provider supports this).
When a provider doesn't support Rotate Secrets from the Vercel dashboard, reset the credential in the provider's console. What happens to the old credential depends on the provider:
- The old credential stops working immediately: Resetting a database password for Neon, MongoDB Atlas, or Redis invalidates the current password as soon as you confirm. Projects that use it can't connect to the database until you redeploy them, so redeploy right after the reset.
- The old and new credentials work at the same time: Hypertune lets you create a new token before you delete the old one. You can redeploy first, then delete the old token, and avoid downtime.
Each set of steps starts in the provider's console. To open it from Vercel, select Integrations in the dashboard sidebar, select Manage next to the provider, open the installed product, and select the button that opens the provider, such as Open in Neon.
After you reset a credential, the provider syncs the new value to your Vercel team. Redeploy every project connected to the resource so that it uses the new value.
Resetting a role's password in Neon invalidates the current password immediately.
- In the Neon console, select the project you want to update.
- On the project dashboard, select Connect.
- In the connection details, select Reset password, then select Reset to confirm.
- In Vercel, confirm that the integration shows the new secret, then redeploy every connected project.
See Reset a password in the Neon documentation.
Changing a database user's password in MongoDB Atlas invalidates the current password immediately.
- In MongoDB Atlas, under Security, select Database & Network.
- Select Edit next to the database user.
- Select Edit Password, then Autogenerate Secure Password.
- Select Update User.
- In Vercel, confirm that the integration shows the new environment variables, then redeploy every connected project.
See Configure database users in the MongoDB Atlas documentation.
Changing a database password in Redis invalidates the current credentials immediately and restarts the database instance.
- In the Redis console, select the database you want to update.
- Select Edit.
- In the Security section, enter a new password.
- Select Save Database.
- In Vercel, confirm that the integration shows the new secret, then redeploy every connected project.
See Default user in the Redis Cloud documentation.
Hypertune tokens can overlap, so create the new token, redeploy, and then delete the old token.
- In Hypertune, select the project with the same name as your Vercel installed product.
- Open the project's Settings page and select New token.
- Enter a Token name and select Create token.
- In Vercel, redeploy every connected project.
- After the new deployments are live, return to the project's Settings page in Hypertune and delete the previous token.
If your deployment fails after updating a credential:
- Check that you copied the new credential correctly (no extra spaces or line breaks).
- Verify that the new credential is active in your third-party service.
- Make sure you selected the correct environment (Production, Preview, or Development) when updating the variable.
- Check your application logs in the Vercel dashboard for specific error messages.
Environment variable changes only apply to new deployments. If you visit an old deployment URL, it will still use the old credential. This is expected behavior.
Once you invalidate the old credential, old deployments that relied on it will fail if they make API calls using that credential. Redeploy the old deployment to fix this, as each new deployment picks up the latest version of the environment variables.
If you rotated a team-level environment variable and multiple projects broke, you may have missed redeploying some projects:
- Go to your team's Environment Variables settings.
- Find the variable you rotated and check which projects have access to it.
- Redeploy any projects you missed.
Was this helpful?