Nginx – What are the best practices for exporting secrets (passwords, keys) to the environment of systemd managed services

environment-variablesnginxSecuritysystemd

What are the best practices for managing account credentials and SHA256
secrets and providing them to systemd managed services?

In the old init.d way, I'd just install a script in /etc/default that gets sourced. From there I could import whatever content I want into environment variables which are then available to my services.

So my question is, what is considered "best practice" for providing logind id/password credentials and other "secrets" to systemd managed services? Is passing it via the environment considered "good" or is there an accepted better/more secure way?

(i.e. what is the best place to put your service (e.g. mysql) passwords, SHA256 secrets, etc and how do you most effectively communicate those to long running background services that need it? Is there a better managed way than setting them in the environment before processes are launched by systemd?)

Best Answer

I don't there's one right way to pass secure credentials with systemd. The Environment= and EnvironmentFile= directives are definitely there to help pass environment variables, similar to older init systems. If you are looking for a direct translation of what you used to do, that's it.

Your app might also use it's own config system like node-config for Node.js. The config package may then in turn provide further alternatives for managing secrets. As an example, node-config can also load values from environment variables, but it's also possible to work git-crypt, to work with values that have been stored encrypted in Git.

Some things to be aware of with environment variables: Even if you don't keep the environment variables you set in a file, if you pass them to a process when it's started up, the environment variables and their values may be found in file names like /proc/27/environ on Linux, for users to have permissions to read the file. These "start up environment" values persist there even if the process later deletes them.

If you do load environment variables into an apps configuration system, considering having the process delete the environment variables from process once they are in the configuration system. Then at least if you have the sensitive information in one less place.

Related Topic