Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
# Macros for all user login domains.
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# role_tty_type_change(starting_role, ending_role)
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
# change from role $1_r to $2_r and relabel tty appropriately
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
undefine(`role_tty_type_change')
Chris PeBenito 31b7c0
define(`role_tty_type_change', `
Chris PeBenito 31b7c0
allow $1_r $2_r;
Chris PeBenito 31b7c0
type_change $2_t $1_devpts_t:chr_file $2_devpts_t;
Chris PeBenito 31b7c0
type_change $2_t $1_tty_device_t:chr_file $2_tty_device_t;
Chris PeBenito 31b7c0
# avoid annoying messages on terminal hangup
Chris PeBenito 31b7c0
dontaudit $1_t { $2_devpts_t $2_tty_device_t }:chr_file ioctl;
Chris PeBenito 31b7c0
')
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
# reach_sysadm(user)
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
# Reach sysadm_t via programs like userhelper/sudo/su
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
undefine(`reach_sysadm')
Chris PeBenito 31b7c0
define(`reach_sysadm', `
Chris PeBenito 31b7c0
ifdef(`userhelper.te', `userhelper_domain($1)')
Chris PeBenito 31b7c0
ifdef(`sudo.te', `sudo_domain($1)')
Chris PeBenito 31b7c0
ifdef(`su.te', `
Chris PeBenito 31b7c0
su_domain($1)
Chris PeBenito 31b7c0
# When an ordinary user domain runs su, su may try to
Chris PeBenito 31b7c0
# update the /root/.Xauthority file, and the user shell may
Chris PeBenito 31b7c0
# try to update the shell history. This is not allowed, but 
Chris PeBenito 31b7c0
# we dont need to audit it.
Chris PeBenito 31b7c0
dontaudit $1_su_t { sysadm_home_dir_t staff_home_dir_t }:dir search;
Chris PeBenito 31b7c0
dontaudit $1_su_t { sysadm_home_t staff_home_t }:dir rw_dir_perms;
Chris PeBenito 31b7c0
dontaudit $1_su_t { sysadm_home_t staff_home_t }:file create_file_perms;
Chris PeBenito 31b7c0
') dnl ifdef su.te
Chris PeBenito 31b7c0
ifdef(`xauth.te', `
Chris PeBenito 31b7c0
file_type_auto_trans($1_xauth_t, sysadm_home_dir_t, sysadm_xauth_home_t,file)
Chris PeBenito 31b7c0
ifdef(`userhelper.te', `
Chris PeBenito 31b7c0
file_type_auto_trans($1_userhelper_t, sysadm_home_dir_t, sysadm_xauth_home_t,file)
Chris PeBenito 31b7c0
') dnl userhelper.te 
Chris PeBenito 31b7c0
') dnl xauth.te 
Chris PeBenito 31b7c0
') dnl reach_sysadm
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
# priv_user(user)
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
# Privileged user domain
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
undefine(`priv_user')
Chris PeBenito 31b7c0
define(`priv_user', `
Chris PeBenito 31b7c0
# Reach sysadm_t
Chris PeBenito 31b7c0
reach_sysadm($1)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Read file_contexts for rpm and get security decisions. 
Chris PeBenito 31b7c0
r_dir_file($1_t, file_context_t)
Chris PeBenito 31b7c0
can_getsecurity($1_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Signal and see information about unprivileged user domains.
Chris PeBenito 31b7c0
allow $1_t unpriv_userdomain:process signal_perms;
Chris PeBenito 31b7c0
can_ps($1_t, unpriv_userdomain)
Chris PeBenito 31b7c0
allow $1_t { ttyfile ptyfile tty_device_t }:chr_file getattr;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Read /root files if boolean is enabled.
Chris PeBenito 31b7c0
if (staff_read_sysadm_file) {
Chris PeBenito 31b7c0
allow $1_t sysadm_home_dir_t:dir { getattr search };
Chris PeBenito 31b7c0
allow $1_t sysadm_home_t:file { getattr read };
Chris PeBenito 31b7c0
}
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
') dnl priv_user
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
# user_domain(domain_prefix)
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
# Define derived types and rules for an ordinary user domain.
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
# The type declaration and role authorization for the domain must be
Chris PeBenito 31b7c0
# provided separately.  Likewise, domain transitions into this domain
Chris PeBenito 31b7c0
# must be specified separately.  
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# user_domain() is also called by the admin_domain() macro
Chris PeBenito 31b7c0
undefine(`user_domain')
Chris PeBenito 31b7c0
define(`user_domain', `
Chris PeBenito 31b7c0
# Use capabilities
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Type for home directory.
Chris PeBenito 31b7c0
type $1_home_dir_t, file_type, sysadmfile, home_dir_type, home_type, user_home_dir_type, polydir;
Chris PeBenito 31b7c0
type $1_home_t, file_type, sysadmfile, home_type, user_home_type, $1_file_type, polymember;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Transition manually for { lnk sock fifo }. The rest is in content macros.
Chris PeBenito 31b7c0
tmp_domain_notrans($1, `, user_tmpfile, $1_file_type')
Chris PeBenito 31b7c0
file_type_auto_trans($1_t, tmp_t, $1_tmp_t, { lnk_file sock_file fifo_file })
Chris PeBenito 31b7c0
allow $1_t $1_tmp_t:{ dir file } { relabelto relabelfrom };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
ifdef(`support_polyinstantiation', `
Chris PeBenito 31b7c0
type_member $1_t tmp_t:dir $1_tmp_t;
Chris PeBenito 31b7c0
type_member $1_t $1_home_dir_t:dir $1_home_t;
Chris PeBenito 31b7c0
')
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
base_user_domain($1)
Chris PeBenito 31b7c0
ifdef(`mls_policy', `', `
Chris PeBenito 31b7c0
access_removable_media($1_t)
Chris PeBenito 31b7c0
')
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# do not allow privhome access to sysadm_home_dir_t
Chris PeBenito 31b7c0
file_type_auto_trans(privhome, $1_home_dir_t, $1_home_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow $1_t boot_t:dir { getattr search };
Chris PeBenito 31b7c0
dontaudit $1_t boot_t:lnk_file read;
Chris PeBenito 31b7c0
dontaudit $1_t boot_t:file read;
Chris PeBenito 31b7c0
allow $1_t system_map_t:file { getattr read };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Instantiate derived domains for a number of programs.
Chris PeBenito 31b7c0
# These derived domains encode both information about the calling
Chris PeBenito 31b7c0
# user domain and the program, and allow us to maintain separation
Chris PeBenito 31b7c0
# between different instances of the program being run by different
Chris PeBenito 31b7c0
# user domains.
Chris PeBenito 31b7c0
ifelse($1, sysadm, `',`
Chris PeBenito 31b7c0
ifdef(`apache.te', `apache_user_domain($1)')
Chris PeBenito 31b7c0
ifdef(`i18n_input.te', `i18n_input_domain($1)')
Chris PeBenito 31b7c0
ifdef(`spamd.te', `home_domain_ro_access(spamd_t, $1)')
Chris PeBenito 31b7c0
')
Chris PeBenito 31b7c0
ifdef(`slocate.te', `locate_domain($1)')
Chris PeBenito 31b7c0
ifdef(`lockdev.te', `lockdev_domain($1)')
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
can_kerberos($1_t)
Chris PeBenito 31b7c0
# allow port_t name binding for UDP because it is not very usable otherwise
Chris PeBenito 31b7c0
allow $1_t port_t:udp_socket name_bind;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
# Need the following rule to allow users to run vpnc
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
ifdef(`xserver.te', `
Chris PeBenito 31b7c0
allow $1_t xserver_port_t:tcp_socket name_bind;
Chris PeBenito 31b7c0
')
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Allow users to run TCP servers (bind to ports and accept connection from
Chris PeBenito 31b7c0
# the same domain and outside users)  disabling this forces FTP passive mode
Chris PeBenito 31b7c0
# and may change other protocols
Chris PeBenito 31b7c0
if (user_tcp_server) {
Chris PeBenito 31b7c0
allow $1_t port_t:tcp_socket name_bind;
Chris PeBenito 31b7c0
}
Chris PeBenito 31b7c0
# port access is audited even if dac would not have allowed it, so dontaudit it here
Chris PeBenito 31b7c0
dontaudit $1_t { reserved_port_type reserved_port_t }:tcp_socket name_bind;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Allow system log read
Chris PeBenito 31b7c0
if (user_dmesg) {
Chris PeBenito 31b7c0
allow $1_t kernel_t:system syslog_read;
Chris PeBenito 31b7c0
} else {
Chris PeBenito 31b7c0
# else do not log it
Chris PeBenito 31b7c0
dontaudit $1_t kernel_t:system syslog_read;
Chris PeBenito 31b7c0
}
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Allow read access to utmp.
Chris PeBenito 31b7c0
allow $1_t initrc_var_run_t:file { getattr read lock };
Chris PeBenito 31b7c0
# The library functions always try to open read-write first,
Chris PeBenito 31b7c0
# then fall back to read-only if it fails. 
Chris PeBenito 31b7c0
# Do not audit write denials to utmp to avoid the noise.
Chris PeBenito 31b7c0
dontaudit $1_t initrc_var_run_t:file write;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# do not audit read on disk devices
Chris PeBenito 31b7c0
dontaudit $1_t { removable_device_t fixed_disk_device_t }:blk_file read;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
ifdef(`xdm.te', `
Chris PeBenito 31b7c0
allow xdm_t $1_home_t:lnk_file read;
Chris PeBenito 31b7c0
allow xdm_t $1_home_t:dir search;
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
# Changing this to dontaudit should cause the .xsession-errors file to be written to /tmp
Chris PeBenito 31b7c0
# 
Chris PeBenito 31b7c0
dontaudit xdm_t $1_home_t:file rw_file_perms;
Chris PeBenito 31b7c0
')dnl end ifdef xdm.te
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
ifdef(`ftpd.te', `
Chris PeBenito 31b7c0
if (ftp_home_dir) {
Chris PeBenito 31b7c0
file_type_auto_trans(ftpd_t, $1_home_dir_t, $1_home_t)
Chris PeBenito 31b7c0
}
Chris PeBenito 31b7c0
')dnl end ifdef ftpd
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
')dnl end user_domain macro
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
###########################################################################
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
# Domains for ordinary users.
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
undefine(`limited_user_role')
Chris PeBenito 31b7c0
define(`limited_user_role', `
Chris PeBenito 31b7c0
# user_t/$1_t is an unprivileged users domain.
Chris PeBenito 31b7c0
type $1_t, domain, userdomain, unpriv_userdomain, nscd_client_domain, privfd;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
#Type for tty devices.
Chris PeBenito 31b7c0
type $1_tty_device_t, sysadmfile, ttyfile, user_tty_type, dev_fs;
Chris PeBenito 31b7c0
# Type and access for pty devices.
Chris PeBenito 31b7c0
can_create_pty($1, `, userpty_type, user_tty_type')
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Access ttys.
Chris PeBenito 31b7c0
allow $1_t privfd:fd use;
Chris PeBenito 31b7c0
allow $1_t $1_tty_device_t:chr_file { setattr rw_file_perms };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Grant read/search permissions to some of /proc.
Chris PeBenito 31b7c0
r_dir_file($1_t, proc_t)
Chris PeBenito 31b7c0
# netstat needs to access proc_net_t; if you want to hide this info use dontaudit here instead
Chris PeBenito 31b7c0
r_dir_file($1_t, proc_net_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
base_file_read_access($1_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Execute from the system shared libraries.
Chris PeBenito 31b7c0
uses_shlib($1_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Read /etc.
Chris PeBenito 31b7c0
r_dir_file($1_t, etc_t)
Chris PeBenito 31b7c0
allow $1_t etc_runtime_t:file r_file_perms;
Chris PeBenito 31b7c0
allow $1_t etc_runtime_t:lnk_file { getattr read };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow $1_t self:process { fork sigchld setpgid signal_perms };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# read localization information
Chris PeBenito 31b7c0
read_locale($1_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
read_sysctl($1_t)
Chris PeBenito 31b7c0
can_exec($1_t, { bin_t sbin_t shell_exec_t ls_exec_t })
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow $1_t self:dir search;
Chris PeBenito 31b7c0
allow $1_t self:file { getattr read };
Chris PeBenito 31b7c0
allow $1_t self:fifo_file rw_file_perms;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow $1_t self:lnk_file read;
Chris PeBenito 31b7c0
allow $1_t self:unix_stream_socket create_socket_perms;
Chris PeBenito 31b7c0
allow $1_t urandom_device_t:chr_file { getattr read };
Chris PeBenito 31b7c0
dontaudit $1_t { var_spool_t var_log_t }:dir search;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Read /dev directories and any symbolic links.
Chris PeBenito 31b7c0
allow $1_t device_t:dir r_dir_perms;
Chris PeBenito 31b7c0
allow $1_t device_t:lnk_file { getattr read };
Chris PeBenito 31b7c0
allow $1_t devtty_t:chr_file { read write };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
')
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
undefine(`full_user_role')
Chris PeBenito 31b7c0
define(`full_user_role', `
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
limited_user_role($1)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
typeattribute  $1_t web_client_domain;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
attribute $1_file_type;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
ifdef(`useradd.te', `
Chris PeBenito 31b7c0
# Useradd relabels /etc/skel files so needs these privs 
Chris PeBenito 31b7c0
allow useradd_t $1_file_type:dir create_dir_perms;
Chris PeBenito 31b7c0
allow useradd_t $1_file_type:notdevfile_class_set create_file_perms;
Chris PeBenito 31b7c0
')
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
can_exec($1_t, usr_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Read directories and files with the readable_t type.
Chris PeBenito 31b7c0
# This type is a general type for "world"-readable files.
Chris PeBenito 31b7c0
allow $1_t readable_t:dir r_dir_perms;
Chris PeBenito 31b7c0
allow $1_t readable_t:notdevfile_class_set r_file_perms;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Stat lost+found.
Chris PeBenito 31b7c0
allow $1_t lost_found_t:dir getattr;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Read /var, /var/spool, /var/run.
Chris PeBenito 31b7c0
r_dir_file($1_t, var_t)
Chris PeBenito 31b7c0
# what about pipes and sockets under /var/spool?
Chris PeBenito 31b7c0
r_dir_file($1_t, var_spool_t)
Chris PeBenito 31b7c0
r_dir_file($1_t, var_run_t)
Chris PeBenito 31b7c0
allow $1_t var_lib_t:dir r_dir_perms;
Chris PeBenito 31b7c0
allow $1_t var_lib_t:file { getattr read };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# for running depmod as part of the kernel packaging process
Chris PeBenito 31b7c0
allow $1_t modules_conf_t:file { getattr read };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Read man directories and files.
Chris PeBenito 31b7c0
r_dir_file($1_t, man_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Allow users to rw usb devices
Chris PeBenito 31b7c0
if (user_rw_usb) {
Chris PeBenito 31b7c0
rw_dir_create_file($1_t,usbdevfs_t)
Chris PeBenito 31b7c0
} else {
Chris PeBenito 31b7c0
r_dir_file($1_t,usbdevfs_t)
Chris PeBenito 31b7c0
}
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
r_dir_file($1_t,sysfs_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Do not audit write denials to /etc/ld.so.cache.
Chris PeBenito 31b7c0
dontaudit $1_t ld_so_cache_t:file write;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# $1_t is also granted permissions specific to user domains.
Chris PeBenito 31b7c0
user_domain($1)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
dontaudit $1_t sysadm_home_t:file { read append };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
ifdef(`syslogd.te', `
Chris PeBenito 31b7c0
# Some programs that are left in $1_t will try to connect
Chris PeBenito 31b7c0
# to syslogd, but we do not want to let them generate log messages.
Chris PeBenito 31b7c0
# Do not audit.
Chris PeBenito 31b7c0
dontaudit $1_t devlog_t:sock_file { read write };
Chris PeBenito 31b7c0
dontaudit $1_t syslogd_t:unix_dgram_socket sendto;
Chris PeBenito 31b7c0
')
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Stop warnings about access to /dev/console
Chris PeBenito 31b7c0
dontaudit $1_t init_t:fd use;
Chris PeBenito 31b7c0
dontaudit $1_t initrc_t:fd use;
Chris PeBenito 31b7c0
allow $1_t initrc_t:fifo_file write;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
# Rules used to associate a homedir as a mountpoint
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
allow $1_home_t self:filesystem associate;
Chris PeBenito 31b7c0
allow $1_file_type $1_home_t:filesystem associate;
Chris PeBenito 31b7c0
')
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
undefine(`in_user_role')
Chris PeBenito 31b7c0
define(`in_user_role', `
Chris PeBenito 31b7c0
role user_r types $1;
Chris PeBenito 31b7c0
role staff_r types $1;
Chris PeBenito 31b7c0
')
Chris PeBenito 31b7c0