guix-daemon.cil.in 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. ; -*- lisp -*-
  2. ;;; GNU Guix --- Functional package management for GNU
  3. ;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
  4. ;;; Copyright © 2020 Daniel Brooks <db48x@db48x.net>
  5. ;;; Copyright © 2020 Marius Bakke <marius@gnu.org>
  6. ;;;
  7. ;;; This file is part of GNU Guix.
  8. ;;;
  9. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  10. ;;; under the terms of the GNU General Public License as published by
  11. ;;; the Free Software Foundation; either version 3 of the License, or (at
  12. ;;; your option) any later version.
  13. ;;;
  14. ;;; GNU Guix is distributed in the hope that it will be useful, but
  15. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;;; GNU General Public License for more details.
  18. ;;;
  19. ;;; You should have received a copy of the GNU General Public License
  20. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  21. ;; This is a specification for SELinux 2.7 written in the SELinux Common
  22. ;; Intermediate Language (CIL). It refers to types that must be defined in
  23. ;; the system's base policy.
  24. ;; If you, like me, need advice about fixing an SELinux policy, I recommend
  25. ;; reading https://danwalsh.livejournal.com/55324.html
  26. ;; In particular, you can run semanage permissive -a guix_daemon.guix_daemon_t
  27. ;; to allow guix-daemon to do whatever it wants. SELinux will still check its
  28. ;; permissions, and when it doesn't have permission it will still send an
  29. ;; audit message to your system logs. This lets you know what permissions it
  30. ;; ought to have. Use ausearch --raw to find the permissions violations, then
  31. ;; pipe that to audit2allow to generate an updated policy. You'll still need
  32. ;; to translate that policy into CIL in order to update this file, but that's
  33. ;; fairly straight-forward. Annoying, but easy.
  34. (block guix_daemon
  35. ;; Require existing types
  36. (typeattributeset cil_gen_require init_t)
  37. (typeattributeset cil_gen_require tmp_t)
  38. (typeattributeset cil_gen_require nscd_var_run_t)
  39. (typeattributeset cil_gen_require var_log_t)
  40. (typeattributeset cil_gen_require domain)
  41. ;; Declare own types
  42. (type guix_daemon_t)
  43. (roletype object_r guix_daemon_t)
  44. (type guix_daemon_conf_t)
  45. (roletype object_r guix_daemon_conf_t)
  46. (typeattributeset file_type guix_daemon_conf_t)
  47. (type guix_daemon_exec_t)
  48. (roletype object_r guix_daemon_exec_t)
  49. (typeattributeset file_type guix_daemon_exec_t)
  50. (type guix_daemon_socket_t)
  51. (roletype object_r guix_daemon_socket_t)
  52. (typeattributeset file_type guix_daemon_socket_t)
  53. (type guix_store_content_t)
  54. (roletype object_r guix_store_content_t)
  55. (typeattributeset file_type guix_store_content_t)
  56. (type guix_profiles_t)
  57. (roletype object_r guix_profiles_t)
  58. (typeattributeset file_type guix_profiles_t)
  59. ;; These types are domains, thereby allowing process rules
  60. (typeattributeset domain (guix_daemon_t guix_daemon_exec_t))
  61. (level low (s0))
  62. ;; When a process in init_t or guix_store_content_t spawns a
  63. ;; guix_daemon_exec_t process, let it run in the guix_daemon_t context
  64. (typetransition init_t guix_daemon_exec_t
  65. process guix_daemon_t)
  66. (typetransition guix_store_content_t guix_daemon_exec_t
  67. process guix_daemon_t)
  68. (roletype system_r guix_daemon_t)
  69. ;; allow init_t to read and execute guix files
  70. (allow init_t
  71. guix_profiles_t
  72. (lnk_file (read)))
  73. (allow init_t
  74. guix_daemon_exec_t
  75. (file (execute)))
  76. (allow init_t
  77. guix_daemon_t
  78. (process (transition)))
  79. (allow init_t
  80. guix_store_content_t
  81. (lnk_file (read)))
  82. (allow init_t
  83. guix_store_content_t
  84. (file (open read execute)))
  85. ;; guix-daemon needs to know the names of users
  86. (allow guix_daemon_t
  87. passwd_file_t
  88. (file (getattr open read)))
  89. ;; Permit communication with NSCD
  90. (allow guix_daemon_t
  91. nscd_var_run_t
  92. (file (map read)))
  93. (allow guix_daemon_t
  94. nscd_var_run_t
  95. (dir (search)))
  96. (allow guix_daemon_t
  97. nscd_var_run_t
  98. (sock_file (write)))
  99. (allow guix_daemon_t
  100. nscd_t
  101. (fd (use)))
  102. (allow guix_daemon_t
  103. nscd_t
  104. (unix_stream_socket (connectto)))
  105. (allow guix_daemon_t nscd_t
  106. (nscd (getgrp gethost getpwd getserv shmemgrp shmemhost shmempwd shmemserv)))
  107. ;; permit downloading packages via HTTP(s)
  108. (allow guix_daemon_t http_port_t
  109. (tcp_socket (name_connect)))
  110. (allow guix_daemon_t ftp_port_t
  111. (tcp_socket (name_connect)))
  112. (allow guix_daemon_t ephemeral_port_t
  113. (tcp_socket (name_connect)))
  114. ;; Permit logging and temp file access
  115. (allow guix_daemon_t
  116. tmp_t
  117. (lnk_file (create rename setattr unlink)))
  118. (allow guix_daemon_t
  119. tmp_t
  120. (file (link
  121. rename create execute execute_no_trans write
  122. unlink setattr map relabelto relabelfrom)))
  123. (allow guix_daemon_t
  124. tmp_t
  125. (fifo_file (open read write create getattr ioctl setattr unlink)))
  126. (allow guix_daemon_t
  127. tmp_t
  128. (dir (create rename
  129. rmdir relabelto relabelfrom reparent
  130. add_name remove_name
  131. open read write
  132. getattr setattr
  133. search)))
  134. (allow guix_daemon_t
  135. tmp_t
  136. (sock_file (create getattr setattr unlink write)))
  137. (allow guix_daemon_t
  138. var_log_t
  139. (file (create getattr open write)))
  140. (allow guix_daemon_t
  141. var_log_t
  142. (dir (getattr create write add_name)))
  143. (allow guix_daemon_t
  144. var_run_t
  145. (lnk_file (read)))
  146. (allow guix_daemon_t
  147. var_run_t
  148. (dir (search)))
  149. ;; Spawning processes, execute helpers
  150. (allow guix_daemon_t
  151. self
  152. (process (fork execmem setrlimit setpgid setsched)))
  153. (allow guix_daemon_t
  154. guix_daemon_exec_t
  155. (file (execute
  156. execute_no_trans read write open entrypoint map
  157. getattr link unlink)))
  158. ;; TODO: unknown
  159. (allow guix_daemon_t
  160. root_t
  161. (dir (mounton)))
  162. (allow guix_daemon_t
  163. fs_t
  164. (filesystem (getattr)))
  165. (allow guix_daemon_conf_t
  166. fs_t
  167. (filesystem (associate)))
  168. ;; Build isolation
  169. (allow guix_daemon_t
  170. guix_store_content_t
  171. (file (ioctl mounton)))
  172. (allow guix_store_content_t
  173. fs_t
  174. (filesystem (associate)))
  175. (allow guix_daemon_t
  176. guix_store_content_t
  177. (dir (read mounton)))
  178. (allow guix_daemon_t
  179. guix_daemon_t
  180. (capability (net_admin
  181. fsetid fowner
  182. chown setuid setgid
  183. dac_override dac_read_search
  184. sys_chroot
  185. sys_admin)))
  186. (allow guix_daemon_t
  187. fs_t
  188. (filesystem (unmount)))
  189. (allow guix_daemon_t
  190. devpts_t
  191. (dir (search)))
  192. (allow guix_daemon_t
  193. devpts_t
  194. (filesystem (mount)))
  195. (allow guix_daemon_t
  196. devpts_t
  197. (chr_file (ioctl open read write setattr getattr)))
  198. (allow guix_daemon_t
  199. tmpfs_t
  200. (filesystem (getattr mount)))
  201. (allow guix_daemon_t
  202. tmpfs_t
  203. (file (create open read unlink write)))
  204. (allow guix_daemon_t
  205. tmpfs_t
  206. (dir (getattr add_name remove_name write)))
  207. (allow guix_daemon_t
  208. proc_t
  209. (file (getattr open read)))
  210. (allow guix_daemon_t
  211. proc_t
  212. (dir (read)))
  213. (allow guix_daemon_t
  214. proc_t
  215. (filesystem (associate mount)))
  216. (allow guix_daemon_t
  217. null_device_t
  218. (chr_file (getattr open read write)))
  219. (allow guix_daemon_t
  220. kvm_device_t
  221. (chr_file (getattr)))
  222. (allow guix_daemon_t
  223. zero_device_t
  224. (chr_file (getattr)))
  225. (allow guix_daemon_t
  226. urandom_device_t
  227. (chr_file (getattr)))
  228. (allow guix_daemon_t
  229. random_device_t
  230. (chr_file (getattr)))
  231. (allow guix_daemon_t
  232. devtty_t
  233. (chr_file (getattr)))
  234. ;; Access to store items
  235. (allow guix_daemon_t
  236. guix_store_content_t
  237. (dir (reparent
  238. create
  239. getattr setattr
  240. search rename
  241. add_name remove_name
  242. open write
  243. rmdir relabelfrom)))
  244. (allow guix_daemon_t
  245. guix_store_content_t
  246. (file (create
  247. lock
  248. setattr getattr
  249. execute execute_no_trans
  250. link unlink
  251. map
  252. rename
  253. append
  254. open read write relabelfrom)))
  255. (allow guix_daemon_t
  256. guix_store_content_t
  257. (lnk_file (create
  258. getattr setattr
  259. link unlink
  260. read
  261. rename)))
  262. (allow guix_daemon_t
  263. guix_store_content_t
  264. (fifo_file (create getattr open read unlink write)))
  265. (allow guix_daemon_t
  266. guix_store_content_t
  267. (sock_file (create getattr setattr unlink write)))
  268. ;; Access to configuration files and directories
  269. (allow guix_daemon_t
  270. guix_daemon_conf_t
  271. (dir (search create
  272. setattr getattr
  273. add_name remove_name
  274. open read write)))
  275. (allow guix_daemon_t
  276. guix_daemon_conf_t
  277. (file (create rename
  278. lock
  279. map
  280. getattr setattr
  281. unlink
  282. open read write)))
  283. (allow guix_daemon_t
  284. guix_daemon_conf_t
  285. (lnk_file (create getattr rename unlink read)))
  286. (allow guix_daemon_t net_conf_t
  287. (file (getattr open read)))
  288. (allow guix_daemon_t net_conf_t
  289. (lnk_file (read)))
  290. (allow guix_daemon_t NetworkManager_var_run_t
  291. (dir (search)))
  292. ;; Access to profiles
  293. (allow guix_daemon_t
  294. guix_profiles_t
  295. (dir (search getattr setattr read write open create add_name)))
  296. (allow guix_daemon_t
  297. guix_profiles_t
  298. (lnk_file (read getattr)))
  299. ;; Access to profile links in the home directory
  300. ;; TODO: allow access to profile links *anywhere* on the filesystem
  301. (allow guix_daemon_t
  302. user_home_t
  303. (lnk_file (read getattr)))
  304. (allow guix_daemon_t
  305. user_home_t
  306. (dir (search)))
  307. (allow guix_daemon_t
  308. cache_home_t
  309. (dir (search)))
  310. (allow guix_daemon_t
  311. cache_home_t
  312. (lnk_file (getattr read)))
  313. ;; self upgrades
  314. (allow guix_daemon_t
  315. self
  316. (dir (add_name write)))
  317. (allow guix_daemon_t
  318. self
  319. (netlink_route_socket (bind create getattr nlmsg_read read write getopt)))
  320. ;; Socket operations
  321. (allow guix_daemon_t
  322. guix_daemon_socket_t
  323. (sock_file (unlink write)))
  324. (allow guix_daemon_t
  325. init_t
  326. (fd (use)))
  327. (allow guix_daemon_t
  328. init_t
  329. (unix_stream_socket (write)))
  330. (allow guix_daemon_t
  331. guix_daemon_conf_t
  332. (unix_stream_socket (listen)))
  333. (allow guix_daemon_t
  334. guix_daemon_conf_t
  335. (sock_file (create unlink)))
  336. (allow guix_daemon_t
  337. self
  338. (unix_stream_socket (create
  339. read write
  340. connect bind accept
  341. getopt setopt)))
  342. (allow guix_daemon_t
  343. self
  344. (tcp_socket (accept listen bind connect create setopt getopt getattr ioctl read write shutdown)))
  345. (allow guix_daemon_t
  346. unreserved_port_t
  347. (tcp_socket (name_bind name_connect accept listen)))
  348. (allow guix_daemon_t
  349. self
  350. (udp_socket (connect getattr bind getopt setopt read write)))
  351. (allow guix_daemon_t
  352. self
  353. (fifo_file (write read)))
  354. (allow guix_daemon_t
  355. self
  356. (udp_socket (ioctl create)))
  357. (allow guix_daemon_t
  358. self
  359. (unix_stream_socket (connectto)))
  360. (allow guix_daemon_t
  361. self
  362. (unix_dgram_socket (create bind connect sendto read write)))
  363. ;; For some esoteric build jobs (i.e. running PostgreSQL, etc).
  364. (allow guix_daemon_t
  365. self
  366. (capability (kill)))
  367. (allow guix_daemon_t
  368. node_t
  369. (tcp_socket (node_bind)))
  370. (allow guix_daemon_t
  371. node_t
  372. (udp_socket (node_bind)))
  373. (allow guix_daemon_t
  374. port_t
  375. (tcp_socket (name_connect)))
  376. (allow guix_daemon_t
  377. tmpfs_t
  378. (file (map read write link getattr)))
  379. (allow guix_daemon_t
  380. usermodehelper_t
  381. (file (read)))
  382. (allow guix_daemon_t
  383. hugetlbfs_t
  384. (file (map read write)))
  385. (allow guix_daemon_t
  386. proc_net_t
  387. (file (read)))
  388. (allow guix_daemon_t
  389. postgresql_port_t
  390. (tcp_socket (name_connect name_bind)))
  391. (allow guix_daemon_t
  392. rtp_media_port_t
  393. (udp_socket (name_bind)))
  394. (allow guix_daemon_t
  395. vnc_port_t
  396. (tcp_socket (name_bind)))
  397. ;; I guess sometimes it needs random numbers
  398. (allow guix_daemon_t
  399. random_device_t
  400. (chr_file (read)))
  401. ;; guix system vm
  402. (allow guix_daemon_t
  403. kvm_device_t
  404. (chr_file (ioctl open read write)))
  405. (allow guix_daemon_t
  406. kernel_t
  407. (system (ipc_info)))
  408. ;; Label file system
  409. (filecon "@guix_sysconfdir@/guix(/.*)?"
  410. any (system_u object_r guix_daemon_conf_t (low low)))
  411. (filecon "@guix_localstatedir@/guix(/.*)?"
  412. any (system_u object_r guix_daemon_conf_t (low low)))
  413. (filecon "@guix_localstatedir@/guix/profiles(/.*)?"
  414. any (system_u object_r guix_profiles_t (low low)))
  415. (filecon "/gnu"
  416. dir (unconfined_u object_r guix_store_content_t (low low)))
  417. (filecon "@storedir@(/.+)?"
  418. any (unconfined_u object_r guix_store_content_t (low low)))
  419. (filecon "@storedir@/[^/]+/.+"
  420. any (unconfined_u object_r guix_store_content_t (low low)))
  421. (filecon "@prefix@/bin/guix-daemon"
  422. file (system_u object_r guix_daemon_exec_t (low low)))
  423. (filecon "@storedir@/.+-(guix-.+|profile)/bin/guix-daemon"
  424. file (system_u object_r guix_daemon_exec_t (low low)))
  425. (filecon "@storedir@/[a-z0-9]+-guix-daemon"
  426. file (system_u object_r guix_daemon_exec_t (low low)))
  427. (filecon "@guix_localstatedir@/guix/daemon-socket/socket"
  428. any (system_u object_r guix_daemon_socket_t (low low))))