Repository navigation
test(engine): cover rejection of empty appended rules - #3935
Conversation
|
Welcome @Jvlegod! It looks like this is your first PR to falcosecurity/falco 🎉 |
|
This PR may bring feature or behavior changes in the Falco engine and may require the engine version to be bumped. Please double check userspace/engine/falco_engine_version.h file. See versioning for FALCO_ENGINE_VERSION. /hold |
|
Maybe I don't think |
False positive |
|
LGTM label has been added. DetailsGit tree hash: c623d718650d68e1f58e51908cd3829069000546 |
leogr
left a comment
There was a problem hiding this comment.
Hey @Jvlegod
Thanks for this PR, and sorry for the long wait!
I had a closer look at the red test-packages jobs. Apart from the 11 UTF-8 tests (unrelated, they fail only because the merge commit predates #3942), there is one real failure caused by this change: TestFalco_Legacy_InvalidAppendRuleWithoutCondition in falcosecurity/testing expects LOAD_ERR_VALIDATE, while the THROW in the reader emits LOAD_ERR_YAML_VALIDATE.
For the record, master already rejects an appended rule without condition/exceptions: in the append branch the reader reads only those two properties, so the collector's has_any_value() check fails and it throws the very same message (see rule_loader_collector.cpp), with LOAD_ERR_VALIDATE. So re-enabling the check in the reader does not change what is accepted or rejected. It only changes the error code, and the order in which two errors are reported (an append to an unknown rule with no condition would now report "Appended rule must have..." instead of "no rule by that name already exists").
That said, the new unit test is valuable, since we had no coverage for this case. So, may you drop the rule_loader_reader.cpp change and keep the tests? They should pass on master as is, since check_error_message() matches the message text. See also my inline comment about the renamed test.
This way we also avoid a cross-repo dance with falcosecurity/testing, whose main is used by the CI of every Falco PR.
Thanks 🙏
| THROW((!v.cond.has_value() && !v.exceptions.has_value()), | ||
| "Appended rule must have exceptions or condition property", | ||
| v.ctx); |
There was a problem hiding this comment.
This is where the error code changes: the THROW macro in this file uses LOAD_ERR_YAML_VALIDATE, while the collector already throws the same message with LOAD_ERR_VALIDATE for exactly this case (rule_loader_collector.cpp, has_any_value() check in append()).
May you drop this hunk, leaving the file as it is on master? Otherwise TestFalco_Legacy_InvalidAppendRuleWithoutCondition in falcosecurity/testing keeps failing, since it asserts LOAD_ERR_VALIDATE.
|
|
||
| // todo!: Probably we shouldn't allow this syntax | ||
| TEST_F(test_falco_engine, rule_enabled_is_ignored_by_append) { | ||
| TEST_F(test_falco_engine, rule_enabled_is_rejected_by_append) { |
There was a problem hiding this comment.
Nit. The new name says that enabled is rejected, but what gets rejected here is the missing condition/exceptions (an append with a condition and enabled: true still loads fine). This makes it nearly identical to empty_append_rule_is_rejected below.
May you restore rule_enabled_is_ignored_by_append as it is on master (it's the only test documenting that enabled is ignored on append), and keep empty_append_rule_is_rejected as the new coverage?
|
Of course, I will submit the changes shortly. |
Thanks, let us know! 🙏 |
An appended rule (`append: true`) with neither `condition` nor `exceptions` is already rejected by the rule loader collector, via the `has_any_value()` check in `rule_loader::collector::append()`, with error code `LOAD_ERR_VALIDATE`. However, no unit test covered this case. Add `empty_append_rule_is_rejected` to lock the behavior in. The commented-out reader-level check is left as is, since restoring it would only change the reported error code to `LOAD_ERR_YAML_VALIDATE`. Signed-off-by: Keke Ming <ming.jvle@gmail.com> Signed-off-by: Leonardo Grasso <me@leonardograsso.com>
de50619 to
05bf224
Compare
|
Hey @Jvlegod Since we'd like to have this in Falco 0.45.0 and the code freeze is close, I went ahead and applied the change we agreed on Sep 4 (see #3935 (review)), and force-pushed to your branch. You are still the author of the commit, I just added my sign-off next to yours. I hope you don't mind 🙏 What changed, in short:
The new test is the valuable part here, since we had no coverage for this case. Thanks again for the contribution! N.B. The force-push dropped the /kind test |
|
@leogr: The label(s) DetailsIn response to this:
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-sigs/prow repository. |
|
/kind cleanup |
|
LGTM label has been added. DetailsGit tree hash: aa541d297c0fcae6e4d66c6fe0d31f01484153d0 |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Jvlegod, leogr, sgaist The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind bug
Any specific area of the project related to this PR?
/area engine
/area tests
What this PR does / why we need it:
This PR adds a unit test covering the rejection of
append: truerules that do not actually append anything (noconditionand noexceptions).The rule loader collector already rejects them with
LOAD_ERR_VALIDATE("Appended rule must have exceptions or condition property"), but the case had no test coverage. The commented-out reader-level check is left as is, since restoring it would only change the reported error code toLOAD_ERR_YAML_VALIDATE, which is not whatfalcosecurity/testingexpects.N.B. Scope reduced to the test on September 7th by the maintainers, as agreed in the review (see the comments below).
Which issue(s) this PR fixes:
N/A
Special notes for your reviewer:
Tested with:
Does this PR introduce a user-facing change?: