diff --git a/changelog/18125.txt b/changelog/18125.txt new file mode 100644 index 000000000..5d9f05a91 --- /dev/null +++ b/changelog/18125.txt @@ -0,0 +1,3 @@ +```release-note:improvement +command/server: Environment variable keys are now logged at startup. +``` \ No newline at end of file diff --git a/command/server.go b/command/server.go index be9caa322..7f6a34b43 100644 --- a/command/server.go +++ b/command/server.go @@ -1168,6 +1168,21 @@ func (c *ServerCommand) Run(args []string) int { info := make(map[string]string) info["log level"] = config.LogLevel infoKeys = append(infoKeys, "log level") + + // returns a slice of env vars formatted as "key=value" + envVars := os.Environ() + var envVarKeys []string + for _, v := range envVars { + splitEnvVars := strings.Split(v, "=") + envVarKeys = append(envVarKeys, splitEnvVars[0]) + } + + sort.Strings(envVarKeys) + + key := "environment variables" + info[key] = strings.Join(envVarKeys, ", ") + infoKeys = append(infoKeys, key) + barrierSeal, barrierWrapper, unwrapSeal, seals, sealConfigError, err := setSeal(c, config, infoKeys, info) // Check error here if err != nil { diff --git a/command/server_test.go b/command/server_test.go index e19b499e2..18add1d23 100644 --- a/command/server_test.go +++ b/command/server_test.go @@ -203,63 +203,70 @@ func TestServer(t *testing.T) { contents string exp string code int - flag string + args []string }{ { "common_ha", testBaseHCL(t, "") + inmemHCL, "(HA available)", 0, - "-test-verify-only", + []string{"-test-verify-only"}, }, { "separate_ha", testBaseHCL(t, "") + inmemHCL + haInmemHCL, "HA Storage:", 0, - "-test-verify-only", + []string{"-test-verify-only"}, }, { "bad_separate_ha", testBaseHCL(t, "") + inmemHCL + badHAInmemHCL, "Specified HA storage does not support HA", 1, - "-test-verify-only", + []string{"-test-verify-only"}, }, { "good_listener_timeout_config", testBaseHCL(t, goodListenerTimeouts) + inmemHCL, "", 0, - "-test-server-config", + []string{"-test-server-config"}, }, { "bad_listener_read_header_timeout_config", testBaseHCL(t, badListenerReadHeaderTimeout) + inmemHCL, "unknown unit \"km\" in duration \"12km\"", 1, - "-test-server-config", + []string{"-test-server-config"}, }, { "bad_listener_read_timeout_config", testBaseHCL(t, badListenerReadTimeout) + inmemHCL, "unknown unit \"\\xe6\\x97\\xa5\" in duration", 1, - "-test-server-config", + []string{"-test-server-config"}, }, { "bad_listener_write_timeout_config", testBaseHCL(t, badListenerWriteTimeout) + inmemHCL, "unknown unit \"lbs\" in duration \"56lbs\"", 1, - "-test-server-config", + []string{"-test-server-config"}, }, { "bad_listener_idle_timeout_config", testBaseHCL(t, badListenerIdleTimeout) + inmemHCL, "unknown unit \"gophers\" in duration \"78gophers\"", 1, - "-test-server-config", + []string{"-test-server-config"}, + }, + { + "environment_variables_logged", + testBaseHCL(t, "") + inmemHCL, + "Environment Variables", + 0, + []string{"-test-verify-only"}, }, } @@ -278,11 +285,11 @@ func TestServer(t *testing.T) { f.Close() defer os.Remove(f.Name()) - code := cmd.Run([]string{ - "-config", f.Name(), - tc.flag, - }) + args := append(tc.args, "-config", f.Name()) + + code := cmd.Run(args) output := ui.ErrorWriter.String() + ui.OutputWriter.String() + if code != tc.code { t.Errorf("expected %d to be %d: %s", code, tc.code, output) }