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

Better rules parsing errors #708

Merged
merged 4 commits into from
Jul 11, 2019
Merged

Better rules parsing errors #708

merged 4 commits into from
Jul 11, 2019

Conversation

mstemm
Copy link
Contributor

@mstemm mstemm commented Jul 5, 2019

What type of PR is this?

/kind cleanup

Any specific area of the project related to this PR?

/area engine

/area rules

What this PR does / why we need it:

This cleans up rule validation to pass back consistent and appropriate error messages along with meaningful context. It can be used by callers that want to validate falco rules files.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Improve rule validation (-V) output to provide consistent info ("Ok", or error string) to stdout, including appropriate context.

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.

I'd like to see the lua files formatted right before trying to understand and test the new logic.

The cpp stuff looks good rn but I'll test it better once the lua formatting is done

return changed or changed_left or changed_right
local status, changed_left = expand_macros(ast.left, defs, false)
if status == false then
return false, changed_left
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about the formatting of this one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we have a lua formatter yet?


elseif ast.type == "UnaryBoolOp" then
if (ast.argument.type == "Macro") then
if (defs[ast.argument.value] == nil) then
error("Undefined macro ".. ast.argument.value .. " used in filter.")
return false, "Undefined macro ".. ast.argument.value .. " used in filter."
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto


row, col = string.match(rules, pat)
if row ~= nil and col ~= nil then
rules = string.gsub(rules, pat, "")
Copy link
Contributor

Choose a reason for hiding this comment

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

again formatting here

leodido
leodido previously approved these changes Jul 10, 2019
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.

Except some formatting glitches (we'll fix soon in dedicated PR after having introduced lua coding style) it looks go to me

@poiana
Copy link

poiana commented Jul 10, 2019

LGTM label has been added.

Git tree hash: 4a23a0b60ca6b4d984c853c2dac11062ab4eef3b

New test options stdout_is/stderr_is do a direct comparison between
stdout/stderr and the provided value.

Test option validate_rules_file maps to -V arguments, which validate
rules and exits.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
When parsing rules files with -V (validate), print info on the result of
loading the rules file to stdout. That way a caller can capture stdout
to pass along any rules parsing error.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Instead of relying on lua errors to pass back parse errors, pass back an
explicit true + required engine version or false + error message.

Also clean up the error message to display info + context on the
error. When the error related to yaml parsing, use the row number passed
back in lyaml's error string to print the specific line with the error.

When parsing rules/macros/lists, print the object being parsed alongside
the error.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Add a bunch of additional test cases for validating rules files. Each
has a specific kind of parse failure and checks for the appropriate
error info on stdout.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
@poiana poiana added the lgtm label Jul 11, 2019
@poiana
Copy link

poiana commented Jul 11, 2019

LGTM label has been added.

Git tree hash: 4f46d0e4761b438e14c8d56a94be06745def0618

@mstemm
Copy link
Contributor Author

mstemm commented Jul 11, 2019

@fntlnz , since we agreed that any lua formatting changes will occur in a separate PR, can you approve this one? I can't merge w/ requested changes.

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.

LGTM

@poiana
Copy link

poiana commented Jul 11, 2019

[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

@mstemm
Copy link
Contributor Author

mstemm commented Jul 11, 2019

Thank you!

@mstemm mstemm merged commit 01f65e3 into dev Jul 11, 2019
@poiana poiana deleted the better-rules-parsing-errors branch July 11, 2019 18:24
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

4 participants