This solution is general, in that it is useful for both open and closed source applications.
- Create an OS user for your application. See http://en.wikipedia.org/wiki/Principle_of_least_privilege
- Create a (non-session) OS environment variable for that user, with the password
- Run the application as that user
Advantages:
- You won't check your passwords into source control by accident, because you can't
- You won't accidentally screw up file permissions. Well, you might, but it won't affect this.
- Can only be read by root or that user. Root can read all your files and encryption keys anyways.
- If you use encryption, how are you storing the key securely?
- Works x-platform
- Be sure to not pass the envvar to untrusted child processes
This method is suggested by Heroku, who are very successful.