Skip to content

Commit

Permalink
Bugfix: Sort environment variables before processing
Browse files Browse the repository at this point in the history
Environment variables were processed in a non-deterministic order, resulting in equivalent DOPPLER_ and ENCLAVE_ environment variables competing with each other. We now always process ENCLAVE_ variables after DOPPLER_ variables, thereby giving ENCLAVE_ variables precedence. This is done for compatibility reasons.
  • Loading branch information
Piccirello committed Sep 18, 2020
1 parent e8324bb commit f05b061
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/configuration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,20 @@ func LocalConfig(cmd *cobra.Command) models.ScopedOptions {
// environment variables
if !utils.GetBoolFlag(cmd, "no-read-env") {
pairs := models.EnvPairs(&localConfig)
for envVar, pair := range pairs {
envVars := []string{}
for envVar := range pairs {
envVars = append(envVars, envVar)
}

// sort variables so that they are processed in a deterministic order
// this also ensures ENCLAVE_ variables are given precedence over (i.e. read after) DOPPLER_ variables,
// which is necessary for backwards compatibility until we drop support for ENCLAVE_ variables
sort.Strings(envVars)

for _, envVar := range envVars {
envValue := os.Getenv(envVar)
if envValue != "" {
pair := pairs[envVar]
pair.Value = envValue
pair.Scope = "/"
pair.Source = models.EnvironmentSource.String()
Expand Down

0 comments on commit f05b061

Please sign in to comment.