Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
# Macros for gpg and pgp
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
# Author:  Russell Coker <russell@coker.com.au>
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
# based on the work of:
Chris PeBenito 31b7c0
# Stephen Smalley <sds@epoch.ncsc.mil> and Timothy Fraser
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
# gpg_domain(domain_prefix)
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
# Define a derived domain for the gpg/pgp 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/gpg.te.
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
define(`gpg_domain', `
Chris PeBenito 31b7c0
# Derived domain based on the calling user domain and the program.
Chris PeBenito 31b7c0
type $1_gpg_t, domain, privlog;
Chris PeBenito 31b7c0
type $1_gpg_secret_t, file_type, $1_file_type, sysadmfile;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Transition from the user domain to the derived domain.
Chris PeBenito 31b7c0
domain_auto_trans($1_t, gpg_exec_t, $1_gpg_t)
Chris PeBenito 31b7c0
role $1_r types $1_gpg_t;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
can_network($1_gpg_t)
Chris PeBenito 31b7c0
allow $1_gpg_t port_type:tcp_socket name_connect;
Chris PeBenito 31b7c0
can_ypbind($1_gpg_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# for a bug in kmail
Chris PeBenito 31b7c0
dontaudit $1_gpg_t $1_t:unix_stream_socket { getattr read write };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow $1_gpg_t device_t:dir r_dir_perms;
Chris PeBenito 31b7c0
allow $1_gpg_t { random_device_t urandom_device_t }:chr_file r_file_perms;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow $1_gpg_t etc_t:file r_file_perms;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow $1_gpg_t self:unix_stream_socket create_stream_socket_perms;
Chris PeBenito 31b7c0
allow $1_gpg_t self:tcp_socket create_stream_socket_perms;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
access_terminal($1_gpg_t, $1)
Chris PeBenito 31b7c0
ifdef(`gnome-pty-helper.te', `allow $1_gpg_t $1_gph_t:fd use;')
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Inherit and use descriptors
Chris PeBenito 31b7c0
allow $1_gpg_t { privfd $1_t }:fd use;
Chris PeBenito 31b7c0
allow { $1_t $1_gpg_t } $1_gpg_t:process signal;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# setrlimit is for ulimit -c 0
Chris PeBenito 31b7c0
allow $1_gpg_t self:process { setrlimit setcap setpgid };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# allow ps to show gpg
Chris PeBenito 31b7c0
can_ps($1_t, $1_gpg_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
uses_shlib($1_gpg_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Access .gnupg
Chris PeBenito 31b7c0
rw_dir_create_file($1_gpg_t, $1_gpg_secret_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Read content to encrypt/decrypt/sign
Chris PeBenito 31b7c0
read_content($1_gpg_t, $1)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Write content to encrypt/decrypt/sign
Chris PeBenito 31b7c0
write_trusted($1_gpg_t, $1)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow $1_gpg_t self:capability { ipc_lock setuid };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow $1_gpg_t { etc_t usr_t }:dir r_dir_perms;
Chris PeBenito 31b7c0
allow $1_gpg_t fs_t:filesystem getattr;
Chris PeBenito 31b7c0
allow $1_gpg_t usr_t:file r_file_perms;
Chris PeBenito 31b7c0
read_locale($1_gpg_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
dontaudit $1_gpg_t var_t:dir search;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
ifdef(`gpg-agent.te', `gpg_agent_domain($1)')
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# for helper programs (which automatically fetch keys)
Chris PeBenito 31b7c0
# Note: this is only tested with the hkp interface. If you use eg the 
Chris PeBenito 31b7c0
# mail interface you will likely need additional permissions.
Chris PeBenito 31b7c0
type $1_gpg_helper_t, domain;
Chris PeBenito 31b7c0
role $1_r types $1_gpg_helper_t;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
domain_auto_trans($1_gpg_t, gpg_helper_exec_t, $1_gpg_helper_t)
Chris PeBenito 31b7c0
uses_shlib($1_gpg_helper_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# allow gpg to fork so it can call the helpers
Chris PeBenito 31b7c0
allow $1_gpg_t self:process { fork sigchld };
Chris PeBenito 31b7c0
allow $1_gpg_t self:fifo_file { getattr read write };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
dontaudit $1_gpg_helper_t $1_gpg_secret_t:file read;
Chris PeBenito 31b7c0
if (use_nfs_home_dirs) {
Chris PeBenito 31b7c0
dontaudit $1_gpg_helper_t nfs_t:file { read write };
Chris PeBenito 31b7c0
}
Chris PeBenito 31b7c0
if (use_samba_home_dirs) {
Chris PeBenito 31b7c0
dontaudit $1_gpg_helper_t cifs_t:file { read write };
Chris PeBenito 31b7c0
}
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# communicate with the user 
Chris PeBenito 31b7c0
allow $1_gpg_helper_t $1_t:fd use;
Chris PeBenito 31b7c0
allow $1_gpg_helper_t $1_t:fifo_file write;
Chris PeBenito 31b7c0
# get keys from the network
Chris PeBenito 31b7c0
can_network_client($1_gpg_helper_t)
Chris PeBenito 31b7c0
allow $1_gpg_helper_t port_type:tcp_socket name_connect;
Chris PeBenito 31b7c0
allow $1_gpg_helper_t etc_t:file { getattr read };
Chris PeBenito 31b7c0
allow $1_gpg_helper_t urandom_device_t:chr_file read;
Chris PeBenito 31b7c0
allow $1_gpg_helper_t self:unix_stream_socket create_stream_socket_perms;
Chris PeBenito 31b7c0
# for nscd
Chris PeBenito 31b7c0
dontaudit $1_gpg_helper_t var_t:dir search;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
can_pipe_xdm($1_gpg_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
')dnl end gpg_domain definition