How do you handle sensitive data like secret API keys, hash salts when you keep your code in a public git repo?
Obviously keeping the sensitive data in the code will compromise it.
Another solution is to not hardcode the secret info in the code, but store it in a stand-alone file and gitignore the file. This has the disadvantage that when someone pulls your code for the first time the secret information will be missing and it won't run out of the box. This can be accounted for by writing a "initialize if missing" routine in the code, but then you're letting the git system slip into your code, which is IMO not a good thing.
And another solution is making a "default" secret information file, commit it at the start of the project and then use your own information without committing it. But this may make git complain that you have un-commited changes when you pull.
So what is the common way to handle this?
The "default" secret information file is a good idea, however, there is no way to avoid the git warnings, even if you ignore the file. From the github help page:
Therefore, adding a "dummy" or "default" file and then ignoring it won't prevent warnings. While the approach will work, it will be inconvenient as you will always have to manually exclude the sensitive file from every commit.
Untracking the file removes it from github, which defeats the purpose of having the file in the first place.
Perhaps the submodule suggestion will work.
Arguably you shouldn't hardcode these properties into your source, since an administrator will want the option to change them on a given system. If these properties are in a properties file (e.g. in your home directory) the problem is solved.
For users that might run into trouble you can check in a defaults file that they can copy to their home folder and modify. If the error messages and README are clear on the subject of missing this particular file this setup will work quite well.
If someone need for their Android project, there is the simplest way I find:
step 1: create: res/values/secrets.xml with:
step 2: use it in code or xml file
or
step 3: add this line into .gitignore file
here is the full article
The best solution would be a private
git submodule
and a public git repository.See this quesiton for more information; a nice quote for you:
Try to use .gitattributes for path with configured encryption/decryption filter:
And in the .git/config add the configuration for crypt filter: