Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
evgenyz committed Feb 6, 2024
1 parent 2034992 commit afaaaa5
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 36 deletions.
8 changes: 4 additions & 4 deletions shared/macros/10-oval.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Generates the :code:`<affected>` tag for OVAL check using correct product platfo
#}}
{{%- macro oval_affected(products) %}}
<affected family="unix">
{{{ prodtype_to_platform(products)|indent(2) }}}
{{{ product_to_platform(products)|indent(2) }}}
</affected>
{{%- endmacro %}}

Expand Down Expand Up @@ -132,7 +132,7 @@ Generates the :code:`<affected>` tag for OVAL check using correct product platfo
<def-group>
<definition class="compliance" id="{{{ rule_id }}}" version="1">
{{{ oval_metadata("Ensure '" + parameter + "' is configured with value '" + value | replace("(?i)", "") | replace("(?-i)", "") + (" in section '" + section if section else "") + "' in " + path) }}}
{{% set dir_path = path + ".d" %}}
{{% set dir_path = path + ".d" %}}
<criteria comment="{{{ application }}} is configured correctly"
operator="OR">
{{{- oval_line_in_file_criterion(path, parameter) }}}
Expand Down Expand Up @@ -1057,9 +1057,9 @@ Generates the :code:`<affected>` tag for OVAL check using correct product platfo
<extend_definition comment="sshd is required or requirement is unset"
definition_ref="sshd_required_or_unset" />
{{% if product in ['opensuse', 'sle12','sle15'] %}}
<extend_definition comment="rpm package openssh installed"
<extend_definition comment="rpm package openssh installed"
definition_ref="package_openssh_installed" />
{{% else %}}
{{% else %}}
<extend_definition comment="rpm package openssh-server installed"
definition_ref="package_openssh-server_installed" />
{{% endif %}}
Expand Down
1 change: 0 additions & 1 deletion shared/schemas/rule.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
"required": [
"documentation_complete",
"title",
"prodtype",
"description",
"rationale",
"severity"
Expand Down
3 changes: 1 addition & 2 deletions ssg/build_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,7 @@ def __deepcopy__(self, memo):
def _has_platforms_to_convert(rule, product_cpes):
# Convert the platform names to CPE names
# But only do it if an env_yaml was specified (otherwise there would
# be no product CPEs to lookup), and the rule's prodtype matches the
# product being built also if the rule already has cpe_platform_names
# be no product CPEs to lookup) and if the rule already has cpe_platform_names
# specified (compiled rule) do not evaluate platforms again
return product_cpes and not rule.cpe_platform_names

Expand Down
1 change: 0 additions & 1 deletion ssg/entities/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def resolve(self, all_profiles, rules_by_id, controls_manager=None):
if rid not in rules_by_id:
msg = (
"Rule {rid} is selected by {profile}, but the rule is not available. "
"This may be caused by a discrepancy of prodtypes."
.format(rid=rid, profile=self.id_))
raise ValueError(msg)

Expand Down
8 changes: 4 additions & 4 deletions ssg/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

from .constants import JINJA_MACROS_DIRECTORY
from .utils import (required_key,
prodtype_to_name,
product_to_name,
name_to_platform,
prodtype_to_platform,
product_to_platform,
banner_regexify,
banner_anchor_wrap,
escape_id,
Expand Down Expand Up @@ -135,9 +135,9 @@ def process_file(filepath, substitutions_dict):


def add_python_functions(substitutions_dict):
substitutions_dict['prodtype_to_name'] = prodtype_to_name
substitutions_dict['product_to_name'] = product_to_name
substitutions_dict['name_to_platform'] = name_to_platform
substitutions_dict['prodtype_to_platform'] = prodtype_to_platform
substitutions_dict['product_to_platform'] = product_to_platform
substitutions_dict['url_encode'] = url_encode
substitutions_dict['raise'] = raise_exception
substitutions_dict['expand_yaml_path'] = expand_yaml_path
Expand Down
17 changes: 8 additions & 9 deletions ssg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ def map_name(version):
% (version))


def prodtype_to_name(prod):
def product_to_name(prod):
"""
Converts a vaguely-prodtype-like thing into one or more full product names.
Converts a vaguely-product-id-like thing into one or more full product names.
"""
for name, prod_type in FULL_NAME_TO_PRODUCT_MAPPING.items():
if prod == prod_type:
Expand All @@ -150,14 +150,14 @@ def name_to_platform(names):
return "\n".join(map(name_to_platform, names))


def prodtype_to_platform(prods):
def product_to_platform(prods):
"""
Converts one or more prodtypes into a string with one or more <platform>
Converts one or more product ids into a string with one or more <platform>
elements.
"""
if isinstance(prods, str):
return name_to_platform(prodtype_to_name(prods))
return "\n".join(map(prodtype_to_platform, prods))
return name_to_platform(product_to_name(prods))
return "\n".join(map(product_to_platform, prods))


def parse_name(product):
Expand All @@ -181,7 +181,7 @@ def parse_name(product):

def get_fixed_product_version(product, product_version):
# Some product versions have a dot in between the numbers
# While the prodtype doesn't have the dot, the full product name does
# While the product id doesn't have the dot, the full product name does
if product == "ubuntu" or product == "macos":
product_version = product_version[:2] + "." + product_version[2:]
return product_version
Expand Down Expand Up @@ -230,8 +230,7 @@ def is_applicable_for_product(platform, product):
def is_applicable(platform, product):
"""
Function to check if a platform is applicable for the product.
Handles when a platform is really a list of products, i.e., a
prodtype field from a rule.yml.
Handles when a platform is really a list of products.
Returns true iff product is applicable for the platform or list
of products
Expand Down
11 changes: 0 additions & 11 deletions tests/ssg_test_suite/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,17 +322,6 @@ def _get_rules_to_test(self):
rule, local_env_yaml = common.load_rule_and_env(
dirpath, product_yaml, product)

# Before we get too far, we wish to search the rule YAML to see if
# it is applicable to the current product. If we have a product
# and the rule isn't applicable for the product, there's no point
# in continuing with the rest of the loading. This should speed up
# the loading of the templated tests. Note that we've already
# parsed the prodtype into local_env_yaml
if product and local_env_yaml['products']:
prodtypes = local_env_yaml['products']
if "all" not in prodtypes and product not in prodtypes:
continue

tests_dir = os.path.join(dirpath, "tests")
template_name = None
if rule.template and rule.template['vars']:
Expand Down
2 changes: 0 additions & 2 deletions utils/fix_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ def has_empty_identifier(rule_path, rule, rule_lines):
def has_no_cce(yaml_file, product_yaml=None):
rule = yaml.open_and_macro_expand(yaml_file, product_yaml)
product = product_yaml["product"]
if "prodtype" in rule and product not in rule["prodtype"]:
return False
if 'identifiers' in rule and rule['identifiers'] is None:
return True

Expand Down
2 changes: 1 addition & 1 deletion utils/gen_srg_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ def get_rules_by_srgid(build_dir, product):
data = dict()
data["srgs"] = ssg.build_stig.parse_srgs(args.srgs)
data["rules_by_srgid"] = get_rules_by_srgid(args.build_dir, args.product)
data["full_name"] = ssg.utils.prodtype_to_name(args.product)
data["full_name"] = ssg.utils.product_to_name(args.product)
render_template(data, SRGMAP_TEMPLATE, args.srgmap)
render_template(data, SRGMAP_FLAT_TEMPLATE, args.srgmap_flat)
1 change: 0 additions & 1 deletion utils/generate_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ def generate(self, control: pycompliance.Control):
)
output = {
'documentation_complete': False,
'prodtype': self.product_type,
'title': LiteralUnicode(control.title),
'description': description,
'rationale': LiteralUnicode(control.rationale),
Expand Down

0 comments on commit afaaaa5

Please sign in to comment.