## Libvirt virtualization API ######################################## ## ## Creates types and rules for a basic ## qemu process domain. ## ## ## ## Prefix for the domain. ## ## # template(`virt_domain_template',` gen_require(` type virtd_t; attribute virt_image_type; attribute virt_domain; ') type $1_t, virt_domain; domain_type($1_t) role system_r types $1_t; type $1_tmp_t; files_tmp_file($1_tmp_t) type $1_tmpfs_t; files_tmpfs_file($1_tmpfs_t) type $1_image_t, virt_image_type; files_type($1_image_t) dev_node($1_image_t) type $1_var_run_t; files_pid_file($1_var_run_t) manage_dirs_pattern($1_t, $1_image_t, $1_image_t) manage_files_pattern($1_t, $1_image_t, $1_image_t) read_lnk_files_pattern($1_t, $1_image_t, $1_image_t) rw_blk_files_pattern($1_t, $1_image_t, $1_image_t) manage_dirs_pattern($1_t, $1_tmp_t, $1_tmp_t) manage_files_pattern($1_t, $1_tmp_t, $1_tmp_t) manage_lnk_files_pattern($1_t, $1_tmp_t, $1_tmp_t) files_tmp_filetrans($1_t, $1_tmp_t, { file dir }) manage_dirs_pattern($1_t, $1_tmpfs_t, $1_tmpfs_t) manage_files_pattern($1_t, $1_tmpfs_t, $1_tmpfs_t) manage_lnk_files_pattern($1_t, $1_tmpfs_t, $1_tmpfs_t) fs_tmpfs_filetrans($1_t, $1_tmpfs_t, { dir file lnk_file }) stream_connect_pattern(virtd_t, $1_var_run_t, $1_var_run_t, virt_domain) manage_dirs_pattern(virtd_t, $1_var_run_t, $1_var_run_t) manage_files_pattern(virtd_t, $1_var_run_t, $1_var_run_t) manage_sock_files_pattern(virtd_t, $1_var_run_t, $1_var_run_t) manage_dirs_pattern($1_t, $1_var_run_t, $1_var_run_t) manage_files_pattern($1_t, $1_var_run_t, $1_var_run_t) manage_sock_files_pattern($1_t, $1_var_run_t, $1_var_run_t) manage_lnk_files_pattern($1_t, $1_var_run_t, $1_var_run_t) files_pid_filetrans($1_t, $1_var_run_t, { dir file }) stream_connect_pattern($1_t, $1_var_run_t, $1_var_run_t, virtd_t) ') ######################################## ## ## Make the specified type usable as a virt image ## ## ## ## Type to be used as a virtual image ## ## # interface(`virt_image',` gen_require(` attribute virt_image_type; ') typeattribute $1 virt_image_type; files_type($1) # virt images can be assigned to blk devices dev_node($1) ') ######################################## ## ## Execute a domain transition to run virt. ## ## ## ## Domain allowed to transition. ## ## # interface(`virt_domtrans',` gen_require(` type virtd_t, virtd_exec_t; ') domtrans_pattern($1, virtd_exec_t, virtd_t) ') ####################################### ## ## Connect to virt over an unix domain stream socket. ## ## ## ## Domain allowed access. ## ## # interface(`virt_stream_connect',` gen_require(` type virtd_t, virt_var_run_t; ') files_search_pids($1) stream_connect_pattern($1, virt_var_run_t, virt_var_run_t, virtd_t) ') ######################################## ## ## Allow domain to attach to virt TUN devices ## ## ## ## Domain allowed access. ## ## # interface(`virt_attach_tun_iface',` gen_require(` type virtd_t; ') allow $1 virtd_t:tun_socket relabelfrom; allow $1 self:tun_socket relabelto; ') ######################################## ## ## Read virt config files. ## ## ## ## Domain allowed access. ## ## # interface(`virt_read_config',` gen_require(` type virt_etc_t; type virt_etc_rw_t; ') files_search_etc($1) read_files_pattern($1, virt_etc_t, virt_etc_t) read_files_pattern($1, virt_etc_rw_t, virt_etc_rw_t) ') ######################################## ## ## manage virt config files. ## ## ## ## Domain allowed access. ## ## # interface(`virt_manage_config',` gen_require(` type virt_etc_t; type virt_etc_rw_t; ') files_search_etc($1) manage_files_pattern($1, virt_etc_t, virt_etc_t) manage_files_pattern($1, virt_etc_rw_t, virt_etc_rw_t) ') ######################################## ## ## Allow domain to manage virt image files ## ## ## ## Domain to not audit. ## ## # interface(`virt_read_content',` gen_require(` type virt_content_t; ') virt_search_lib($1) allow $1 virt_content_t:dir list_dir_perms; list_dirs_pattern($1, virt_content_t, virt_content_t) read_files_pattern($1, virt_content_t, virt_content_t) read_lnk_files_pattern($1, virt_content_t, virt_content_t) read_blk_files_pattern($1, virt_content_t, virt_content_t) tunable_policy(`virt_use_nfs',` fs_list_nfs($1) fs_read_nfs_files($1) fs_read_nfs_symlinks($1) ') tunable_policy(`virt_use_samba',` fs_list_cifs($1) fs_read_cifs_files($1) fs_read_cifs_symlinks($1) ') ') ######################################## ## ## Read virt PID files. ## ## ## ## Domain allowed access. ## ## # interface(`virt_read_pid_files',` gen_require(` type virt_var_run_t; ') files_search_pids($1) read_files_pattern($1, virt_var_run_t, virt_var_run_t) ') ######################################## ## ## Manage virt pid files. ## ## ## ## Domain allowed access. ## ## # interface(`virt_manage_pid_files',` gen_require(` type virt_var_run_t; ') files_search_pids($1) manage_files_pattern($1, virt_var_run_t, virt_var_run_t) ') ######################################## ## ## Search virt lib directories. ## ## ## ## Domain allowed access. ## ## # interface(`virt_search_lib',` gen_require(` type virt_var_lib_t; ') allow $1 virt_var_lib_t:dir search_dir_perms; files_search_var_lib($1) ') ######################################## ## ## Read virt lib files. ## ## ## ## Domain allowed access. ## ## # interface(`virt_read_lib_files',` gen_require(` type virt_var_lib_t; ') files_search_var_lib($1) read_files_pattern($1, virt_var_lib_t, virt_var_lib_t) ') ######################################## ## ## Create, read, write, and delete ## virt lib files. ## ## ## ## Domain allowed access. ## ## # interface(`virt_manage_lib_files',` gen_require(` type virt_var_lib_t; ') files_search_var_lib($1) manage_files_pattern($1, virt_var_lib_t, virt_var_lib_t) ') ######################################## ## ## Allow the specified domain to read virt's log files. ## ## ## ## Domain allowed access. ## ## ## # interface(`virt_read_log',` gen_require(` type virt_log_t; ') logging_search_logs($1) read_files_pattern($1, virt_log_t, virt_log_t) ') ######################################## ## ## Allow the specified domain to append ## virt log files. ## ## ## ## Domain allowed to transition. ## ## # interface(`virt_append_log',` gen_require(` type virt_log_t; ') logging_search_logs($1) append_files_pattern($1, virt_log_t, virt_log_t) ') ######################################## ## ## Allow domain to manage virt log files ## ## ## ## Domain to not audit. ## ## # interface(`virt_manage_log',` gen_require(` type virt_log_t; ') manage_dirs_pattern($1, virt_log_t, virt_log_t) manage_files_pattern($1, virt_log_t, virt_log_t) manage_lnk_files_pattern($1, virt_log_t, virt_log_t) ') ######################################## ## ## Allow domain to read virt image files ## ## ## ## Domain to not audit. ## ## # interface(`virt_read_images',` gen_require(` type virt_var_lib_t; attribute virt_image_type; ') virt_search_lib($1) allow $1 virt_image_type:dir list_dir_perms; list_dirs_pattern($1, virt_image_type, virt_image_type) read_files_pattern($1, virt_image_type, virt_image_type) read_lnk_files_pattern($1, virt_image_type, virt_image_type) read_blk_files_pattern($1, virt_image_type, virt_image_type) tunable_policy(`virt_use_nfs',` fs_list_nfs($1) fs_read_nfs_files($1) fs_read_nfs_symlinks($1) ') tunable_policy(`virt_use_samba',` fs_list_cifs($1) fs_read_cifs_files($1) fs_read_cifs_symlinks($1) ') ') ######################################## ## ## Create, read, write, and delete ## svirt cache files. ## ## ## ## Domain allowed access. ## ## # interface(`virt_manage_svirt_cache',` gen_require(` type svirt_cache_t; ') files_search_var($1) manage_dirs_pattern($1, svirt_cache_t, svirt_cache_t) manage_files_pattern($1, svirt_cache_t, svirt_cache_t) manage_lnk_files_pattern($1, svirt_cache_t, svirt_cache_t) ') ######################################## ## ## Allow domain to manage virt image files ## ## ## ## Domain to not audit. ## ## # interface(`virt_manage_images',` gen_require(` type virt_var_lib_t; attribute virt_image_type; ') virt_search_lib($1) allow $1 virt_image_type:dir list_dir_perms; manage_dirs_pattern($1, virt_image_type, virt_image_type) manage_files_pattern($1, virt_image_type, virt_image_type) read_lnk_files_pattern($1, virt_image_type, virt_image_type) rw_blk_files_pattern($1, virt_image_type, virt_image_type) tunable_policy(`virt_use_nfs',` fs_manage_nfs_dirs($1) fs_manage_nfs_files($1) fs_read_nfs_symlinks($1) ') tunable_policy(`virt_use_samba',` fs_manage_cifs_files($1) fs_manage_cifs_files($1) fs_read_cifs_symlinks($1) ') ') ######################################## ## ## All of the rules required to administrate ## an virt environment ## ## ## ## Domain allowed access. ## ## ## ## ## Role allowed access. ## ## ## # interface(`virt_admin',` gen_require(` type virtd_t, virtd_initrc_exec_t; ') allow $1 virtd_t:process { ptrace signal_perms }; ps_process_pattern($1, virtd_t) init_labeled_script_domtrans($1, virtd_initrc_exec_t) domain_system_change_exemption($1) role_transition $2 virtd_initrc_exec_t system_r; allow $2 system_r; virt_manage_pid_files($1) virt_manage_lib_files($1) virt_manage_log($1) ')