selinux.scm 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (gnu packages selinux)
  20. #:use-module ((guix licenses) #:prefix license:)
  21. #:use-module (guix packages)
  22. #:use-module (guix download)
  23. #:use-module (guix git-download)
  24. #:use-module (guix utils)
  25. #:use-module (guix build-system gnu)
  26. #:use-module (guix build-system python)
  27. #:use-module (gnu packages)
  28. #:use-module (gnu packages admin)
  29. #:use-module (gnu packages bison)
  30. #:use-module (gnu packages docbook)
  31. #:use-module (gnu packages flex)
  32. #:use-module (gnu packages gettext)
  33. #:use-module (gnu packages glib)
  34. #:use-module (gnu packages linux)
  35. #:use-module (gnu packages networking)
  36. #:use-module (gnu packages pcre)
  37. #:use-module (gnu packages pkg-config)
  38. #:use-module (gnu packages python)
  39. #:use-module (gnu packages python-xyz)
  40. #:use-module (gnu packages swig)
  41. #:use-module (gnu packages textutils)
  42. #:use-module (gnu packages xml))
  43. ;; Update the SELinux packages together!
  44. (define-public libsepol
  45. (package
  46. (name "libsepol")
  47. (version "2.7")
  48. (source (let ((release "20170804"))
  49. (origin
  50. (method git-fetch)
  51. (uri (git-reference
  52. (url "https://github.com/SELinuxProject/selinux.git")
  53. (commit release)))
  54. (file-name (string-append "selinux-" release "-checkout"))
  55. (sha256
  56. (base32
  57. "1l1nn8bx08v4cxkw5kb0wgr61rfqj5ra9dh1dy5jslillj93vivq")))))
  58. (build-system gnu-build-system)
  59. (arguments
  60. `(#:tests? #f ; tests require checkpolicy, which requires libsepol
  61. #:test-target "test"
  62. #:make-flags
  63. (let ((out (assoc-ref %outputs "out")))
  64. (list (string-append "PREFIX=" out)
  65. (string-append "DESTDIR=" out)
  66. (string-append "MAN3DIR=" out "/share/man/man3")
  67. (string-append "MAN5DIR=" out "/share/man/man5")
  68. (string-append "MAN8DIR=" out "/share/man/man8")
  69. (string-append "LDFLAGS=-Wl,-rpath=" out "/lib")
  70. "CC=gcc"))
  71. #:phases
  72. (modify-phases %standard-phases
  73. (delete 'configure)
  74. (add-after 'unpack 'enter-dir
  75. (lambda _ (chdir ,name) #t))
  76. (add-after 'enter-dir 'portability
  77. (lambda _
  78. (substitute* "src/ibpkeys.c"
  79. (("#include \"ibpkey_internal.h\"" line)
  80. (string-append line "\n#include <inttypes.h>\n"))
  81. (("%#lx") "%#\" PRIx64 \""))
  82. #t)))))
  83. (native-inputs
  84. `(("flex" ,flex)))
  85. (home-page "https://selinuxproject.org/")
  86. (synopsis "Library for manipulating SELinux policies")
  87. (description
  88. "The libsepol library provides an API for the manipulation of SELinux
  89. binary policies. It is used by @code{checkpolicy} (the policy compiler) and
  90. similar tools, and programs such as @code{load_policy}, which must perform
  91. specific transformations on binary policies (for example, customizing policy
  92. boolean settings).")
  93. (license license:lgpl2.1+)))
  94. (define-public checkpolicy
  95. (package (inherit libsepol)
  96. (name "checkpolicy")
  97. (arguments
  98. `(#:tests? #f ; there is no check target
  99. #:make-flags
  100. (let ((out (assoc-ref %outputs "out")))
  101. (list (string-append "PREFIX=" out)
  102. (string-append "LIBSEPOLA="
  103. (assoc-ref %build-inputs "libsepol")
  104. "/lib/libsepol.a")
  105. "CC=gcc"))
  106. #:phases
  107. (modify-phases %standard-phases
  108. (delete 'configure)
  109. (delete 'portability)
  110. (add-after 'unpack 'enter-dir
  111. (lambda _ (chdir ,name) #t)))))
  112. (inputs
  113. `(("libsepol" ,libsepol)))
  114. (native-inputs
  115. `(("bison" ,bison)
  116. ("flex" ,flex)))
  117. (synopsis "Check SELinux security policy configurations and modules")
  118. (description
  119. "This package provides the tools \"checkpolicy\" and \"checkmodule\".
  120. Checkpolicy is a program that checks and compiles a SELinux security policy
  121. configuration into a binary representation that can be loaded into the kernel.
  122. Checkmodule is a program that checks and compiles a SELinux security policy
  123. module into a binary representation.")
  124. ;; GPLv2 only
  125. (license license:gpl2)))
  126. (define-public libselinux
  127. (package (inherit libsepol)
  128. (name "libselinux")
  129. (arguments
  130. (substitute-keyword-arguments (package-arguments libsepol)
  131. ((#:make-flags flags)
  132. `(cons* "PYTHON=python3"
  133. (string-append "LIBSEPOLA="
  134. (assoc-ref %build-inputs "libsepol")
  135. "/lib/libsepol.a")
  136. (string-append "PYSITEDIR="
  137. (assoc-ref %outputs "out")
  138. "/lib/python"
  139. ,(version-major+minor (package-version python))
  140. "/site-packages/")
  141. ,flags))
  142. ((#:phases phases)
  143. `(modify-phases ,phases
  144. (delete 'portability)
  145. (replace 'enter-dir
  146. (lambda _ (chdir ,name) #t))
  147. (add-after 'enter-dir 'remove-Werror
  148. (lambda _
  149. ;; GCC complains about the fact that the output does not (yet)
  150. ;; have an "include" directory, even though it is referenced.
  151. (substitute* '("src/Makefile"
  152. "utils/Makefile")
  153. (("-Werror ") ""))
  154. #t))
  155. (add-after 'build 'pywrap
  156. (lambda* (#:key make-flags #:allow-other-keys)
  157. (apply invoke "make" "pywrap" make-flags)))
  158. (add-after 'install 'install-pywrap
  159. (lambda* (#:key make-flags #:allow-other-keys)
  160. (apply invoke "make" "install-pywrap" make-flags)))))))
  161. ;; These libraries are in "Requires.private" in libselinux.pc.
  162. (propagated-inputs
  163. `(("libsepol" ,libsepol)
  164. ("pcre" ,pcre)))
  165. ;; For pywrap phase
  166. (inputs
  167. `(("python" ,python-wrapper)))
  168. ;; These inputs are only needed for the pywrap phase.
  169. (native-inputs
  170. `(("swig" ,swig)
  171. ("pkg-config" ,pkg-config)))
  172. (synopsis "SELinux core libraries and utilities")
  173. (description
  174. "The libselinux library provides an API for SELinux applications to get
  175. and set process and file security contexts, and to obtain security policy
  176. decisions. It is required for any applications that use the SELinux API, and
  177. used by all applications that are SELinux-aware. This package also includes
  178. the core SELinux management utilities.")
  179. (license license:public-domain)))
  180. (define-public libsemanage
  181. (package (inherit libsepol)
  182. (name "libsemanage")
  183. (arguments
  184. (substitute-keyword-arguments (package-arguments libsepol)
  185. ((#:make-flags flags)
  186. `(cons* "PYTHON=python3"
  187. (string-append "PYSITEDIR="
  188. (assoc-ref %outputs "out")
  189. "/lib/python"
  190. ,(version-major+minor (package-version python))
  191. "/site-packages/")
  192. ,flags))
  193. ((#:phases phases)
  194. `(modify-phases ,phases
  195. (delete 'portability)
  196. (replace 'enter-dir
  197. (lambda _ (chdir ,name) #t))
  198. (add-after 'build 'pywrap
  199. (lambda* (#:key make-flags #:allow-other-keys)
  200. (apply invoke "make" "pywrap" make-flags)))
  201. (add-after 'install 'install-pywrap
  202. (lambda* (#:key make-flags #:allow-other-keys)
  203. (apply invoke "make" "install-pywrap" make-flags)))))))
  204. (inputs
  205. `(("libsepol" ,libsepol)
  206. ("libselinux" ,libselinux)
  207. ("audit" ,audit)
  208. ("ustr" ,ustr)
  209. ;; For pywrap phase
  210. ("python" ,python-wrapper)))
  211. (native-inputs
  212. `(("bison" ,bison)
  213. ("flex" ,flex)
  214. ;; For pywrap phase
  215. ("swig" ,swig)
  216. ("pkg-config" ,pkg-config)))
  217. (synopsis "SELinux policy management libraries")
  218. (description
  219. "The libsemanage library provides an API for the manipulation of SELinux
  220. binary policies.")
  221. (license license:lgpl2.1+)))
  222. (define-public secilc
  223. (package (inherit libsepol)
  224. (name "secilc")
  225. (arguments
  226. (substitute-keyword-arguments (package-arguments libsepol)
  227. ((#:make-flags flags)
  228. `(let ((docbook (assoc-ref %build-inputs "docbook-xsl")))
  229. (cons (string-append "XMLTO=xmlto --skip-validation -x "
  230. docbook "/xml/xsl/docbook-xsl-"
  231. ,(package-version 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) #t))))))
  239. (inputs
  240. `(("libsepol" ,libsepol)))
  241. (native-inputs
  242. `(("xmlto" ,xmlto)
  243. ("docbook-xsl" ,docbook-xsl)))
  244. (synopsis "SELinux common intermediate language (CIL) compiler")
  245. (description "The SELinux CIL compiler is a compiler that converts the
  246. @dfn{common intermediate language} (CIL) into a kernel binary policy file.")
  247. (license license:bsd-2)))
  248. (define-public python-sepolgen
  249. (package (inherit libsepol)
  250. (name "python-sepolgen")
  251. (arguments
  252. `(#:modules ((srfi srfi-1)
  253. (guix build gnu-build-system)
  254. (guix build utils))
  255. ,@(substitute-keyword-arguments (package-arguments libsepol)
  256. ((#:phases phases)
  257. `(modify-phases ,phases
  258. (delete 'portability)
  259. (replace 'enter-dir
  260. (lambda _ (chdir "python/sepolgen") #t))
  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 outputs #: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. (substitute* "src/sepolgen/Makefile"
  274. (("^PACKAGEDIR.*")
  275. (string-append "PACKAGEDIR="
  276. (assoc-ref outputs "out")
  277. "/lib/python"
  278. (get-python-version
  279. (assoc-ref inputs "python"))
  280. "/site-packages/sepolgen")))
  281. (substitute* "src/share/Makefile"
  282. (("\\$\\(DESTDIR\\)") (assoc-ref outputs "out"))))
  283. #t)))))))
  284. (inputs
  285. `(("python" ,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.1.1")
  304. (source (origin
  305. (method git-fetch)
  306. (uri (git-reference
  307. (url "https://github.com/TresysTechnology/setools.git")
  308. (commit version)))
  309. (file-name (string-append name "-" version "-checkout"))
  310. (sha256
  311. (base32
  312. "0459xxly6zzqc5azcwk3rbbcxvj60dq08f8z6xr05y7dsbb16cg6"))))
  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. (string-append (assoc-ref inputs "libsepol")
  323. "/lib/libsepol.a"))))
  324. (add-after 'unpack 'remove-Werror
  325. (lambda _
  326. (substitute* "setup.py"
  327. (("'-Werror',") ""))
  328. #t))
  329. (add-after 'unpack 'fix-target-paths
  330. (lambda* (#:key outputs #:allow-other-keys)
  331. (substitute* "setup.py"
  332. (("join\\(sys.prefix")
  333. (string-append "join(\"" (assoc-ref outputs "out") "/\"")))
  334. #t)))))
  335. (propagated-inputs
  336. `(("python-networkx" ,python-networkx)))
  337. (inputs
  338. `(("libsepol" ,libsepol)
  339. ("libselinux" ,libselinux)))
  340. (native-inputs
  341. `(("bison" ,bison)
  342. ("flex" ,flex)
  343. ("swig" ,swig)))
  344. (home-page "https://github.com/TresysTechnology/setools")
  345. (synopsis "Tools for SELinux policy analysis")
  346. (description "SETools is a collection of graphical tools, command-line
  347. tools, and libraries designed to facilitate SELinux policy analysis.")
  348. ;; Some programs are under GPL, all libraries under LGPL.
  349. (license (list license:lgpl2.1+
  350. license:gpl2+))))
  351. (define-public policycoreutils
  352. (package (inherit libsepol)
  353. (name "policycoreutils")
  354. (arguments
  355. `(#:test-target "test"
  356. #:make-flags
  357. (let ((out (assoc-ref %outputs "out")))
  358. (list "CC=gcc"
  359. (string-append "PREFIX=" out)
  360. (string-append "LOCALEDIR=" out "/share/locale")
  361. (string-append "BASHCOMPLETIONDIR=" out
  362. "/share/bash-completion/completions")
  363. "INSTALL=install -c -p"
  364. "INSTALL_DIR=install -d"
  365. ;; These ones are needed because some Makefiles define the
  366. ;; directories relative to DESTDIR, not relative to PREFIX.
  367. (string-append "SBINDIR=" out "/sbin")
  368. (string-append "ETCDIR=" out "/etc")
  369. (string-append "SYSCONFDIR=" out "/etc/sysconfig")
  370. (string-append "MAN5DIR=" out "/share/man/man5")
  371. (string-append "INSTALL_NLS_DIR=" out "/share/locale")
  372. (string-append "AUTOSTARTDIR=" out "/etc/xdg/autostart")
  373. (string-append "DBUSSERVICEDIR=" out "/share/dbus-1/services")
  374. (string-append "SYSTEMDDIR=" out "/lib/systemd")
  375. (string-append "INITDIR=" out "/etc/rc.d/init.d")
  376. (string-append "SELINUXDIR=" out "/etc/selinux")))
  377. #:phases
  378. (modify-phases %standard-phases
  379. (delete 'configure)
  380. (delete 'portability)
  381. (add-after 'unpack 'enter-dir
  382. (lambda _ (chdir ,name) #t))
  383. (add-after 'enter-dir 'ignore-/usr-tests
  384. (lambda* (#:key inputs #:allow-other-keys)
  385. ;; The Makefile decides to build restorecond only if it finds the
  386. ;; inotify header somewhere under /usr.
  387. (substitute* "Makefile"
  388. (("ifeq.*") "")
  389. (("endif.*") ""))
  390. ;; Rewrite lookup paths for header files.
  391. (substitute* '("newrole/Makefile"
  392. "setfiles/Makefile"
  393. "run_init/Makefile")
  394. (("/usr(/include/security/pam_appl.h)" _ file)
  395. (string-append (assoc-ref inputs "pam") file))
  396. (("/usr(/include/libaudit.h)" _ file)
  397. (string-append (assoc-ref inputs "audit") file)))
  398. #t)))))
  399. (inputs
  400. `(("audit" ,audit)
  401. ("pam" ,linux-pam)
  402. ("libsepol" ,libsepol)
  403. ("libselinux" ,libselinux)
  404. ("libsemanage" ,libsemanage)))
  405. (native-inputs
  406. `(("gettext" ,gettext-minimal)))
  407. (synopsis "SELinux core utilities")
  408. (description "The policycoreutils package contains the core utilities that
  409. are required for the basic operation of an SELinux-enabled GNU system and its
  410. policies. These utilities include @code{load_policy} to load policies,
  411. @code{setfiles} to label file systems, @code{newrole} to switch roles, and
  412. @code{run_init} to run service scripts in their proper context.")
  413. (license license:gpl2+)))