def main():
    args = parse_args()

    env_yaml = ssg.environment.open_environment(args.build_config_yaml,
                                                args.product_yaml)

    product = ssg.utils.required_key(env_yaml, "product")
    output_dirs = prepare_output_dirs(args.output_dir, args.remediation_type)
    product_cpes = ProductCPEs(env_yaml)
    cpe_platforms = dict()
    for platform_file in os.listdir(args.platforms_dir):
        platform_path = os.path.join(args.platforms_dir, platform_file)
        try:
            platform = ssg.build_yaml.Platform.from_yaml(
                platform_path, env_yaml, product_cpes)
        except ssg.build_yaml.DocumentationNotComplete:
            # Happens on non-debug build when a platform is
            # "documentation-incomplete"
            continue
        cpe_platforms[platform.name] = platform

    for rule_file in os.listdir(args.resolved_rules_dir):
        rule_path = os.path.join(args.resolved_rules_dir, rule_file)
        try:
            rule = ssg.build_yaml.Rule.from_yaml(rule_path, env_yaml)
        except ssg.build_yaml.DocumentationNotComplete:
            # Happens on non-debug build when a rule is
            # "documentation-incomplete"
            continue
        collect_remediations(rule, args.remediation_type,
                             args.fixes_from_templates_dir, product,
                             output_dirs, env_yaml, cpe_platforms)
    sys.exit(0)
Beispiel #2
0
def main():
    parser = create_parser()
    args = parser.parse_args()

    env_yaml = get_env_yaml(args.build_config_yaml, args.product_yaml)
    product_cpes = ProductCPEs(env_yaml)

    build_root = os.path.dirname(args.build_config_yaml)

    logfile = "{build_root}/{product}/control_profiles.log".format(
        build_root=build_root, product=env_yaml["product"])
    logging.basicConfig(filename=logfile, level=logging.INFO)

    loader = ssg.build_yaml.BuildLoader(None, env_yaml, product_cpes,
                                        args.sce_metadata,
                                        args.stig_references)
    load_benchmark_source_data_from_directory_tree(loader, env_yaml,
                                                   args.product_yaml)

    profiles_by_id = get_all_resolved_profiles_by_id(env_yaml,
                                                     args.product_yaml, loader,
                                                     product_cpes,
                                                     args.controls_dir)

    save_everything(args.resolved_base, loader, profiles_by_id.values())
Beispiel #3
0
 def __init__(self, env_yaml, resolved_rules_dir, templates_dir,
              remediations_dir, checks_dir):
     self.env_yaml = env_yaml
     self.resolved_rules_dir = resolved_rules_dir
     self.templates_dir = templates_dir
     self.remediations_dir = remediations_dir
     self.checks_dir = checks_dir
     self.output_dirs = dict()
     for lang in languages:
         lang_dir = lang
         if lang == "oval" or lang.startswith("sce-"):
             # OVAL and SCE checks need to be put to a different directory
             # because they are processed differently than remediations
             # later in the build process
             output_dir = self.checks_dir
             if lang.startswith("sce-"):
                 lang_dir = "sce"
         else:
             output_dir = self.remediations_dir
         dir_ = os.path.join(output_dir, lang_dir)
         self.output_dirs[lang] = dir_
     # scan directory structure and dynamically create list of templates
     for item in sorted(os.listdir(self.templates_dir)):
         itempath = os.path.join(self.templates_dir, item)
         maybe_template = Template(templates_dir, item)
         if maybe_template.looks_like_template():
             maybe_template.load()
             templates[item] = maybe_template
     self.product_cpes = ProductCPEs(env_yaml)
Beispiel #4
0
def _get_platform_cpes(platform):
    ssg_root = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
    if platform.startswith("multi_platform_"):
        try:
            products = MULTI_PLATFORM_MAPPING[platform]
        except KeyError:
            logging.error(
                "Unknown multi_platform specifier: %s is not from %s" %
                (platform, ", ".join(MULTI_PLATFORM_MAPPING.keys())))
            raise ValueError
        platform_cpes = set()
        for p in products:
            product_yaml_path = os.path.join(ssg_root, "products", p,
                                             "product.yml")
            product_yaml = load_product_yaml(product_yaml_path)
            p_cpes = ProductCPEs(product_yaml)
            platform_cpes |= set(p_cpes.get_product_cpe_names())
        return platform_cpes
    else:
        # scenario platform is specified by a full product name
        try:
            product = FULL_NAME_TO_PRODUCT_MAPPING[platform]
        except KeyError:
            logging.error(
                "Unknown product name: %s is not from %s" %
                (platform, ", ".join(FULL_NAME_TO_PRODUCT_MAPPING.keys())))
            raise ValueError
        product_yaml_path = os.path.join(ssg_root, "products", product,
                                         "product.yml")
        product_yaml = load_product_yaml(product_yaml_path)
        product_cpes = ProductCPEs(product_yaml)
        platform_cpes = set(product_cpes.get_product_cpe_names())
        return platform_cpes
Beispiel #5
0
def _get_platform_cpes(platform):
    if platform.startswith("multi_platform_"):
        try:
            products = MULTI_PLATFORM_MAPPING[platform]
        except KeyError:
            logging.error(
                "Unknown multi_platform specifier: %s is not from %s" %
                (platform, ", ".join(MULTI_PLATFORM_MAPPING.keys())))
            raise ValueError
        platform_cpes = set()
        for p in products:
            p_cpes = ProductCPEs(p)
            platform_cpes |= set(p_cpes.get_product_cpe_names())
        return platform_cpes
    else:
        # scenario platform is specified by a full product name
        try:
            product = FULL_NAME_TO_PRODUCT_MAPPING[platform]
        except KeyError:
            logging.error(
                "Unknown product name: %s is not from %s" %
                (platform, ", ".join(FULL_NAME_TO_PRODUCT_MAPPING.keys())))
            raise ValueError
        product_cpes = ProductCPEs(product)
        platform_cpes = set(product_cpes.get_product_cpe_names())
        return platform_cpes
Beispiel #6
0
def product_cpes():
    product_yaml_path = os.path.join(DATADIR, "product.yml")
    product_yaml = open_raw(product_yaml_path)
    product_yaml["product_dir"] = os.path.dirname(product_yaml_path)
    return ProductCPEs(product_yaml)