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

Allow installing a second agent on the same machine for development #4822

Merged
merged 54 commits into from
Jun 20, 2024

Conversation

cmacknz
Copy link
Member

@cmacknz cmacknz commented May 28, 2024

Allows installing or running a second Elastic Agent on the same machine for development using the --develop argument. The core problem this PR aims to solve is allowing agent developers to install a second agent on their machines when there is also an InfoSec managed agent installed. Once installed, the second agent is available with the elastic-development-agent command. I put development in the middle instead of at the end because it makes tab based autocompletion in the shell easier.

I have manually tested that the development agent can enroll with Fleet and upgrade. The changes needed for a second agent are isolated to install time and interacting with the daemon. Features like upgrades and enrolling in Fleet require no changes because they are contained into the agent's installation directory. For this reason I have only added integration tests to ensure installing a second agent alongside an existing one works. We shouldn't need to test anything else as there are no features that reach outside the agent installation directory.

I sanity checked what happens if you install Defend a second time on the same machine to make sure nothing explodes, and it fails immediately in a nice place before the second install is even attempted:

sudo elastic-development-agent status
┌─ fleet
│  └─ status: (HEALTHY) Connected
└─ elastic-agent
├─ status: (DEGRADED) 1 or more components/units in a failed state
└─ endpoint-default
    ├─ status: (FAILED) failed to start connection info service endpoint: failed to start connection credentials listener: listen tcp 127.0.0.1:6788: bind: address already in use
    ├─ endpoint-default
    │  └─ status: (FAILED) failed to start connection info service endpoint: failed to start connection credentials listener: listen tcp 127.0.0.1:6788: bind: address already in use
    └─ endpoint-default-53f5058f-8a9f-460d-b36c-5d4db6131658
        └─ status: (FAILED) failed to start connection info service endpoint: failed to start connection credentials listener: listen tcp 127.0.0.1:6788: bind: address already in use

Reproducing the added README section for instructions on how to install and test:

Development Installations

⚠️ Development installations are not officially supported and are intended for Elastic Agent developers.

If you are an Elastic employee, you already have an Information Security managed Elastic Agent installed on your machine for endpoint protection. This prevents you from installing the Elastic Agent a second time for development without using a VM or Docker container. To eliminate this point of friction, Elastic Agent has a development mode that permits installing the Elastic Agent on your machine a second time:

# All other arguments to the install command are still supported when --develop is specified.
sudo ./elastic-agent install --develop
# The run command also supports the --develop option to allow running without installing when there is another agent on the machine.
./elastic-agent run -e --develop

Using the --develop option will install the agent in an isolated Agent-Development agent directory in the chosen base path.

Development agents enrolled in Fleet will have the Development tag added automatically. Using the default base path on MacOS you will see:

sudo ls /Library/Elastic/
Agent
Agent-Development

The elastic-agent command in the shell is replaced with elastic-development-agent to interact with the development agent:

# For a privileged agent
sudo elastic-development-agent status
# For an unprivileged agent
sudo -u elastic-agent-user elastic-development-agent status

The primary restriction of --develop installations is that you cannot run Elastic Defend a second time on the same machine. Attempting toinstall Defend twice will fail with resource conflicts. All other integrations should be usable provided conflicting configurations are changed ahead of time. For example two agents cannot bind to the same agent.monitoring.http.port to expose their monitoring servers

@cmacknz cmacknz self-assigned this May 28, 2024
Copy link
Contributor

mergify bot commented May 28, 2024

This pull request does not have a backport label. Could you fix it @cmacknz? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v./d./d./d is the label to automatically backport to the 8./d branch. /d is the digit

NOTE: backport-skip has been added to this pull request.

@ycombinator ycombinator added the Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team label May 28, 2024
.golangci.yml Outdated Show resolved Hide resolved
@ycombinator ycombinator removed the request for review from kaanyalti June 11, 2024 22:01
Copy link
Contributor

mergify bot commented Jun 12, 2024

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b second-agent-same-machine upstream/second-agent-same-machine
git merge upstream/main
git push upstream second-agent-same-machine

Copy link
Contributor

mergify bot commented Jun 13, 2024

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b second-agent-same-machine upstream/second-agent-same-machine
git merge upstream/main
git push upstream second-agent-same-machine

Copy link

Quality Gate failed Quality Gate failed

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

See analysis details on SonarQube

@alexsapran
Copy link
Contributor

that would be great, as this is something that would be helpful with the work I am doing.

Having the ability to just download an elastic-agent and just run it locally without installing it.

@cmacknz cmacknz requested a review from blakerouse June 20, 2024 13:32
Copy link
Contributor

@blakerouse blakerouse left a comment

Choose a reason for hiding this comment

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

Looks good thanks for the fixes and the exposing of --namespace optional as a command line option.

@cmacknz
Copy link
Member Author

cmacknz commented Jun 20, 2024

31.3% Coverage on New Code (required ≥ 40%)

I am going to force merge past this, most of the uncovered code is from the conversion of variables into functions and the uncovered code is tested in integration tests.

@cmacknz cmacknz merged commit c6f4133 into elastic:main Jun 20, 2024
12 of 13 checks passed
@cmacknz cmacknz deleted the second-agent-same-machine branch June 20, 2024 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants