|
Chris PeBenito |
31b7c0 |
#DESC Userhelper - SELinux utility to run a shell with a new role
|
|
Chris PeBenito |
31b7c0 |
#
|
|
Chris PeBenito |
31b7c0 |
# Authors: Dan Walsh (Red Hat)
|
|
Chris PeBenito |
31b7c0 |
# Maintained by Dan Walsh <dwalsh@redhat.com>
|
|
Chris PeBenito |
31b7c0 |
#
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
#
|
|
Chris PeBenito |
31b7c0 |
# userhelper_domain(domain_prefix)
|
|
Chris PeBenito |
31b7c0 |
#
|
|
Chris PeBenito |
31b7c0 |
# Define a derived domain for the userhelper/userhelper program when executed by
|
|
Chris PeBenito |
31b7c0 |
# a user domain.
|
|
Chris PeBenito |
31b7c0 |
#
|
|
Chris PeBenito |
31b7c0 |
# The type declaration for the executable type for this program is
|
|
Chris PeBenito |
31b7c0 |
# provided separately in domains/program/userhelper.te.
|
|
Chris PeBenito |
31b7c0 |
#
|
|
Chris PeBenito |
31b7c0 |
define(`userhelper_domain',`
|
|
Chris PeBenito |
31b7c0 |
type $1_userhelper_t, domain, userhelperdomain, privlog, privrole, privowner, auth_chkpwd, privfd, privuser, nscd_client_domain;
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
in_user_role($1_userhelper_t)
|
|
Chris PeBenito |
31b7c0 |
role sysadm_r types $1_userhelper_t;
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
ifelse($1, sysadm, `
|
|
Chris PeBenito |
31b7c0 |
typealias sysadm_userhelper_t alias userhelper_t;
|
|
Chris PeBenito |
31b7c0 |
domain_auto_trans(initrc_t, userhelper_exec_t, sysadm_userhelper_t)
|
|
Chris PeBenito |
31b7c0 |
')
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
general_domain_access($1_userhelper_t);
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
uses_shlib($1_userhelper_t)
|
|
Chris PeBenito |
31b7c0 |
read_locale($1_userhelper_t)
|
|
Chris PeBenito |
31b7c0 |
read_sysctl($1_userhelper_t)
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
# for when the user types "exec userhelper" at the command line
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t privfd:process sigchld;
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
domain_auto_trans($1_t, userhelper_exec_t, $1_userhelper_t)
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
# Inherit descriptors from the current session.
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t { init_t privfd }:fd use;
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
can_exec($1_userhelper_t, { bin_t sbin_t userhelper_exec_t })
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
# Execute shells
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t { sbin_t bin_t }:dir r_dir_perms;
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t { sbin_t bin_t }:lnk_file read;
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t shell_exec_t:file r_file_perms;
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
# By default, revert to the calling domain when a program is executed.
|
|
Chris PeBenito |
31b7c0 |
domain_auto_trans($1_userhelper_t, { bin_t sbin_t }, $1_t)
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
# Allow $1_userhelper_t to transition to user domains.
|
|
Chris PeBenito |
31b7c0 |
domain_trans($1_userhelper_t, { bin_t sbin_t exec_type }, unpriv_userdomain)
|
|
Chris PeBenito |
31b7c0 |
if (!secure_mode) {
|
|
Chris PeBenito |
31b7c0 |
# if we are not in secure mode then we can transition to sysadm_t
|
|
Chris PeBenito |
31b7c0 |
domain_trans($1_userhelper_t, { bin_t sbin_t exec_type }, sysadm_t)
|
|
Chris PeBenito |
31b7c0 |
}
|
|
Chris PeBenito |
31b7c0 |
can_setexec($1_userhelper_t)
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
ifdef(`distro_redhat', `
|
|
Chris PeBenito |
31b7c0 |
ifdef(`rpm.te', `
|
|
Chris PeBenito |
31b7c0 |
# Allow transitioning to rpm_t, for up2date
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t rpm_t:process { transition siginh rlimitinh noatsecure };
|
|
Chris PeBenito |
31b7c0 |
')
|
|
Chris PeBenito |
31b7c0 |
')
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
# Use capabilities.
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t self:capability { setuid setgid net_bind_service dac_override chown sys_tty_config };
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
# Write to utmp.
|
|
Chris PeBenito |
31b7c0 |
file_type_auto_trans($1_userhelper_t, var_run_t, initrc_var_run_t, file)
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
# Read the devpts root directory.
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t devpts_t:dir r_dir_perms;
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
# Read the /etc/security/default_type file
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t etc_t:file r_file_perms;
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
# Read /var.
|
|
Chris PeBenito |
31b7c0 |
r_dir_file($1_userhelper_t, var_t)
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
# Read /dev directories and any symbolic links.
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t device_t:dir r_dir_perms;
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
# Relabel terminals.
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t { ttyfile ptyfile }:chr_file { relabelfrom relabelto };
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
# Access terminals.
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t { ttyfile ptyfile devtty_t }:chr_file rw_file_perms;
|
|
Chris PeBenito |
31b7c0 |
ifdef(`gnome-pty-helper.te', `allow $1_userhelper_t gphdomain:fd use;')
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
#
|
|
Chris PeBenito |
31b7c0 |
# Allow $1_userhelper to obtain contexts to relabel TTYs
|
|
Chris PeBenito |
31b7c0 |
#
|
|
Chris PeBenito |
31b7c0 |
can_getsecurity($1_userhelper_t)
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t fs_t:filesystem getattr;
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
# for some PAM modules and for cwd
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t { home_root_t $1_home_dir_t }:dir search;
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t proc_t:dir search;
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t proc_t:file { getattr read };
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
# for when the network connection is killed
|
|
Chris PeBenito |
31b7c0 |
dontaudit unpriv_userdomain $1_userhelper_t:process signal;
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t userhelper_conf_t:file rw_file_perms;
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t userhelper_conf_t:dir rw_dir_perms;
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
ifdef(`pam.te', `
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t pam_var_run_t:dir create_dir_perms;
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t pam_var_run_t:file create_file_perms;
|
|
Chris PeBenito |
31b7c0 |
')
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t urandom_device_t:chr_file { getattr read };
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t autofs_t:dir search;
|
|
Chris PeBenito |
31b7c0 |
role system_r types $1_userhelper_t;
|
|
Chris PeBenito |
31b7c0 |
r_dir_file($1_userhelper_t, nfs_t)
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
ifdef(`xdm.te', `
|
|
Chris PeBenito |
31b7c0 |
can_pipe_xdm($1_userhelper_t)
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t xdm_var_run_t:dir search;
|
|
Chris PeBenito |
31b7c0 |
')
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
r_dir_file($1_userhelper_t, selinux_config_t)
|
|
Chris PeBenito |
31b7c0 |
r_dir_file($1_userhelper_t, default_context_t)
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
ifdef(`xauth.te', `
|
|
Chris PeBenito |
31b7c0 |
domain_auto_trans($1_userhelper_t, xauth_exec_t, $1_xauth_t)
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t $1_xauth_home_t:file { getattr read };
|
|
Chris PeBenito |
31b7c0 |
')
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
ifdef(`pamconsole.te', `
|
|
Chris PeBenito |
31b7c0 |
allow $1_userhelper_t pam_var_console_t:dir { search };
|
|
Chris PeBenito |
31b7c0 |
')
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
ifdef(`mozilla.te', `
|
|
Chris PeBenito |
31b7c0 |
domain_auto_trans($1_mozilla_t, userhelper_exec_t, $1_userhelper_t)
|
|
Chris PeBenito |
31b7c0 |
')
|
|
Chris PeBenito |
31b7c0 |
|
|
Chris PeBenito |
31b7c0 |
')dnl end userhelper macro
|