From 8f6a97b81b6d9eec63b70324218c29ad7bf1b42a Mon Sep 17 00:00:00 2001 From: hghaf099 <83242695+hghaf099@users.noreply.github.com> Date: Fri, 1 Apr 2022 10:34:27 -0400 Subject: [PATCH] Vault-4279 reporting redundant/unused keys in config (#14752) * Vault-4279 reporting redundant/unused keys in config * missing validate step * CL * Change the log level --- changelog/14752.txt | 3 +++ command/server.go | 22 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 changelog/14752.txt diff --git a/changelog/14752.txt b/changelog/14752.txt new file mode 100644 index 000000000..3cc5fd0f3 --- /dev/null +++ b/changelog/14752.txt @@ -0,0 +1,3 @@ +```release-note:bug +core: report unused or redundant keys in server configuration +``` diff --git a/command/server.go b/command/server.go index 85a846521..e27f31d93 100644 --- a/command/server.go +++ b/command/server.go @@ -428,7 +428,7 @@ func (c *ServerCommand) parseConfig() (*server.Config, []configutil.ConfigError, } func (c *ServerCommand) runRecoveryMode() int { - config, _, err := c.parseConfig() + config, configErrors, err := c.parseConfig() if err != nil { c.UI.Error(err.Error()) return 1 @@ -458,6 +458,11 @@ func (c *ServerCommand) runRecoveryMode() int { JSONFormat: logFormat == logging.JSONFormat, }) + // reporting Errors found in the config + for _, cErr := range configErrors { + c.logger.Warn(cErr.String()) + } + // Ensure logging is flushed if initialization fails defer c.flushLog() @@ -1071,7 +1076,7 @@ func (c *ServerCommand) Run(args []string) int { config.Listeners[0].Telemetry.UnauthenticatedMetricsAccess = true } - parsedConfig, _, err := c.parseConfig() + parsedConfig, configErrors, err := c.parseConfig() if err != nil { c.UI.Error(err.Error()) return 1 @@ -1116,6 +1121,11 @@ func (c *ServerCommand) Run(args []string) int { }) } + // reporting Errors found in the config + for _, cErr := range configErrors { + c.logger.Warn(cErr.String()) + } + // Ensure logging is flushed if initialization fails defer c.flushLog() @@ -1539,6 +1549,7 @@ func (c *ServerCommand) Run(args []string) int { // Check for new log level var config *server.Config var level hclog.Level + var configErrors []configutil.ConfigError for _, path := range c.flagConfigs { current, err := server.LoadConfig(path) if err != nil { @@ -1546,6 +1557,8 @@ func (c *ServerCommand) Run(args []string) int { goto RUNRELOADFUNCS } + configErrors = append(configErrors, current.Validate(path)...) + if config == nil { config = current } else { @@ -1559,6 +1572,11 @@ func (c *ServerCommand) Run(args []string) int { goto RUNRELOADFUNCS } + // reporting Errors found in the config + for _, cErr := range configErrors { + c.logger.Warn(cErr.String()) + } + core.SetConfig(config) // reloading custom response headers to make sure we have