flipt
flipt copied to clipboard
[FLI-907] config: add ability to specify env vars
Problem
Currently, Flipt supports configuration via YAML or ENV vars (https://www.flipt.io/docs/configuration/overview). Environment variables override config files. Env var keys that Flipt supports comes directly from the keys of the YAML config.
What we don't currently allow is specifying env vars in the conf file format.
Why this could be a problem is the env var keys become exceptionally long depending on how deeply nested the corresponding YAML config is. Example:
authentication.methods.oidc.providers.github.client_id
in YAML becomes FLIPT_AUTHENTICATION_METHODS_OIDC_PROVIDERS_GITHUB_CLIENT_ID
as an env var.
Ideal Solution
It would be nice if we could provide a 'shortcut' for specifying configuration in YAML that would allow users to specify env var keys that we should look in for the correct value.
Ie: "${env:FLIPT_GITHUB_CLIENT_ID}"
This would allow users to swap in whatever env var keys they want and we could look for those values at startup, failing fast if we cant find the env var value.
Search
- [X] I searched for other open and closed issues before opening this
Additional Context
Since we use Viper for config parsing, I think we could use some of the tactics described in this blog post: https://sagikazarmark.hu/blog/decoding-custom-formats-with-viper/ to decode a value that follows with the above format ${env:value}
💯 we already extensively used custom decoder hooks. So it could be added here:
https://github.com/flipt-io/flipt/blob/19a5acc55ad771fb6e906423f0541c33a7f5b0b6/internal/config/config.go#L21-L30
It could likely be implemented as one that maps from string to string.