Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log redacted config on config changes #1671

Merged
merged 9 commits into from
Aug 12, 2022
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
- Add start_time and minimum_execution_duration to actions to allow fleet-server to schedule agent actions. {pull}1381[1381]
- Fleet Server now allows setting global labels on APM instrumentation. {pull}1649[1649]
- Fleet Server now allows setting transaction sample rate on APM instrumentation {pull}1681[1681]
- Log redacted config when config updates. {issue}1626[1626] {pull}1668[1668]
25 changes: 21 additions & 4 deletions cmd/fleet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,10 @@ func redactOutputCfg(cfg *config.Config) config.Output {
redacted.Elasticsearch.APIKey = kRedacted
}

if redacted.Elasticsearch.ServiceToken != "" {
redacted.Elasticsearch.ServiceToken = kRedacted
}

if redacted.Elasticsearch.TLS != nil {
newTLS := *redacted.Elasticsearch.TLS

Expand Down Expand Up @@ -621,25 +625,38 @@ func redactServerCfg(cfg *config.Config) config.Server {
return redacted
}

func redactConfig(cfg *config.Config) *config.Config {
redacted := &config.Config{
Fleet: cfg.Fleet,
Output: cfg.Output,
Inputs: make([]config.Input, 1),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having this as cfg.Inputs causes one of the integration tests to fail.

Logging: cfg.Logging,
HTTP: cfg.HTTP,
}
redacted.Inputs[0].Server = redactServerCfg(cfg)
redacted.Output = redactOutputCfg(cfg)
return redacted
}

func configChangedServer(curCfg, newCfg *config.Config) bool {

zlog := log.With().Interface("new", redactServerCfg(newCfg)).Logger()
zlog := log.With().Interface("new", redactConfig(newCfg)).Logger()

changed := true
switch {
case curCfg == nil:
zlog.Info().Msg("initial server configuration")
case !reflect.DeepEqual(curCfg.Fleet, newCfg.Fleet):
zlog.Info().
Interface("old", curCfg).
Interface("old", redactConfig(curCfg)).
Msg("fleet configuration has changed")
case !reflect.DeepEqual(curCfg.Output, newCfg.Output):
zlog.Info().
Interface("old", redactOutputCfg(curCfg)).
Interface("old", redactConfig(curCfg)).
Msg("output configuration has changed")
case !reflect.DeepEqual(curCfg.Inputs[0].Server, newCfg.Inputs[0].Server):
zlog.Info().
Interface("old", redactServerCfg(curCfg)).
Interface("old", redactConfig(curCfg)).
Msg("server configuration has changed")
default:
changed = false
Expand Down