Skip to content

Commit

Permalink
Vault-4279 reporting redundant/unused keys in config (#14752)
Browse files Browse the repository at this point in the history
* Vault-4279 reporting redundant/unused keys in config

* missing validate step

* CL

* Change the log level
  • Loading branch information
hghaf099 committed Apr 1, 2022
1 parent b1012f2 commit 6f6e901
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelog/14752.txt
@@ -0,0 +1,3 @@
```release-note:bug
core: report unused or redundant keys in server configuration
```
22 changes: 20 additions & 2 deletions command/server.go
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -1539,13 +1549,16 @@ 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 {
c.logger.Error("could not reload config", "path", path, "error", err)
goto RUNRELOADFUNCS
}

configErrors = append(configErrors, current.Validate(path)...)

if config == nil {
config = current
} else {
Expand All @@ -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
Expand Down

0 comments on commit 6f6e901

Please sign in to comment.