Skip to content

Commit dc6d9a7

Browse files
committed
Allow conditional building of SCE content
Introduces the SSG_SCE_ENABLED variable (defaulting to false) to enable/disable SCE content generation. Note that an empty metadata.json will still be generated, but no SCE content will be generated. Signed-off-by: Alexander Scheel <[email protected]>
1 parent 7dbd76d commit dc6d9a7

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ option(SSG_ANSIBLE_PLAYBOOKS_PER_RULE_ENABLED "If enabled, Ansible Playbooks for
5252
option(SSG_BASH_SCRIPTS_ENABLED "If enabled, Bash remediation scripts for each profile will be built and installed." TRUE)
5353
option(SSG_JINJA2_CACHE_ENABLED "If enabled, the jinja2 templating files will be cached into bytecode. Also see SSG_JINJA2_CACHE_DIR." TRUE)
5454
option(SSG_BATS_TESTS_ENABLED "If enabled, bats will be used to run unit-tests of bash remediations." TRUE)
55+
option(SSG_SCE_ENABLED "If enabled, additional SCE audit content will be enabled alongside OVAL-based auditing." FALSE)
5556
set(SSG_JINJA2_CACHE_DIR "${CMAKE_BINARY_DIR}/jinja2_cache" CACHE PATH "Where the jinja2 cached bytecode should be stored. This speeds up builds at the expense of disk space. You can use one location for multiple SSG builds for performance improvements.")
5657

5758
# SSG_PRODUCT_DEFAULT modifies the behavior of all other options. Products

build_config.yml.in

+2
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ target_oval_version_str: "@SSG_TARGET_OVAL_VERSION@"
77

88
jinja2_cache_enabled: @SSG_JINJA2_CACHE_ENABLED_BOOL@
99
jinja2_cache_dir: "@SSG_JINJA2_CACHE_DIR@"
10+
11+
sce_enabled: "@SSG_SCE_ENABLED@"

cmake/SSGCommon.cmake

+29-15
Original file line numberDiff line numberDiff line change
@@ -393,19 +393,31 @@ macro(ssg_build_sce PRODUCT)
393393
# in the combine paths below.
394394
set(SCE_COMBINE_PATHS "${SSG_SHARED}/checks/sce" "${CMAKE_CURRENT_SOURCE_DIR}/checks/sce")
395395

396-
# Unlike build_oval_unlinked, we don't depend on templated content yet.
397-
#
398-
# This is for two reasons:
399-
# 1. Support for templated SCE isn't yet implemented.
400-
# 2. Generating YAML->Shorthand (in ssg_build_shorthand_xml) relies on
401-
# our data, so we need it to occur earlier. However, templating depends
402-
# the Shorthand, so we'd have a dependency circle.
403-
add_custom_command(
404-
OUTPUT "${BUILD_CHECKS_DIR}/sce/metadata.json"
405-
COMMAND env "PYTHONPATH=$ENV{PYTHONPATH}" "${PYTHON_EXECUTABLE}" "${SSG_BUILD_SCRIPTS}/build_sce.py" --build-config-yaml "${CMAKE_BINARY_DIR}/build_config.yml" --product-yaml "${CMAKE_CURRENT_SOURCE_DIR}/product.yml" --output "${BUILD_CHECKS_DIR}/sce" ${SCE_COMBINE_PATHS}
406-
DEPENDS "${SSG_BUILD_SCRIPTS}/build_sce.py"
407-
COMMENT "[${PRODUCT}-content] generating sce/metadata.json"
408-
)
396+
if (SSG_SCE_ENABLED)
397+
# Unlike build_oval_unlinked, we don't depend on templated content yet.
398+
#
399+
# This is for two reasons:
400+
# 1. Support for templated SCE isn't yet implemented.
401+
# 2. Generating YAML->Shorthand (in ssg_build_shorthand_xml) relies on
402+
# our data, so we need it to occur earlier. However, templating depends
403+
# the Shorthand, so we'd have a dependency circle.
404+
add_custom_command(
405+
OUTPUT "${BUILD_CHECKS_DIR}/sce/metadata.json"
406+
COMMAND env "PYTHONPATH=$ENV{PYTHONPATH}" "${PYTHON_EXECUTABLE}" "${SSG_BUILD_SCRIPTS}/build_sce.py" --build-config-yaml "${CMAKE_BINARY_DIR}/build_config.yml" --product-yaml "${CMAKE_CURRENT_SOURCE_DIR}/product.yml" --output "${BUILD_CHECKS_DIR}/sce" ${SCE_COMBINE_PATHS}
407+
DEPENDS "${SSG_BUILD_SCRIPTS}/build_sce.py"
408+
COMMENT "[${PRODUCT}-content] generating sce/metadata.json"
409+
)
410+
else()
411+
# Here we fake generating SCE metadata by creating an empty file.
412+
# Because every other step reads data from this metadata file, if
413+
# it is empty, no SCE content will actually be generated.
414+
add_custom_command(
415+
OUTPUT "${BUILD_CHECKS_DIR}/sce/metadata.json"
416+
COMMAND ${CMAKE_COMMAND} -E make_directory "${BUILD_CHECKS_DIR}/sce"
417+
COMMAND ${CMAKE_COMMAND} -E touch "${BUILD_CHECKS_DIR}/sce/metadata.json"
418+
COMMENT "[${PRODUCT}-content] generating sce/metadata.json"
419+
)
420+
endif()
409421
add_custom_target(
410422
generate-internal-${PRODUCT}-sce-metadata.json
411423
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/checks/sce/metadata.json"
@@ -920,8 +932,10 @@ macro(ssg_build_product PRODUCT)
920932
DESTINATION "${SSG_CONTENT_INSTALL_DIR}")
921933
endif()
922934

923-
install(DIRECTORY "${CMAKE_BINARY_DIR}/${PRODUCT}/checks/sce/"
924-
DESTINATION "${SSG_CONTENT_INSTALL_DIR}/${PRODUCT}/checks/sce")
935+
if (SSG_SCE_ENABLED)
936+
install(DIRECTORY "${CMAKE_BINARY_DIR}/${PRODUCT}/checks/sce/"
937+
DESTINATION "${SSG_CONTENT_INSTALL_DIR}/${PRODUCT}/checks/sce")
938+
endif()
925939

926940
install(FILES "${CMAKE_BINARY_DIR}/ssg-${PRODUCT}-ds.xml"
927941
DESTINATION "${SSG_CONTENT_INSTALL_DIR}")

ssg/build_yaml.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1594,7 +1594,7 @@ def __init__(self, profiles_dir, bash_remediation_fns, env_yaml,
15941594
os.mkdir(resolved_rules_dir)
15951595

15961596
self.sce_metadata = None
1597-
if sce_metadata_path:
1597+
if sce_metadata_path and os.path.getsize(sce_metadata_path):
15981598
self.sce_metadata = json.load(open(sce_metadata_path, 'r'))
15991599

16001600
def _process_values(self):

0 commit comments

Comments
 (0)