selinux.scm 21 KB

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