policy_module(unconfineduser, 1.0.0)

########################################
#
# Declarations
#
attribute unconfined_login_domain;

## <desc>
## <p>
## allow unconfined users to transition to the chrome sandbox domains when running chrome-sandbox
## </p>
## </desc>
gen_tunable(unconfined_chrome_sandbox_transition, false)

## <desc>
## <p>
## Allow unconfined users to transition to the Mozilla plugin domain when running xulrunner plugin-container.
## </p>
## </desc>
gen_tunable(unconfined_mozilla_plugin_transition, false)

## <desc>
## <p>
## Allow a user to login as an unconfined domain
## </p>
## </desc>
gen_tunable(unconfined_login, true)

## <desc>
## <p>
## Allow a unconfined user to dynamically transition to a new context using setcon.
## </p>
## </desc>
gen_tunable(unconfined_dyntrans_all, false)

# usage in this module of types created by these
# calls is not correct, however we dont currently
# have another method to add access to these types
userdom_base_user_template(unconfined)
userdom_manage_home_role(unconfined_r, unconfined_t)
userdom_manage_tmp_role(unconfined_r, unconfined_t)
userdom_unpriv_type(unconfined_t)
userdom_login_userdomain(unconfined_t)
userdom_home_filetrans_user_home_dir(unconfined_t)

type unconfined_exec_t;
application_domain(unconfined_t, unconfined_exec_t)
role unconfined_r types unconfined_t;
role_transition system_r unconfined_exec_t unconfined_r;
allow system_r unconfined_r;

domain_user_exemption_target(unconfined_t)
allow system_r unconfined_r;
allow unconfined_r system_r;
init_script_role_transition(unconfined_r)
role system_r types unconfined_t;
typealias unconfined_t alias unconfined_crontab_t;

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

dontaudit unconfined_t self:dir write;
dontaudit unconfined_t self:file setattr;

allow unconfined_t self:system syslog_read;
dontaudit unconfined_t self:capability sys_module;

allow unconfined_t file_type:system module_load;

allow unconfined_t self:cap_userns all_cap_userns_perms;

allow unconfined_t self:bpf { map_create map_read map_write prog_load prog_run };

kernel_rw_unlabeled_socket(unconfined_t)
kernel_rw_unlabeled_rawip_socket(unconfined_t)
kernel_rw_unlabeled_smc_socket(unconfined_t)
kernel_rw_unlabeled_vsock_socket(unconfined_t)

files_create_boot_flag(unconfined_t)
files_create_default_dir(unconfined_t)
files_root_filetrans_default(unconfined_t, dir)

init_domtrans_script(unconfined_t)
init_telinit(unconfined_t)
init_prog_run_bpf(unconfined_t)

logging_send_syslog_msg(unconfined_t)

systemd_config_all_services(unconfined_t)

ssh_dyntransition_to(unconfined_t)

unconfined_domain_noaudit(unconfined_t)
domain_named_filetrans(unconfined_t)
domain_transition_all(unconfined_t)

usermanage_run_passwd(unconfined_t, unconfined_r)

