8000 Do not build eBPF non CO-RE object during tracee-ebpf execution by rafaeldtinoco · Pull Request #1273 · aquasecurity/tracee · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Do not build eBPF non CO-RE object during tracee-ebpf execution #1273

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

Merged
merged 10 commits into from
Jan 17, 2022
Merged

Do not build eBPF non CO-RE object during tracee-ebpf execution #1273

merged 10 commits into from
Jan 17, 2022

Conversation

rafaeldtinoco
Copy link
Contributor
@rafaeldtinoco rafaeldtinoco commented Dec 16, 2021

With this commit we have 2 different Makefiles:

  1. builder/Makefile.tracee (responsible for building tracee containers in 3 flavors: core, core-btfhub and nocore). We should have 3 official images:
  • tracee-core
  • tracee-core-btfhub
  • tracee-nocore

In all of them you can opt to execute "tracee" (tracee-ebpf + tracee-rules) by default OR to export a TRACEE_EBPF_ONLY=1 variable and have them running as "tracee-ebpf" only.

$ make -f builder/Makefile.tracee help

To generate tracee container(s):

    $ make -f builder/Makefile.tracee build-alpine-tracee-core
    $ make -f builder/Makefile.tracee build-alpine-tracee-core-btfhub
    $ make -f builder/Makefile.tracee build-alpine-tracee-nocore

To execute tracee container(s):

    $ make -f builder/Makefile.tracee run-alpine-tracee-core
    $ make -f builder/Makefile.tracee run-alpine-tracee-nocore

To execute tracee-ebpf container(s):

    $ make -f builder/Makefile.tracee run-alpine-tracee-ebpf-core
    $ make -f builder/Makefile.tracee run-alpine-tracee-ebpf-nocore

Note:

You may provide arguments to executions using ARG variable

Example:

    $ make -f builder/Makefile.tracee build-alpine-tracee-core-btfhub

    $ make -f builder/Makefile.tracee \
          run-alpine-tracee-ebpf-core \
          ARG="--debug -trace event!='sched*'"
  1. builder/Makefile.tracee-make (responsible for creating a building & execution controlled environment using 2 distributions: alpine & ubuntu).
$ make -f builder/Makefile.tracee-make help

To create an alpine-tracee-make container:

    $ make -f builder/Makefile.tracee-make alpine-prepare

To create an ubuntu-tracee-make container:

    $ make -f builder/Makefile.tracee-make ubuntu-prepare

To execute an alpine-tracee-make shell:

    $ make -f builder/Makefile.tracee-make alpine-shell

To execute an ubuntu-tracee-make shell:

    $ make -f builder/Makefile.tracee-make ubuntu-shell

Examples:

    $ make -f builder/Makefile.tracee-make ubuntu-make ARG="clean"
    $ make -f builder/Makefile.tracee-make ubuntu-make ARG="bpf-core"
    $ make -f builder/Makefile.tracee-make ubuntu-make ARG="tracee-ebpf"

Tell tracee-make to do STATIC builds:

    $ STATIC=0 make -f builder/Makefile.tracee-make alpine-make ARG="tracee-ebpf"
    $ STATIC=1 make -f builder/Makefile.tracee-make alpine-make ARG="tracee-ebpf"

Regarding the Makefile.tracee (responsible for the container images generation), here is an example on how it works:

$ make -f builder/Makefile.tracee build-alpine-tracee-core
$ make -f builder/Makefile.tracee run-alpine-tracee-core
docker run --privileged --pid=host \
	-v /etc/os-release:/etc/os-release-host:ro \
	-e LIBBPFGO_OSRELEASE_FILE=/etc/os-release-host \
	-e TRACEE_EBPF_ONLY=0 \
	--rm -it tracee \

starting tracee-ebpf...
starting tracee-rules...
Loaded 14 signature(s): [TRC-1 TRC-13 TRC-2 TRC-14 TRC-3 TRC-11 TRC-9 TRC-4 TRC-5 TRC-12 TRC-8 TRC-6 TRC-10 TRC-7]

*** Detection ***
Time: 2022-01-10T21:19:23Z
Signature ID: TRC-2
Signature: Anti-Debugging
Data: map[]
Command: strace
Hostname: fujitsu

@rafaeldtinoco rafaeldtinoco marked this pull request as ready for review December 16, 2021 03:06
@yanivagman
Copy link
Collaborator

I think that adding the builder image (Dockerfile) should be part of this PR (or a different PR that will be merged before this one) as we are now removing this functionality here. WDYT?

@yanivagman
Copy link
Collaborator

Also, this one can safely close #959

@rafaeldtinoco
Copy link
Contributor Author
rafaeldtinoco commented Dec 16, 2021

I think that adding the builder image (Dockerfile) should be part of this PR (or a different PR that will be merged before this one) as we are now removing this functionality here. WDYT?

Yes, I'm currently working on that as we speak (will finish tomorrow most likely). I should have kept this as draft, sorry. But it's good for an initial screening anyways.

@rafaeldtinoco rafaeldtinoco linked an issue Dec 16, 2021 that may be closed by this pull request
@rafaeldtinoco rafaeldtinoco marked this pull request as draft December 17, 2021 04:18
@rafaeldtinoco
Copy link
Contributor Author

