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 specifying explicit kernel release and version for falco-driver-loader #2728

Merged
merged 1 commit into from
Aug 24, 2023

Conversation

johananl
Copy link
Contributor

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind feature

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area build

/area engine

/area tests

/area proposals

/area CI

What this PR does / why we need it:

This PR adds the ability to specify explicit kernel release and version when running falco-driver-loader. This is important in cases where the Falco driver needs to be compiled for a kernel other than the currently-running kernel (such as when the kernel had been updated but not yet booted into).

Which issue(s) this PR fixes:

Fixes #2658

Special notes for your reviewer:

None

Does this PR introduce a user-facing change?:

feat: Allow specifying explicit kernel release and version for falco-driver-loader

Signed-off-by: Johanan Liebermann <jliebermann@microsoft.com>
@poiana
Copy link
Contributor

poiana commented Aug 14, 2023

Welcome @johananl! It looks like this is your first PR to falcosecurity/falco 🎉

@poiana poiana added the size/S label Aug 14, 2023
@FedeDP
Copy link
Contributor

FedeDP commented Aug 14, 2023

/milestone 0.36.0
Thanks for taking the time to tackle this one! We are going to look into it asap!

@poiana poiana added this to the 0.36.0 milestone Aug 14, 2023
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.

Thank you for this!
/approve

@poiana
Copy link
Contributor

poiana commented Aug 22, 2023

LGTM label has been added.

Git tree hash: 15c8df01fe85054ab9832eda5ee00556b1333b84

local -r kernel_version_major=$(uname -r | cut -d. -f1)
local -r kernel_version=$(uname -r | cut -d- -f1)
KERNEL_EXTRA_VERSION="-$(uname -r | cut -d- -f2)"
local -r kernel_version_major=$(echo "${DRIVER_KERNEL_RELEASE}" | cut -d. -f1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be better to use KERNEL_RELEASE here?
I mean, i think we should use KERNEL_RELEASE and KERNEL_VERSION everywhere, not their DRIVER_ counterparts.

Copy link
Member

Choose a reason for hiding this comment

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

Good catch!

Copy link
Contributor Author

@johananl johananl Aug 23, 2023

Choose a reason for hiding this comment

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

The places where I used e.g. DRIVER_KERNEL_RELEASE are places where there was an explicit call to uname -r. Note that the values of KERNEL_RELEASE and KERNEL_VERSION change throughout the script, which can be tricky to follow as there is lots of distro-specific logic and special cases.

In this case, for example, KERNEL_RELEASE may not hold the same value as uname -r at this point in the execution, because we do various assignments to this variable earlier:

KERNEL_RELEASE="${BASH_REMATCH[1]}${ARCH_extra}"

KERNEL_RELEASE="${VERSION_ID}"

This fact is likely the reason uname -r was called here instead of reusing KERNEL_RELEASE.

My idea was to keep existing functionality as is by storing the result of uname -r and uname -v once at the start of the execution (in DRIVER_KERNEL_RELEASE and DRIVER_KERNEL_VERSION, respectively), then reuse these values. This allows specifying explicit release and version values as arguments without altering the entire script.

Does that make sense? Did I miss anything?

Copy link
Contributor Author

@johananl johananl Aug 23, 2023

Choose a reason for hiding this comment

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

FWIW, I think we can make the script easier to maintain by making it more "functional" (as in functional programming) by passing explicit values to functions rather than relying on global variables.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see. It makes sense to me now.

This also adheres to our implicit convention that the DRIVER_ prefix represents input values (those that may be set using env vars), whereas other vars like KERNEL_RELEASE are just for internal use.

👍

Thank you!

N.B.: I've checked the whole PR. Just giving my 2 cents (specifically related to the above comment).

Copy link
Contributor

Choose a reason for hiding this comment

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

Does that make sense? Did I miss anything?

I see! Thank you for the explanation. I think you are right!
Also, i share the same though about making the script more functional. At the same time, we don't probably want to spend much time on this since sooner or later we are going to revamp the script porting it to eg: a go tool (perhaps inside falcoctl?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that makes sense to me.

@johananl
Copy link
Contributor Author

johananl commented Aug 23, 2023

Forgot to mention that I tested my changes by executing the script manually in both modes (kmod and BPF) with default values as well as with explicit kernel release and version on the following distros:

  • Amazon Linux
  • Debian (kmod compilation didn't work for me, but that's true even before my changes)
  • Ubuntu
  • Flatcar (download doesn't work because the driver repo doesn't contain files for Flatcar, bpf compilation didn't work due to Relocate tools on Flatcar in BPF mode #2729 but should work works after rebasing)

If we refactor the script to be functional, we could use something like https://github.com/bats-core/bats-core to unit-test the file.

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 merged commit e7c5139 into falcosecurity:master Aug 24, 2023
@poiana
Copy link
Contributor

poiana commented Aug 24, 2023

[APPROVALNOTIFIER] This PR is APPROVED

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

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:

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

@johananl johananl deleted the specify-kernel-version branch August 24, 2023 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Allow specifying explicit kernel release and version for falco-driver-loader
5 participants