Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment variables for sensitive configuration file values #560

Open
tobru opened this issue Oct 30, 2021 · 6 comments
Open

Environment variables for sensitive configuration file values #560

tobru opened this issue Oct 30, 2021 · 6 comments
Labels
feature All about new features sandbox-and-shipping Issues and patches related to sandbox and shipping infrastructure

Comments

@tobru
Copy link
Contributor

tobru commented Oct 30, 2021

The configuration file contains sensitive data like passwords. Is it possible to pass values via environment variables into the configuration of mqttwarn? That would allow me to e.g. share my configuration in public, without having to place passwords into the configuration file.

@jpmens
Copy link
Collaborator

jpmens commented Oct 31, 2021

I don't think this is yet possible, but it is a good idea, and maybe we could take this a step further.

Whenever a password is required in the service code, the service invokes a function pass() with the configured secret. If the secret begins with a special token, we obtain the clear text password appropriately, otherwise, we use the verbatim password.

  1. pass("$ENV:SECRET") would use the value from the environment's $SECRET
  2. pass("$FS:/etc/mysecret") would use the value from the first white-space trimmed line in /etc/mysecret
  3. pass("bla17") would use the password "bla17"

Using these special tokens would mean that in the above example a password must not begin with either $ENV: or with $FS: (regex ^\$[A-Z]+:), but I think we should be able to risk that.

This is also extensible; imagine $ETCD: or $GPG:, etc. Imagination can now run wild.

@tobru
Copy link
Contributor Author

tobru commented Oct 31, 2021

This proposal sounds great, it would extend the possibilities to have sensitive data stored on another (secure) place than the non-sensitive configuration data.

@amotl
Copy link
Member

amotl commented Oct 31, 2021

Hi Tobias and JP,

I also believe this would make a sweet feature, kudos!

Because ConfigParser already has interpolation capabilities [1], with specific examples how to expand environment variables [2,3], I would suggest building this feature on top of this in a generic way instead of having to tweak all service plugins by sprinkling calls to getpass(), or similar.

Attaching to the suggestion by @jpmens to support multiple password backends, I would like to add HashiCorp's Vault to the list. From the perspetive of Salt, where I just happen to have an example at hand, reading secrets from Vault (in this case, a TLS private key) looks like salt['vault'].read_secret('acme/infra/files/www.example.org.key').

With kind regards,
Andreas.

[1] https://docs.python.org/3.6/library/configparser.html#interpolation-of-values
[2] https://newbedev.com/configparser-and-string-interpolation-with-env-variable
[3] https://gist.github.com/malexer/ee2f93b1973120925e8beb3f36b184b8

@amotl amotl added enhancement feature All about new features labels Aug 21, 2022
@amotl amotl added sandbox-and-shipping Issues and patches related to sandbox and shipping infrastructure and removed enhancement labels Sep 20, 2022
@psyciknz
Copy link
Contributor

psyciknz commented Jul 6, 2023

Hello again.
Did this function get shipped? I'm trying to push all keys etc to environment vars, so for example my pushover config, Id like to use the following:

'HomeAssistant' : [ '${PUSHOVER_KEY}', 'apjvopwx2jrqbdzaneh6tzvskq1b84', 'none'],

Where PUSHOVER_KEY is an environment variable for the container. Which I can see when I post an env in the container.
Odd that for the mqtt client name I have
clientid = 'mqttwarn-${HOSTNAME}'
Which gets resolved properly.

@amotl
Copy link
Member

amotl commented Jul 6, 2023

Dear @psyciknz. Thank you for asking. We did not work on this feature yet.

@jhakonen
Copy link
Contributor

I have a need for this feature as well so I've written a pull request (#681) that implements it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature All about new features sandbox-and-shipping Issues and patches related to sandbox and shipping infrastructure
Projects
None yet
Development

No branches or pull requests

5 participants