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

falco-driver-loader - break apart logic and improvements #1200

Merged
merged 4 commits into from
May 18, 2020

Conversation

leogr
Copy link
Member

@leogr leogr commented May 8, 2020

What type of PR is this?

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

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

/kind feature

If contributing rules or changes to rules, please make sure to also uncomment one of the following line:

/kind rule-update

/kind rule-create

Any specific area of the project related to this PR?

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

/area build

/area engine

/area examples

/area rules

/area integrations

/area tests

/area proposals

What this PR does / why we need it:
See #1193

Which issue(s) this PR fixes:

Fixes #1193
Fixes #1125 (again)

Special notes for your reviewer:

Usage:
  falco-driver-loader [driver] [options]

Available drivers:
  module        kernel module (default)
  bpf           eBPF probe

Options:
  --help        show brief help
  --compile     try to compile the driver locally
  --download    try to download a prebuilt driver

With no options and arguments, it preserves the previous behavior (we should test it deeply).

Notable improvements in messages:

  • All info messages start with * Message...
  • Success messages with * Success: message...
  • Messages without * represent the output of another program or an error
  • Verbosity increased

/cc @kris-nova
/cc @leodido
/cc @fntlnz

falco-driver-loader (pre refactoring behavior)

Preflight check:

  • if not root, then exit 1
  • if not curl, then exit 1

module

Preflight check:

  • if not lsmod, then exit 1
  • if not modprobe, then exit 1
  • if not rmmod, then exit 1
  1. Unload module, if present
  2. If module still loaded, then exit 0
  3. If UEK host, then
    • do nothing
      else
    • if dkms install and insmod then exit 0
  4. if modprobe module, then exit 0
  5. if unsupported OS, then exit 1 (see get_target_id)
  6. if ~/.falco/falco_<target_id>_<kernel_release>_<kernel_version>.ko, then:
    • if insmod then exit 0, else exit 1
  7. if curl module, then
    • if insmod then exit 0, else exit 1
      else
    • exit 1
  8. exit 0

bpf

Preflight check:

  • Mount debugfs (continue on error)
  • if kernel config not found, exit 1 (see get_kernel_config)
  • if unsupported OS, then exit 1 (see get_target_id)
  1. if NOT ~/.falco/falco_<target_id>_<kernel_release>_<kernel_version>.o, then go to step 6.
    • if COS, MINKUBE, or BPF_USE_LOCAL_KERNEL_SOURCES then download kernel source
      • if download failed, then exit 1
      • customize_kernel_build
    • make bpf probe to ~/.falco/falco_<target_id>_<kernel_release>_<kernel_version>.o
  2. if NOT ~/.falco/falco_<target_id>_<kernel_release>_<kernel_version>.o,
    • curl bpf probe (continue on error)
  3. if ~/.falco/falco_<target_id>_<kernel_release>_<kernel_version>.o, then
    • if symlink to ~/.falco/falco-bpf.o then exit 0, else exit 1
      else
    • exit 1
  4. exit 0

N.B.: bpf exists with 0 even though curl failed (see step 2.)

Does this PR introduce a user-facing change?:

update(scripts): improve `falco-driver-loader` output messages
new(scripts): options and command-line usage for `falco-driver-loader`

scripts/falco-driver-loader Outdated Show resolved Hide resolved
Copy link
Member

@leodido leodido left a comment

Choose a reason for hiding this comment

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

SGTM but need time to verify it a bit more.

Left one comment, thanks! 🎉

scripts/falco-driver-loader Outdated Show resolved Hide resolved
@leogr leogr force-pushed the update/falco-driver-loader branch from 1713e86 to 7a594ba Compare May 11, 2020 09:14
@leogr leogr requested a review from leodido May 11, 2020 09:18
Copy link
Member

@leodido leodido left a comment

Choose a reason for hiding this comment

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

As said this looks mostly good.

The only thing I'm not really sure about is the usage of check_skip_load to circuit-break only the load phase of the drivers (not their installation).

So, implemented in this way, what's the use case of --skip-load? Maybe I'm missing something..

