Chris PeBenito 0fbfa5
#
Chris PeBenito 0fbfa5
# Macros for gpg and pgp
Chris PeBenito 0fbfa5
#
Chris PeBenito 0fbfa5
# Author:  Russell Coker <russell@coker.com.au>
Chris PeBenito 0fbfa5
#
Chris PeBenito 0fbfa5
# based on the work of:
Chris PeBenito 0fbfa5
# Stephen Smalley <sds@epoch.ncsc.mil> and Timothy Fraser
Chris PeBenito 0fbfa5
#
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
#
Chris PeBenito 0fbfa5
# gpg_domain(domain_prefix)
Chris PeBenito 0fbfa5
#
Chris PeBenito 0fbfa5
# Define a derived domain for the gpg/pgp program when executed by
Chris PeBenito 0fbfa5
# a user domain.
Chris PeBenito 0fbfa5
#
Chris PeBenito 0fbfa5
# The type declaration for the executable type for this program is
Chris PeBenito 0fbfa5
# provided separately in domains/program/gpg.te.
Chris PeBenito 0fbfa5
#
Chris PeBenito 0fbfa5
define(`gpg_domain', `
Chris PeBenito 0fbfa5
# Derived domain based on the calling user domain and the program.
Chris PeBenito 0fbfa5
type $1_gpg_t, domain, privlog;
Chris PeBenito 0fbfa5
type $1_gpg_secret_t, file_type, $1_file_type, sysadmfile;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# Transition from the user domain to the derived domain.
Chris PeBenito 0fbfa5
domain_auto_trans($1_t, gpg_exec_t, $1_gpg_t)
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
can_network($1_gpg_t)
Chris PeBenito 0fbfa5
can_ypbind($1_gpg_t)
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# for a bug in kmail
Chris PeBenito 0fbfa5
dontaudit $1_gpg_t $1_t:unix_stream_socket { getattr read write };
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# The user role is authorized for this domain.
Chris PeBenito 0fbfa5
role $1_r types $1_gpg_t;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# Legacy
Chris PeBenito 0fbfa5
if (allow_gpg_execstack) {
Chris PeBenito 0fbfa5
legacy_domain($1_gpg)
Chris PeBenito 0fbfa5
allow $1_gpg_t locale_t:file execute;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# Not quite sure why this is needed... 
Chris PeBenito 0fbfa5
allow $1_gpg_t gpg_exec_t:file execmod;
Chris PeBenito 0fbfa5
}
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
allow $1_t $1_gpg_secret_t:file getattr;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
allow $1_gpg_t device_t:dir r_dir_perms;
Chris PeBenito 0fbfa5
allow $1_gpg_t { random_device_t urandom_device_t }:chr_file r_file_perms;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
allow $1_gpg_t etc_t:file r_file_perms;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
allow $1_gpg_t self:unix_stream_socket create_stream_socket_perms;
Chris PeBenito 0fbfa5
allow $1_gpg_t self:tcp_socket create_stream_socket_perms;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
access_terminal($1_gpg_t, $1)
Chris PeBenito 0fbfa5
ifdef(`gnome-pty-helper.te', `allow $1_gpg_t $1_gph_t:fd use;')
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# Inherit and use descriptors
Chris PeBenito 0fbfa5
allow $1_gpg_t { privfd $1_t }:fd use;
Chris PeBenito 0fbfa5
allow { $1_t $1_gpg_t } $1_gpg_t:process signal;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# setrlimit is for ulimit -c 0
Chris PeBenito 0fbfa5
allow $1_gpg_t self:process { setrlimit setcap };
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# allow ps to show gpg
Chris PeBenito 0fbfa5
can_ps($1_t, $1_gpg_t)
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
uses_shlib($1_gpg_t)
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# should not need read access...
Chris PeBenito 0fbfa5
allow $1_gpg_t home_root_t:dir { read search };
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# use $1_gpg_secret_t for files it creates
Chris PeBenito 0fbfa5
# NB we are doing the type transition for directory creation only!
Chris PeBenito 0fbfa5
# so ~/.gnupg will be of $1_gpg_secret_t, then files created under it such as
Chris PeBenito 0fbfa5
# secring.gpg will be of $1_gpg_secret_t too.  But when you use gpg to decrypt
Chris PeBenito 0fbfa5
# a file and write output to your home directory it will use user_home_t.
Chris PeBenito 0fbfa5
file_type_auto_trans($1_gpg_t, $1_home_dir_t, $1_gpg_secret_t, dir)
Chris PeBenito 0fbfa5
rw_dir_create_file($1_gpg_t, $1_gpg_secret_t)
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
file_type_auto_trans($1_gpg_t, $1_home_dir_t, $1_home_t, file)
Chris PeBenito 0fbfa5
create_dir_file($1_gpg_t, $1_home_t)
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# allow the usual access to /tmp
Chris PeBenito 0fbfa5
file_type_auto_trans($1_gpg_t, tmp_t, $1_tmp_t)
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
if (use_nfs_home_dirs) {
Chris PeBenito 0fbfa5
create_dir_file($1_gpg_t, nfs_t)
Chris PeBenito 0fbfa5
}
Chris PeBenito 0fbfa5
if (use_samba_home_dirs) {
Chris PeBenito 0fbfa5
create_dir_file($1_gpg_t, cifs_t)
Chris PeBenito 0fbfa5
}
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
allow $1_gpg_t self:capability { ipc_lock setuid };
Chris PeBenito 0fbfa5
rw_dir_create_file($1_gpg_t, $1_file_type)
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
allow $1_gpg_t { etc_t usr_t }:dir r_dir_perms;
Chris PeBenito 0fbfa5
allow $1_gpg_t fs_t:filesystem getattr;
Chris PeBenito 0fbfa5
allow $1_gpg_t usr_t:file r_file_perms;
Chris PeBenito 0fbfa5
read_locale($1_gpg_t)
Chris PeBenito 0fbfa5
allow $1_t $1_gpg_secret_t:dir rw_dir_perms;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
dontaudit $1_gpg_t var_t:dir search;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
ifdef(`gpg-agent.te', `gpg_agent_domain($1)')
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# for helper programs (which automatically fetch keys)
Chris PeBenito 0fbfa5
# Note: this is only tested with the hkp interface. If you use eg the 
Chris PeBenito 0fbfa5
# mail interface you will likely need additional permissions.
Chris PeBenito 0fbfa5
type $1_gpg_helper_t, domain;
Chris PeBenito 0fbfa5
role $1_r types $1_gpg_helper_t;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
domain_auto_trans($1_gpg_t, gpg_helper_exec_t, $1_gpg_helper_t)
Chris PeBenito 0fbfa5
uses_shlib($1_gpg_helper_t)
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# allow gpg to fork so it can call the helpers
Chris PeBenito 0fbfa5
allow $1_gpg_t self:process { fork sigchld };
Chris PeBenito 0fbfa5
allow $1_gpg_t self:fifo_file { getattr read write };
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
dontaudit $1_gpg_helper_t $1_gpg_secret_t:file read;
Chris PeBenito 0fbfa5
if (use_nfs_home_dirs) {
Chris PeBenito 0fbfa5
dontaudit $1_gpg_helper_t nfs_t:file { read write };
Chris PeBenito 0fbfa5
}
Chris PeBenito 0fbfa5
if (use_samba_home_dirs) {
Chris PeBenito 0fbfa5
dontaudit $1_gpg_helper_t cifs_t:file { read write };
Chris PeBenito 0fbfa5
}
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# communicate with the user 
Chris PeBenito 0fbfa5
allow $1_gpg_helper_t $1_t:fd use;
Chris PeBenito 0fbfa5
allow $1_gpg_helper_t $1_t:fifo_file write;
Chris PeBenito 0fbfa5
# get keys from the network
Chris PeBenito 0fbfa5
can_network_client($1_gpg_helper_t)
Chris PeBenito 0fbfa5
allow $1_gpg_helper_t etc_t:file { getattr read };
Chris PeBenito 0fbfa5
allow $1_gpg_helper_t urandom_device_t:chr_file read;
Chris PeBenito 0fbfa5
allow $1_gpg_helper_t self:unix_stream_socket create_stream_socket_perms;
Chris PeBenito 0fbfa5
# for nscd
Chris PeBenito 0fbfa5
dontaudit $1_gpg_helper_t var_t:dir search;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
ifdef(`xdm.te', `
Chris PeBenito 0fbfa5
dontaudit $1_gpg_t xdm_t:fd use;
Chris PeBenito 0fbfa5
dontaudit $1_gpg_t xdm_t:fifo_file read;
Chris PeBenito 0fbfa5
')
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
')dnl end gpg_domain definition