selinux.scm 17 KB

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