tunable_policy(`deny_execmem',`',`
	allow unconfined_t self:process execmem;
')

tunable_policy(`selinuxuser_execstack',`
	allow unconfined_t self:process execstack;
')

tunable_policy(`selinuxuser_execmod',`
	userdom_execmod_user_home_files(unconfined_t)
')

tunable_policy(`unconfined_login',`
	corecmd_shell_domtrans(unconfined_login_domain,unconfined_t)
	allow unconfined_t unconfined_login_domain:fd use;
	allow unconfined_t unconfined_login_domain:fifo_file rw_file_perms;
	allow unconfined_t unconfined_login_domain:process sigchld;
')

tunable_policy(`unconfined_dyntrans_all',`
    domain_dyntrans(unconfined_t)
')

optional_policy(`
	gen_require(`
		type unconfined_t;
	')

	optional_policy(`
		abrt_dbus_chat(unconfined_t)
		abrt_run_helper(unconfined_t, unconfined_r)
	')

	optional_policy(`
		avahi_dbus_chat(unconfined_t)
	')

	optional_policy(`
		blueman_dbus_chat(unconfined_t)
	')

	optional_policy(`
		certmonger_dbus_chat(unconfined_t)
	')

	optional_policy(`
		devicekit_dbus_chat(unconfined_t)
		devicekit_dbus_chat_disk(unconfined_t)
		devicekit_dbus_chat_power(unconfined_t)
	')

	optional_policy(`
		hal_dbus_chat(unconfined_t)
	')

    optional_policy(`
        kpatch_run(unconfined_t,unconfined_r)
    ')

	optional_policy(`
		networkmanager_dbus_chat(unconfined_t)
	')

	optional_policy(`
		rtkit_scheduled(unconfined_t)
	')

	# Might remove later if this proves to be problematic, but would like to gather AVCs
	optional_policy(`
		thumb_role(unconfined_r, unconfined_t)
	')

	optional_policy(`
		setroubleshoot_dbus_chat(unconfined_t)
		setroubleshoot_dbus_chat_fixit(unconfined_t)
	')

	optional_policy(`
		sandbox_transition(unconfined_t, unconfined_r)
	')

	optional_policy(`
		sandbox_x_transition(unconfined_t, unconfined_r)
	')

    optional_policy(`
        vmtools_run_helper(unconfined_t, unconfined_r)
    ')

	optional_policy(`
		gen_require(`
			type user_tmpfs_t;
		')
	
		xserver_rw_session(unconfined_t, user_tmpfs_t)
		xserver_dbus_chat_xdm(unconfined_t)
	')
')

ifdef(`distro_gentoo',`
	seutil_run_runinit(unconfined_t, unconfined_r)
	seutil_init_script_run_runinit(unconfined_t, unconfined_r)
')

optional_policy(`
	accountsd_dbus_chat(unconfined_t)
')

optional_policy(`
    cron_unconfined_role(unconfined_r, unconfined)
')

optional_policy(`
	chrome_role_notrans(unconfined_r, unconfined_t)

	tunable_policy(`unconfined_chrome_sandbox_transition',`
		chrome_domtrans_sandbox(unconfined_t)
	')
')

optional_policy(`
	container_runtime_entrypoint(unconfined_t)
')

optional_policy(`
	oddjob_mkhomedir_entrypoint(unconfined_t)
')

optional_policy(`
	dbus_role_template(unconfined, unconfined_r, unconfined_t)
	role system_r types unconfined_dbusd_t;

	optional_policy(`
		unconfined_domain_noaudit(unconfined_dbusd_t)

		optional_policy(`
			xserver_rw_shm(unconfined_dbusd_t)
		')
	')

	init_dbus_chat(unconfined_t)
	init_dbus_chat_script(unconfined_t)
    init_prog_run_bpf(unconfined_t)

	dbus_stub(unconfined_t)

	optional_policy(`
		bluetooth_dbus_chat(unconfined_t)
	')

	optional_policy(`
		consolekit_dbus_chat(unconfined_t)
	')

	optional_policy(`
		cups_dbus_chat_config(unconfined_t)
	')

	optional_policy(`
		fprintd_dbus_chat(unconfined_t)
	')

	optional_policy(`
		systemd_dbus_chat_timedated(unconfined_t)
		gnome_dbus_chat_gconfdefault(unconfined_t)
		gnome_command_domtrans_gkeyringd(unconfined_dbusd_t,unconfined_t)
	')

	optional_policy(`
       		gnome_filetrans_fontconfig_home_content(unconfined_t)
	')

    optional_policy(`
        gnome_filetrans_cert_home_content(unconfined_t)
    ')

	optional_policy(`
		ipsec_mgmt_dbus_chat(unconfined_t)
	')

	optional_policy(`
		kerneloops_dbus_chat(unconfined_t)
	')

	optional_policy(`
	        telepathy_command_domtrans(unconfined_dbusd_t, unconfined_t)
	')

	optional_policy(`
		oddjob_dbus_chat(unconfined_t)
	')

	optional_policy(`
		systemd_systemctl_entrypoint(unconfined_t)
	')

	optional_policy(`
		vpn_dbus_chat(unconfined_t)
	')

	optional_policy(`
		firewalld_dbus_chat(unconfined_t)
	')

	optional_policy(`
		firewallgui_dbus_chat(unconfined_t)
	')
')

optional_policy(`
	firstboot_run(unconfined_t, unconfined_r)
')

optional_policy(`
	fsadm_manage_pid(unconfined_t)
')

optional_policy(`
        gpsd_run(unconfined_t, unconfined_r)
')

optional_policy(`
    anaconda_run_install(unconfined_t, unconfined_r)
')

optional_policy(`
	java_run_unconfined(unconfined_t, unconfined_r)
')

optional_policy(`
	livecd_run(unconfined_t, unconfined_r)
')

#optional_policy(`
#	mock_role(unconfined_r, unconfined_t)
#')

optional_policy(`
	mozilla_role_plugin(unconfined_r)

	tunable_policy(`unconfined_mozilla_plugin_transition', `
			mozilla_domtrans_plugin(unconfined_t)
	')
')

optional_policy(`
	ipa_run_helper(unconfined_t, unconfined_r)
')

optional_policy(`
	chronyd_run_chronyc(unconfined_t, unconfined_r)
')

optional_policy(`
	oddjob_run_mkhomedir(unconfined_t, unconfined_r)
	oddjob_run(unconfined_t, unconfined_r)
')

optional_policy(`
	# Allow SELinux aware applications to request rpm_script execution
	rpm_transition_script(unconfined_t, unconfined_r)
	rpm_dbus_chat(unconfined_t)
	rpmdb_run_rpmdb(unconfined_t, unconfined_r)
')

optional_policy(`
	optional_policy(`
		samba_run_unconfined_net(unconfined_t, unconfined_r)
	')

	samba_role_notrans(unconfined_r)
	samba_run_smbcontrol(unconfined_t, unconfined_r)
')

optional_policy(`
	sysnet_run_dhcpc(unconfined_t, unconfined_r)
	sysnet_dbus_chat_dhcpc(unconfined_t)
	sysnet_role_transition_dhcpc(unconfined_r)
')

optional_policy(`
	openshift_run(unconfined_usertype, unconfined_r)
')

optional_policy(`
	tlp_filetrans_named_content(unconfined_t)
')

optional_policy(`
	virt_prog_run_bpf(unconfined_t)
	virt_transition_svirt(unconfined_t, unconfined_r)
	virt_transition_svirt_sandbox(unconfined_t, unconfined_r)
	virt_sandbox_entrypoint(unconfined_t)
')

optional_policy(`
	xserver_run(unconfined_t, unconfined_r)
	xserver_manage_home_fonts(unconfined_t)
	xserver_xsession_entry_type(unconfined_t)
')

gen_user(unconfined_u, user, unconfined_r system_r, s0, s0 - mls_systemhigh, mcs_allcats)

