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

Ensure that the connecting Elastic Agent is a supported version. #239

Merged
merged 5 commits into from
Apr 15, 2021

Conversation

blakerouse
Copy link
Contributor

What does this PR do?

Adds checks to the enrollment and checkin API to ensure that the User-Agent header is correct for an Elastic Agent. This verifies that the version of the Elastic Agent is a support version.

This does allow an Elastic Agent to be on a higher patched version than the Fleet Server, but not higher on the MAJOR.MINOR.

Why is it important?

Older Elastic Agents will not work correctly with new Fleet Server, so they need to not connect to the Fleet Server.

Checklist

  • My code follows the style guidelines of this project
  • 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.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Related issues

@blakerouse blakerouse added Team:Elastic-Agent Label for the Agent team v7.13.0 labels Apr 14, 2021
@blakerouse blakerouse self-assigned this Apr 14, 2021
@elasticmachine
Copy link
Contributor

elasticmachine commented Apr 14, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: Pull request #239 updated

  • Start Time: 2021-04-15T13:22:04.920+0000

  • Duration: 5 min 36 sec

  • Commit: 7eb7b4f

Test stats 🧪

Test Results
Failed 0
Passed 95
Skipped 0
Total 95

Trends 🧪

Image of Build Times

Image of Tests

Copy link
Contributor

@aleksmaus aleksmaus left a comment

Choose a reason for hiding this comment

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

couple of nits, otherwise lgtm

if err != nil {
return err
}

Copy link
Contributor

Choose a reason for hiding this comment

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

question: should we validate after the metric that counts checkin calls?
@scunningham what was the purpose of the counter? should it include all checkin calls or just authenticated and validated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I put it before the metric in both check-in and enroll. Can change in follow up if needed.

@@ -79,6 +81,7 @@ type CheckinT struct {
}

func NewCheckinT(
verCon version.Constraints,
Copy link
Contributor

Choose a reason for hiding this comment

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

are we always going to have the version constraint?
if not not then make it option function?
nit: the number of params in the constructor "is too darn high" :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes we should always have it

if len(segments) > 2 {
segments = segments[:2]
}
segments = append(segments, int(^uint(0)>>1)) // max int
Copy link
Contributor

Choose a reason for hiding this comment

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

math.MaxInt32

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

didn't know about it, will change to that

return ErrInvalidUserAgent
}
userAgent = strings.ToLower(userAgent)
if !strings.HasPrefix(userAgent, "elastic agent ") {
Copy link
Contributor

Choose a reason for hiding this comment

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

const prefix = "elastic agent "

?
could be local to func
cause it is used in two places

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do

@blakerouse blakerouse merged commit 91af65a into elastic:master Apr 15, 2021
@blakerouse blakerouse deleted the ensure-agent-version branch April 15, 2021 14:00
mergify bot pushed a commit that referenced this pull request Apr 15, 2021
* Ensure that the connecting Elastic Agent is a supported version.

* Revert change to fleet-server.yml

* Fix added space in fleet-server.yml.

* Fixes from code review.

* Update go.mod.

(cherry picked from commit 91af65a)
mergify bot added a commit that referenced this pull request Apr 15, 2021
… (#242)

* Ensure that the connecting Elastic Agent is a supported version.

* Revert change to fleet-server.yml

* Fix added space in fleet-server.yml.

* Fixes from code review.

* Update go.mod.

(cherry picked from commit 91af65a)

Co-authored-by: Blake Rouse <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Elastic-Agent Label for the Agent team v7.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validate Elastic Agent compatibility
3 participants