> You are welcome, I just saved you weeks of onboarding, confusion, and devs passing around .envs on Slack.
Don't get it. At one company I worked, .env files for the DEV environment were open (the file itself was stored on Vault, so only engineers had access to it), and one could only access DEV resources via VPN. So, starting a service using the DEV .env file was rather easy an uncomplicated.
Here is the problem with that. A dev pushes a change that requires a change to the env file. Another dev pulls down the code, but doesn't change the env file. Everything breaks. At really bad companies, DevOps sets env vars from somewhere other than that file passed around by devs - another failure point.
My proposal:
1. Key Vault | HashiCorp Vault | whatever is the source of truth for secrets.
2. When a developer adds a key, they add it to Key Vault and update code to use it.
3. On app startup, code checks the dev's local for 2 env vars ONLY, which allow access to key vault.
4. The app then tries to pull in all the env vars it needs by secret name.
5. If any are missing, it fails.
This keeps devs from having to pass around .env files outside of source control. Btw, Azure (and all other cloud) builds can be configured to pull env vars directly from Key Vault, so there's that benefit too.
There's an optional but very helpful sixth step: expose the loaded configuration (by pushing it to the logs, or as a /_config endpoint). For secrets, obviously don't expose the secret value itself, but do expose the vault address, secret identifier, and which version of the secret was loaded. This helps check that an application isn't using an outdated version of a secret.
I do and have done both and a blend. Secrets for external services needed in dev usually in parameter store. Kinda depends on the existing work flow. There is so much to do you should be tackling problems that move the needle and chip away at small stuff, pet peeve stuff in smaller time-boxed increments.
My company enforces this with two rules. One, deployment always builds and deploys exactly what's in the git repository, so there is no way to include anything else (secrets, configuration...) in a deployment. Two, it's obviously forbidden to commit secrets to the git repository (we enforce this through training and reviews, but it's fairly easy to add pre-commit hooks as well).
Don't get it. At one company I worked, .env files for the DEV environment were open (the file itself was stored on Vault, so only engineers had access to it), and one could only access DEV resources via VPN. So, starting a service using the DEV .env file was rather easy an uncomplicated.