r/webdev • u/Sweet_Good_2358 • 4d ago
Discussion How are you managing secrets across multiple projects and environments?
Im curious how other developers and small teams handle secrets when they have multiple projects and environments (Dev, Testing, Staging, Production).
I'm finding that the workflow gets messy surprisingly quickly when multiple people are involved. Sharing .env files, managing access, making sure someone doesn't accidentally overwrite production credentials, keeping everything organized across projects, etc.
What are you using? What frustrates you the most about your current setup?
21
Upvotes
62
u/lbunch1 4d ago
I'm not telling
65
u/Saver411 4d ago
the biggest mistake teams make is letting humans hold production credentials on their machines at all.
Keep local dev strictly on dummy or shared sandbox keys. Production secrets should only exist inside the deployment pipeline, gated behind restricted roles. If a developer can accidentally overwrite prod configs from their laptop, the permissions model is already broken.
8
u/zambono_2 4d ago
You handle secrets in the cloud, and you pull them from your backend
14
u/whoiami31 4d ago •
AWS kms free tier
5
u/waterkip 4d ago
ansible-vault
11
u/scarfwizard 4d ago
AWS Parameter Store or Secrets Manager is the correct answer.
/myapp/dev/DB_URL
/myapp/staging/DB_URL
/myapp/prod/DB_URL
/otherapp/prod/STRIPE_KEY
1
u/miria01 4d ago
Make the deploy identity environment-scoped too: the dev and staging pipelines should have no permission to read production secrets, even if projects or secret stores are separated. That keeps a dev deploy from gaining access to prod credentials through a config mix-up.
1
u/regularjackk 4d ago
fnox
1
u/nn_gyunx 4d ago
Small backend team, five or so services across dev, staging and prod, and what made the mess stop was deciding that prod values never sit on a laptop. Dev and staging run on shared sandbox keys, and prod secrets only exist inside the deploy environment, read at startup by the role the service already runs as, so nobody can overwrite prod config by editing a file by accident. Storage turned out to be the easy part. Rotation is what hurts, because a key quietly shared by three services means one rotation turns into a small incident where you find out from error logs which ones were using it, so I push for every service to get its own credentials even when the provider makes you click through five screens for it.
How do you handle the local dev side of third party stuff, do you hand out sandbox keys or run a stub locally? That is the part that keeps biting new people on our side and I still do not have a clean answer for it.
1
u/No_Tradition6625 4d ago
I write them all on a sticky note and point my life camera feed at it... Or I use bitwarden 🤷🏻♂️
1
u/vtshopjh 4d ago
Keyvaults, be it azure or openshift
1
u/AhmedAmer2nd 3d ago
What helped us most was getting rid of shared .env files completely. Each environment pulls its secrets from one manager at deploy time (Doppler, Infisical, AWS Secrets Manager or Vault all work). Devs only get read access to dev and staging, and production keys can only be read by CI and the runtime role. That alone stops the "someone overwrote prod" problem. Also give each service its own credentials, so rotating one key doesn't break five apps.
1
u/Standard_Scarcity_74 3d ago
We stopped sharing .env files and moved to a secrets manager like infisical or doppler, with separate secrets per project and environment, so the team pulls dev values by command and only one or two people can touch production.
1
u/DoOmXx_ 3d ago
sops with age keys in the repo, no more .env files in slack
1
u/rbobby full-stack 3d ago
In VisualStudio user secrets work very well for developers. You need to manage them explicitly, eg. use your corporate secret manager, eg. 1Password, to create a secure note that you share with your fellow devs.
1
u/davidbalbino 3d ago
if you're on Laravel there's
php artisan env:encrypt --env=production, it generates.env.production.encryptedthat you can commit, and only the deploy has the key to runenv:decrypt. outside Laravel, sops + age does pretty much the same for any stack, one encrypted file per env and a different key per env. so nobody passes .env on slack anymore and dev keys simply can't open prod file. imo it's way simpler than running Vault when the team is small1
u/_sarant 3d ago
either 1password enviroments and connect it through the CLI or https://docs.phase.dev/console/environments either works though phase is more scoped to devs
1
u/tramspellen 3d ago
Azure Key Vault. One vault for each environment.
1
u/Both_Kaleidoscope711 3d ago
Here is my preferred approach:
1
u/Afnan_CH_Digital 3d ago
For small projects I keep it boring: the host's environment variable settings hold the real values, a password manager holds the backup copy, and the repo only ever has a .env.example with empty keys. Local dev gets throwaway keys, so nothing on my laptop can touch production. It is not fancy, but it has not leaked anything yet, and anyone I hand a project to can set up in ten minutes.
1
u/LittleThingsStudio 3d ago
At the companies I previously worked for, we handled this through separation of duties.
Developers only had access to development secrets and configs, QA only had access to the testing environment, and only the operations team had access to production.
Developers provided deployment instructions, while the operations team handled deployment and designed the automated deployment process.
I think defining who can access each environment is more important than choosing a particular secrets management tool. Even with a good tool, poorly defined permissions can still cause problems.
1
u/Hostman_com 2d ago
For planned rotations where the provider allows two active keys, update each consumer and verify a successful API call with the new key before disabling the old one. Include scheduled jobs, not just the web app.
After disabling it, repeat those checks and watch for authentication failures. If the key is used to obtain longer-lived tokens, test obtaining a fresh token too; an existing session can hide a consumer still configured with the old key.
1
u/CorpT 4d ago
This is a very solved problem that doesn't need another tool. The fact that you're finding it getting messy quickly is a large red flag against using the tool you're creating.
-1
u/smkaisser 4d ago
Small team here, a handful of Laravel apps across a few VPSes. What finally stopped the mess for me was deciding that prod secrets don't live on anyone's laptop. Devs get a .env.example and their own local values, staging and prod values only exist on the server or wherever the deploy pulls them from, and the only thing allowed to write to prod is the deploy itself.
The thing that bit me the most wasn't the tooling, it was shared credentials. One API key used by three projects means one leak or one rotation hits all three. Now every project and every environment gets its own key, even when the provider makes that annoying.
Biggest frustration honestly is rotation. Storing secrets is mostly solved, but nobody remembers which services break when you rotate a key until you actually do it. Do you keep any kind of map of what uses what?
0
u/kelkes 4d ago
Vault or infiscal.
0
u/Ecstatic-Text-2282 3d ago
What worked for our small team: secrets live in one place per environment (we use the hosting provider's env settings plus a password manager vault for the source of truth), and the repo only has a .env.example with every key name and a one-line comment. Prod credentials are readable by two people, period. Devs get their own dev/staging keys, so nobody ever has a reason to touch prod values. The thing that bit us most wasn't storage, it was rotation. Nobody knew which services used which key, so write that down next to each secret.
0
u/Ahmed_Hisham0 3d ago
the part that bites later isn't storing them, it's rotating them. you can have a perfect vault and still have a prod key living in someone's .env from the one time they hotfixed something at 2am.
what actually worked for us: every secret gets an owner and a rotation date, and anything that can't be rotated inside an hour gets flagged. sounds bureaucratic, but it's the only thing that stopped the drift.
tooling: doppler or infisical if you want hosted, sops + age if you want them encrypted in the repo, and 1password cli is underrated for small teams because it injects at runtime so nothing lands on disk.
0
u/Ok-Snow-6553 3d ago
Even as a solo dev, this gets messy fast. I've definitely had a few heart-stopping moments where I almost committed a
.envfile to Git.For my own SaaS, I just use the built-in environment variables in my hosting provider (like Vercel/Cloudflare) and keep local secrets in a separate
.env.localthat's gitignored.For actual team use though, I'm curious about Doppler or Infisical. Are they overkill for small projects?
0
u/allpunks 3d ago
As every decent dev i use GCP secret manager to manage them and their production counterparta are restricted only to specific IAMs