Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux - securing environment variables

Just wondering if there is any way to secure the environment variables in a *nix system such that they can not be read from any plain text file, but is available in the environment.

I know we can always use filesystem level permissions for .bashrc/.bash_profile, but what if certain variables (like db passwords) are to be hidden completely?

One way to do would be to write some sort of program/perl script to:

  1. Take inputs from a plain text file and encrypt/hash the content (and then get rid of the plain text file)
  2. Use the same to decrypt the file runtime and export the values from the decrypted output (I know this program can be used to dump the decrypted values somewhere, but I am not concerned about that right now)

Is there any other better and more obvious way to achieve this?

Thanks!

-Gaurav

like image 253
Gaurav Avatar asked Nov 09 '10 01:11

Gaurav


People also ask

How do I set environment variables permanently in Linux?

To make the change permanent, enter the command PATH=$PATH:/opt/bin into your home directory's . bashrc file. When you do this, you're creating a new PATH variable by appending a directory to the current PATH variable, $PATH .

Can environment variables be encrypted?

Encrypto-env is a cli tool that makes it easy to setup, encrypt, and access environment variables for your personal projects. To encrypt the . env file, an RSA key is used (stored in a pem file). The user can then access the environment variables by specifying the location of the .

Are environment variables more secure than files?

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.

Is it safe to store key in environment variable?

The good practice is to store them in the ConfigVars: they are separated from the code and are 'safe' in case someone gains access to the files of the application. Locally it is ok to use . env (with the package dotenv) but the file is typically never pushed or stored with the application.


1 Answers

No way. Even if you hide it from text file, it is still available from /proc/<pid>/environ (linux) or ps e (other unix).

like image 181
J-16 SDiZ Avatar answered Oct 03 '22 03:10

J-16 SDiZ