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

Feature: Add support for testing falco rules using declarative YAML files in event-generator #211

Merged
merged 1 commit into from
Jun 18, 2024

Conversation

GLVSKiriti
Copy link
Contributor

@GLVSKiriti GLVSKiriti commented May 29, 2024

What type of PR is this?

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

/kind bug

/kind cleanup

/kind documentation

/kind tests

/kind feature

Any specific area of the project related to this PR?

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

/area commands

/area pkg

/area events

What this PR does / why we need it:
This PR is to add support for testing falco rules using declarative YAML files in event-generator. The implementation idea is here

Which issue(s) this PR fixes:

Part of GSoC 2024 project "Falco: Upgrading event-generator and automating Falco performance testing"
falcosecurity/evolution#362
Special notes for your reviewer:
cc @jasondellaluce @alacuku

@GLVSKiriti
Copy link
Contributor Author

I'm encountering an issue with my YAML test configuration. When running the following single-test YAML file:

tests:
  - rule: WriteBelowRoot
    runner: HostRunner
    before: ""
    steps:
      - syscall: "write"
        args:
          filepath: "/root/created-by-event-generator"
          content: ""
    after: "rm -f /root/created-by-event-generator"

The rule triggers and the test passes successfully, as shown in the screenshot below:

Screenshot from 2024-06-02 15-27-06

However, when I use a YAML file with multiple tests, like this:

tests:
  - rule: WriteBelowRoot
    runner: HostRunner
    before: ""
    steps:
      - syscall: "write"
        args:
          filepath: "/root/created-by-event-generator"
          content: ""
    after: "rm -f /root/created-by-event-generator"

  - rule: WriteBelowEtc
    runner: HostRunner
    before: ""
    steps:
      - syscall: "write"
        args:
          filepath: "/etc/created-by-event-generator"
          content: ""
    after: "rm -f /etc/created-by-event-generator"

The tests fail to pass, as shown in this screenshot:
Screenshot from 2024-06-02 15-31-01

Individually, both tests pass, but they fail when combined in a single YAML file. What could be causing this issue?

cc @jasondellaluce @alacuku

Copy link
Member

@leogr leogr left a comment

Choose a reason for hiding this comment

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

Very random comments after a very first look :)

cmd/declarative.go Outdated Show resolved Hide resolved
events/exampleyamlfile.yml Show resolved Hide resolved
// Yaml file structure
type SyscallStep struct {
Syscall string `yaml:"syscall"`
Args map[string]string `yaml:"args"`
Copy link
Member

Choose a reason for hiding this comment

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

Can we map all args values as strings?

cmd/declarative.go Show resolved Hide resolved
cmd/declarative.go Outdated Show resolved Hide resolved
@GLVSKiriti GLVSKiriti changed the base branch from main to gsoc2024 June 11, 2024 10:50
@GLVSKiriti GLVSKiriti changed the title [WIP]: Feature: Add support for testing falco rules using declarative YAML files in event-generator Feature: Add support for testing falco rules using declarative YAML files in event-generator Jun 17, 2024
Copy link
Member

@alacuku alacuku left a comment

Choose a reason for hiding this comment

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

I left some suggestions.
Please use conventional commits and squash them.

cmd/common.go Outdated Show resolved Hide resolved
cmd/common.go Outdated Show resolved Hide resolved
cmd/declarative.go Outdated Show resolved Hide resolved
- Added a new subcommand declarative for run command
- Implemented parsing of YAML test files
- Added HostRunner for executing tests on the host
- Setup and Cleanup scripts execution
- Steps execution for write syscall
- Added detailed error handling and logging
- Ensure continuation of test even if one fails
- Added required helpers to test rule Write Below Root and Write Below Etc

Signed-off-by: GLVS Kiriti <[email protected]>
Copy link
Member

@alacuku alacuku left a comment

Choose a reason for hiding this comment

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

/lgtm

@poiana
Copy link

poiana commented Jun 18, 2024

LGTM label has been added.

Git tree hash: fc7e525e5f896819d08b4901e558b8e19a249163

@alacuku
Copy link
Member

alacuku commented Jun 18, 2024

/approve

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
Copy link

poiana commented Jun 18, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alacuku, FedeDP, GLVSKiriti

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

@poiana poiana merged commit 5bd71c8 into falcosecurity:gsoc2024 Jun 18, 2024
3 of 4 checks passed
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.

None yet

5 participants