From b4eb5b87b6b4ef88ca8e61cc72dd78c0732c89e3 Mon Sep 17 00:00:00 2001 From: Mark Stemm Date: Fri, 2 Oct 2020 16:51:43 -0700 Subject: [PATCH] Automated tests for exceptions Handle various positive and negative cases. Should handle every error and warning path when reading exceptions objects or rule exception fields, and various positive cases of using exceptions to prevent alerts. Signed-off-by: Mark Stemm --- test/falco_tests_exceptions.yaml | 323 ++++++++++++++++++ ...ppend_item_fields_values_len_mismatch.yaml | 31 ++ .../rules/exceptions/append_item_no_name.yaml | 30 ++ .../exceptions/append_item_not_in_rule.yaml | 31 ++ .../item_comps_fields_len_mismatch.yaml | 25 ++ .../item_fields_values_len_mismatch.yaml | 26 ++ test/rules/exceptions/item_no_fields.yaml | 23 ++ test/rules/exceptions/item_no_name.yaml | 23 ++ test/rules/exceptions/item_unknown_comp.yaml | 25 ++ .../rules/exceptions/item_unknown_fields.yaml | 24 ++ .../rule_exception_append_comp.yaml | 38 +++ .../rule_exception_append_multiple.yaml | 42 +++ .../rule_exception_append_one_value.yaml | 37 ++ .../rule_exception_append_second_item.yaml | 41 +++ .../rule_exception_append_second_value.yaml | 36 ++ .../rule_exception_append_third_item.yaml | 41 +++ .../rules/exceptions/rule_exception_comp.yaml | 34 ++ .../exceptions/rule_exception_no_values.yaml | 28 ++ .../exceptions/rule_exception_one_value.yaml | 30 ++ .../exceptions/rule_exception_quoted.yaml | 36 ++ .../rule_exception_second_item.yaml | 34 ++ .../rule_exception_second_value.yaml | 32 ++ .../rule_exception_single_field.yaml | 30 ++ .../rule_exception_single_field_append.yaml | 37 ++ .../exceptions/rule_exception_third_item.yaml | 34 ++ .../rule_exception_values_list.yaml | 29 ++ .../rule_exception_values_listref.yaml | 32 ++ ...ule_exception_values_listref_noparens.yaml | 32 ++ .../exceptions/rule_without_exception.yaml | 21 ++ test/run_regression_tests.sh | 2 +- 30 files changed, 1206 insertions(+), 1 deletion(-) create mode 100644 test/falco_tests_exceptions.yaml create mode 100644 test/rules/exceptions/append_item_fields_values_len_mismatch.yaml create mode 100644 test/rules/exceptions/append_item_no_name.yaml create mode 100644 test/rules/exceptions/append_item_not_in_rule.yaml create mode 100644 test/rules/exceptions/item_comps_fields_len_mismatch.yaml create mode 100644 test/rules/exceptions/item_fields_values_len_mismatch.yaml create mode 100644 test/rules/exceptions/item_no_fields.yaml create mode 100644 test/rules/exceptions/item_no_name.yaml create mode 100644 test/rules/exceptions/item_unknown_comp.yaml create mode 100644 test/rules/exceptions/item_unknown_fields.yaml create mode 100644 test/rules/exceptions/rule_exception_append_comp.yaml create mode 100644 test/rules/exceptions/rule_exception_append_multiple.yaml create mode 100644 test/rules/exceptions/rule_exception_append_one_value.yaml create mode 100644 test/rules/exceptions/rule_exception_append_second_item.yaml create mode 100644 test/rules/exceptions/rule_exception_append_second_value.yaml create mode 100644 test/rules/exceptions/rule_exception_append_third_item.yaml create mode 100644 test/rules/exceptions/rule_exception_comp.yaml create mode 100644 test/rules/exceptions/rule_exception_no_values.yaml create mode 100644 test/rules/exceptions/rule_exception_one_value.yaml create mode 100644 test/rules/exceptions/rule_exception_quoted.yaml create mode 100644 test/rules/exceptions/rule_exception_second_item.yaml create mode 100644 test/rules/exceptions/rule_exception_second_value.yaml create mode 100644 test/rules/exceptions/rule_exception_single_field.yaml create mode 100644 test/rules/exceptions/rule_exception_single_field_append.yaml create mode 100644 test/rules/exceptions/rule_exception_third_item.yaml create mode 100644 test/rules/exceptions/rule_exception_values_list.yaml create mode 100644 test/rules/exceptions/rule_exception_values_listref.yaml create mode 100644 test/rules/exceptions/rule_exception_values_listref_noparens.yaml create mode 100644 test/rules/exceptions/rule_without_exception.yaml diff --git a/test/falco_tests_exceptions.yaml b/test/falco_tests_exceptions.yaml new file mode 100644 index 00000000..02844c55 --- /dev/null +++ b/test/falco_tests_exceptions.yaml @@ -0,0 +1,323 @@ +# +# Copyright (C) 2016-2020 The Falco Authors.. +# +# This file is part of falco. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +trace_files: !mux + + rule_exception_no_fields: + exit_status: 1 + stdout_is: |+ + 1 errors: + Rule exception item ex1: must have fields property with a list of fields + --- + - rule: My Rule + desc: Some desc + condition: evt.type=open and proc.name=cat + output: Some output + exceptions: + - name: ex1 + priority: error + --- + validate_rules_file: + - rules/exceptions/item_no_fields.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_no_name: + exit_status: 1 + stdout_is: |+ + 1 errors: + Rule exception item must have name property + --- + - rule: My Rule + desc: Some desc + condition: evt.type=open and proc.name=cat + output: Some output + exceptions: + - fields: [proc.name, fd.filename] + priority: error + --- + validate_rules_file: + - rules/exceptions/item_no_name.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_append_no_name: + exit_status: 1 + stdout_is: |+ + 1 errors: + Rule exception item must have name property + --- + - rule: My Rule + exceptions: + - values: + - [nginx, /tmp/foo] + append: true + --- + validate_rules_file: + - rules/exceptions/append_item_no_name.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_unknown_fields: + exit_status: 1 + stdout_is: |+ + 1 errors: + Rule exception item ex1: field name not.exist is not a supported filter field + --- + - rule: My Rule + desc: Some desc + condition: evt.type=open and proc.name=cat + output: Some output + exceptions: + - name: ex1 + fields: [not.exist] + priority: error + --- + validate_rules_file: + - rules/exceptions/item_unknown_fields.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_comps_fields_len_mismatch: + exit_status: 1 + stdout_is: |+ + 1 errors: + Rule exception item ex1: fields and comps lists must have equal length + --- + - rule: My Rule + desc: Some desc + condition: evt.type=open and proc.name=cat + output: Some output + exceptions: + - name: ex1 + fields: [proc.name, fd.filename] + comps: [=] + priority: error + --- + validate_rules_file: + - rules/exceptions/item_comps_fields_len_mismatch.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_unknown_comp: + exit_status: 1 + stdout_is: |+ + 1 errors: + Rule exception item ex1: comparison operator no-comp is not a supported comparison operator + --- + - rule: My Rule + desc: Some desc + condition: evt.type=open and proc.name=cat + output: Some output + exceptions: + - name: ex1 + fields: [proc.name, fd.filename] + comps: [=, no-comp] + priority: error + --- + validate_rules_file: + - rules/exceptions/item_unknown_comp.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_fields_values_len_mismatch: + exit_status: 1 + stdout_is: |+ + 1 errors: + Exception item ex1: fields and values lists must have equal length + --- + - rule: My Rule + desc: Some desc + condition: evt.type=open and proc.name=cat + output: Some output + exceptions: + - name: ex1 + fields: [proc.name, fd.filename] + values: + - [nginx] + priority: error + --- + validate_rules_file: + - rules/exceptions/item_fields_values_len_mismatch.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_append_fields_values_len_mismatch: + exit_status: 1 + stdout_is: |+ + 1 errors: + Exception item ex1: fields and values lists must have equal length + --- + - rule: My Rule + desc: Some desc + condition: evt.type=open and proc.name=cat + output: Some output + exceptions: + - name: ex1 + fields: [proc.name, fd.filename] + priority: error + + - rule: My Rule + exceptions: + - name: ex1 + values: + - [nginx] + append: true + --- + validate_rules_file: + - rules/exceptions/append_item_fields_values_len_mismatch.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_append_item_not_in_rule: + exit_status: 0 + stderr_contains: |+ + 1 warnings: + Rule My Rule with append=true: no set of fields matching name ex2 + validate_rules_file: + - rules/exceptions/append_item_not_in_rule.yaml + trace_file: trace_files/cat_write.scap + + rule_without_exception: + exit_status: 0 + stderr_contains: |+ + 1 warnings: + Rule My Rule: consider adding an exceptions property to define supported exceptions fields + validate_rules_file: + - rules/exceptions/rule_without_exception.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_no_values: + detect: True + detect_level: WARNING + rules_file: + - rules/exceptions/rule_exception_no_values.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_one_value: + detect: False + detect_level: WARNING + rules_file: + - rules/exceptions/rule_exception_one_value.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_append_one_value: + detect: False + detect_level: WARNING + rules_file: + - rules/exceptions/rule_exception_append_one_value.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_second_value: + detect: False + detect_level: WARNING + rules_file: + - rules/exceptions/rule_exception_second_value.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_append_second_value: + detect: False + detect_level: WARNING + rules_file: + - rules/exceptions/rule_exception_append_second_value.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_second_item: + detect: False + detect_level: WARNING + rules_file: + - rules/exceptions/rule_exception_second_item.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_append_second_item: + detect: False + detect_level: WARNING + rules_file: + - rules/exceptions/rule_exception_append_second_item.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_third_item: + detect: False + detect_level: WARNING + rules_file: + - rules/exceptions/rule_exception_third_item.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_append_third_item: + detect: False + detect_level: WARNING + rules_file: + - rules/exceptions/rule_exception_append_third_item.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_quoted: + detect: False + detect_level: WARNING + rules_file: + - rules/exceptions/rule_exception_quoted.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_append_multiple_values: + detect: False + detect_level: WARNING + rules_file: + - rules/exceptions/rule_exception_append_multiple.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_comp: + detect: False + detect_level: WARNING + rules_file: + - rules/exceptions/rule_exception_comp.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_append_comp: + detect: False + detect_level: WARNING + rules_file: + - rules/exceptions/rule_exception_append_comp.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_values_listref: + detect: False + detect_level: WARNING + rules_file: + - rules/exceptions/rule_exception_values_listref.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_values_listref_noparens: + detect: False + detect_level: WARNING + rules_file: + - rules/exceptions/rule_exception_values_listref_noparens.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_values_list: + detect: False + detect_level: WARNING + rules_file: + - rules/exceptions/rule_exception_values_list.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_single_field: + detect: False + detect_level: WARNING + rules_file: + - rules/exceptions/rule_exception_single_field.yaml + trace_file: trace_files/cat_write.scap + + rule_exception_single_field_append: + detect: False + detect_level: WARNING + rules_file: + - rules/exceptions/rule_exception_single_field_append.yaml + trace_file: trace_files/cat_write.scap + + diff --git a/test/rules/exceptions/append_item_fields_values_len_mismatch.yaml b/test/rules/exceptions/append_item_fields_values_len_mismatch.yaml new file mode 100644 index 00000000..21a7ad7a --- /dev/null +++ b/test/rules/exceptions/append_item_fields_values_len_mismatch.yaml @@ -0,0 +1,31 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +- rule: My Rule + desc: Some desc + condition: evt.type=open and proc.name=cat + output: Some output + exceptions: + - name: ex1 + fields: [proc.name, fd.filename] + priority: error + +- rule: My Rule + exceptions: + - name: ex1 + values: + - [nginx] + append: true diff --git a/test/rules/exceptions/append_item_no_name.yaml b/test/rules/exceptions/append_item_no_name.yaml new file mode 100644 index 00000000..3aff2de8 --- /dev/null +++ b/test/rules/exceptions/append_item_no_name.yaml @@ -0,0 +1,30 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +- rule: My Rule + desc: Some desc + condition: evt.type=open and proc.name=cat + output: Some output + exceptions: + - name: ex1 + fields: [proc.name, fd.filename] + priority: error + +- rule: My Rule + exceptions: + - values: + - [nginx, /tmp/foo] + append: true diff --git a/test/rules/exceptions/append_item_not_in_rule.yaml b/test/rules/exceptions/append_item_not_in_rule.yaml new file mode 100644 index 00000000..e160d641 --- /dev/null +++ b/test/rules/exceptions/append_item_not_in_rule.yaml @@ -0,0 +1,31 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +- rule: My Rule + desc: Some desc + condition: evt.type=open and proc.name=cat + output: Some output + exceptions: + - name: ex1 + fields: [proc.name, fd.filename] + priority: error + +- rule: My Rule + exceptions: + - name: ex2 + values: + - [apache, /tmp] + append: true diff --git a/test/rules/exceptions/item_comps_fields_len_mismatch.yaml b/test/rules/exceptions/item_comps_fields_len_mismatch.yaml new file mode 100644 index 00000000..c832c358 --- /dev/null +++ b/test/rules/exceptions/item_comps_fields_len_mismatch.yaml @@ -0,0 +1,25 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +- rule: My Rule + desc: Some desc + condition: evt.type=open and proc.name=cat + output: Some output + exceptions: + - name: ex1 + fields: [proc.name, fd.filename] + comps: [=] + priority: error diff --git a/test/rules/exceptions/item_fields_values_len_mismatch.yaml b/test/rules/exceptions/item_fields_values_len_mismatch.yaml new file mode 100644 index 00000000..32e89bb1 --- /dev/null +++ b/test/rules/exceptions/item_fields_values_len_mismatch.yaml @@ -0,0 +1,26 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +- rule: My Rule + desc: Some desc + condition: evt.type=open and proc.name=cat + output: Some output + exceptions: + - name: ex1 + fields: [proc.name, fd.filename] + values: + - [nginx] + priority: error diff --git a/test/rules/exceptions/item_no_fields.yaml b/test/rules/exceptions/item_no_fields.yaml new file mode 100644 index 00000000..72feb7fc --- /dev/null +++ b/test/rules/exceptions/item_no_fields.yaml @@ -0,0 +1,23 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +- rule: My Rule + desc: Some desc + condition: evt.type=open and proc.name=cat + output: Some output + exceptions: + - name: ex1 + priority: error diff --git a/test/rules/exceptions/item_no_name.yaml b/test/rules/exceptions/item_no_name.yaml new file mode 100644 index 00000000..0631c362 --- /dev/null +++ b/test/rules/exceptions/item_no_name.yaml @@ -0,0 +1,23 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +- rule: My Rule + desc: Some desc + condition: evt.type=open and proc.name=cat + output: Some output + exceptions: + - fields: [proc.name, fd.filename] + priority: error diff --git a/test/rules/exceptions/item_unknown_comp.yaml b/test/rules/exceptions/item_unknown_comp.yaml new file mode 100644 index 00000000..76ef2902 --- /dev/null +++ b/test/rules/exceptions/item_unknown_comp.yaml @@ -0,0 +1,25 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +- rule: My Rule + desc: Some desc + condition: evt.type=open and proc.name=cat + output: Some output + exceptions: + - name: ex1 + fields: [proc.name, fd.filename] + comps: [=, no-comp] + priority: error diff --git a/test/rules/exceptions/item_unknown_fields.yaml b/test/rules/exceptions/item_unknown_fields.yaml new file mode 100644 index 00000000..9090df1e --- /dev/null +++ b/test/rules/exceptions/item_unknown_fields.yaml @@ -0,0 +1,24 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +- rule: My Rule + desc: Some desc + condition: evt.type=open and proc.name=cat + output: Some output + exceptions: + - name: ex1 + fields: [not.exist] + priority: error diff --git a/test/rules/exceptions/rule_exception_append_comp.yaml b/test/rules/exceptions/rule_exception_append_comp.yaml new file mode 100644 index 00000000..662a5003 --- /dev/null +++ b/test/rules/exceptions/rule_exception_append_comp.yaml @@ -0,0 +1,38 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +- rule: Open From Cat + desc: A process named cat does an open + condition: evt.type=open and proc.name=cat + output: "An open was seen (command=%proc.cmdline)" + exceptions: + - name: proc_name + fields: [proc.name] + - name: proc_name_contains + fields: [proc.name] + comps: [contains] + - name: proc_name_cmdline + fields: [proc.name, proc.cmdline] + - name: proc_name_cmdline_pname + fields: [proc.name, proc.cmdline, proc.pname] + priority: WARNING + +- rule: Open From Cat + exceptions: + - name: proc_name_contains + values: + - [cat] + append: true diff --git a/test/rules/exceptions/rule_exception_append_multiple.yaml b/test/rules/exceptions/rule_exception_append_multiple.yaml new file mode 100644 index 00000000..91672fa3 --- /dev/null +++ b/test/rules/exceptions/rule_exception_append_multiple.yaml @@ -0,0 +1,42 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +- rule: Open From Cat + desc: A process named cat does an open + condition: evt.type=open and proc.name=cat + output: "An open was seen (command=%proc.cmdline)" + exceptions: + - name: proc_name + fields: [proc.name] + - name: proc_name_cmdline + fields: [proc.name, proc.cmdline] + - name: proc_name_cmdline_pname + fields: [proc.name, proc.cmdline, proc.pname] + priority: WARNING + +- rule: Open From Cat + exceptions: + - name: proc_name + values: + - [not-cat] + append: true + +- rule: Open From Cat + exceptions: + - name: proc_name + values: + - [cat] + append: true diff --git a/test/rules/exceptions/rule_exception_append_one_value.yaml b/test/rules/exceptions/rule_exception_append_one_value.yaml new file mode 100644 index 00000000..b431b2a8 --- /dev/null +++ b/test/rules/exceptions/rule_exception_append_one_value.yaml @@ -0,0 +1,37 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +- rule: Open From Cat + desc: A process named cat does an open + condition: evt.type=open and proc.name=cat + output: "An open was seen (command=%proc.cmdline)" + exceptions: + - name: proc_name + fields: [proc.name] + values: + - [cat] + - name: proc_name_cmdline + fields: [proc.name, proc.cmdline] + - name: proc_name_cmdline_pname + fields: [proc.name, proc.cmdline, proc.pname] + priority: WARNING + +- rule: Open From Cat + exceptions: + - name: proc_name + values: + - [cat] + append: true \ No newline at end of file diff --git a/test/rules/exceptions/rule_exception_append_second_item.yaml b/test/rules/exceptions/rule_exception_append_second_item.yaml new file mode 100644 index 00000000..b59bff3d --- /dev/null +++ b/test/rules/exceptions/rule_exception_append_second_item.yaml @@ -0,0 +1,41 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +- rule: Open From Cat + desc: A process named cat does an open + condition: evt.type=open and proc.name=cat + output: "An open was seen (command=%proc.cmdline)" + exceptions: + - name: proc_name + fields: [proc.name] + - name: proc_name_cmdline + fields: [proc.name, proc.cmdline] + - name: proc_name_cmdline_pname + fields: [proc.name, proc.cmdline, proc.pname] + priority: WARNING + +- rule: Open From Cat + exceptions: + - name: proc_name + values: + - [not-cat] + - name: proc_name_cmdline + values: + - [cat, "cat /dev/null"] + - name: proc_name_cmdline_pname + values: + - [not-cat, "cat /dev/null", bash] + append: true diff --git a/test/rules/exceptions/rule_exception_append_second_value.yaml b/test/rules/exceptions/rule_exception_append_second_value.yaml new file mode 100644 index 00000000..c3b242c9 --- /dev/null +++ b/test/rules/exceptions/rule_exception_append_second_value.yaml @@ -0,0 +1,36 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +- rule: Open From Cat + desc: A process named cat does an open + condition: evt.type=open and proc.name=cat + output: "An open was seen (command=%proc.cmdline)" + exceptions: + - name: proc_name + fields: [proc.name] + - name: proc_name_cmdline + fields: [proc.name, proc.cmdline] + - name: proc_name_cmdline_pname + fields: [proc.name, proc.cmdline, proc.pname] + priority: WARNING + +- rule: Open From Cat + exceptions: + - name: proc_name_cmdline + values: + - [not-cat, not-cat] + - [cat, "cat /dev/null"] + append: true diff --git a/test/rules/exceptions/rule_exception_append_third_item.yaml b/test/rules/exceptions/rule_exception_append_third_item.yaml new file mode 100644 index 00000000..9ad0c1ab --- /dev/null +++ b/test/rules/exceptions/rule_exception_append_third_item.yaml @@ -0,0 +1,41 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +- rule: Open From Cat + desc: A process named cat does an open + condition: evt.type=open and proc.name=cat + output: "An open was seen (command=%proc.cmdline)" + exceptions: + - name: proc_name + fields: [proc.name] + - name: proc_name_cmdline + fields: [proc.name, proc.cmdline] + - name: proc_name_cmdline_pname + fields: [proc.name, proc.cmdline, proc.pname] + priority: WARNING + +- rule: Open From Cat + exceptions: + - name: proc_name + values: + - [not-cat] + - name: proc_name_cmdline + values: + - [not-cat, "cat /dev/null"] + - name: proc_name_cmdline_pname + values: + - [cat, "cat /dev/null", bash] + append: true diff --git a/test/rules/exceptions/rule_exception_comp.yaml b/test/rules/exceptions/rule_exception_comp.yaml new file mode 100644 index 00000000..fb531294 --- /dev/null +++ b/test/rules/exceptions/rule_exception_comp.yaml @@ -0,0 +1,34 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +- rule: Open From Cat + desc: A process named cat does an open + condition: evt.type=open and proc.name=cat + output: "An open was seen (command=%proc.cmdline)" + exceptions: + - name: proc_name + fields: [proc.name] + - name: proc_name_contains + fields: [proc.name] + comps: [contains] + values: + - [cat] + - name: proc_name_cmdline + fields: [proc.name, proc.cmdline] + - name: proc_name_cmdline_pname + fields: [proc.name, proc.cmdline, proc.pname] + priority: WARNING + diff --git a/test/rules/exceptions/rule_exception_no_values.yaml b/test/rules/exceptions/rule_exception_no_values.yaml new file mode 100644 index 00000000..73083bf3 --- /dev/null +++ b/test/rules/exceptions/rule_exception_no_values.yaml @@ -0,0 +1,28 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +- rule: Open From Cat + desc: A process named cat does an open + condition: evt.type=open and proc.name=cat + output: "An open was seen (command=%proc.cmdline)" + exceptions: + - name: proc_name + fields: [proc.name] + - name: proc_name_cmdline + fields: [proc.name, proc.cmdline] + - name: proc_name_cmdline_pname + fields: [proc.name, proc.cmdline, proc.pname] + priority: WARNING diff --git a/test/rules/exceptions/rule_exception_one_value.yaml b/test/rules/exceptions/rule_exception_one_value.yaml new file mode 100644 index 00000000..8f6e3111 --- /dev/null +++ b/test/rules/exceptions/rule_exception_one_value.yaml @@ -0,0 +1,30 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +- rule: Open From Cat + desc: A process named cat does an open + condition: evt.type=open and proc.name=cat + output: "An open was seen (command=%proc.cmdline)" + exceptions: + - name: proc_name + fields: [proc.name] + values: + - [cat] + - name: proc_name_cmdline + fields: [proc.name, proc.cmdline] + - name: proc_name_cmdline_pname + fields: [proc.name, proc.cmdline, proc.pname] + priority: WARNING diff --git a/test/rules/exceptions/rule_exception_quoted.yaml b/test/rules/exceptions/rule_exception_quoted.yaml new file mode 100644 index 00000000..c716ea89 --- /dev/null +++ b/test/rules/exceptions/rule_exception_quoted.yaml @@ -0,0 +1,36 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +- rule: Open From Cat + desc: A process named cat does an open + condition: evt.type=open and proc.name=cat + output: "An open was seen (command=%proc.cmdline)" + exceptions: + - name: proc_name + fields: [proc.name] + - name: proc_name_cmdline + fields: [proc.name, proc.cmdline] + - name: proc_name_cmdline_pname + fields: [proc.name, proc.cmdline, proc.pname] + priority: WARNING + +- rule: Open From Cat + exceptions: + - name: proc_name_cmdline + values: + - [not-cat, not-cat] + - [cat, '"cat /dev/null"'] + append: true diff --git a/test/rules/exceptions/rule_exception_second_item.yaml b/test/rules/exceptions/rule_exception_second_item.yaml new file mode 100644 index 00000000..19ee00ee --- /dev/null +++ b/test/rules/exceptions/rule_exception_second_item.yaml @@ -0,0 +1,34 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +- rule: Open From Cat + desc: A process named cat does an open + condition: evt.type=open and proc.name=cat + output: "An open was seen (command=%proc.cmdline)" + exceptions: + - name: proc_name + fields: [proc.name] + values: + - [not-cat] + - name: proc_name_cmdline + fields: [proc.name, proc.cmdline] + values: + - [cat, "cat /dev/null"] + - name: proc_name_cmdline_pname + fields: [proc.name, proc.cmdline, proc.pname] + values: + - [not-cat, "cat /dev/null", bash] + priority: WARNING diff --git a/test/rules/exceptions/rule_exception_second_value.yaml b/test/rules/exceptions/rule_exception_second_value.yaml new file mode 100644 index 00000000..18d6eb71 --- /dev/null +++ b/test/rules/exceptions/rule_exception_second_value.yaml @@ -0,0 +1,32 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +- rule: Open From Cat + desc: A process named cat does an open + condition: evt.type=open and proc.name=cat + output: "An open was seen (command=%proc.cmdline)" + exceptions: + - name: proc_name + fields: [proc.name] + - name: proc_name_cmdline + fields: [proc.name, proc.cmdline] + values: + - [not-cat, not-cat] + - [cat, "cat /dev/null"] + - name: proc_name_cmdline_pname + fields: [proc.name, proc.cmdline, proc.pname] + priority: WARNING + diff --git a/test/rules/exceptions/rule_exception_single_field.yaml b/test/rules/exceptions/rule_exception_single_field.yaml new file mode 100644 index 00000000..d3533073 --- /dev/null +++ b/test/rules/exceptions/rule_exception_single_field.yaml @@ -0,0 +1,30 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +- rule: Open From Cat + desc: A process named cat does an open + condition: evt.type=open and proc.name=cat + output: "An open was seen (command=%proc.cmdline)" + exceptions: + - name: proc_cmdline + fields: proc.cmdline + comps: in + values: + - cat /dev/zero + - "cat /dev/null" + priority: WARNING + diff --git a/test/rules/exceptions/rule_exception_single_field_append.yaml b/test/rules/exceptions/rule_exception_single_field_append.yaml new file mode 100644 index 00000000..1695bf7e --- /dev/null +++ b/test/rules/exceptions/rule_exception_single_field_append.yaml @@ -0,0 +1,37 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +- rule: Open From Cat + desc: A process named cat does an open + condition: evt.type=open and proc.name=cat + output: "An open was seen (command=%proc.cmdline)" + exceptions: + - name: proc_cmdline + fields: proc.cmdline + comps: in + values: + - cat /dev/zero + priority: WARNING + +- rule: Open From Cat + exceptions: + - name: proc_cmdline + values: + - "cat /dev/null" + append: true + + diff --git a/test/rules/exceptions/rule_exception_third_item.yaml b/test/rules/exceptions/rule_exception_third_item.yaml new file mode 100644 index 00000000..5315c585 --- /dev/null +++ b/test/rules/exceptions/rule_exception_third_item.yaml @@ -0,0 +1,34 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +- rule: Open From Cat + desc: A process named cat does an open + condition: evt.type=open and proc.name=cat + output: "An open was seen (command=%proc.cmdline)" + exceptions: + - name: proc_name + fields: [proc.name] + values: + - [not-cat] + - name: proc_name_cmdline + fields: [proc.name, proc.cmdline] + values: + - [not-cat, "cat /dev/null"] + - name: proc_name_cmdline_pname + fields: [proc.name, proc.cmdline, proc.pname] + values: + - [cat, "cat /dev/null", bash] + priority: WARNING diff --git a/test/rules/exceptions/rule_exception_values_list.yaml b/test/rules/exceptions/rule_exception_values_list.yaml new file mode 100644 index 00000000..484f9559 --- /dev/null +++ b/test/rules/exceptions/rule_exception_values_list.yaml @@ -0,0 +1,29 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +- rule: Open From Cat + desc: A process named cat does an open + condition: evt.type=open and proc.name=cat + output: "An open was seen (command=%proc.cmdline)" + exceptions: + - name: proc_name_cmdline + fields: [proc.name, proc.cmdline] + comps: [=, in] + values: + - [cat, [cat /dev/zero, "cat /dev/null"]] + priority: WARNING + diff --git a/test/rules/exceptions/rule_exception_values_listref.yaml b/test/rules/exceptions/rule_exception_values_listref.yaml new file mode 100644 index 00000000..52d2f306 --- /dev/null +++ b/test/rules/exceptions/rule_exception_values_listref.yaml @@ -0,0 +1,32 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +- list: cat_cmdlines + items: [cat /dev/zero, "cat /dev/null"] + +- rule: Open From Cat + desc: A process named cat does an open + condition: evt.type=open and proc.name=cat + output: "An open was seen (command=%proc.cmdline)" + exceptions: + - name: proc_name_cmdline + fields: [proc.name, proc.cmdline] + comps: [=, in] + values: + - [cat, (cat_cmdlines)] + priority: WARNING + diff --git a/test/rules/exceptions/rule_exception_values_listref_noparens.yaml b/test/rules/exceptions/rule_exception_values_listref_noparens.yaml new file mode 100644 index 00000000..0677d74a --- /dev/null +++ b/test/rules/exceptions/rule_exception_values_listref_noparens.yaml @@ -0,0 +1,32 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +- list: cat_cmdlines + items: [cat /dev/zero, "cat /dev/null"] + +- rule: Open From Cat + desc: A process named cat does an open + condition: evt.type=open and proc.name=cat + output: "An open was seen (command=%proc.cmdline)" + exceptions: + - name: proc_name_cmdline + fields: [proc.name, proc.cmdline] + comps: [=, in] + values: + - [cat, cat_cmdlines] + priority: WARNING + diff --git a/test/rules/exceptions/rule_without_exception.yaml b/test/rules/exceptions/rule_without_exception.yaml new file mode 100644 index 00000000..a885bed9 --- /dev/null +++ b/test/rules/exceptions/rule_without_exception.yaml @@ -0,0 +1,21 @@ +# +# Copyright (C) 2020 The Falco Authors. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +- rule: My Rule + desc: Some desc + condition: evt.type=open and proc.name=cat + output: Some output + priority: error diff --git a/test/run_regression_tests.sh b/test/run_regression_tests.sh index bd8e61e8..29cf28f1 100755 --- a/test/run_regression_tests.sh +++ b/test/run_regression_tests.sh @@ -98,7 +98,7 @@ function run_tests() { # as we're watching the return status when running avocado. set +e TEST_RC=0 - suites=($SCRIPTDIR/falco_traces.yaml $SCRIPTDIR/falco_tests.yaml $SCRIPTDIR/falco_k8s_audit_tests.yaml $SCRIPTDIR/falco_tests_psp.yaml) + suites=($SCRIPTDIR/falco_traces.yaml $SCRIPTDIR/falco_tests.yaml $SCRIPTDIR/falco_k8s_audit_tests.yaml $SCRIPTDIR/falco_tests_psp.yaml $SCRIPTDIR/falco_tests_exceptions.yaml) if [ "$SKIP_PACKAGES_TESTS" = false ] ; then suites+=($SCRIPTDIR/falco_tests_package.yaml)