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

Populate _rule_id virtual template parameter in Automatus #11943

Merged
merged 1 commit into from
May 6, 2024

Commits on May 6, 2024

  1. Populate _rule_id virtual template parameter in Automatus

    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
    jan-cerny committed May 6, 2024
    Configuration menu
    Copy the full SHA
    8df9cbc View commit details
    Browse the repository at this point in the history