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 1464628 commit 7135cdc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 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
```
23 changes: 20 additions & 3 deletions command/server.go
Expand Up @@ -427,7 +427,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 @@ -457,6 +457,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 @@ -1066,7 +1071,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 @@ -1111,6 +1116,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 @@ -1213,7 +1223,6 @@ func (c *ServerCommand) Run(args []string) int {
info["log level"] = logLevelString
infoKeys = append(infoKeys, "log level")
barrierSeal, barrierWrapper, unwrapSeal, seals, sealConfigError, err := setSeal(c, config, infoKeys, info)

// Check error here
if err != nil {
c.UI.Error(err.Error())
Expand Down Expand Up @@ -1520,13 +1529,16 @@ func (c *ServerCommand) Run(args []string) int {
// Check for new log level
var config *server.Config
var level log.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 @@ -1540,6 +1552,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)

if config.LogLevel != "" {
Expand Down

0 comments on commit 7135cdc

Please sign in to comment.