r/programming • u/BlondieCoder • Jul 21 '26
Secrets Don’t Belong in Config
https://secretspec.dev/blog/secrets-dont-belong-in-config/
174
Upvotes
r/programming • u/BlondieCoder • Jul 21 '26
136
u/foxsimile Jul 21 '26
They belong in the treehouse!
73
u/putergud Jul 21 '26
Some secrets belong in config.
Some secrets do not.
Some config belongs in code.
Some config does not.
There is not one right answer. The application needs the config and the secrets. How you get them there depends very much on the application itself and the environment in which it is run.
11
u/Sokaron Jul 21 '26
I really like .NET's solution to this for local development. Run a command to persist the secret locally on your machine outside the project directory and then it gets read in at runtime. Zero risk of a secret being committed due to a faulty gitignore etc.
15
u/YoghurtFlan Jul 21 '26
The other thing is to basically make secrets less important. Principle of least privilege - have loads of tiny scope secrets instead of a few powerful ones. Make it easy to rotate them. Take away their power.
You don't always have control over that, especially with third parties, but you can always proxy them internally and use other mechanisms to keep them away from the internet-facing network.
41
u/nicholashairs Jul 21 '26 edited Jul 21 '26
Whilst I'm sure there's at least one person that will hate this, the method I've settled on is being able to have stackable config files. So yes secrets do belong in config just a dedicated secret only config.
some-tool -c common.yml -c dev.yaml -c dev.secret.yml(And at some point in the future I'd like to make it so I can pull that secret config file from an actual secure place like
-c aws-kms:///path/to/secretand then use workload identities to manage whether it is allowed to or not)Edit: for those that think I should just be using env files, I explain my reasoning in a comment below. Though I'm certainly not suggesting this is some objective truth, it's just my personal preference.
Also I'm not suggesting that this is somehow unique and that I'm the first person to have done this, it's a pattern I adopted after inspiration from elsewhere.
10
u/derangedtranssexual Jul 21 '26
Secrets belong in your public GitHub repo
5
u/ndev42 Jul 22 '26
Everyone's debating where secrets should live and 42 NixOS modules are just dumping them world-readable into /nix/store
4
u/siromega37 Jul 23 '26
I didn’t get past much of this. Maybe it’s my more operations-focused background, but I like to pull them from the vault at runtime via a startup script into environment variables like it’s 1999. Script can be code-reviewed and the vault, as it should be, is heavily monitored. It’s simple, easy to maintain, and easy to troubleshoot. The naming standard is clearly written so if/when we get new credentials of any sort there’s zero coordination needed between teams really. Don’t be fancy, be reliable.
6
u/delinka Jul 21 '26
I put my bcrypt’ed password in config. AI tells me it’ll take centuries to crack. Checkmate, hackers!
2
u/phrmends Jul 22 '26
I really like secretspec and devenv
1
u/Rakn Jul 23 '26
We just have an http endpoint on each service and someone logs in after a restart and enters all the passwords from the production notebook in the office. It can be this simple.
1
u/schlenk Jul 24 '26 edited Jul 24 '26
We solved this by adding a generic secrets layer to our python runtime system.
Its pluggable and offers a secrets tree with mountable wallets that override parts of the tree. So you can mount environment variables, K8s secrets, encrypted files with unlock secrets stashed into different files, some wallet that produces access_tokens for Microsoft Graph on demand and so on.
The developers just see a unified secrets infrastructure and just do store.resolve(secrets_path) anywhere they need a secret. The simply do not need to think about it.
And the admin/devops/local developer teams mount the appropriate wallets for the necessary security level. Like plain files for local dev or K8s secrets when running in a cluster or some Vault style stuff when needed.
Keeps it nicely agnostic and multi cloud/on-prem capable.
Its a bit like Secretsspec actually, but older (wrote it like 2020 or so). Maybe i should write a backend to from/to secretsspec.
1
u/gnahraf Jul 25 '26
To my knowledge, no matter how much indirection one employs (keystore, secrets service, etc), any process with the same (unix) privileges can also retrieve the secret. (Unless the program asks for it interactively, the passkey is available in plain text somewhere.) The standard unix way to deal with this is with file permissions. I don't know of another way.. is there any other way?
As for the risk of putting secrets in repos, excepting as samples or for testing, I think config files don't belong in git, let alone any secrets they may contain.
1
u/SailorTech Aug 01 '26
The useful distinction here is lifecycle. Config should be easy to review and version, while secrets need access control, rotation, and auditability.
0
u/RedEyed__ Jul 21 '26
They belong to env var (no)
-3
u/igloomaster Jul 22 '26
I encrypt them using md5 before committing
5
u/[deleted] Jul 22 '26
[removed] — view removed comment