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

build(minimal-build): allow using eBPF driver with minimal builds #1325

Merged
merged 2 commits into from
Sep 29, 2023

Conversation

Molter73
Copy link
Contributor

@Molter73 Molter73 commented Sep 5, 2023

What type of PR is this?

/kind feature

Any specific area of the project related to this PR?

/area build

Does this PR require a change in the driver versions?

What this PR does / why we need it:
Historically, the minimal build was only able to run using the kernel module driver, but since the addition of the modern probe this has also become an option for running with minimal builds. I believe there's value in allowing adopters of the libs to use the minimal build with the eBPF probe.

This change means that scap will always be linked against zlib and libelf, but I believe this is a worthwhile trade off.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@Molter73
Copy link
Contributor Author

Molter73 commented Sep 5, 2023

I know we are in the middle of cutting a release, just wanted to open the PR so I don't forget, we can look into this at a later time.

@Andreagit97
Copy link
Member

Thank you @Molter73 this is really valuable! we will take a look ASAP, probably after the release :/

@Andreagit97 Andreagit97 added this to the 0.14.0 milestone Sep 5, 2023
CMakeLists.txt Outdated
option(MUSL_OPTIMIZED_BUILD "Enable if you want a musl optimized build" OFF)
option(USE_BUNDLED_DRIVER "Use the driver/ subdirectory in the build process (only available in Linux)" ON)
option(ENABLE_DRIVERS_TESTS "Enable driver tests (bpf, kernel module, modern bpf)" OFF)
option(ENABLE_LIBSCAP_TESTS "Enable libscap unit tests" OFF)
option(BUILD_SHARED_LIBS "Build libscap and libsinsp as shared libraries" OFF)
option(ENABLE_VM_TESTS "Enable driver sanity tests" OFF)

option(MINIMAL_BUILD "Produce a minimal build with only the essential features (no eBPF probe driver, no kubernetes, no mesos, no marathon and no container metadata)" OFF)
Copy link
Member

Choose a reason for hiding this comment

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

just a minor note on the fly on which maybe we want to start discussing:

  • What about having a unique MINIMAL_BUILD? Is not clear to me why bpf was excluded in principle 🤔
  • What about enabling also the modern probe in MINIMAL_BUILD? In the end is just another ebpf driver and could be really useful for example in Falco with minimal build because we can test it even if we have no prebuilt drivers

WDYT? @falcosecurity/libs-maintainers

Copy link
Member

Choose a reason for hiding this comment

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

  • What about enabling also the modern probe in MINIMAL_BUILD?

👍

We can also think of including zlib in the minimal build. I don't see it as a huge issue. wdyt?
cc @gnosek

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • What about having a unique MINIMAL_BUILD? Is not clear to me why bpf was excluded in principle 🤔

AFAICT, ebpf was excluded to allow for building without linking to zlib, doesn't seem to be any other reason for this. If we can directly add eBPF into the minimal build, this PR will become a lot smaller.

  • What about enabling also the modern probe in MINIMAL_BUILD?

Because of how everything is setup, it's already possible to set MINIMAL_BUILD and BUILD_LIBSCAP_MODERN_BPF to ON and everything will be setup and work correctly, so no change is needed for this to work (at least when I tried it, it worked this way).

Copy link
Member

Choose a reason for hiding this comment

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

Because of how everything is setup, it's already possible to set MINIMAL_BUILD and BUILD_LIBSCAP_MODERN_BPF to ON and everything will be setup and work correctly, so no change is needed for this to work (at least when I tried it, it worked this way).

oh, great news! never tried! thanks

AFAICT, ebpf was excluded to allow for building without linking to zlib, doesn't seem to be any other reason for this. If we can directly add eBPF into the minimal build, this PR will become a lot smaller.

To be honest i would go for it, so including also zlib, in this way we could avoid yet another cmake option :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to say this out loud, my initial intention was to split the MINIMAL_BUILD into multiple options that could be toggled individually or set them all with MINIMAL_BUILD, but desisted because it would've been a lot of work and I only needed the minimal build to run with eBPF. We can discuss this alternative approach if it's something that would be interesting for the community.

Copy link
Member

Choose a reason for hiding this comment

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

yeah until we don't have a clear use case I would avoid putting this burden on your shoulders :) If we find alternative use cases i would be happy to consider this splitting you proposed!

@gnosek
Copy link
Contributor

gnosek commented Sep 7, 2023

TBH I'm not sure why we even have a dedicated minimal build mode in the first place. Ideally, we'd have feature flags for all the major features that MINIMAL_BUILD disables and then you'd either disable e.g. zlib (which would take eBPF away AIUI) or not, independent from other features.

Until that day comes, 👍 from me, although the checks like https://github.com/falcosecurity/libs/pull/1325/files#diff-3ef409c4a80658bffe80055929e4bfd351c6dc05877b1eb1162b19b76a3c9842R24 start to become ugly

@Molter73
Copy link
Contributor Author

Molter73 commented Sep 7, 2023

Until that day comes, 👍 from me, although the checks like https://github.com/falcosecurity/libs/pull/1325/files#diff-3ef409c4a80658bffe80055929e4bfd351c6dc05877b1eb1162b19b76a3c9842R24 start to become ugly

Yeah, it's ugly as hell, I apologize for it.

@dwindsor
Copy link
Contributor

dwindsor commented Sep 11, 2023

Hello! We definitely need something like this, as we're using the modern eBPF probe in our closed source application - meaning that we have to use MINIMAL_BUILD.

Currently, we're patching userspace/libscap/CMakeLists.txt as such, and it just works:

