-
Couldn't load subscription status.
- Fork 2.1k
Description
Preflight Checklist
- I have searched the issue tracker for an issue that matches the one I want to file, without success.
Problem Description
Hello
We use this tool in our applications to configure them but we have found a gap running on Kubernetes. Kubernetes supports setting secrets as environment variables but there is a component known as "Secrets CSI Driver" which is based on providing secrets as files but not in a yaml format or so.
This component generates a file per secret using the secret name as file name and secret content as file content. Although it's technically possible to provide a yaml/json file as secret content, usually secrets are stored one by one on cloud secret vaults and mounted one by one into the Kubernetes pods (the component handles it to add all the files needed)
Proposed Solution
I'd like to propose a new configuration "remote config" system based on reading multiple files, binding a single key from each file. For example, this directory
/mnt/secrets
->mySecrets.secretA # (content: ValueForA)
->mySecrets.secretB # (content: ValueForB)
->appSecret # (content: ValueForAppSecret)Would be treated as:
mySecrets:
secretA: ValueForA
secretB: ValueForB
appSecret: ValueForAppSecretAdditionally, to not enforce strange local setups, this config source should be optional, not failing if the folder doesn't exist on the local machine.
Alternatives Considered
No response
Additional Information
Currently, we are achieving the same behaviour with this function:
func setValuesFromFiles(keyPerFilePath string) error {
if keyPerFilePath == "" {
return nil
}
files, err := os.ReadDir(keyPerFilePath)
if err != nil {
return err
}
for _, file := range files {
if !file.IsDir() {
content, err := os.ReadFile(path.Join(keyPerFilePath, file.Name())) //nolint: gosec // this is intended
if err != nil {
return err
}
// Replace __ with . to generate the hierarchy
viper.Set(strings.ReplaceAll(file.Name(), "__", "."), string(content))
}
}
return nil
}where basically we pass a path and include all the files as keys with the content as value.
This is enough for us but it's error prone when we need to add the code to each project. That's why we would like to contribute to this awesome tool adding the support for Kubernetes Secret CSI driver with a native configuration support