Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[8.x](backport #5864) Feature/4890 detect fail early upgrade #5978

Merged
merged 1 commit into from
Nov 13, 2024

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Nov 8, 2024

  • Enhancement

What does this PR do?

This PR restricts using the cli to upgrade fleet managed elastic agents. With this implementation, the only way to upgrade a fleet managed agent using the cli is only if the agent is running in privileged mode and the user provides a force flag.

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/fragments using the changelog tool
  • [ ] I have added an integration test or an E2E test

Disruptive User Impact

If users are upgrading fleet-managed agents using the cli for some reason, they should be aware that the upgrade command will stop working for agents running in unprivileged mode. For any fleet managed agents running in privileged mode, users will need to go through an interactive step and use the --force flag to be able to upgrade an agent.

How to test this PR locally

Setup

  • Create an ESS deployment
  • Go to fleet and click add agent
  • Create a new policy if there isn't already one
  • Build the agent locally by running DEV=true SNAPSHOT=true mage build
  • Uncompress the tar
  • If there isn't an agent on your machine already just execute the provided command on fleet ui
  • If there is already an agent on your machine add --develop flag to your installation command

Test cases

Unprivileged

  • Add --unprivileged flag to your installation command
  • Ensure that the agent is enrolled
  • Run sudo -u elastic-agent-user elastic-development-agent upgrade <VERSION>. The command should not execute.
  • Make sure that --force flag does not change the behavior

Privileged

  • Install the agent and make sure that it is enrolled
  • Run sudo elastic-development-agent upgrade <VERSION>. The command should not execute
  • Run the same command with --force flag sudo elastcit-development-agent upgrade <VERSION> --force.
  • Confirm the prompted message. Agent upgrade should start

Related issues


This is an automatic backport of pull request #5864 done by [Mergify](https://mergify.com).

* feature(4890): added shouldUpgrade function in the upgrade cli file

* feature(4890): added shouldUpgrade check into the upgrade command

* feature(4890): ran gofmt

* feature(4890): added a "force" flag, marked it as hidden

* feature(4890): removed dpkg, rpm and container logic

* feature(4890): ran gofmt

* feature(4890): updated the function signature of the upgrade command, updated tests, added new tests

* feature(4890): update comments

* feature(4890): added changelog fragment

* feature(4890): added fatal log in case there is an error while marking force flag as hidden

* feature(4890): added error checks in tests

* feature(4890): updated the summary in the changelog fragment

* feature(4890): removed the shorthand flag for the force flag

* feature(4890): updated synchronization in the tests

* Update internal/pkg/agent/cmd/upgrade_test.go

Co-authored-by: Paolo Chilà <paolo.chila@elastic.co>

* feature(4890): using streams err output instead of defaulting to stderr

* feature(4890): use EXPECT instead of On

* feature(4890): moved unconfirmed upgrade error to a package var

* feature(4890): removed confirmation from upgrade check for when force flag is set

* Update internal/pkg/agent/cmd/upgrade.go

Co-authored-by: Paolo Chilà <paolo.chila@elastic.co>

* Update internal/pkg/agent/cmd/upgrade.go

Co-authored-by: Paolo Chilà <paolo.chila@elastic.co>

* feature(4890): fix errors

* Update internal/pkg/agent/cmd/upgrade.go

Co-authored-by: Craig MacKenzie <craig.mackenzie@elastic.co>

* feature(4890): update test

* fearure(4890): replace ageninfo with state call

- updated agentinfo proto
- updated relevant generated code
- implemented state call in the upgrade cmd

* feature(4890): updated proto, client and server implementation

* feature(4890): fix struct tag

* feature(4890): added skip-verify checks

* feature(4890): ran addLicenseHeaders

* feature(4890): ran mage clean

* feature(4890): fix typo

* feature(4890): added timeout to connection

* feature(4890): changed condition check order

* feature(4890): fix unit tests

* feature(4890): refactored tests, using mock client

* Update internal/pkg/agent/cmd/upgrade.go

Co-authored-by: Andrzej Stencel <andrzej.stencel@elastic.co>

* feature(4890): use lower case "f" in error messages to be more consistent

* feature(4890): remove duplicate line

* feature(4890): ran mage controlProto with correct protoc version

---------

Co-authored-by: Paolo Chilà <paolo.chila@elastic.co>
Co-authored-by: Craig MacKenzie <craig.mackenzie@elastic.co>
Co-authored-by: Andrzej Stencel <andrzej.stencel@elastic.co>
(cherry picked from commit 8579474)
@mergify mergify bot requested a review from a team as a code owner November 8, 2024 08:36
@mergify mergify bot added the backport label Nov 8, 2024
@mergify mergify bot requested review from pkoutsovasilis and swiatekm and removed request for a team November 8, 2024 08:36
@michalpristas michalpristas added the Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team label Nov 8, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane)

Copy link

Quality Gate failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 40%)

See analysis details on SonarQube

Copy link
Contributor Author

mergify bot commented Nov 11, 2024

This pull request has not been merged yet. Could you please review and merge it @kaanyalti? 🙏

@kaanyalti kaanyalti merged commit 8e61536 into 8.x Nov 13, 2024
15 of 16 checks passed
@kaanyalti kaanyalti deleted the mergify/bp/8.x/pr-5864 branch November 13, 2024 14:27
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
backport 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.

4 participants