I still need to add the build logic (to generate tracee container AND a builder container, capable of compiling tracee.bpf.noncore.o.

@rafaeldtinoco rafaeldtinoco marked this pull request as ready for review December 21, 2021 03:10
Copy link
Contributor
@danielpacak danielpacak left a comment

Choose a reason for hiding this comment

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

👋 @rafaeldtinoco LGTM! Except fakeCapabilities and tests for unused methods. See my comment.

From now on, it is the user responsibility to have the non CO-RE eBPF
object correctly placed in "/tmp/tracee" directory. Tracee will load
it, instead of CO-RE eBPF object, as a last resource if there is no:

    1. BTF file pointed by TRACEE_BTF_FILE environment variable
    2. Embedded BTF available in running kernel (/sys/kernel/btf/vmlinux)
    3. BTF file embedded into "tracee-ebpf" binary (from BTFhub)

User might use "make" to install the non CO-RE object:

    $ make -f Makefile.one install-bpf-nocore

And observe BPF object from /tmp/tracee being used, if needed, just like:

    $ sudo ./dist/tracee-ebpf --debug --trace 'event!=sched*'

    OSInfo: ARCH: x86_64
    OSInfo: VERSION: "20.04.3 LTS (Focal Fossa)"
    OSInfo: ID: ubuntu
    OSInfo: ID_LIKE: debian
    OSInfo: PRETTY_NAME: "Ubuntu 20.04.3 LTS"
    OSInfo: VERSION_ID: "20.04"
    OSInfo: VERSION_CODENAME: focal
    OSInfo: KERNEL_RELEASE: 5.8.0-63-generic
    BTF: bpfenv = false, btfenv = false, vmlinux = false
    BPF: no BTF file was found or provided, trying non CO-RE eBPF at
         /tmp/tracee/tracee.bpf.5_8_0-63-generic.v0_6_5-20-g3353501.o

If you're willing to generate the non CO-RE eBPF object using the
tracee-make container, you're able to by doing:

    $ make -f builder/Makefile.docker alpine-prepare # use ubuntu also
    $ make -f builder/Makefile.docker alpine-shell   # use ubuntu also

and then, inside the docker container:

    tracee@f65bab137305[/tracee]$ make -f Makefile.one clean
    tracee@f65bab137305[/tracee]$ make -f Makefile.one tracee-ebpf
    tracee@f65bab137305[/tracee]$ make -f Makefile.one install-bpf-nocore

    tracee@f65bab137305[/tracee]$ sudo ./dist/tracee-ebpf --debug --trace 'event!=sched*'

    KConfig: warning: could not check enabled kconfig features
    (could not read /boot/config-5.8.0-63-generic: ...)
    KConfig: warning: assuming kconfig values, might have unexpected behavior
    OSInfo: KERNEL_RELEASE: 5.8.0-63-generic
    OSInfo: ARCH: x86_64
    OSInfo: VERSION: "21.04 (Hirsute Hippo)"
    OSInfo: ID: ubuntu
    OSInfo: ID_LIKE: debian
    OSInfo: PRETTY_NAME: "Ubuntu 21.04"
    OSInfo: VERSION_ID: "21.04"
    OSInfo: VERSION_CODENAME: hirsute
    BTF: bpfenv = false, btfenv = false, vmlinux = false
    BPF: no BTF file was found or provided
    BPF: trying non CO-RE eBPF at /tmp/tracee/tracee.bpf.5_8_0-63-generic.v0_6_5-20-g0b921b1.o
    KConfig: warning: assuming kconfig values, might have unexpected behavior
    TIME             UID    COMM             PID     TID     RET ...
Dockerfile to build tracee-core & tracee-nocore containers.
This change allows the creation of a Makefile.tracee which will be
responsible for creating tracee containers.
Create a Makefile for tracee container creation. These containers will,
eventually, become the default containers for distribution (once
Makefile.one becomes standard building mechanism).
This upgrade is needed since we've bumped minimum golang version from
1.16 to 1.17. I'm using the default versions that either come with
alpine or ubuntu, so we just need upgrade the "tracee-make" environment.
This change makes it possible to have 3 containers generated:

1. tracee		# uses CO-RE by default
2. tracee-btfhub	# uses CO-RE by default and has embedded BTFs
3. tracee-nocore	# does not use CO-RE eBPF object (builds it)

The "tracee" container is the "slim" version and "tracee-nocore" is the
fat version of tracee (sort of speak).

If you want to execute "tracee-ebpf" instead of full tracee, those 3
flavors allow you to do so by exporting: TRACEE_EBPF_ONLY=1 environment
variable to docker. With that, the entrypoint will be changed
automatically to execute "tracee-ebpf" instead of "tracee".
@rafaeldtinoco
Copy link
Contributor Author

@danielpacak I have fixed the test you pointed out. I have included a tiny fix for "test-tracee-rules" build target (missing a \ at end of line).

@rafaeldtinoco rafaeldtinoco merged commit 9d60228 into aquasecurity:main Jan 17, 2022
@rafaeldtinoco rafaeldtinoco deleted the nocore-nobuild branch January 17, 2022 15:27
@yanivagman
Copy link
Collaborator
yanivagman commented Jan 17, 2022

Go it. However, I'd separate Dockerfile and Makefiles that are absolutely necessary to perform tracee release from build artifacts that are used more for compatibility testing. WDYT? I'm afraid that one day a "release manager" might be overwhelmed with the number of build config files.

Agree. I also think it is a little confusing that a makefile named builder/Makefile.tracee is used to build the containers as the name doesn't imply it (while builder/Makefile.tracee-make is used for a regular build).

@yanivagman
Copy link
Collaborator
yanivagman commented Jan 17, 2022

Sorry for my late comment, but I think that README-no-CORE.md file should be part of the documentation, as it is a "breaking change" for some environments.
In addition, I would also add a few words about using TRACEE_BPF_FILE to override all the other options when using the non-core bpf object

@rafaeldtinoco
Copy link
Contributor Author

@yanivagman agreed. I still have to "document" the new building schema in an "official way". Adding an issue (to include @danielpacak and his drawing as well).

@yanivagman
Copy link
Collaborator

One more thing - we probably don't need to embed the bpf sources anymore, right?

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