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

Support overriding configuration via environment variables / additional config files #6218

Closed
duckfullstop opened this issue Feb 12, 2023 · 13 comments
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@duckfullstop
Copy link
Contributor

Is your feature request related to a problem? Please describe.
A common problem encountered when running any software in a container is how to handle passing secrets to the container. At present, secrets are stored in the main configuration file, which means that committing the configuration to public repositories (or even private ones) would leak any and all secrets.

At present, thanks to @andig's e220091, there is support for overriding most configuration using the environment (e.g EVCC_MQTT.PASSWORD - but it is not possible to override things such as the vehicles entry (i.e you can't do EVCC_VEHICLES[0].PASSWORD.

Describe the solution you'd like
There's a few possible options for alleviating this:

  • Allow overriding of configuration arrays via environment variables (for example, EVCC_VEHICLE_NAME, EVCC_VEHICLE_PASSWORD, or maybe something like EVCC_VEHICLE_superexpensivetesla_PASSWORD) - this would require specific lookups on each key by hand
  • Allow special configuration values that causes a lookup from the environment, e.g password: ENV_VEHICLE_PASSWORD would check VEHICLE_PASSWORD
    • We can't use the evcc_ space because that's already used for Viper's configuration overloading (as e220091)
  • Allow for loading multiple configuration files, e.g evcc.yaml and secrets.yaml, then merge them to produce a final in-memory configuration that can be used freely
    • e.g secrets.yaml may contain its own Vehicles configuration

All of these methods have their upsides and downsides, hence why I'm raising this as an issue for further discussion instead of going straight to PR.

Describe alternatives you've considered
Treating my entire configuration file as a secret isn't ideal, as it means I'm obscuring a large part of my infrastructure from my public repositories.

Additional context
Discussed in Slack: https://evccgroup.slack.com/archives/C01321PUJAD/p1676019600376789

@StefanSchoof
Copy link
Contributor

Related #405

@andig
Copy link
Member

andig commented Feb 12, 2023

there is support for overriding most configuration using the environment

is that really true? That would already be great, but I didnt test it yet. Does that really work when reading from the unmarshaled config struct or does it require using the viper functions for reading?

@andig andig added the enhancement New feature or request label Feb 13, 2023
@duckfullstop
Copy link
Contributor Author

duckfullstop commented Feb 13, 2023

@andig Yup, try setting EVCC_SITE.TITLE in your environment and it'll override whatever's in your config (at runtime)!

@andig
Copy link
Member

andig commented Feb 14, 2023

Wow, that's better then I thought. Seems I can remove any calls to viper.Get... and replace them with accessing the global config like everywhere else. That is really good news as it makes the code more consistent. Always wanted to experiment but never got around to try it.

For this issue the solution should be within Viper, I'd suggest to add an issue there:

EVCC_VEHICLE_0_PASSWORD

should work for things that are slices.

@andig andig added the wontfix This will not be worked on label Feb 14, 2023
@goebelmeier

This comment was marked as off-topic.

@andig

This comment was marked as off-topic.

@StefanSchoof
Copy link
Contributor

There are some issues on viper that sound similar: spf13/viper#761 spf13/viper#935

@andig andig closed this as completed Feb 16, 2023
@andig
Copy link
Member

andig commented Feb 17, 2023

@andig Yup, try setting EVCC_SITE.TITLE in your environment and it'll override whatever's in your config (at runtime)!

@duckfullstop OT, but

EVCC_DATABASE_DSN=/tmp/foo.db3 evcc

doesn't work for me.

Update solution:

viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))

@duckfullstop
Copy link
Contributor Author

@andig Yup, try setting EVCC_SITE.TITLE in your environment and it'll override whatever's in your config (at runtime)!

@duckfullstop OT, but

EVCC_DATABASE_DSN=/tmp/foo.db3 evcc

doesn't work for me.

Did you try EVCC_DATABASE.DSN? For whatever reason viper wants periods in the middle of environment variables

@andig
Copy link
Member

andig commented Feb 17, 2023

See #6286. . doesn't work art least on mac.

@andig
Copy link
Member

andig commented Aug 16, 2023

Also not recent comments like #9363 (reply in thread)

@StefanSchoof
Copy link
Contributor

Es wurde gerade spf13/viper#1429 gemergt. Möglicherweise lässt sich das Problem jetzt lösen.

@andig
Copy link
Member

andig commented Dec 6, 2023

Lustig- die Notification hab ich auch bekommen. Steht auf meiner Todoliste :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants