guix-daemon.cil.in 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. ; -*- lisp -*-
  2. ;;; GNU Guix --- Functional package management for GNU
  3. ;;; Copyright © 2018, 2022 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 domain)
  37. (typeattributeset cil_gen_require init_t)
  38. (typeattributeset cil_gen_require init_var_run_t)
  39. (typeattributeset cil_gen_require nscd_var_run_t)
  40. (typeattributeset cil_gen_require system_dbusd_var_run_t)
  41. (typeattributeset cil_gen_require tmp_t)
  42. (typeattributeset cil_gen_require var_log_t)
  43. ;; Declare own types
  44. (type guix_daemon_t)
  45. (roletype object_r guix_daemon_t)
  46. (type guix_daemon_conf_t)
  47. (roletype object_r guix_daemon_conf_t)
  48. (typeattributeset file_type guix_daemon_conf_t)
  49. (type guix_daemon_exec_t)
  50. (roletype object_r guix_daemon_exec_t)
  51. (typeattributeset file_type guix_daemon_exec_t)
  52. (type guix_daemon_socket_t)
  53. (roletype object_r guix_daemon_socket_t)
  54. (typeattributeset file_type guix_daemon_socket_t)
  55. (type guix_store_content_t)
  56. (roletype object_r guix_store_content_t)
  57. (typeattributeset file_type guix_store_content_t)
  58. (type guix_profiles_t)
  59. (roletype object_r guix_profiles_t)
  60. (typeattributeset file_type guix_profiles_t)
  61. ;; These types are domains, thereby allowing process rules
  62. (typeattributeset domain (guix_daemon_t guix_daemon_exec_t))
  63. (level low (s0))
  64. ;; When a process in init_t or guix_store_content_t spawns a
  65. ;; guix_daemon_exec_t process, let it run in the guix_daemon_t context
  66. (typetransition init_t guix_daemon_exec_t
  67. process guix_daemon_t)
  68. (typetransition guix_store_content_t guix_daemon_exec_t
  69. process guix_daemon_t)
  70. (roletype system_r guix_daemon_t)
  71. ;; allow init_t to read and execute guix files
  72. (allow init_t
  73. guix_profiles_t
  74. (lnk_file (read)))
  75. (allow init_t
  76. guix_daemon_exec_t
  77. (file (execute)))
  78. (allow init_t
  79. guix_daemon_t
  80. (process (transition)))
  81. (allow init_t
  82. guix_store_content_t
  83. (lnk_file (read)))
  84. (allow init_t
  85. guix_store_content_t
  86. (file (open read execute)))
  87. (allow init_t
  88. guix_profiles_t
  89. (dir (setattr)))
  90. ;; guix-daemon needs to know the names of users
  91. (allow guix_daemon_t
  92. passwd_file_t
  93. (file (getattr open read)))
  94. ;; Permit communication with NSCD
  95. (allow guix_daemon_t
  96. nscd_var_run_t
  97. (file (map read)))
  98. (allow guix_daemon_t
  99. nscd_var_run_t
  100. (dir (search)))
  101. (allow guix_daemon_t
  102. nscd_var_run_t
  103. (sock_file (write)))
  104. (allow guix_daemon_t
  105. nscd_t
  106. (fd (use)))
  107. (allow guix_daemon_t
  108. nscd_t
  109. (unix_stream_socket (connectto)))
  110. (allow guix_daemon_t nscd_t
  111. (nscd (getgrp gethost getpwd getserv shmemgrp shmemhost shmempwd shmemserv)))
  112. ;; permit downloading packages via HTTP(s)
  113. (allow guix_daemon_t http_port_t
  114. (tcp_socket (name_connect)))
  115. (allow guix_daemon_t ftp_port_t
  116. (tcp_socket (name_connect)))
  117. (allow guix_daemon_t ephemeral_port_t
  118. (tcp_socket (name_connect)))
  119. ;; Permit logging and temp file access
  120. (allow guix_daemon_t
  121. tmp_t
  122. (lnk_file (create rename setattr unlink)))
  123. (allow guix_daemon_t
  124. tmp_t
  125. (file (link
  126. rename create execute execute_no_trans write
  127. unlink setattr map relabelto relabelfrom)))
  128. (allow guix_daemon_t
  129. tmp_t
  130. (fifo_file (open read write create getattr ioctl setattr unlink)))
  131. (allow guix_daemon_t
  132. tmp_t
  133. (dir (create rename
  134. rmdir relabelto relabelfrom reparent
  135. add_name remove_name
  136. open read write
  137. getattr setattr
  138. search)))
  139. (allow guix_daemon_t
  140. tmp_t
  141. (sock_file (create getattr setattr unlink write)))
  142. (allow guix_daemon_t
  143. var_log_t
  144. (file (create getattr open write)))
  145. (allow guix_daemon_t
  146. var_log_t
  147. (dir (getattr create write add_name)))
  148. (allow guix_daemon_t
  149. var_run_t
  150. (lnk_file (read)))
  151. (allow guix_daemon_t
  152. var_run_t
  153. (dir (search)))
  154. ;; Spawning processes, execute helpers
  155. (allow guix_daemon_t
  156. self
  157. (process (fork execmem setrlimit setpgid setsched)))
  158. (allow guix_daemon_t
  159. guix_daemon_exec_t
  160. (file (execute
  161. execute_no_trans read write open entrypoint map
  162. getattr link unlink)))
  163. ;; Remounting /gnu/store read-write.
  164. (allow guix_daemon_t
  165. fs_t
  166. (filesystem (remount)))
  167. ;; TODO: unknown
  168. (allow guix_daemon_t
  169. root_t
  170. (dir (mounton)))
  171. (allow guix_daemon_t
  172. fs_t
  173. (filesystem (getattr)))
  174. (allow guix_daemon_conf_t
  175. fs_t
  176. (filesystem (associate)))
  177. ;; Build isolation
  178. (allow guix_daemon_t
  179. guix_store_content_t
  180. (file (ioctl mounton)))
  181. (allow guix_store_content_t
  182. fs_t
  183. (filesystem (associate)))
  184. (allow guix_daemon_t
  185. guix_store_content_t
  186. (dir (read mounton)))
  187. (allow guix_daemon_t
  188. guix_daemon_t
  189. (capability (net_admin
  190. fsetid fowner
  191. chown setuid setgid
  192. dac_override dac_read_search
  193. sys_chroot
  194. sys_admin)))
  195. (allow guix_daemon_t
  196. fs_t
  197. (filesystem (unmount)))
  198. (allow guix_daemon_t
  199. devpts_t
  200. (dir (search)))
  201. (allow guix_daemon_t
  202. devpts_t
  203. (filesystem (mount)))
  204. (allow guix_daemon_t
  205. devpts_t
  206. (chr_file (ioctl open read write setattr getattr)))
  207. (allow guix_daemon_t
  208. tmpfs_t
  209. (filesystem (getattr mount)))
  210. (allow guix_daemon_t
  211. tmpfs_t
  212. (file (create open read unlink write)))
  213. (allow guix_daemon_t ;same as above, but with tmp_t
  214. tmp_t
  215. (file (create open read unlink write)))
  216. (allow guix_daemon_t
  217. tmpfs_t
  218. (dir (getattr add_name remove_name write)))
  219. (allow guix_daemon_t
  220. proc_t
  221. (file (getattr open read)))
  222. (allow guix_daemon_t
  223. proc_t
  224. (dir (read)))
  225. (allow guix_daemon_t
  226. proc_t
  227. (filesystem (associate mount)))
  228. (allow guix_daemon_t
  229. null_device_t
  230. (chr_file (getattr open read write)))
  231. (allow guix_daemon_t
  232. kvm_device_t
  233. (chr_file (getattr)))
  234. (allow guix_daemon_t
  235. zero_device_t
  236. (chr_file (getattr)))
  237. (allow guix_daemon_t
  238. urandom_device_t
  239. (chr_file (getattr)))
  240. (allow guix_daemon_t
  241. random_device_t
  242. (chr_file (getattr)))
  243. (allow guix_daemon_t
  244. devtty_t
  245. (chr_file (getattr)))
  246. ;; Access to store items
  247. (allow guix_daemon_t
  248. guix_store_content_t
  249. (dir (reparent
  250. create
  251. getattr setattr
  252. search rename
  253. add_name remove_name
  254. open write
  255. rmdir relabelfrom)))
  256. (allow guix_daemon_t
  257. guix_store_content_t
  258. (file (create
  259. lock
  260. setattr getattr
  261. execute execute_no_trans
  262. link unlink
  263. map
  264. rename
  265. append
  266. open read write relabelfrom)))
  267. (allow guix_daemon_t
  268. guix_store_content_t
  269. (lnk_file (create
  270. getattr setattr
  271. link unlink
  272. read
  273. rename)))
  274. (allow guix_daemon_t
  275. guix_store_content_t
  276. (fifo_file (create getattr open read unlink write)))
  277. (allow guix_daemon_t
  278. guix_store_content_t
  279. (sock_file (create getattr setattr unlink write)))
  280. ;; Access to run state directories
  281. (allow guix_daemon_t
  282. system_dbusd_var_run_t
  283. (dir (search)))
  284. (allow guix_daemon_t
  285. init_var_run_t
  286. (dir (search)))
  287. ;; Access to configuration files and directories
  288. (allow guix_daemon_t
  289. guix_daemon_conf_t
  290. (dir (search create
  291. setattr getattr
  292. add_name remove_name
  293. open read write)))
  294. (allow guix_daemon_t
  295. guix_daemon_conf_t
  296. (file (create rename
  297. lock
  298. map
  299. getattr setattr
  300. unlink
  301. open read write)))
  302. (allow guix_daemon_t
  303. guix_daemon_conf_t
  304. (lnk_file (create getattr rename unlink read)))
  305. (allow guix_daemon_t net_conf_t
  306. (file (getattr open read)))
  307. (allow guix_daemon_t net_conf_t
  308. (lnk_file (read)))
  309. (allow guix_daemon_t NetworkManager_var_run_t
  310. (dir (search)))
  311. ;; Access to profiles
  312. (allow guix_daemon_t
  313. guix_profiles_t
  314. (dir (search getattr setattr read write open create add_name)))
  315. (allow guix_daemon_t
  316. guix_profiles_t
  317. (lnk_file (read getattr)))
  318. ;; Access to profile links in the home directory
  319. ;; TODO: allow access to profile links *anywhere* on the filesystem
  320. (allow guix_daemon_t
  321. user_home_t
  322. (lnk_file (read getattr)))
  323. (allow guix_daemon_t
  324. user_home_t
  325. (dir (search)))
  326. (allow guix_daemon_t
  327. cache_home_t
  328. (dir (search)))
  329. (allow guix_daemon_t
  330. cache_home_t
  331. (lnk_file (getattr read)))
  332. ;; self upgrades
  333. (allow guix_daemon_t
  334. self
  335. (dir (add_name write)))
  336. (allow guix_daemon_t
  337. self
  338. (netlink_route_socket (bind create getattr nlmsg_read read write getopt)))
  339. ;; Socket operations
  340. (allow guix_daemon_t
  341. guix_daemon_socket_t
  342. (sock_file (unlink write)))
  343. (allow guix_daemon_t
  344. init_t
  345. (fd (use)))
  346. (allow guix_daemon_t
  347. init_t
  348. (unix_stream_socket (write)))
  349. (allow guix_daemon_t
  350. guix_daemon_conf_t
  351. (unix_stream_socket (listen)))
  352. (allow guix_daemon_t
  353. guix_daemon_conf_t
  354. (sock_file (create unlink write)))
  355. (allow guix_daemon_t
  356. self
  357. (unix_stream_socket (create
  358. read write
  359. connect bind accept
  360. getopt setopt)))
  361. (allow guix_daemon_t
  362. self
  363. (tcp_socket (accept listen bind connect create setopt getopt getattr ioctl read write shutdown)))
  364. (allow guix_daemon_t
  365. unreserved_port_t
  366. (tcp_socket (name_bind name_connect accept listen)))
  367. (allow guix_daemon_t
  368. self
  369. (udp_socket (connect getattr bind getopt setopt read write)))
  370. (allow guix_daemon_t
  371. self
  372. (fifo_file (write read)))
  373. (allow guix_daemon_t
  374. self
  375. (udp_socket (ioctl create)))
  376. (allow guix_daemon_t
  377. self
  378. (unix_stream_socket (connectto)))
  379. (allow guix_daemon_t
  380. self
  381. (unix_dgram_socket (create bind connect sendto read write)))
  382. ;; For some esoteric build jobs (i.e. running PostgreSQL, etc).
  383. (allow guix_daemon_t
  384. self
  385. (capability (kill)))
  386. (allow guix_daemon_t
  387. node_t
  388. (tcp_socket (node_bind)))
  389. (allow guix_daemon_t
  390. node_t
  391. (udp_socket (node_bind)))
  392. (allow guix_daemon_t
  393. port_t
  394. (tcp_socket (name_connect)))
  395. (allow guix_daemon_t
  396. tmpfs_t
  397. (file (map read write link getattr)))
  398. (allow guix_daemon_t
  399. usermodehelper_t
  400. (file (read)))
  401. (allow guix_daemon_t
  402. hugetlbfs_t
  403. (file (map read write)))
  404. (allow guix_daemon_t
  405. proc_net_t
  406. (file (read)))
  407. (allow guix_daemon_t
  408. postgresql_port_t
  409. (tcp_socket (name_connect name_bind)))
  410. (allow guix_daemon_t
  411. rtp_media_port_t
  412. (udp_socket (name_bind)))
  413. (allow guix_daemon_t
  414. vnc_port_t
  415. (tcp_socket (name_bind)))
  416. ;; I guess sometimes it needs random numbers
  417. (allow guix_daemon_t
  418. random_device_t
  419. (chr_file (read)))
  420. ;; guix system vm
  421. (allow guix_daemon_t
  422. kvm_device_t
  423. (chr_file (ioctl open read write)))
  424. (allow guix_daemon_t
  425. kernel_t
  426. (system (ipc_info)))
  427. ;; Label file system
  428. (filecon "@guix_sysconfdir@/guix(/.*)?"
  429. any (system_u object_r guix_daemon_conf_t (low low)))
  430. (filecon "@guix_localstatedir@/guix(/.*)?"
  431. any (system_u object_r guix_daemon_conf_t (low low)))
  432. (filecon "@guix_localstatedir@/guix/profiles(/.*)?"
  433. any (system_u object_r guix_profiles_t (low low)))
  434. (filecon "/gnu"
  435. dir (unconfined_u object_r guix_store_content_t (low low)))
  436. (filecon "@storedir@(/.+)?"
  437. any (unconfined_u object_r guix_store_content_t (low low)))
  438. (filecon "@storedir@/[^/]+/.+"
  439. any (unconfined_u object_r guix_store_content_t (low low)))
  440. (filecon "@prefix@/bin/guix-daemon"
  441. file (system_u object_r guix_daemon_exec_t (low low)))
  442. (filecon "@guix_localstatedir@/guix/profiles/per-user/[^/]+/current-guix/bin/guix-daemon"
  443. file (system_u object_r guix_daemon_exec_t (low low)))
  444. (filecon "@storedir@/.+-(guix-.+|profile)/bin/guix-daemon"
  445. file (system_u object_r guix_daemon_exec_t (low low)))
  446. (filecon "@storedir@/[a-z0-9]+-guix-daemon"
  447. file (system_u object_r guix_daemon_exec_t (low low)))
  448. (filecon "@guix_localstatedir@/guix/daemon-socket/socket"
  449. any (system_u object_r guix_daemon_socket_t (low low))))