Debian Codegraph @

storage/columnstore/columnstore/cmake/selinux_policy.cmake

raw
1 # Build SELinux policy and package it for RPM on RHEL-like systems >= 9 only
2 # Builds from: storage/columnstore/columnstore/build/security/columnstore.te
3 # Produces: columnstore.pp packaged under ${ENGINE_SUPPORTDIR}/policy/selinux
4 # Adds BuildRequires: selinux-policy-devel (RPM, RHEL-like >= 9)
5
6 # Detect if we are building an RPM package
7 if(NOT RPM)
8 return()
9 endif()
10
11 columnstore_detect_os(_os_id _os_version_major)
12 columnstore_is_rhel_like("${_os_id}" _is_rhel_like)
13
14 # We only build on RHEL-like >= 10, however 9 was reported to have same troubles
15 if(NOT _is_rhel_like
16 OR (NOT _os_version_major)
17 OR (_os_version_major LESS 9)
18 )
19 message(
20 STATUS
21 "SELinux policy build skipped: OS '${_os_id}' version '${_os_version_major}' not matching RHEL-like >= 9 or undetected."
22 )
23 return()
24 endif()
25
26 # Use the common appender macro to handle comma separation.
27 # As a SRPM directive, it is global rather than for the component
28 columnstore_append_for_cpack(CPACK_RPM_BUILDREQUIRES "selinux-policy-devel")
29
30 # Paths
31 set(SELINUX_SRC_DIR "${CMAKE_CURRENT_LIST_DIR}/../build/security")
32 set(SELINUX_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/selinux")
33 set(SELINUX_TE "${SELINUX_SRC_DIR}/columnstore.te")
34 set(SELINUX_PP "${SELINUX_BUILD_DIR}/columnstore.pp")
35
36 file(MAKE_DIRECTORY "${SELINUX_BUILD_DIR}")
37
38 # Ensure selinux-policy-devel is available
39 if(NOT EXISTS "/usr/share/selinux/devel/Makefile")
40 message(
41 FATAL_ERROR
42 "SELinux policy build requires '/usr/share/selinux/devel/Makefile'. Please install 'selinux-policy-devel' (RHEL/Rocky >= 9) and re-run CMake."
43 )
44 endif()
45
46 # Custom command to build the .pp from .te using the upstream devel Makefile
47 add_custom_command(
48 OUTPUT "${SELINUX_PP}"
49 COMMAND ${CMAKE_COMMAND} -E copy "${SELINUX_TE}" "${SELINUX_BUILD_DIR}/columnstore.te"
50 COMMAND make -f /usr/share/selinux/devel/Makefile columnstore.pp
51 WORKING_DIRECTORY "${SELINUX_BUILD_DIR}"
52 DEPENDS "${SELINUX_TE}"
53 COMMENT "Building SELinux policy columnstore.pp from columnstore.te"
54 VERBATIM
55 )
56
57 add_custom_target(selinux_policy ALL DEPENDS "${SELINUX_PP}")
58
59 # Install the compiled policy into the package (no runtime dep). Post-install will load it conditionally.
60 install(
61 FILES "${SELINUX_PP}"
62 DESTINATION "${ENGINE_SUPPORTDIR}/policy/selinux"
63 COMPONENT columnstore-engine
64 )
65