selinux.scm 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016, 2017, 2018 Ricardo Wurmus <rekado@elephly.net>
  3. ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
  4. ;;; Copyright © 2019, 2020, 2022 Marius Bakke <marius@gnu.org>
  5. ;;; Copyright © 2021 Efraim Flashner <efraim@flashner.co.il>
  6. ;;; Copyright © 2021 Guillaume Le Vaillant <glv@posteo.net>
  7. ;;;
  8. ;;; This file is part of GNU Guix.
  9. ;;;
  10. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  11. ;;; under the terms of the GNU General Public License as published by
  12. ;;; the Free Software Foundation; either version 3 of the License, or (at
  13. ;;; your option) any later version.
  14. ;;;
  15. ;;; GNU Guix is distributed in the hope that it will be useful, but
  16. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;;; GNU General Public License for more details.
  19. ;;;
  20. ;;; You should have received a copy of the GNU General Public License
  21. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  22. (define-module (gnu packages selinux)
  23. #:use-module ((guix licenses) #:prefix license:)
  24. #:use-module (guix packages)
  25. #:use-module (guix gexp)
  26. #:use-module (guix download)
  27. #:use-module (guix git-download)
  28. #:use-module (guix utils)
  29. #:use-module (guix build-system gnu)
  30. #:use-module (guix build-system python)
  31. #:use-module (gnu packages)
  32. #:use-module (gnu packages admin)
  33. #:use-module (gnu packages bison)
  34. #:use-module (gnu packages docbook)
  35. #:use-module (gnu packages flex)
  36. #:use-module (gnu packages gettext)
  37. #:use-module (gnu packages glib)
  38. #:use-module (gnu packages linux)
  39. #:use-module (gnu packages networking)
  40. #:use-module (gnu packages pcre)
  41. #:use-module (gnu packages pkg-config)
  42. #:use-module (gnu packages python)
  43. #:use-module (gnu packages python-xyz)
  44. #:use-module (gnu packages qt)
  45. #:use-module (gnu packages swig)
  46. #:use-module (gnu packages xml))
  47. ;; Update the SELinux packages together!
  48. (define-public libsepol
  49. (package
  50. (name "libsepol")
  51. (version "3.4")
  52. (source (origin
  53. (method git-fetch)
  54. (uri (git-reference
  55. (url "https://github.com/SELinuxProject/selinux")
  56. (commit version)))
  57. (file-name (git-file-name "selinux" version))
  58. (sha256
  59. (base32
  60. "1lcmgmfr0q7g5cwg6b7jm6ncw8cw6c1jblkm93v1g37bfhcgrqc0"))))
  61. (build-system gnu-build-system)
  62. (arguments
  63. (list
  64. #:tests? #f ; tests require checkpolicy, which requires libsepol
  65. #:test-target "test"
  66. #:make-flags
  67. #~(let ((out #$output))
  68. (list (string-append "PREFIX=" out)
  69. (string-append "SHLIBDIR=" out "/lib")
  70. (string-append "MAN3DIR=" out "/share/man/man3")
  71. (string-append "MAN5DIR=" out "/share/man/man5")
  72. (string-append "MAN8DIR=" out "/share/man/man8")
  73. (string-append "CFLAGS=-Wno-error")
  74. (string-append "LDFLAGS=-Wl,-rpath=" out "/lib")
  75. (string-append "CC=" #$(cc-for-target))))
  76. #:phases
  77. #~(modify-phases %standard-phases
  78. (delete 'configure)
  79. (add-after 'unpack 'enter-dir
  80. (lambda _ (chdir #$name)))
  81. (add-after 'enter-dir 'portability
  82. (lambda _
  83. (substitute* "src/ibpkeys.c"
  84. (("#include \"ibpkey_internal.h\"" line)
  85. (string-append line "\n#include <inttypes.h>\n"))
  86. (("%#lx") "%#\" PRIx64 \"")))))))
  87. (native-inputs
  88. (list flex))
  89. (home-page "https://selinuxproject.org/")
  90. (synopsis "Library for manipulating SELinux policies")
  91. (description
  92. "The libsepol library provides an API for the manipulation of SELinux
  93. binary policies. It is used by @code{checkpolicy} (the policy compiler) and
  94. similar tools, and programs such as @code{load_policy}, which must perform
  95. specific transformations on binary policies (for example, customizing policy
  96. boolean settings).")
  97. (license license:lgpl2.1+)))
  98. (define-public checkpolicy
  99. (package/inherit libsepol
  100. (name "checkpolicy")
  101. (arguments
  102. (list
  103. #:tests? #f ; there is no check target
  104. #:make-flags
  105. #~(list (string-append "PREFIX=" #$output)
  106. (string-append "LIBSEPOLA="
  107. (search-input-file %build-inputs
  108. "/lib/libsepol.a"))
  109. (string-append "CC=" #$(cc-for-target)))
  110. #:phases
  111. #~(modify-phases %standard-phases
  112. (delete 'configure)
  113. (delete 'portability)
  114. (add-after 'unpack 'enter-dir
  115. (lambda _ (chdir #$name))))))
  116. (inputs
  117. (list libsepol))
  118. (native-inputs
  119. (list bison flex))
  120. (synopsis "Check SELinux security policy configurations and modules")
  121. (description
  122. "This package provides the tools \"checkpolicy\" and \"checkmodule\".
  123. Checkpolicy is a program that checks and compiles a SELinux security policy
  124. configuration into a binary representation that can be loaded into the kernel.
  125. Checkmodule is a program that checks and compiles a SELinux security policy
  126. module into a binary representation.")
  127. ;; GPLv2 only
  128. (license license:gpl2)))
  129. (define-public libselinux
  130. (package/inherit libsepol
  131. (name "libselinux")
  132. (outputs '("out" "python"))
  133. (arguments
  134. (substitute-keyword-arguments (package-arguments libsepol)
  135. ((#:make-flags flags)
  136. #~(cons* "PYTHON=python3"
  137. (string-append "LIBSEPOLA="
  138. (search-input-file %build-inputs
  139. "/lib/libsepol.a"))
  140. (string-append "PYTHONLIBDIR="
  141. #$output:python
  142. "/lib/python"
  143. #$(version-major+minor (package-version python))
  144. "/site-packages/")
  145. #$flags))
  146. ((#:phases phases)
  147. #~(modify-phases #$phases
  148. (delete 'portability)
  149. (replace 'enter-dir
  150. (lambda _ (chdir #$name)))
  151. (add-after 'build 'pywrap
  152. (lambda* (#:key make-flags #:allow-other-keys)
  153. (apply invoke "make" "pywrap" make-flags)))
  154. (add-after 'install 'install-pywrap
  155. (lambda* (#:key make-flags #:allow-other-keys)
  156. ;; The build system uses "python setup.py install" to install
  157. ;; Python bindings. Instruct it to use the correct output.
  158. (substitute* "src/Makefile"
  159. (("--prefix=\\$\\(PREFIX\\)")
  160. (string-append "--prefix=" #$output:python
  161. ;; Python 3.10 refuses to execute the install
  162. ;; command unless these flags are present.
  163. " --single-version-externally-managed"
  164. " --root=/")))
  165. (apply invoke "make" "install-pywrap" make-flags)))))))
  166. ;; These libraries are in "Requires.private" in libselinux.pc.
  167. (propagated-inputs
  168. (list libsepol pcre2))
  169. ;; For pywrap phase
  170. (inputs
  171. (list python-wrapper))
  172. ;; These inputs are only needed for the pywrap phase.
  173. (native-inputs
  174. (list pkg-config swig))
  175. (synopsis "SELinux core libraries and utilities")
  176. (description
  177. "The libselinux library provides an API for SELinux applications to get
  178. and set process and file security contexts, and to obtain security policy
  179. decisions. It is required for any applications that use the SELinux API, and
  180. used by all applications that are SELinux-aware. This package also includes
  181. the core SELinux management utilities.")
  182. (license license:public-domain)))
  183. (define-public libsemanage
  184. (package/inherit libsepol
  185. (name "libsemanage")
  186. (arguments
  187. (substitute-keyword-arguments (package-arguments libsepol)
  188. ((#:make-flags flags)
  189. #~(cons* "PYTHON=python3"
  190. (string-append "PYTHONLIBDIR="
  191. #$output
  192. "/lib/python"
  193. #$(version-major+minor (package-version python))
  194. "/site-packages/")
  195. #$flags))
  196. ((#:phases phases)
  197. #~(modify-phases #$phases
  198. (delete 'portability)
  199. (replace 'enter-dir
  200. (lambda _ (chdir #$name)))
  201. (add-before 'install 'adjust-semanage-conf-location
  202. (lambda _
  203. (substitute* "src/Makefile"
  204. (("DEFAULT_SEMANAGE_CONF_LOCATION=/etc")
  205. "DEFAULT_SEMANAGE_CONF_LOCATION=$(PREFIX)/etc"))))
  206. (add-after 'build 'pywrap
  207. (lambda* (#:key make-flags #:allow-other-keys)
  208. (apply invoke "make" "pywrap" make-flags)))
  209. (add-after 'install 'install-pywrap
  210. (lambda* (#:key make-flags #:allow-other-keys)
  211. (apply invoke "make" "install-pywrap" make-flags)))))))
  212. (inputs
  213. (list audit libsepol libselinux python-wrapper))
  214. (native-inputs
  215. (list bison flex pkg-config swig))
  216. (synopsis "SELinux policy management libraries")
  217. (description
  218. "The libsemanage library provides an API for the manipulation of SELinux
  219. binary policies.")
  220. (license license:lgpl2.1+)))
  221. (define-public secilc
  222. (package/inherit libsepol
  223. (name "secilc")
  224. (arguments
  225. (substitute-keyword-arguments (package-arguments libsepol)
  226. ((#:make-flags flags)
  227. #~(let ((xsl (search-input-directory %build-inputs "xml/xsl")))
  228. (cons (string-append "XMLTO=xmlto --skip-validation -x "
  229. xsl "/docbook-xsl-"
  230. #$(package-version
  231. (this-package-native-input "docbook-xsl"))
  232. "/manpages/docbook.xsl")
  233. #$flags)))
  234. ((#:phases phases)
  235. #~(modify-phases #$phases
  236. (delete 'portability)
  237. (replace 'enter-dir
  238. (lambda _ (chdir #$name)))))))
  239. (inputs
  240. (list libsepol))
  241. (native-inputs
  242. (list xmlto docbook-xsl))
  243. (synopsis "SELinux common intermediate language (CIL) compiler")
  244. (description "The SELinux CIL compiler is a compiler that converts the
  245. @dfn{common intermediate language} (CIL) into a kernel binary policy file.")
  246. (license license:bsd-2)))
  247. (define-public python-sepolgen
  248. (package/inherit libsepol
  249. (name "python-sepolgen")
  250. (arguments
  251. (substitute-keyword-arguments (package-arguments libsepol)
  252. ((#:modules _ #~%gnu-build-system-modules)
  253. '((srfi srfi-1)
  254. (guix build gnu-build-system)
  255. (guix build utils)))
  256. ((#:phases phases)
  257. #~(modify-phases #$phases
  258. (delete 'portability)
  259. (replace 'enter-dir
  260. (lambda _ (chdir "python/sepolgen")))
  261. ;; By default all Python files would be installed to
  262. ;; $out/gnu/store/...-python-.../, so we override the
  263. ;; PACKAGEDIR to fix this.
  264. (add-after 'enter-dir 'fix-target-path
  265. (lambda* (#:key inputs #:allow-other-keys)
  266. (let ((get-python-version
  267. ;; FIXME: copied from python-build-system
  268. (lambda (python)
  269. (let* ((version (last (string-split python #\-)))
  270. (components (string-split version #\.))
  271. (major+minor (take components 2)))
  272. (string-join major+minor "."))))
  273. (python (dirname (dirname (search-input-file
  274. inputs "bin/python3")))))
  275. (substitute* "src/sepolgen/Makefile"
  276. (("^PACKAGEDIR.*")
  277. (string-append "PACKAGEDIR="
  278. #$output
  279. "/lib/python"
  280. (get-python-version python)
  281. "/site-packages/sepolgen")))
  282. (substitute* "src/share/Makefile"
  283. (("\\$\\(DESTDIR\\)") #$output)))))))))
  284. (inputs
  285. (list python-wrapper))
  286. (native-inputs '())
  287. (synopsis "Python module for generating SELinux policies")
  288. (description
  289. "This package contains a Python module that forms the core of
  290. @code{audit2allow}, a part of the package @code{policycoreutils}. The
  291. sepolgen library contains: Reference Policy Representation, which are Objects
  292. for representing policies and the reference policy interfaces. It has objects
  293. and algorithms for representing access and sets of access in an abstract way
  294. and searching that access. It also has a parser for reference policy
  295. \"headers\". It contains infrastructure for parsing SELinux related messages
  296. as produced by the audit system. It has facilities for generating policy
  297. based on required access.")
  298. ;; GPLv2 only
  299. (license license:gpl2)))
  300. (define-public python-setools
  301. (package
  302. (name "python-setools")
  303. (version "4.4.0")
  304. (source (origin
  305. (method git-fetch)
  306. (uri (git-reference
  307. (url "https://github.com/SELinuxProject/setools")
  308. (commit version)))
  309. (file-name (string-append name "-" version "-checkout"))
  310. (sha256
  311. (base32
  312. "1qvd5j6zwq4fmlahg45swjplhif2z89x7s6pnp07gvcp2fbqdsh5"))))
  313. (build-system python-build-system)
  314. (arguments
  315. `(#:tests? #f ; the test target causes a rebuild
  316. #:phases
  317. (modify-phases %standard-phases
  318. (delete 'portability)
  319. (add-after 'unpack 'set-SEPOL-variable
  320. (lambda* (#:key inputs #:allow-other-keys)
  321. (setenv "SEPOL"
  322. (search-input-file inputs "/lib/libsepol.a"))))
  323. (add-after 'unpack 'remove-Werror
  324. (lambda _
  325. (substitute* "setup.py"
  326. (("'-Werror',") ""))
  327. #t))
  328. (add-after 'unpack 'fix-target-paths
  329. (lambda* (#:key outputs #:allow-other-keys)
  330. (substitute* "setup.py"
  331. (("join\\(sys.prefix")
  332. (string-append "join(\"" (assoc-ref outputs "out") "/\"")))
  333. #t)))))
  334. (propagated-inputs
  335. (list python-networkx))
  336. (inputs
  337. (list libsepol libselinux python-pyqt))
  338. (native-inputs
  339. (list bison flex python-cython swig))
  340. (home-page "https://github.com/SELinuxProject/setools")
  341. (synopsis "Tools for SELinux policy analysis")
  342. (description "SETools is a collection of graphical tools, command-line
  343. tools, and libraries designed to facilitate SELinux policy analysis.")
  344. ;; Some programs are under GPL, all libraries under LGPL.
  345. (license (list license:lgpl2.1+
  346. license:gpl2+))))
  347. (define-public policycoreutils
  348. (package/inherit libsepol
  349. (name "policycoreutils")
  350. (arguments
  351. (list
  352. #:test-target "test"
  353. #:make-flags
  354. #~(let ((out #$output))
  355. (list (string-append "CC=" #$(cc-for-target))
  356. (string-append "PREFIX=" out)
  357. (string-append "LOCALEDIR=" out "/share/locale")
  358. (string-append "BASHCOMPLETIONDIR=" out
  359. "/share/bash-completion/completions")
  360. "INSTALL=install -c -p"
  361. "INSTALL_DIR=install -d"
  362. ;; These ones are needed because some Makefiles define the
  363. ;; directories relative to DESTDIR, not relative to PREFIX.
  364. (string-append "SBINDIR=" out "/sbin")
  365. (string-append "ETCDIR=" out "/etc")
  366. (string-append "SYSCONFDIR=" out "/etc/sysconfig")
  367. (string-append "MAN5DIR=" out "/share/man/man5")
  368. (string-append "INSTALL_NLS_DIR=" out "/share/locale")
  369. (string-append "AUTOSTARTDIR=" out "/etc/xdg/autostart")
  370. (string-append "DBUSSERVICEDIR=" out "/share/dbus-1/services")
  371. (string-append "SYSTEMDDIR=" out "/lib/systemd")
  372. (string-append "INITDIR=" out "/etc/rc.d/init.d")
  373. (string-append "SELINUXDIR=" out "/etc/selinux")))
  374. #:phases
  375. #~(modify-phases %standard-phases
  376. (delete 'configure)
  377. (add-after 'unpack 'enter-dir
  378. (lambda _ (chdir #$name)))
  379. (add-after 'enter-dir 'ignore-/usr-tests
  380. (lambda* (#:key inputs #:allow-other-keys)
  381. ;; Rewrite lookup paths for header files.
  382. (substitute* '("newrole/Makefile"
  383. "setfiles/Makefile"
  384. "run_init/Makefile")
  385. (("/usr(/include/security/pam_appl.h)" _ file)
  386. (search-input-file inputs file))
  387. (("/usr(/include/libaudit.h)" _ file)
  388. (search-input-file inputs file))))))))
  389. (inputs
  390. (list audit
  391. linux-pam
  392. libsepol
  393. libselinux
  394. libsemanage))
  395. (native-inputs
  396. (list gettext-minimal))
  397. (synopsis "SELinux core utilities")
  398. (description "The policycoreutils package contains the core utilities that
  399. are required for the basic operation of an SELinux-enabled GNU system and its
  400. policies. These utilities include @code{load_policy} to load policies,
  401. @code{setfiles} to label file systems, @code{newrole} to switch roles, and
  402. @code{run_init} to run service scripts in their proper context.")
  403. (license license:gpl2+)))