[8.17](backport #6329) Prevent leaking secrets when logging component model #6383
+93
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Implements
MarshalJSON
method on thecomponent.Component
struct, so that when the component model is logged, the output does not contain any secrets that might be part of the component model (e.g. API keys to HTTP endpoints etc.).This change also restores the debug log dumping the component model that was removed in #5201.
Why is it important?
This is part of the effort to prevent leaking secrets in logs as much as possible.
Checklist
[ ] I have commented my code, particularly in hard-to-understand areas[ ] I have made corresponding changes to the documentation[ ] I have made corresponding change to the default configuration files[ ] I have added tests that prove my fix is effective or that my feature works./changelog/fragments
using the changelog tool[ ] I have added an integration test or an E2E testHow to test this PR locally
go build .
)agent.logging.level
todebug
inelastic-agent.yml
filesudo ./elastic-agent
)The output I'm seeing is:
{"log.level":"debug","@timestamp":"2024-12-13T13:40:20.271Z","log.origin":{"function":"github.com/elastic/elastic-agent/internal/pkg/agent/application/coordinator.(*Coordinator).refreshComponentModel","file.name":"coordinator/coordinator.go","file.line":1403},"message":"Updating running component model","log":{"source":"elastic-agent"},"components":[{"ID":"system/metrics-default","InputType":"system/metrics","OutputType":"elasticsearch","ErrMsg":"input not supported","Units":[{"ID":"system/metrics-default-unique-system-metrics-input"},{"ID":"system/metrics-default"}]},{"ID":"filestream-monitoring","InputType":"filestream","OutputType":"elasticsearch","ErrMsg":"input not supported","Units":[{"ID":"filestream-monitoring-filestream-monitoring-agent"},{"ID":"filestream-monitoring"}]},{"ID":"beat/metrics-monitoring","InputType":"beat/metrics","OutputType":"elasticsearch","ErrMsg":"input not supported","Units":[{"ID":"beat/metrics-monitoring-metrics-monitoring-beats"},{"ID":"beat/metrics-monitoring"}]},{"ID":"http/metrics-monitoring","InputType":"http/metrics","OutputType":"elasticsearch","ErrMsg":"input not supported","Units":[{"ID":"http/metrics-monitoring-metrics-monitoring-agent"},{"ID":"http/metrics-monitoring"}]}],"ecs.version":"1.6.0"}
Here's the formatted and JSON-sorted version of this debug log:
logged component model - after change
Here's the same debug log before MarshalJSON was implemented - note that it includes details like
"api_key": "example-key"
, which is not present in the modified output.logged component model - before change