Skip to content

Conversation

@mergify
Copy link
Contributor

@mergify mergify bot commented Nov 6, 2025

What is the problem this PR solves?

Handles a possible error in loading the model.Agent where the components field might be invalid JSON or a string (due to another bug). This changes the code to be more defensive, also should do less on parsing the components model when that is not needed.

How does this PR solve the problem?

Changes the components field to be a json.RawMessage that does two things. One it stops it from being parsed when the model.Agent is loaded from elasticsearch, which happens often and will reduce the time it takes to parse this field. Two, it stops that field from erroring to be unmarshalled when it is an invalid format.

How to test this PR locally

mage unitTest does a great job of covering it.

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
  • I have added an entry in ./changelog/fragments using the changelog tool

Related issues

* Handle malformatted JSON in .fleet-agents components field.

* Add changelog.

* Add logs and update test to use require.

(cherry picked from commit f9dbe41)

# Conflicts:
#	internal/pkg/api/handleCheckin.go
@mergify mergify bot added backport conflicts There is a conflict in the backported pull request labels Nov 6, 2025
@mergify mergify bot requested a review from a team as a code owner November 6, 2025 20:45
@mergify mergify bot requested review from pchila and ycombinator November 6, 2025 20:45
@mergify
Copy link
Contributor Author

mergify bot commented Nov 6, 2025

Cherry-pick of f9dbe41 has failed:

On branch mergify/bp/9.1/pr-5858
Your branch is up to date with 'origin/9.1'.

You are currently cherry-picking commit f9dbe41.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   changelog/fragments/1762447389-fix-issue-where-malformed-components-field-prevents-agent-authentication.yaml
	modified:   internal/pkg/api/handleCheckin_test.go
	modified:   internal/pkg/model/schema.go
	modified:   model/schema.json

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   internal/pkg/api/handleCheckin.go

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@prodsecmachine
Copy link

prodsecmachine commented Nov 6, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Licenses 0 0 0 0 0 issues
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions github-actions bot added the Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team label Nov 6, 2025
@michalpristas michalpristas merged commit 53f8e32 into 9.1 Nov 7, 2025
11 checks passed
@michalpristas michalpristas deleted the mergify/bp/9.1/pr-5858 branch November 7, 2025 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport conflicts There is a conflict in the backported pull request Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants