-
Notifications
You must be signed in to change notification settings - Fork 698
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
Populate _rule_id virtual template parameter in Automatus #11943
Conversation
Templates have an implicit (virtual) parameter `_rule_id` that contains rule ID of the currently processed rule. This parameter is added by the build system and is passed to template preprocessing function. However, this parameter isn't set in when invoking the templating subsystem Automatus when resolving templated TSs. This causes some of the template preprocessing functions to traceback when testing templated rules in Automatus. Addressing: ``` Traceback (most recent call last): File "/home/jcerny/work/git/scap-security-guide/tests/automatus.py", line 518, in <module> main() File "/home/jcerny/work/git/scap-security-guide/tests/automatus.py", line 514, in main options.func(options) File "/home/jcerny/work/git/scap-security-guide/tests/ssg_test_suite/rule.py", line 676, in perform_rule_check checker.test_target() File "/home/jcerny/work/git/scap-security-guide/tests/ssg_test_suite/oscap.py", line 685, in test_target self._test_target() File "/home/jcerny/work/git/scap-security-guide/tests/ssg_test_suite/rule.py", line 444, in _test_target test_content_by_rule_id = self._get_test_content_by_rule_id( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jcerny/work/git/scap-security-guide/tests/ssg_test_suite/rule.py", line 427, in _get_test_content_by_rule_id rule_test_content = self._get_rule_test_content(rule) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jcerny/work/git/scap-security-guide/tests/ssg_test_suite/rule.py", line 409, in _get_rule_test_content all_tests = self._load_all_tests(rule) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jcerny/work/git/scap-security-guide/tests/ssg_test_suite/rule.py", line 399, in _load_all_tests templated_tests = common.load_templated_tests( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jcerny/work/git/scap-security-guide/tests/ssg_test_suite/common.py", line 494, in load_templated_tests test = load_test(path, template, local_env_yaml) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jcerny/work/git/scap-security-guide/tests/ssg_test_suite/common.py", line 506, in load_test template_parameters = maybe_template.preprocess(template_vars, "tests") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jcerny/work/git/scap-security-guide/tests/../ssg/templates.py", line 95, in preprocess parameters = self._preprocess_with_template_module(parameters, lang) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jcerny/work/git/scap-security-guide/tests/../ssg/templates.py", line 112, in _preprocess_with_template_module parameters = preprocess_mod.preprocess(parameters.copy(), lang) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jcerny/work/git/scap-security-guide/shared/templates/audit_rules_watch/template.py", line 3, in preprocess data["key"] = data["_rule_id"] ~~~~^^^^^^^^^^^^ KeyError: '_rule_id' ``` Fixes: ComplianceAsCode#11940
🤖 A k8s content image for this PR is available at: Click here to see how to deploy itIf you alread have Compliance Operator deployed: Otherwise deploy the content and operator together by checking out ComplianceAsCode/compliance-operator and: |
Code Climate has analyzed commit 8df9cbc and detected 0 issues on this pull request. The test coverage on the diff in this pull request is 100.0% (50% is the threshold). This pull request will bring the total coverage in the repository to 59.4% (0.0% change). View more on Code Climate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR.
I confirmed that this PR fixes the issue.
Templates have an implicit (virtual) parameter
_rule_id
that contains rule ID of the currently processed rule. This parameter is added by the build system and is passed to template preprocessing function. However, this parameter isn't set in when invoking the templating subsystem Automatus when resolving templated TSs. This causes some of the template preprocessing functions to traceback when testing templated rules in Automatus.Addressing:
Fixes: #11940