policy_module(sosreport)

########################################
#
# Declarations
#

attribute_role sosreport_roles;
roleattribute system_r sosreport_roles;

type sosreport_t;
type sosreport_exec_t;
application_domain(sosreport_t, sosreport_exec_t)
role sosreport_roles types sosreport_t;

type sosreport_runtime_t alias sosreport_var_run_t;
files_runtime_file(sosreport_runtime_t)

type sosreport_tmp_t;
files_tmp_file(sosreport_tmp_t)

type sosreport_tmpfs_t;
files_tmpfs_file(sosreport_tmpfs_t)

optional_policy(`
	pulseaudio_tmpfs_content(sosreport_tmpfs_t)
')

########################################
#
# Local policy
#

allow sosreport_t self:capability { dac_override kill net_admin net_raw setuid sys_admin sys_nice };
dontaudit sosreport_t self:capability sys_ptrace;
allow sosreport_t self:process { setpgid setsched signal_perms };
allow sosreport_t self:fifo_file rw_fifo_file_perms;
allow sosreport_t self:tcp_socket { accept listen };
allow sosreport_t self:unix_stream_socket { accept listen };

manage_dirs_pattern(sosreport_t, sosreport_tmp_t, sosreport_tmp_t)
manage_fifo_files_pattern(sosreport_t, sosreport_tmp_t, sosreport_tmp_t)
manage_files_pattern(sosreport_t, sosreport_tmp_t, sosreport_tmp_t)
manage_lnk_files_pattern(sosreport_t, sosreport_tmp_t, sosreport_tmp_t)
manage_sock_files_pattern(sosreport_t, sosreport_tmp_t, sosreport_tmp_t)
files_root_filetrans(sosreport_t, sosreport_tmp_t, file, ".ismount-test-file")
files_tmp_filetrans(sosreport_t, sosreport_tmp_t, { file dir })

manage_files_pattern(sosreport_t, sosreport_tmpfs_t, sosreport_tmpfs_t)
fs_tmpfs_filetrans(sosreport_t, sosreport_tmpfs_t, file)

manage_files_pattern(sosreport_t, sosreport_runtime_t, sosreport_runtime_t)
manage_dirs_pattern(sosreport_t, sosreport_runtime_t, sosreport_runtime_t)
manage_sock_files_pattern(sosreport_t, sosreport_runtime_t, sosreport_runtime_t)
manage_lnk_files_pattern(sosreport_t, sosreport_runtime_t, sosreport_runtime_t)
files_runtime_filetrans(sosreport_t, sosreport_runtime_t, { file dir sock_file })

kernel_read_network_state(sosreport_t)
kernel_read_all_sysctls(sosreport_t)
kernel_read_software_raid_state(sosreport_t)
kernel_search_debugfs(sosreport_t)
kernel_read_messages(sosreport_t)
kernel_request_load_module(sosreport_t)

corecmd_exec_all_executables(sosreport_t)

dev_getattr_all_chr_files(sosreport_t)
dev_getattr_all_blk_files(sosreport_t)
dev_getattr_mtrr_dev(sosreport_t)
dev_read_rand(sosreport_t)
dev_read_urand(sosreport_t)
dev_read_raw_memory_cond(sosreport_t, allow_raw_memory_access)
dev_read_sysfs(sosreport_t)
dev_rw_generic_usb_dev(sosreport_t)

domain_getattr_all_domains(sosreport_t)
domain_read_all_domains_state(sosreport_t)
domain_getattr_all_sockets(sosreport_t)
domain_getattr_all_pipes(sosreport_t)

files_getattr_all_sockets(sosreport_t)
files_getattr_all_files(sosreport_t)
files_getattr_all_pipes(sosreport_t)
files_exec_etc_files(sosreport_t)
files_list_all(sosreport_t)
files_read_config_files(sosreport_t)
files_read_generic_tmp_files(sosreport_t)
files_read_non_auth_files(sosreport_t)
files_read_usr_files(sosreport_t)
files_read_var_lib_files(sosreport_t)
files_read_var_symlinks(sosreport_t)
files_read_kernel_modules(sosreport_t)
files_read_all_symlinks(sosreport_t)
files_manage_etc_runtime_files(sosreport_t)
files_etc_filetrans_etc_runtime(sosreport_t, file)
files_map_usr_files(sosreport_t)

fs_getattr_all_fs(sosreport_t)
fs_list_inotifyfs(sosreport_t)

selinux_compute_access_vector(sosreport_t)
selinux_compute_create_context(sosreport_t)
selinux_get_all_booleans(sosreport_t)
selinux_read_policy(sosreport_t)
selinux_validate_context(sosreport_t)

storage_dontaudit_read_fixed_disk(sosreport_t)
storage_dontaudit_read_removable_device(sosreport_t)

term_use_generic_ptys(sosreport_t)

auth_use_nsswitch(sosreport_t)

init_get_all_units_status(sosreport_t)
init_dbus_chat(sosreport_t)
init_domtrans_script(sosreport_t)

libs_run_ldconfig(sosreport_t, sosreport_roles)

logging_read_all_logs(sosreport_t)
logging_send_syslog_msg(sosreport_t)

miscfiles_read_localization(sosreport_t)

modutils_read_module_deps(sosreport_t)

userdom_use_inherited_user_terminals(sosreport_t)

optional_policy(`
	abrt_manage_runtime_files(sosreport_t)
	abrt_manage_cache(sosreport_t)
	abrt_stream_connect(sosreport_t)
')

optional_policy(`
	cups_stream_connect(sosreport_t)
')

optional_policy(`
	devicekit_dbus_chat(sosreport_t)
	devicekit_dbus_chat_disk(sosreport_t)
')

optional_policy(`
	dmesg_domtrans(sosreport_t)
')

optional_policy(`
	firewalld_dbus_chat(sosreport_t)
')

optional_policy(`
	fstools_run(sosreport_t, sosreport_roles)
')

optional_policy(`
	dbus_system_bus_client(sosreport_t)

	optional_policy(`
		rpm_dbus_chat(sosreport_t)
	')
')

optional_policy(`
	lvm_run(sosreport_t, sosreport_roles)
')

optional_policy(`
	mount_run(sosreport_t, sosreport_roles)
')

optional_policy(`
	networkmanager_dbus_chat(sosreport_t)
')

optional_policy(`
	ntp_dbus_chat(sosreport_t)
')

optional_policy(`
	pulseaudio_run(sosreport_t, sosreport_roles)
')

optional_policy(`
	rpm_exec(sosreport_t)
	rpm_dontaudit_manage_db(sosreport_t)
	rpm_read_db(sosreport_t)
')

optional_policy(`
	setroubleshoot_signull(sosreport_t)
')

optional_policy(`
	systemd_dbus_chat_hostnamed(sosreport_t)
	systemd_dbus_chat_logind(sosreport_t)
	systemd_map_hwdb(sosreport_t)
	systemd_read_journal_files(sosreport_t)
')

optional_policy(`
	xserver_stream_connect(sosreport_t)
')
