mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-30 02:02:43 +00:00 
			
		
		
		
	Log environment variable keys at startup (#18125)
* Log environment variable keys at startup * run make fmt * change name * add changelog * fix changelog nubmer * fix title * add test * fix message * Update changelog/18125.txt Co-authored-by: Jason O'Donnell <2160810+jasonodonnell@users.noreply.github.com> * add trace test * remove check for >= debug, trace * Update changelog/18125.txt Co-authored-by: Jason O'Donnell <2160810+jasonodonnell@users.noreply.github.com> Co-authored-by: Jason O'Donnell <2160810+jasonodonnell@users.noreply.github.com>
This commit is contained in:
		
							
								
								
									
										3
									
								
								changelog/18125.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								changelog/18125.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | ```release-note:improvement | ||||||
|  | command/server: Environment variable keys are now logged at startup. | ||||||
|  | ``` | ||||||
| @@ -1168,6 +1168,21 @@ func (c *ServerCommand) Run(args []string) int { | |||||||
| 	info := make(map[string]string) | 	info := make(map[string]string) | ||||||
| 	info["log level"] = config.LogLevel | 	info["log level"] = config.LogLevel | ||||||
| 	infoKeys = append(infoKeys, "log level") | 	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) | 	barrierSeal, barrierWrapper, unwrapSeal, seals, sealConfigError, err := setSeal(c, config, infoKeys, info) | ||||||
| 	// Check error here | 	// Check error here | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|   | |||||||
| @@ -203,63 +203,70 @@ func TestServer(t *testing.T) { | |||||||
| 		contents string | 		contents string | ||||||
| 		exp      string | 		exp      string | ||||||
| 		code     int | 		code     int | ||||||
| 		flag     string | 		args     []string | ||||||
| 	}{ | 	}{ | ||||||
| 		{ | 		{ | ||||||
| 			"common_ha", | 			"common_ha", | ||||||
| 			testBaseHCL(t, "") + inmemHCL, | 			testBaseHCL(t, "") + inmemHCL, | ||||||
| 			"(HA available)", | 			"(HA available)", | ||||||
| 			0, | 			0, | ||||||
| 			"-test-verify-only", | 			[]string{"-test-verify-only"}, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			"separate_ha", | 			"separate_ha", | ||||||
| 			testBaseHCL(t, "") + inmemHCL + haInmemHCL, | 			testBaseHCL(t, "") + inmemHCL + haInmemHCL, | ||||||
| 			"HA Storage:", | 			"HA Storage:", | ||||||
| 			0, | 			0, | ||||||
| 			"-test-verify-only", | 			[]string{"-test-verify-only"}, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			"bad_separate_ha", | 			"bad_separate_ha", | ||||||
| 			testBaseHCL(t, "") + inmemHCL + badHAInmemHCL, | 			testBaseHCL(t, "") + inmemHCL + badHAInmemHCL, | ||||||
| 			"Specified HA storage does not support HA", | 			"Specified HA storage does not support HA", | ||||||
| 			1, | 			1, | ||||||
| 			"-test-verify-only", | 			[]string{"-test-verify-only"}, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			"good_listener_timeout_config", | 			"good_listener_timeout_config", | ||||||
| 			testBaseHCL(t, goodListenerTimeouts) + inmemHCL, | 			testBaseHCL(t, goodListenerTimeouts) + inmemHCL, | ||||||
| 			"", | 			"", | ||||||
| 			0, | 			0, | ||||||
| 			"-test-server-config", | 			[]string{"-test-server-config"}, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			"bad_listener_read_header_timeout_config", | 			"bad_listener_read_header_timeout_config", | ||||||
| 			testBaseHCL(t, badListenerReadHeaderTimeout) + inmemHCL, | 			testBaseHCL(t, badListenerReadHeaderTimeout) + inmemHCL, | ||||||
| 			"unknown unit \"km\" in duration \"12km\"", | 			"unknown unit \"km\" in duration \"12km\"", | ||||||
| 			1, | 			1, | ||||||
| 			"-test-server-config", | 			[]string{"-test-server-config"}, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			"bad_listener_read_timeout_config", | 			"bad_listener_read_timeout_config", | ||||||
| 			testBaseHCL(t, badListenerReadTimeout) + inmemHCL, | 			testBaseHCL(t, badListenerReadTimeout) + inmemHCL, | ||||||
| 			"unknown unit \"\\xe6\\x97\\xa5\" in duration", | 			"unknown unit \"\\xe6\\x97\\xa5\" in duration", | ||||||
| 			1, | 			1, | ||||||
| 			"-test-server-config", | 			[]string{"-test-server-config"}, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			"bad_listener_write_timeout_config", | 			"bad_listener_write_timeout_config", | ||||||
| 			testBaseHCL(t, badListenerWriteTimeout) + inmemHCL, | 			testBaseHCL(t, badListenerWriteTimeout) + inmemHCL, | ||||||
| 			"unknown unit \"lbs\" in duration \"56lbs\"", | 			"unknown unit \"lbs\" in duration \"56lbs\"", | ||||||
| 			1, | 			1, | ||||||
| 			"-test-server-config", | 			[]string{"-test-server-config"}, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			"bad_listener_idle_timeout_config", | 			"bad_listener_idle_timeout_config", | ||||||
| 			testBaseHCL(t, badListenerIdleTimeout) + inmemHCL, | 			testBaseHCL(t, badListenerIdleTimeout) + inmemHCL, | ||||||
| 			"unknown unit \"gophers\" in duration \"78gophers\"", | 			"unknown unit \"gophers\" in duration \"78gophers\"", | ||||||
| 			1, | 			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() | 			f.Close() | ||||||
| 			defer os.Remove(f.Name()) | 			defer os.Remove(f.Name()) | ||||||
|  |  | ||||||
| 			code := cmd.Run([]string{ | 			args := append(tc.args, "-config", f.Name()) | ||||||
| 				"-config", f.Name(), |  | ||||||
| 				tc.flag, | 			code := cmd.Run(args) | ||||||
| 			}) |  | ||||||
| 			output := ui.ErrorWriter.String() + ui.OutputWriter.String() | 			output := ui.ErrorWriter.String() + ui.OutputWriter.String() | ||||||
|  |  | ||||||
| 			if code != tc.code { | 			if code != tc.code { | ||||||
| 				t.Errorf("expected %d to be %d: %s", code, tc.code, output) | 				t.Errorf("expected %d to be %d: %s", code, tc.code, output) | ||||||
| 			} | 			} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Ellie
					Ellie