From 94eef992f1837f74648ffa0da98d8df9cf9e787d Mon Sep 17 00:00:00 2001 From: hamid ghaf Date: Tue, 29 Mar 2022 06:15:10 -0700 Subject: [PATCH 1/4] Vault-4279 reporting redundant/unused keys in config --- command/server.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/command/server.go b/command/server.go index 85a846521b878..207187d3f00a8 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.Error(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.Error(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 { @@ -1559,6 +1570,11 @@ func (c *ServerCommand) Run(args []string) int { goto RUNRELOADFUNCS } + // reporting Errors found in the config + for _, cErr := range configErrors { + c.logger.Error(cErr.String()) + } + core.SetConfig(config) // reloading custom response headers to make sure we have From a76a463642847006cfbef37e2b8a6c699e633e8b Mon Sep 17 00:00:00 2001 From: hamid ghaf Date: Tue, 29 Mar 2022 06:18:01 -0700 Subject: [PATCH 2/4] missing validate step --- command/server.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/command/server.go b/command/server.go index 207187d3f00a8..134d04ea96031 100644 --- a/command/server.go +++ b/command/server.go @@ -1557,6 +1557,8 @@ func (c *ServerCommand) Run(args []string) int { goto RUNRELOADFUNCS } + configErrors = append(configErrors, current.Validate(path)...) + if config == nil { config = current } else { From d7ac348e50641bab3856259f5e9526994c772847 Mon Sep 17 00:00:00 2001 From: hamid ghaf Date: Tue, 29 Mar 2022 06:27:08 -0700 Subject: [PATCH 3/4] CL --- changelog/14752.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/14752.txt diff --git a/changelog/14752.txt b/changelog/14752.txt new file mode 100644 index 0000000000000..3cc5fd0f37d46 --- /dev/null +++ b/changelog/14752.txt @@ -0,0 +1,3 @@ +```release-note:bug +core: report unused or redundant keys in server configuration +``` From 3014cfbbb12ced8a238d25dfd6b9d82beda8e7e2 Mon Sep 17 00:00:00 2001 From: hamid ghaf Date: Tue, 29 Mar 2022 08:07:14 -0700 Subject: [PATCH 4/4] Change the log level --- command/server.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/command/server.go b/command/server.go index 134d04ea96031..e27f31d93f7ac 100644 --- a/command/server.go +++ b/command/server.go @@ -460,7 +460,7 @@ func (c *ServerCommand) runRecoveryMode() int { // reporting Errors found in the config for _, cErr := range configErrors { - c.logger.Error(cErr.String()) + c.logger.Warn(cErr.String()) } // Ensure logging is flushed if initialization fails @@ -1123,7 +1123,7 @@ func (c *ServerCommand) Run(args []string) int { // reporting Errors found in the config for _, cErr := range configErrors { - c.logger.Error(cErr.String()) + c.logger.Warn(cErr.String()) } // Ensure logging is flushed if initialization fails @@ -1574,7 +1574,7 @@ func (c *ServerCommand) Run(args []string) int { // reporting Errors found in the config for _, cErr := range configErrors { - c.logger.Error(cErr.String()) + c.logger.Warn(cErr.String()) } core.SetConfig(config)