-
Notifications
You must be signed in to change notification settings - Fork 82
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
Add ability to enroll with a specific ID #4290
base: main
Are you sure you want to change the base?
Conversation
After chatting with @blakerouse over slack we should fail the enrollment of this "new" agent if the policy has temper protection enabled. |
Changes so far look good to me, waiting for updates relevant to @jlind23's comment above to approve |
model/openapi.yml
Outdated
If another agent is enrolled with the same ID the other agent will no longer be able to communicate, | ||
this new agent is considered a replacement of the other agent. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a pretty big change from our discussion.
Please also add a sentence saying the (replaced) agent will still be able to send data into ES
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a slight change, because it is not possible to get an API key token again after the initial create. That made me have no choice to change the behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did add more as requested to the description of this field to inform that it will still allow data to flow.
See #4226 (comment) |
@jlind23 @michel-laterman @kaanyalti I have updated this PR based on the discuss I had with @jlind23 about security with this feature. This PR now includes an additional |
Except a small ending of a trace-span the code changes look good to me. I understand the potential pitfalls with this feature and definitely see how the |
@pkoutsovasilis @michalpristas I updated the PR with the request fixes. Thanks for the reviews. |
Quality Gate passedIssues Measures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for resolving comment. one question about behavior other than that I'm ok with the change.
i let you decide how you want to address the point i raised in this iteration
return nil, err | ||
} | ||
|
||
if agent.Id != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can it return agent.id == ""
? if not this if statement is not needed.
if so. we dont have this case handled as this should not be the same as empty ID when req.ID
is not used.
we whould probably not continue with empty id, probably we should fail. generating a new one breaks the purpose of providing it via req.id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It absolutely will return an agent.id == ""
. This happens when we check to see if an existing agent already exists with that ID. The ErrNotFound will not be returned from _checkAgent
, it will return nil
error and this will be `agent.id == "".
What is the problem this PR solves?
This solves an issue where an Elastic Agent is being replaced with a new Elastic Agent instance for the same host, pod, or workload. This allows the enrolling Elastic Agent to tell the ID that it wants to use, that ID can be currently in-use and this enrollment will take over the record of that Elastic Agent. To take off the existing Elastic Agent both the original and the new enrollment must use the same
replace_token
during the enrollment. This ensures that the original enrollment informs Fleet Server that it can be replaced, and ensures that the replacement has the same token to perform the replacement.How does this PR solve the problem?
It solves the issue by taking a new
id
field in the enroll HTTP request. Thatid
is then used as the Elastic Agent ID and determines if this is a new Elastic Agent or if it should take over an existing Elastic Agent record.How to test this PR locally
At the moment the integration tests are the best way to test this, as the ability to use this field has not been exposed yet on the Elastic Agent.
Design Checklist
Checklist
[ ] I have made corresponding change to the default configuration files(no config changes)./changelog/fragments
using the changelog toolRelated issues