Fix panic in GetClientConfig with null agent options config (#47388)#48584
Conversation
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
WalkthroughThis change fixes a server panic in Changes
Sequence Diagram(s)Not applicable. Related issues: Suggested labels: bug, server Suggested reviewers: fleetdm/server-team 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Warning
- Copilot's review of this pull request may be incomplete because some of the changed files are excluded by your Copilot content exclusion settings. See Excluding content from Copilot for details.
Pull request overview
Fixes a server panic in Service.GetClientConfig when resolved agent options contain a JSON null config, causing json.Unmarshal to set the target map to nil and later assignments (e.g. adding packs) to panic.
Changes:
- Add a post-unmarshal nil guard to re-initialize the config map in
GetClientConfig. - Add a regression test covering
{"config":null}agent options plus packs/scheduled queries. - Add a user-visible changes entry (content excluded by policy).
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| server/service/osquery.go | Re-initializes config after unmarshalling when null would otherwise nil out the map. |
| server/service/osquery_test.go | Adds regression coverage ensuring no panic and correct packs serialization with a null agent-options config. |
| changes/47388-getclientconfig-nil-map-panic | Release-note entry for the bugfix (diff content excluded by policy). |
Files excluded by content exclusion policy (1)
- changes/47388-getclientconfig-nil-map-panic
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CI Feedback 🧐A test triggered by this PR failed. Here is an AI-generated analysis of the failure:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #48584 +/- ##
==========================================
+ Coverage 67.99% 68.01% +0.01%
==========================================
Files 3678 3678
Lines 233668 233760 +92
Branches 12304 12304
==========================================
+ Hits 158894 158984 +90
- Misses 60471 60477 +6
+ Partials 14303 14299 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Related issue: Resolves #47388
I'll be doing some separate research on how agent options ends up as
nullin the first place.Obviously you can set
config:in the agent options and hitSaveand the issue is reproduced but seems unlikely (one theory is GitOps doing some overriding).Checklist for submitter
changes/,orbit/changes/oree/fleetd-chrome/changes.See Changes files for more information.
Summary
GetClientConfig(server/service/osquery.go) panicked withassignment to entry in nil map(returning 5XX on/api/v1/osquery/config) when a host's resolved agent options had a nullconfig.Root cause:
configis initialized as an empty map, butjson.Unmarshal([]byte("null"), &config)silently sets the map tonil(no error). When the host also had packs or scheduled queries, the laterconfig["packs"] = ...assignment panicked.This adds a nil-guard that re-initializes the map after the unmarshal.
Testing
Added
TestGetClientConfigNullConfig, which sets{"config":null}agent options plus a pack and asserts no panic/error and thatpacksstill serialize correctly.Summary by CodeRabbit