policy_module(sosreport, 1.3.1)

########################################
#
# 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_tmp_t;
files_tmp_file(sosreport_tmp_t)

type sosreport_tmpfs_t;
files_tmpfs_file(sosreport_tmpfs_t)

type sosreport_var_run_t;
files_pid_file(sosreport_var_run_t)

optional_policy(`
	pulseaudio_tmpfs_content(sosreport_tmpfs_t)
')

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

allow sosreport_t self:capability { kill net_admin net_raw setuid sys_admin sys_nice dac_read_search  };
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 };
allow sosreport_t self:rawip_socket create_socket_perms;
allow sosreport_t self:netlink_kobject_uevent_socket create_socket_perms;

manage_dirs_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)
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_var_run_t, sosreport_var_run_t)
manage_dirs_pattern(sosreport_t, sosreport_var_run_t, sosreport_var_run_t)
manage_sock_files_pattern(sosreport_t, sosreport_var_run_t, sosreport_var_run_t)
manage_lnk_files_pattern(sosreport_t, sosreport_var_run_t, sosreport_var_run_t)
files_pid_filetrans(sosreport_t, sosreport_var_run_t, { file dir sock_file })

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_var_run_t, sosreport_var_run_t)
manage_dirs_pattern(sosreport_t, sosreport_var_run_t, sosreport_var_run_t)
manage_sock_files_pattern(sosreport_t, sosreport_var_run_t, sosreport_var_run_t)
manage_lnk_files_pattern(sosreport_t, sosreport_var_run_t, sosreport_var_run_t)
files_pid_filetrans(sosreport_t, sosreport_var_run_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)

corenet_all_recvfrom_netlabel(sosreport_t)
corenet_tcp_sendrecv_generic_if(sosreport_t)
corenet_tcp_sendrecv_generic_node(sosreport_t)
corenet_tcp_sendrecv_generic_port(sosreport_t)
corenet_tcp_bind_generic_node(sosreport_t)
corenet_tcp_bind_all_rpc_ports(sosreport_t)
corenet_udp_bind_all_rpc_ports(sosreport_t)
corenet_tcp_connect_http_port(sosreport_t)
corenet_tcp_connect_all_ports(sosreport_t)
corenet_sendrecv_http_client_packets(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(sosreport_t)
dev_read_sysfs(sosreport_t)
dev_rw_generic_usb_dev(sosreport_t)
dev_rw_lvm_control(sosreport_t)
dev_getattr_all_chr_files(sosreport_t)
dev_getattr_all_blk_files(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_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)

fs_getattr_all_fs(sosreport_t)
fs_getattr_all_dirs(sosreport_t)
fs_list_inotifyfs(sosreport_t)

storage_dontaudit_read_fixed_disk(sosreport_t)
storage_dontaudit_read_removable_device(sosreport_t)

term_getattr_pty_fs(sosreport_t)
term_getattr_all_ptys(sosreport_t)
term_use_generic_ptys(sosreport_t)

# some config files do not have configfile attribute
# sosreport needs to read various files on system
files_read_non_security_files(sosreport_t)

auth_use_nsswitch(sosreport_t)
auth_dontaudit_read_shadow(sosreport_t)

init_domtrans_script(sosreport_t)
init_getattr_initctl(sosreport_t)
init_status(sosreport_t)
init_stream_connect(sosreport_t)

libs_domtrans_ldconfig(sosreport_t)
libs_use_ld_so(sosreport_t)

logging_read_all_logs(sosreport_t)
logging_send_syslog_msg(sosreport_t)

sysnet_read_config(sosreport_t)

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

optional_policy(`
    bootloader_exec(sosreport_t)
')

optional_policy(`
	brctl_domtrans(sosreport_t)
')

optional_policy(`
	cups_stream_connect(sosreport_t)
')

optional_policy(`
	dmesg_domtrans(sosreport_t)
')

optional_policy(`
	iptables_domtrans(sosreport_t)
')

optional_policy(`
    lvm_read_config(sosreport_t)
    lvm_dontaudit_access_check_lock(sosreport_t)
')

optional_policy(`
	# needed by modinfo
	modutils_read_module_deps(sosreport_t)
')

optional_policy(`
	fstools_domtrans(sosreport_t)
')

optional_policy(`
	dbus_system_bus_client(sosreport_t)

	optional_policy(`
		hal_dbus_chat(sosreport_t)
	')

    optional_policy(`
        rpm_dbus_chat(sosreport_t)
    ')

    optional_policy(`
        networkmanager_dbus_chat(sosreport_t)
    ')
')

optional_policy(`
	lvm_domtrans(sosreport_t)
')

optional_policy(`
	mount_domtrans(sosreport_t)
')

optional_policy(`
    prelink_domtrans(sosreport_t)
')

optional_policy(`
	pulseaudio_run(sosreport_t, sosreport_roles)
')

optional_policy(`
    rhsmcertd_manage_lib_files(sosreport_t)
    rhsmcertd_manage_pid_files(sosreport_t)
')

optional_policy(`
    rpm_dontaudit_manage_db(sosreport_t)
    rpm_manage_cache(sosreport_t)
    rpm_manage_log(sosreport_t)
    rpm_manage_pid_files(sosreport_t)
    rpm_named_filetrans(sosreport_t)
    rpm_read_db(sosreport_t)
    rpm_signull(sosreport_t)
')

optional_policy(`
    setroubleshoot_signull(sosreport_t)
')

optional_policy(`
    systemd_dbus_chat_hostnamed(sosreport_t)
')

optional_policy(`
    unconfined_signull(sosreport_t)
    unconfined_domain(sosreport_t)
')

optional_policy(`
	xserver_stream_connect(sosreport_t)
')