diff -purN orig/userspace/libscap/CMakeLists.txt patched/userspace/libscap/CMakeLists.txt
--- orig/userspace/libscap/CMakeLists.txt	2023-08-21 10:37:15.177875298 -0500
+++ patched/userspace/libscap/CMakeLists.txt	2023-08-21 10:54:44.366683611 -0500
@@ -21,9 +21,13 @@ option(BUILD_LIBSCAP_MODERN_BPF "Enable
 
 include(ExternalProject)
 
-if(WIN32 OR NOT MINIMAL_BUILD)
-	include(zlib)
-endif()
+#if(WIN32 OR NOT MINIMAL_BUILD OR BUILD_LIBSCAP_MODERN_BPF)
+#	include(zlib)
+#endif()

@Andreagit97
Copy link
Member

If we all agree here, I think we can go with only one MINIMAL_BUILD option which allows:

  • kmod
  • legacy bpf
  • modern bpf

@FedeDP
Copy link
Contributor

FedeDP commented Sep 11, 2023

Fully agree with Andrea! 👍 from me

@Molter73
Copy link
Contributor Author

If the general consensus is that we should just allow all drivers to be used with the MINIMAL_BUILD I'll gladly change the PR, I've already started looking into this.

@Molter73 Molter73 force-pushed the minimal-build-with-ebpf branch from 3bd8be7 to f972b8a Compare September 12, 2023 13:24
@Molter73
Copy link
Contributor Author

I've changed the PR to always link scap against zlib and libelf, as well as always adding the bpf engine. IMO, it's a lot more streamlined, but let me know if you see any downsides to this approach and would like it implemented in some other way.

@FedeDP
Copy link
Contributor

FedeDP commented Sep 12, 2023

I love this, much simplier cmake files too.
I agree with @gnosek : sooner or later we'll want to directly expose BUILD_LIBSCAP_ENGINE_X options, and improve the situation. But today is not that day.
👍 for this approach from me!

Also, we are currently frozen for the 0.13 tag, but are nearing the code thaw; if we all agree, we could merge this one right after the thaw!

@FedeDP
Copy link
Contributor

FedeDP commented Sep 12, 2023

/usr/bin/ld: cannot find -l/usr/lib/x86_64-linux-gnu/libz.so: No such file or directory
/usr/bin/ld: cannot find -l/usr/lib/x86_64-linux-gnu/libelf.so: No such file or directory

😆

@Molter73
Copy link
Contributor Author

/usr/bin/ld: cannot find -l/usr/lib/x86_64-linux-gnu/libz.so: No such file or directory
/usr/bin/ld: cannot find -l/usr/lib/x86_64-linux-gnu/libelf.so: No such file or directory

😆

I really should've seen this coming, shouldn't I? 🤣

@FedeDP
Copy link
Contributor

FedeDP commented Sep 26, 2023

Hi @Molter73 can you rebase this one?

@@ -20,8 +20,6 @@ limitations under the License.
//
#define INCLUDE_UNKNOWN_SOCKET_FDS

#ifndef MINIMAL_BUILD
#define USE_ZLIB
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we drop USE_ZLIB altogether since it is always true now?

Copy link
Contributor

Choose a reason for hiding this comment

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

At least on linux ;) i see it being used in scap_zlib.h as follows:

#if defined(USE_ZLIB) && !defined(UDIG) && !defined(_WIN32)

This can become

#if !defined(UDIG) && !defined(_WIN32)

(also, note that since we might drop udig support per #1368, the check would become even simpler!)

@FedeDP
Copy link
Contributor

FedeDP commented Sep 27, 2023

Hi @Molter73 can you rebase this one?

It seems there is no need :) About my other comment, we can fix that while removing UDIG support IMHO. Not a big deal.

list(APPEND libscap_link_libraries ${install_lib_link_library})
if(${install_lib_link_library} MATCHES "/")
# We have a path. Convert it to -L<dir> + -l<lib>.
get_filename_component(scap_lib_dir ${install_lib_link_library} DIRECTORY)
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

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

/approve

@poiana poiana added the lgtm label Sep 27, 2023
@poiana
Copy link
Contributor

poiana commented Sep 27, 2023

LGTM label has been added.

Git tree hash: 53b3a41d41f70213360d93f21c1dc2d691515589

Historically, the minimal build was only able to run using the kernel
module driver, but since the addition of the modern probe this has also
become an option for running with minimal builds. I believe there's
value in allowing adopters of the libs to use the minimal build with the
eBPF probe.

This change means that scap will always be linked against zlib and
libelf, but I believe this is a worthwhile trade off.

Signed-off-by: Mauro Ezequiel Moltrasio <[email protected]>
Signed-off-by: Mauro Ezequiel Moltrasio <[email protected]>
@Molter73 Molter73 force-pushed the minimal-build-with-ebpf branch from cc1bc28 to 083c886 Compare September 29, 2023 07:57
@poiana poiana removed the lgtm label Sep 29, 2023
@poiana poiana requested a review from FedeDP September 29, 2023 07:57
@Molter73
Copy link
Contributor Author

Just finished rebasing, sorry for the delay, I've had a busy couple of days.

Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

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

/approve

@poiana poiana added the lgtm label Sep 29, 2023
@poiana
Copy link
Contributor

poiana commented Sep 29, 2023

LGTM label has been added.

Git tree hash: abf233cbf6dbef80e89782719ea91f84ea899eee

Copy link
Member

@Andreagit97 Andreagit97 left a comment

Choose a reason for hiding this comment

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

/approve

@poiana
Copy link
Contributor

poiana commented Sep 29, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Andreagit97, FedeDP, Molter73

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [Andreagit97,FedeDP,Molter73]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants