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

Osquerybeat: Strip osqueryd binary for linux #38952

Merged
merged 10 commits into from
Apr 22, 2024

Conversation

aleksmaus
Copy link
Member

@aleksmaus aleksmaus commented Apr 15, 2024

Proposed commit message

Strip osqueryd binary for linux that is unstripped in the official osquery tar.gz distro.
Size reduction
ARM: 273,418,504 -> 78,956,480 bytes
x86: 270,282,072 -> 86,097,240 bytes

Changed dev-tools code for linux crossbuilds.
Noticed that the image docker.elastic.co/beats-dev/golang-crossbuild:1.21.9-arm currently exists for both ARM and x86 archs and is being used randomly, which causes a problem for strip tool when arch of binaries are mismatched with the arch of the tool. This affects only linux builds.

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.

How to test this PR locally

Ensure that everything builds as before. The size of osqueryd is 3x smaller than before on linux OS, currently is under 90M.

Related issues

Screenshots

Before:
Screenshot 2024-04-15 at 2 21 00 PM

After:
Screenshot 2024-04-15 at 12 44 19 PM

@aleksmaus aleksmaus added enhancement Team:Elastic-Agent Label for the Agent team >enhancement Team:Security-Deployment and Devices Deployment and Devices Team in Security Solution labels Apr 15, 2024
@aleksmaus aleksmaus requested review from a team as code owners April 15, 2024 18:31
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent (Team:Elastic-Agent)

@botelastic botelastic bot added needs_team Indicates that the issue/PR needs a Team:* label and removed needs_team Indicates that the issue/PR needs a Team:* label labels Apr 15, 2024
@botelastic
Copy link

botelastic bot commented Apr 15, 2024

This pull request doesn't have a Team:<team> label.

Copy link
Contributor

mergify bot commented Apr 15, 2024

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @aleksmaus? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

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

Copy link
Member

@cmacknz cmacknz left a comment

Choose a reason for hiding this comment

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

Thanks!

@elasticmachine
Copy link
Collaborator

elasticmachine commented Apr 15, 2024

💚 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 preview

Expand to view the summary

Build stats

  • Duration: 140 min 12 sec

❕ Flaky test report

No test was executed to be analysed.

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

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.

I ask that this be changed to support agentbeat as well as osquerybeat. Agentbeat must also ship with osqueryd or the osquerybeat subcommand will not work.

See this PR for the changes to make it work with agentbeat - #38951

@aleksmaus
Copy link
Member Author

Updated PR in order to address agentbeat build as well.

Screenshot 2024-04-16 at 2 20 31 PM

Couple of things worth mentioning:

  1. Needed to have the "strip" called from within the container the arch of the binary and the "strip" tool have to match otherwise it fails complaining on the binary architecture, so kept the stripping in GolangCrossBuild still
  2. Didn't see a good way to detect if the crossbuild was initiated from osquerybeat or agentbeat. The build/install directory where osqueryd is unpacked is different. So the script now searched in two locations for osqueryd binary: osquerybeat and if not found agentbeat.

Copy link
Contributor

mergify bot commented Apr 17, 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 feature/strip_linux_oquerybeat upstream/feature/strip_linux_oquerybeat
git merge upstream/main
git push upstream feature/strip_linux_oquerybeat

@blakerouse
Copy link
Contributor

With agentbeat merged, lets get the conflicts resolved and then I can take a better look.

@aleksmaus
Copy link
Member Author

Picked up the latest main, resolved conflicts, improved code slightly

@cmacknz cmacknz added the backport-v8.14.0 Automated backport with mergify label Apr 18, 2024
@cmacknz
Copy link
Member

cmacknz commented Apr 18, 2024

Adding the backport-v8.14 label, IMO not stripping osqueryd is a bug.

@aleksmaus
Copy link
Member Author

Adding the backport-v8.14 label, IMO not stripping osqueryd is a bug.

Or a feature upstream ;-)

}

return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this still here? The code has changed to not need this specifically in osquerybeat.

Copy link
Member Author

Choose a reason for hiding this comment

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

This a mistake on conflict resolution (context switching), the function is not used. Removed.

if err := stripLinuxOsqueryd(); 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.

How does this work for agentbeat? Agentbeat doesn't import the magefile from osquerybeat.

Copy link
Member Author

Choose a reason for hiding this comment

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

This works because agent beat calls out to osquerybeat to build the extension

return callForBeat("crossBuildExt", "osquerybeat")

This path is also followed for stanalone osquerybeat crossbuild.

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.

Okay. I forgot I did it that way. ;-)

Copy link
Contributor

@pkoutsovasilis pkoutsovasilis left a comment

Choose a reason for hiding this comment

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

As stripping the osqueryd binary goes this LGTM! but I am not familiar with AgentBeat and I can't guarantee that nothing erupts there but I trust @aleksmaus comment here

@cmacknz cmacknz merged commit ddddf80 into elastic:main Apr 22, 2024
171 of 188 checks passed
mergify bot pushed a commit that referenced this pull request Apr 22, 2024
* Osquerybeat: Strip osqueryd binary for linux

* Improve code comment, fix a typo

* Address code review request to make it compatible with agentbeat build

* Remove unused function

(cherry picked from commit ddddf80)
@amitkanfer
Copy link
Collaborator

Sweet!!

dliappis added a commit to dliappis/beats that referenced this pull request Apr 23, 2024
cmacknz pushed a commit that referenced this pull request Apr 23, 2024
* Osquerybeat: Strip osqueryd binary for linux

* Improve code comment, fix a typo

* Address code review request to make it compatible with agentbeat build

* Remove unused function

(cherry picked from commit ddddf80)

Co-authored-by: Aleksandr Maus <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v8.14.0 Automated backport with mergify enhancement >enhancement Team:Elastic-Agent Label for the Agent team Team:Security-Deployment and Devices Deployment and Devices Team in Security Solution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Package stripped osqueryd executable with osquerybeat on all platforms
6 participants