@leogr leogr force-pushed the update/falco-driver-loader branch from 7a594ba to 70b0d0b Compare May 11, 2020 10:10
@leogr
Copy link
Member Author

leogr commented May 11, 2020

The only thing I'm not really sure about is the usage of check_skip_load to circuit-break only the load phase of the drivers (not their installation).

So, implemented in this way, what's the use case of --skip-load? Maybe I'm missing something..

My thought when I saw the proposal in the issue was... we might need this for testing purposes only. Ofc, Falco will not work if --skip-load is used.

Should we remove it?

Copy link
Contributor

@fntlnz fntlnz left a comment

Choose a reason for hiding this comment

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

It's very hard for me to review this one.
Commit 70b0d0b contains many things that spans from formatting to adjusting old logic to new logic.

Even if looking at the PR it looks good to me it's very hard to me to spot a possible error here.

This script is fragile for many reasons:

  • Does not have any tests
  • Contains lots of OS specific logic
  • It's used virtually by every user using Falco in a container

@leogr
Copy link
Member Author

leogr commented May 11, 2020

Hey @fntlnz
I'm working on tests, so we can add them.

That being said, really important design question: after talking with @leodido I believe we should remove the --skip-load option. WDYT?
If you agree on to remove it too, I will remove it ASAP.

@leogr leogr force-pushed the update/falco-driver-loader branch from 70b0d0b to 5631bd8 Compare May 11, 2020 12:14
@leodido
Copy link
Member

leodido commented May 11, 2020

I think --skip-load flag should be removed: it adds more complexity than it removes.

The --download and --compile flags are pretty explanatory and they cover the use cases

My 2 cents

@leogr leogr force-pushed the update/falco-driver-loader branch from 5631bd8 to 1d375ce Compare May 11, 2020 12:39
@leogr
Copy link
Member Author

leogr commented May 11, 2020

Update:

  • --skip-load has been removed
  • do not continue when epbf download fails

@leogr
Copy link
Member Author

leogr commented May 11, 2020

IMPORTANT

I have noticed that:

	echo "* Trying to load a system ${DRIVER_NAME} driver, if present"
	if modprobe "${DRIVER_NAME}" > /dev/null 2>&1; then
		echo "* Success: ${DRIVER_NAME} module found and loaded with modprobe"
		exit 0
	fi

might load a kernel module that does not fit the installed Falco version. Currently, it happens before trying a local prebuilt and the download strategy, but that should be the last resort.

@leogr leogr force-pushed the update/falco-driver-loader branch 3 times, most recently from 3ec833f to 3439f61 Compare May 15, 2020 17:25
@leogr leogr changed the title wip: falco-driver-loader - break apart logic and improvements falco-driver-loader - break apart logic and improvements May 15, 2020
@leogr
Copy link
Member Author

leogr commented May 15, 2020

Rebased on top of master to include the fix introduced by #1212

I removed WIP, because it's ok for me, though it's not possible to test every single case.

@fntlnz @leodido So, question: do we want this PR to be merged for the 0.23.0?

@leogr leogr force-pushed the update/falco-driver-loader branch from 3439f61 to 2792af2 Compare May 18, 2020 12:35
@leogr
Copy link
Member Author

leogr commented May 18, 2020

Rebased on top of master to include lastest fixes.

@leogr
Copy link
Member Author

leogr commented May 18, 2020

/milestone 0.23.0

@poiana
Copy link
Contributor

poiana commented May 18, 2020

LGTM label has been added.

Git tree hash: 947bf6a4f4a5ca071a6c0ec2bb56c12d1edb4971

@poiana poiana added this to the 0.23.0 milestone May 18, 2020
@poiana poiana merged commit 3d3d537 into master May 18, 2020
@poiana poiana deleted the update/falco-driver-loader branch May 18, 2020 13:17
@poiana
Copy link
Contributor

poiana commented May 18, 2020

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fntlnz, leodido

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

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.

Break apart logic in falco-driver-loader or rename the script falco-driver-loader improvements proposal
4 participants