Search code examples
ruby-on-railsdjangosecuritypasswordsenvironment-variables

Is it secure to store passwords as environment variables (rather than as plain text) in config files?


I work on a few apps in rails, django (and a little bit of php), and one of the things that I started doing in some of them is storing database and other passwords as environment variables rather than plain text in certain config files (or in settings.py, for django apps).

In discussing this with one of my collaborators, he suggested this is a poor practice - that perhaps this isn't as perfectly secure as it might at first seem.

So, I would like to know - is this a secure practice? Is it more secure to store passwords as plain text in these files (making sure, of course, not to leave these files in public repos or anything)?


Solution

  • On a more theoretical level, I tend to think about levels for security in the following ways (in order of increasing strength) :

    • No security. Plain text. Anyone that knows where to look, can access the data.
    • Security by Obfuscation. You store the data (plaintext) someplace tricky, like an environment variable, or in a file that is meant to look like a configuration file. An attacker will eventually figure out what's going on, or stumble across it.
    • Security provided by encryption that is trivial to break, (think caesar cipher!).
    • Security provided by encryption that can be broken with some effort.
    • Security provided by encryption that is impractical to break given current hardware.
    • The most secure system is one that nobody can use! :)

    Environment variables are more secure than plaintext files, because they are volatile/disposable, not saved; i.e. if you set only a local environment variable, like "set pwd=whatever," and then run the script, with something that exits your command shell at the end of the script, then the variable no longer exists. Your case falls into the first two, which I'd say is fairly insecure. If you were going to do this, I wouldn't recommend deploying outside your immediate intranet/home network, and then only for testing purposes.