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

new(pkg,tests): port falco driver loader tests to use falcoctl. #34

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 0 additions & 91 deletions pkg/falcodriverloader/tester.go
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need a falco-driver-loader tester at all now that driver-loader is a feature of falcoctl.

This file was deleted.

24 changes: 0 additions & 24 deletions pkg/falcodriverloader/tester_options.go

This file was deleted.

62 changes: 0 additions & 62 deletions pkg/falcodriverloader/tester_output.go

This file was deleted.

40 changes: 29 additions & 11 deletions tests/falcodriverloader/drivers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ limitations under the License.
package testfalcodriverloader

import (
"github.com/falcosecurity/testing/pkg/falcoctl"
"testing"
"time"

"github.com/falcosecurity/testing/pkg/falco"
"github.com/falcosecurity/testing/pkg/falcodriverloader"
"github.com/falcosecurity/testing/tests"
"github.com/stretchr/testify/assert"
)
Expand All @@ -40,20 +40,29 @@ import (
//
// We need to use the `--compile` flag because we test against dev versions
func TestFalcoLegacyBPF(t *testing.T) {
loaderRes := falcodriverloader.Test(
tests.NewFalcoDriverLoaderExecutableRunner(t),
falcodriverloader.WithArgs("bpf", "--compile"),
// First, configure falcoctl driver
Copy link
Contributor Author

Choose a reason for hiding this comment

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

2 steps:

  • falcoctl driver config --type X
  • falcoctl driver install

configRes := falcoctl.Test(
tests.NewFalcoctlExecutableRunner(t),
falcoctl.WithArgs("driver", "config", "--type", "ebpf"),
)
assert.NoError(t, configRes.Err(), "%s", configRes.Stderr())
assert.Equal(t, 0, configRes.ExitCode())

loaderRes := falcoctl.Test(
tests.NewFalcoctlExecutableRunner(t),
falcoctl.WithArgs("driver", "install", "--download=false"),
)
assert.NoError(t, loaderRes.Err(), "%s", loaderRes.Stderr())
assert.Equal(t, 0, loaderRes.ExitCode())
// We expect the probe to be symlinked in '/root/.falco/falco-bpf.o'
assert.Regexp(t, `Success: eBPF probe symlinked`, loaderRes.Stdout())
// We expect the probe to be succesfully built and copied to /root/.falco/falco-bpf.o
assert.Regexp(t, `Probe successfully built.`, loaderRes.Stdout())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New success message.


// Now running Falco with `FALCO_BPF_PROBE=/root/.falco/falco-bpf.o` we should be able to run the bpf driver
falcoRes := falco.Test(
tests.NewFalcoExecutableRunner(t),
falco.WithStopAfter(3*time.Second),
falco.WithEnvVars(map[string]string{"FALCO_BPF_PROBE": "/root/.falco/falco-bpf.o"}),
falco.WithArgs("-o", "engine.kind=ebpf"),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Set new Falco engine options to run with ebpf.

falco.WithArgs("-o", "engine.ebpf.probe=/root/.falco/falco-bpf.o"),
)
assert.NoError(t, falcoRes.Err(), "%s", falcoRes.Stderr())
assert.Equal(t, 0, falcoRes.ExitCode())
Expand All @@ -75,19 +84,28 @@ func TestFalcoLegacyBPF(t *testing.T) {
//
// We need to use the `--compile` flag because we test against dev versions
func TestFalcoKmod(t *testing.T) {
loaderRes := falcodriverloader.Test(
tests.NewFalcoDriverLoaderExecutableRunner(t),
falcodriverloader.WithArgs("module", "--compile"),
// First, configure falcoctl driver
configRes := falcoctl.Test(
tests.NewFalcoctlExecutableRunner(t),
falcoctl.WithArgs("driver", "config", "--type", "kmod"),
)
assert.NoError(t, configRes.Err(), "%s", configRes.Stderr())
assert.Equal(t, 0, configRes.ExitCode())

loaderRes := falcoctl.Test(
tests.NewFalcoctlExecutableRunner(t),
falcoctl.WithArgs("driver", "install", "--download=false"),
)
assert.NoError(t, loaderRes.Err(), "%s", loaderRes.Stderr())
assert.Equal(t, 0, loaderRes.ExitCode())
// We expect the module to be loaded in dkms
assert.Regexp(t, `Success: falco module found and loaded in dkms`, loaderRes.Stdout())
assert.Regexp(t, `Module installed in dkms.`, loaderRes.Stdout())

// Now running Falco we should be able to run the kernel module
falcoRes := falco.Test(
tests.NewFalcoExecutableRunner(t),
falco.WithStopAfter(3*time.Second),
falco.WithArgs("-o", "engine.kind=kmod"),
)
assert.NoError(t, falcoRes.Err(), "%s", falcoRes.Stderr())
assert.Equal(t, 0, falcoRes.ExitCode())
Expand Down
18 changes: 5 additions & 13 deletions tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,21 @@ import (

"github.com/falcosecurity/testing/pkg/falco"
"github.com/falcosecurity/testing/pkg/falcoctl"
"github.com/falcosecurity/testing/pkg/falcodriverloader"
"github.com/falcosecurity/testing/pkg/run"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
)

var falcoStatic = false
var falcoBinary = falco.DefaultExecutable
var falcoctlBinary = falcoctl.DefaultLocalExecutable
var falcoDriverLoaderBinary = falcodriverloader.DefaultExecutable
var (
falcoStatic = false
falcoBinary = falco.DefaultExecutable
falcoctlBinary = falcoctl.DefaultLocalExecutable
)

func init() {
flag.BoolVar(&falcoStatic, "falco-static", falcoStatic, "True if the Falco executable is from a static build")
flag.StringVar(&falcoBinary, "falco-binary", falcoBinary, "Falco executable binary path")
flag.StringVar(&falcoctlBinary, "falcoctl-binary", falcoctlBinary, "falcoctl executable binary path")
flag.StringVar(&falcoDriverLoaderBinary, "falco-driver-loader-binary", falcoDriverLoaderBinary, "falco-driver-loader executable binary path")

logrus.SetLevel(logrus.DebugLevel)
logrus.SetFormatter(&logrus.JSONFormatter{})
Expand All @@ -54,13 +53,6 @@ func NewFalcoExecutableRunner(t *testing.T) run.Runner {
return runner
}

// NewFalcoExecutableRunner returns an executable runner for falco-driver-loader.
func NewFalcoDriverLoaderExecutableRunner(t *testing.T) run.Runner {
runner, err := run.NewExecutableRunner(falcoDriverLoaderBinary)
require.Nil(t, err)
return runner
}

// NewFalcoctlExecutableRunner returns an executable runner for falcoctl.
func NewFalcoctlExecutableRunner(t *testing.T) run.Runner {
if _, err := os.Stat(falcoctlBinary); err == nil {
Expand Down