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 append of new exceptions to rules #1768

Closed
wants to merge 10 commits into from

Conversation

sai-arigeli
Copy link
Contributor

@sai-arigeli sai-arigeli commented Nov 2, 2021

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 rules

/area tests

/area proposals

What this PR does / why we need it:
PR introduces appending of new fully valid exception objects to existing rules.
Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


@poiana
Copy link
Contributor

poiana commented Nov 2, 2021

@sai-arigeli: Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@poiana
Copy link
Contributor

poiana commented Nov 2, 2021

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

@poiana poiana added the size/L label Nov 2, 2021
@sai-arigeli sai-arigeli marked this pull request as draft November 2, 2021 11:17
@sai-arigeli sai-arigeli changed the title Allow append of new exceptions to rules wip: Allow append of new exceptions to rules Nov 2, 2021
exceptions = {}
end

if eitem['fields'] == nil then
Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to use the fields/comps variables set at the top of this block, right?


-- You can't append exception fields or comps to an existing rule exception
if fields ~= nil then
return false, build_error_with_context(v['context'], "Can not append exception fields to existing rule, only values"), warnings
Copy link
Contributor

Choose a reason for hiding this comment

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

The indentation looks okay in my editor, but doesn't seem okay here. I wouldn't go crazy trying to fix it, but if you can align the indent with whatever is being used by the other parts of this file it would help with readability.

for _, values in ipairs(eitem['values']) do
reitem['values'][#reitem['values'] + 1] = values
-- Insert the complete exception object
exceptions[#exceptions+1] = eitem
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you need to add the exceptions back to the original rule?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The line 639 is supposed to add the entire exception to the original rule. I have tested this specific insertion to the original table on a lua playground. Will update it if necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh right--tables are references, so the local exceptions variable still points to the same table which is a part of the rule. See my earlier comment about assigning the exceptions variable, though.

@poiana
Copy link
Contributor

poiana commented Nov 4, 2021

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: sai-arigeli
To complete the pull request process, please ask for approval from mstemm after the PR has been reviewed.

The full list of commands accepted by this bot can be found 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

@sai-arigeli sai-arigeli changed the title wip: Allow append of new exceptions to rules Allow append of new exceptions to rules Nov 4, 2021
@sai-arigeli sai-arigeli marked this pull request as ready for review November 4, 2021 11:37
Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Copy link
Contributor

@mstemm mstemm left a comment

Choose a reason for hiding this comment

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

Just a couple of small feedback things, the core logic looks okay and correct, and the tests cover the new functionality.

end
if new_exception then
local exceptions = state.rules_by_name[v['rule']]['exceptions']
if exceptions == nil then
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think there's any need for this check given that the rule object always has exceptions--it's added on line 538. If the check on line 538 were not there, this would not actually work, as the exceptions variable would end up pointing to a local table and not the table that's a part of the rule object.

for _, values in ipairs(eitem['values']) do
reitem['values'][#reitem['values'] + 1] = values
-- Insert the complete exception object
exceptions[#exceptions+1] = eitem
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh right--tables are references, so the local exceptions variable still points to the same table which is a part of the rule. See my earlier comment about assigning the exceptions variable, though.

end

if fields == nil then
return false, build_error_with_context(v['context'], "Rule exception new item "..eitem['name']..": must have fields property with a list of fields"), warnings
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you try to use the local variables defined on lines 595 instead of accessing eitem['name'], eitem['fields'], etc? The prior version wasn't entirely consistent but did try to use those local variables, to make the code a bit easier to read.

If you prefer accessing the name, fields, etc. via eitem['xxx'] instead, that's also ok, but let's be consistent and remove the definitions on line 595-597.

@poiana
Copy link
Contributor

poiana commented Nov 4, 2021

@sai-arigeli: Adding label do-not-merge/contains-merge-commits because PR contains merge commits, which are not allowed in this repository.
Use git rebase to reapply your commits on top of the target branch. Detailed instructions for doing so can be found here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@poiana
Copy link
Contributor

poiana commented Nov 9, 2021

Thanks for your pull request. Before we can look at it, you'll need to add a 'DCO signoff' to your commits.

📝 Please follow instructions in the contributing guide to update your commits with the DCO

Full details of the Developer Certificate of Origin can be found at developercertificate.org.

The list of commits missing DCO signoff:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@sai-arigeli
Copy link
Contributor Author

Closing this PR due to merge issues. All commits squashed and comments addressed on #1780. Please continue the review there.

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.

3 participants