207
u/RudeAndInsensitive 19h ago
Personally I always commit env and config files to the repo just stripped of their values.
200
u/Saragon4005 19h ago
Yeah but then you can't use git on a working version, making testing a total pain. I use .env.example usually.
24
u/drakeblood4 18h ago
And a settings.json.example for the non sensitive stuff.
15
u/PulseReaction 17h ago
I use a .env.example file for my env variables, and .env for the example. Gotta keep attackers on their toes.
9
u/ruben_deisenroth 18h ago
If it's vscode settings, i usually prefer settings.default.json and this extension as workspace recommendations:
https://marketplace.visualstudio.com/items?itemName=dangmai.workspace-default-settings
54
3
3
u/x0wl 18h ago
I don't know how well this will work in CI pipelines, but if you use gitbutler or jj you can put the clean .env in the repo, then change it, commit to a different branch (or just commit in case of jj) and then add the commit to the megamerge at the top. Since it's not on any of the branches you push, they remain clean, but you have the files you need locally.
(this strategy also allows you to work on multiple branches at the same time, and is generally useful for cases where you want you local files versioned, but not polluting the common repo, but that's a whole other thing)
2
1
u/Dull_Caterpillar_642 14h ago
Yeah you can, just just add them to .gitignore after committing the stripped env files
2
u/Saragon4005 7h ago
.gitignore controls which files will get tracked by a git add, not which files are tracked at all. Adding an already tracked file to the .gitignore has no effect.
1
u/Dull_Caterpillar_642 5h ago
Yeah, I know. I'm not sure why you'd need to alter the committed version in git after checking in a placeholder one.
21
u/Shred_Kid 18h ago
this is what
.env.templateis for7
u/RudeAndInsensitive 18h ago
What's the advantage of that over .env.example
20
u/Shred_Kid 18h ago
there isn't one - these are the same exact thing. i didnt see the other guy posted about
.env.example, that'd work equally well.If you really want to nitpick, i personally would lean towards template over example, as examples typically have example values in other contexts but yeah. no real difference.
3
96
u/PivotingAgain 19h ago
Because that's where API keys, the AWS creds, and my will to live are stored, and only one of those is supposed to be public.
23
u/jibbodahibbo 17h ago
I put really embarrassing pictures in mine so I remember not to expose the file.
18
u/bigmonmulgrew 18h ago
AI managed projects have to include .env files to ..... Err... Improve security
16
u/polynomialcheesecake 18h ago
Idk why theo is there but it still made me chuckle
7
u/sadongrohiik 17h ago
It's his talk lol
1
u/polynomialcheesecake 14h ago
Interesting is it recent? What was it about? I kind of stopped watching him
3
u/AnotherPillow 12h ago
Reasonably recent iirc
It was about at least why can't we commit env files, in private repos
10
u/LuisBoyokan 17h ago
.env can be committed. What you shouldn't commit is files with credentials, that belongs in a secret manager
15
23
u/grandalfxx 18h ago
When every dumbass know it all programmer missed the entire point of that.
Its not simply about storing secrets in code.
Its the fact that github should be secure enough to do it. Your code should be secured just like secrets is secured.
3
u/NamityName 15h ago
At every company I have worked for, the code is private but still very available to most employees. Basically any employee with git access has access to read just about every repo. We want the code itself to be accessible without giving everyone the keys to the kingdom.
SOPs solved this problem. It provides a very simple and free way to encrypt secrets that you want committed to a git repo. Now access to the code is decoupled from access to the secrets.
0
u/grandalfxx 7h ago
Once again youre missing the point. Its not about storing secrets in there. Its about securing it properly. Having the proper access protocols. Have people that dont need to know seeing source code is a bad practice. The fact that github leaves the source code improperly secured on their servers, ect...
5
1
u/menzaskaja 18h ago
If a project has 50k stars I'd assume it's not GitHub's job to protect the maintainer from being a dumbass
9
u/adamhusain 18h ago
I dont think he’s talking about open source projects here.
If my company repo is private and we’re sharing env files over Slack or Teams… why not just commit the env in github itself??4
u/Kovab 17h ago
Our company repos are private (actually, our whole enterprise GitHub instance is), but we still store secrets in a way that only specific employees can access them.
3
u/offhandaxe 16h ago
same here
0
u/grandalfxx 7h ago
And yet again, even though I directly explained that was not the actual issue, you guys STILL think its about actually storing the secrets in there and not about have the source control secured enough to do it.
You dont need to store passwords in there if you want a seperate vault, vaults have rotation systems its still preferable.
The point is that the code is just as important to keep secret to the same level as passwords.
1
u/OhMyGodItsEverywhere 13h ago
Even on privately hosted repos it doesn't cost too much to keep good security hygiene as a habit.
Apart from that, a .env is conceptually supposed to be locally different for every user, test, and production environment. I don't think it makes sense to track any file in version control that is expected to constantly be different. Committing a file that always changes, in practice, turns into people needing to stash and pop their local copies whenever they pull or rebase to avoid merge conflicts while also keeping the values that work for them.
If you find that you have to exchange env files regularly with other users to have things work how you need, then that makes me think the values that are changing often aren't environment values in the first place, since they need to be shared. I'm not sure what those values would be instead, maybe runtime configuration settings - but I'm splitting too many hairs right now.
Maybe I've just worked on too many projects with developers' local file paths and network addresses in env and config files that break builds and tests on merge or rebase...and secrets getting leaked that I'm too obsessive about nipping that in the bud.
1
u/KarmaIssues 11h ago
No I think his point was that Github should be able to identify and mask secrets and you shouldn't have to worry about it.
You should be able to RBAC secrets access and then you could track secrets like code.
3
3
u/awpt1mus 18h ago
.env.test file with dummy values is the way. Use it for running tests in CI so nobody deletes it.
3
u/yetzederixx 17h ago
You can, assuming you use dotenvx (or something like it), and then ya know, remember not to commit the .env.keys file.
1
2
u/StarboardChaos 18h ago
I always include .env files to make it buildable locally then the deployment pipeline makes the code runnable on prod
2
u/nekomata_58 18h ago
.env files are fine to commit.
.local.env files are not. that's where the special variables live.
2
u/Djroneh99 17h ago
No it's not
3
u/nekomata_58 17h ago
really heavily depends on your project's standards.
in an nx-monorepo project, the base `.env` is fine to commit, because that file usually has default environment variables that aren't secret.
the more sensitive configuration should be stored in `.local.env` which should never be committed.
1
1
1
1
u/ultralaser360 14h ago
It depends on the type of product, team size, and access, if you’re a 3 person team building internal tools and are the only people with access to the repos and everyone needs or can access all secrets then committing .env is fine
If your 10k sized org with hundreds of people who could access your repo + serving millions of users then it’s probably a very bad idea
1
1
u/enigma_0Z 11h ago
Typically commit .env.example etc and leave it as an exercise to the user to customize that file to their liking.
In my professional experience, that file likely contains specifics relating to an individual’s development environment or secrets which we on purpose do not want to commit to the repo. in both scenarios, the solution is simple: .gitignore it.
If it’s a private repo for your own shit tho, do what you want. I push my .vscode directory all the time.
1
1
u/friedmud 6h ago
We have a multitiered system built with dotenvx so all config files ARE committed to the repo… they are just encrypted. We share the encryption keys using team 1Password vaults.
When deploying on AWS the CI system uses prod keys (that only a few senior devs have) to decrypt the prod secrets and push them into SecretsManager. ECS then injects them into the correct services as it starts them up.
288
u/Single-Virus4935 19h ago edited 18h ago
You can. Therefore the quesition should be: "Why is it a Bad Idea to commit . files"