Chris PeBenito b2b38c
# Copyright (C) 2005 Tresys Technology, LLC
Chris PeBenito b2b38c
Chris PeBenito b2b38c
#######################################
Chris PeBenito b2b38c
#
Chris PeBenito b2b38c
# Per user domain template for this module
Chris PeBenito b2b38c
#
Chris PeBenito b2b38c
# gpg_per_userdomain_template(userdomain_prefix)
Chris PeBenito b2b38c
#
Chris PeBenito b2b38c
define(`gpg_per_userdomain_template',`
Chris PeBenito b2b38c
requires_block_template(`$0'_depend)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
########################################
Chris PeBenito b2b38c
#
Chris PeBenito b2b38c
# Declarations
Chris PeBenito b2b38c
#
Chris PeBenito b2b38c
Chris PeBenito b2b38c
type $1_gpg_t;
Chris PeBenito b2b38c
domain_make_domain($1_gpg_t)
Chris PeBenito b2b38c
domain_make_entrypoint_file($1_gpg_t,gpg_exec_t)
Chris PeBenito b2b38c
role $1_r types $1_gpg_t;
Chris PeBenito b2b38c
Chris PeBenito b2b38c
type $1_gpg_agent_t;
Chris PeBenito b2b38c
domain_make_domain($1_gpg_agent_t)
Chris PeBenito b2b38c
domain_make_entrypoint_file($1_gpg_agent_t,gpg_agent_exec_t)
Chris PeBenito b2b38c
role $1_r types $1_gpg_agent_t;
Chris PeBenito b2b38c
Chris PeBenito b2b38c
type $1_gpg_agent_tmp_t;
Chris PeBenito b2b38c
files_make_file($1_gpg_agent_tmp_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
type $1_gpg_secret_t; #, $1_file_type;
Chris PeBenito b2b38c
files_make_file($1_gpg_secret_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
type $1_gpg_helper_t;
Chris PeBenito b2b38c
domain_make_domain($1_gpg_helper_t)
Chris PeBenito b2b38c
role $1_r types $1_gpg_helper_t;
Chris PeBenito b2b38c
Chris PeBenito b2b38c
type $1_gpg_pinentry_t;
Chris PeBenito b2b38c
domain_make_domain($1_gpg_pinentry_t)
Chris PeBenito b2b38c
role $1_r types $1_gpg_pinentry_t;
Chris PeBenito b2b38c
Chris PeBenito b2b38c
########################################
Chris PeBenito b2b38c
#
Chris PeBenito b2b38c
# GPG local policy
Chris PeBenito b2b38c
#
Chris PeBenito b2b38c
Chris PeBenito b2b38c
# transition from the userdomain to the derived domain
Chris PeBenito b2b38c
allow $1_t $1_gpg_t:process transition;
Chris PeBenito b2b38c
allow $1_t gpg_exec_t:file { getattr read execute };
Chris PeBenito b2b38c
type_transition $1_t gpg_exec_t:process $1_gpg_t;
Chris PeBenito b2b38c
Chris PeBenito b2b38c
allow $1_gpg_t self:capability { ipc_lock setuid };
Chris PeBenito b2b38c
allow { $1_t $1_gpg_t } $1_gpg_t:process signal;
Chris PeBenito b2b38c
# setrlimit is for ulimit -c 0
Chris PeBenito b2b38c
allow $1_gpg_t self:process { setrlimit setcap };
Chris PeBenito b2b38c
Chris PeBenito b2b38c
allow $1_gpg_t self:fifo_file { getattr read write };
Chris PeBenito b2b38c
allow $1_gpg_t self:tcp_socket { create ioctl read getattr write setattr append bind connect getopt setopt shutdown listen accept };
Chris PeBenito b2b38c
Chris PeBenito b2b38c
allow $1_gpg_t $1_gpg_secret_t:dir { read getattr lock search ioctl add_name remove_name write };
Chris PeBenito b2b38c
allow $1_gpg_t $1_gpg_secret_t:file { create ioctl read getattr lock write setattr append link unlink rename };
Chris PeBenito b2b38c
allow $1_gpg_t $1_gpg_secret_t:lnk_file { create read getattr setattr link unlink rename };
Chris PeBenito b2b38c
Chris PeBenito b2b38c
corenetwork_network_tcp_on_all_interfaces($1_gpg_t)
Chris PeBenito b2b38c
corenetwork_network_raw_on_all_interfaces($1_gpg_t)
Chris PeBenito b2b38c
corenetwork_network_udp_on_all_interfaces($1_gpg_t)
Chris PeBenito b2b38c
corenetwork_network_tcp_on_all_nodes($1_gpg_t)
Chris PeBenito b2b38c
corenetwork_network_raw_on_all_nodes($1_gpg_t)
Chris PeBenito b2b38c
corenetwork_network_udp_on_all_nodes($1_gpg_t)
Chris PeBenito b2b38c
corenetwork_network_tcp_on_all_ports($1_gpg_t)
Chris PeBenito b2b38c
corenetwork_network_udp_on_all_ports($1_gpg_t)
Chris PeBenito b2b38c
corenetwork_bind_tcp_on_all_nodes($1_gpg_t)
Chris PeBenito b2b38c
corenetwork_bind_udp_on_all_nodes($1_gpg_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
devices_get_random_data($1_gpg_t)
Chris PeBenito b2b38c
devices_get_pseudorandom_data($1_gpg_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
filesystem_get_persistent_filesystem_attributes($1_gpg_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
files_read_general_system_config($1_gpg_t)
Chris PeBenito b2b38c
files_read_general_application_resources($1_gpg_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
libraries_read_shared_libraries($1_gpg_t)
Chris PeBenito b2b38c
libraries_use_dynamic_loader($1_gpg_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
miscfiles_read_localization($1_gpg_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
logging_send_system_log_message($1_gpg_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
sysnetwork_read_network_config($1_gpg_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
# Legacy
Chris PeBenito b2b38c
if (allow_gpg_execstack) {
Chris PeBenito b2b38c
allow $1_gpg_t self:process execmem;
Chris PeBenito b2b38c
libraries_legacy_read_shared_libraries($1_gpg_t)
Chris PeBenito b2b38c
libraries_legacy_use_dynamic_loader($1_gpg_t)
Chris PeBenito b2b38c
miscfiles_legacy_read_localization($1_gpg_t)
Chris PeBenito b2b38c
# Not quite sure why this is needed... 
Chris PeBenito b2b38c
allow $1_gpg_t gpg_exec_t:file execmod;
Chris PeBenito b2b38c
}
Chris PeBenito b2b38c
Chris PeBenito b2b38c
ifdef(`TODO',`
Chris PeBenito b2b38c
Chris PeBenito b2b38c
can_ypbind($1_gpg_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
allow $1_t $1_gpg_secret_t:file getattr;
Chris PeBenito b2b38c
Chris PeBenito b2b38c
access_terminal($1_gpg_t, $1)
Chris PeBenito b2b38c
ifdef(`gnome-pty-helper.te', `allow $1_gpg_t $1_gph_t:fd use;')
Chris PeBenito b2b38c
Chris PeBenito b2b38c
# Inherit and use descriptors
Chris PeBenito b2b38c
allow $1_gpg_t { privfd $1_t }:fd use;
Chris PeBenito b2b38c
Chris PeBenito b2b38c
# allow ps to show gpg
Chris PeBenito b2b38c
can_ps($1_t, $1_gpg_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
# should not need read access...
Chris PeBenito b2b38c
allow $1_gpg_t home_root_t:dir { read search };
Chris PeBenito b2b38c
Chris PeBenito b2b38c
# use $1_gpg_secret_t for files it creates
Chris PeBenito b2b38c
# NB we are doing the type transition for directory creation only!
Chris PeBenito b2b38c
# so ~/.gnupg will be of $1_gpg_secret_t, then files created under it such as
Chris PeBenito b2b38c
# secring.gpg will be of $1_gpg_secret_t too.  But when you use gpg to decrypt
Chris PeBenito b2b38c
# a file and write output to your home directory it will use user_home_t.
Chris PeBenito b2b38c
file_type_auto_trans($1_gpg_t, $1_home_dir_t, $1_gpg_secret_t, dir)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
file_type_auto_trans($1_gpg_t, $1_home_dir_t, $1_home_t, file)
Chris PeBenito b2b38c
create_dir_file($1_gpg_t, $1_home_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
# allow the usual access to /tmp
Chris PeBenito b2b38c
file_type_auto_trans($1_gpg_t, tmp_t, $1_tmp_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
if (use_nfs_home_dirs) {
Chris PeBenito b2b38c
create_dir_file($1_gpg_t, nfs_t)
Chris PeBenito b2b38c
}
Chris PeBenito b2b38c
if (use_samba_home_dirs) {
Chris PeBenito b2b38c
create_dir_file($1_gpg_t, cifs_t)
Chris PeBenito b2b38c
}
Chris PeBenito b2b38c
Chris PeBenito b2b38c
rw_dir_create_file($1_gpg_t, $1_file_type)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
allow $1_t $1_gpg_secret_t:dir rw_dir_perms;
Chris PeBenito b2b38c
Chris PeBenito b2b38c
dontaudit $1_gpg_t var_t:dir search;
Chris PeBenito b2b38c
') dnl end TODO
Chris PeBenito b2b38c
Chris PeBenito b2b38c
########################################
Chris PeBenito b2b38c
#
Chris PeBenito b2b38c
# GPG helper local policy
Chris PeBenito b2b38c
#
Chris PeBenito b2b38c
Chris PeBenito b2b38c
# for helper programs (which automatically fetch keys)
Chris PeBenito b2b38c
# Note: this is only tested with the hkp interface. If you use eg the 
Chris PeBenito b2b38c
# mail interface you will likely need additional permissions.
Chris PeBenito b2b38c
Chris PeBenito b2b38c
# transition from the gpg domain to the helper domain
Chris PeBenito b2b38c
allow $1_gpg_t $1_gpg_helper_t:process transition;
Chris PeBenito b2b38c
allow $1_gpg_t gpg_helper_exec_t:file { getattr read execute };
Chris PeBenito b2b38c
type_transition $1_gpg_t gpg_helper_exec_t:process $1_gpg_helper_t;
Chris PeBenito b2b38c
Chris PeBenito b2b38c
allow $1_gpg_helper_t self:unix_stream_socket { create ioctl read getattr write setattr append bind connect getopt setopt shutdown listen accept };
Chris PeBenito b2b38c
Chris PeBenito b2b38c
allow $1_gpg_helper_t self:tcp_socket { create connect ioctl read getattr write setattr append bind getopt setopt shutdown };
Chris PeBenito b2b38c
allow $1_gpg_helper_t self:udp_socket { create connect ioctl read getattr write setattr append bind getopt setopt shutdown };
Chris PeBenito b2b38c
Chris PeBenito b2b38c
dontaudit $1_gpg_helper_t $1_gpg_secret_t:file read;
Chris PeBenito b2b38c
Chris PeBenito b2b38c
corenetwork_network_tcp_on_all_interfaces($1_gpg_helper_t)
Chris PeBenito b2b38c
corenetwork_network_raw_on_all_interfaces($1_gpg_helper_t)
Chris PeBenito b2b38c
corenetwork_network_udp_on_all_interfaces($1_gpg_helper_t)
Chris PeBenito b2b38c
corenetwork_network_tcp_on_all_nodes($1_gpg_helper_t)
Chris PeBenito b2b38c
corenetwork_network_udp_on_all_nodes($1_gpg_helper_t)
Chris PeBenito b2b38c
corenetwork_network_raw_on_all_nodes($1_gpg_helper_t)
Chris PeBenito b2b38c
corenetwork_network_tcp_on_all_ports($1_gpg_helper_t)
Chris PeBenito b2b38c
corenetwork_network_udp_on_all_ports($1_gpg_helper_t)
Chris PeBenito b2b38c
corenetwork_bind_tcp_on_all_nodes($1_gpg_helper_t)
Chris PeBenito b2b38c
corenetwork_bind_udp_on_all_nodes($1_gpg_helper_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
devices_get_pseudorandom_data($1_gpg_helper_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
files_read_general_system_config($1_gpg_helper_t)
Chris PeBenito b2b38c
# for nscd
Chris PeBenito b2b38c
files_ignore_search_system_state_data_directory($1_gpg_helper_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
libraries_use_dynamic_loader($1_gpg_helper_t)
Chris PeBenito b2b38c
libraries_read_shared_libraries($1_gpg_helper_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
sysnetwork_read_network_config($1_gpg_helper_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
ifdef(`TODO',`
Chris PeBenito b2b38c
Chris PeBenito b2b38c
if (use_nfs_home_dirs) {
Chris PeBenito b2b38c
dontaudit $1_gpg_helper_t nfs_t:file { read write };
Chris PeBenito b2b38c
}
Chris PeBenito b2b38c
if (use_samba_home_dirs) {
Chris PeBenito b2b38c
dontaudit $1_gpg_helper_t cifs_t:file { read write };
Chris PeBenito b2b38c
}
Chris PeBenito b2b38c
Chris PeBenito b2b38c
# communicate with the user 
Chris PeBenito b2b38c
allow $1_gpg_helper_t $1_t:fd use;
Chris PeBenito b2b38c
allow $1_gpg_helper_t $1_t:fifo_file write;
Chris PeBenito b2b38c
Chris PeBenito b2b38c
ifdef(`xdm.te', `
Chris PeBenito b2b38c
dontaudit $1_gpg_t xdm_t:fd use;
Chris PeBenito b2b38c
dontaudit $1_gpg_t xdm_t:fifo_file read;
Chris PeBenito b2b38c
')
Chris PeBenito b2b38c
') dnl end TODO
Chris PeBenito b2b38c
Chris PeBenito b2b38c
########################################
Chris PeBenito b2b38c
#
Chris PeBenito b2b38c
# GPG agent local policy
Chris PeBenito b2b38c
#
Chris PeBenito b2b38c
Chris PeBenito b2b38c
# rlimit: gpg-agent wants to prevent coredumps
Chris PeBenito b2b38c
allow $1_gpg_agent_t self:process setrlimit;
Chris PeBenito b2b38c
Chris PeBenito b2b38c
allow $1_gpg_agent_t self:unix_stream_socket { create ioctl read getattr write setattr append bind connect getopt setopt shutdown listen accept };
Chris PeBenito b2b38c
allow $1_gpg_agent_t self:fifo_file { getattr read write };
Chris PeBenito b2b38c
Chris PeBenito b2b38c
allow $1_t $1_gpg_agent_tmp_t:dir { create read getattr lock setattr ioctl link unlink rename search add_name remove_name reparent write rmdir };
Chris PeBenito b2b38c
allow $1_t $1_gpg_agent_tmp_t:file { create ioctl read getattr lock write setattr append link unlink rename };
Chris PeBenito b2b38c
allow $1_t $1_gpg_agent_tmp_t:sock_file { create ioctl read getattr lock write setattr append link unlink rename };
Chris PeBenito b2b38c
files_create_private_tmp_data($1_gpg_agent_t, $1_gpg_agent_tmp_t, { file sock_file dir })
Chris PeBenito b2b38c
Chris PeBenito b2b38c
domain_use_widely_inheritable_file_descriptors($1_gpg_agent_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
libraries_use_dynamic_loader($1_gpg_agent_t)
Chris PeBenito b2b38c
libraries_read_shared_libraries($1_gpg_agent_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
miscfiles_read_localization($1_gpg_agent_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
ifdef(`TODO',`
Chris PeBenito b2b38c
# Transition from the user domain to the derived domain.
Chris PeBenito b2b38c
domain_auto_trans($1_t, gpg_agent_exec_t, $1_gpg_agent_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
allow $1_gpg_agent_t xdm_t:fd use;
Chris PeBenito b2b38c
Chris PeBenito b2b38c
# Write to the user domain tty.
Chris PeBenito b2b38c
access_terminal($1_gpg_agent_t, $1)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
# Allow the user shell to signal the gpg-agent program.
Chris PeBenito b2b38c
allow $1_t $1_gpg_agent_t:process { signal sigkill };
Chris PeBenito b2b38c
# allow ps to show gpg-agent
Chris PeBenito b2b38c
can_ps($1_t, $1_gpg_agent_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
allow $1_gpg_agent_t proc_t:dir search;
Chris PeBenito b2b38c
allow $1_gpg_agent_t proc_t:lnk_file read;
Chris PeBenito b2b38c
Chris PeBenito b2b38c
allow $1_gpg_agent_t device_t:dir { getattr read };
Chris PeBenito b2b38c
Chris PeBenito b2b38c
# read and write ~/.gnupg (gpg-agent stores secret keys in ~/.gnupg/private-keys-v1.d )
Chris PeBenito b2b38c
allow $1_gpg_agent_t { home_root_t $1_home_dir_t }:dir search;
Chris PeBenito b2b38c
create_dir_file($1_gpg_agent_t, $1_gpg_secret_t)
Chris PeBenito b2b38c
if (use_nfs_home_dirs) {
Chris PeBenito b2b38c
create_dir_file($1_gpg_agent_t, nfs_t)
Chris PeBenito b2b38c
}
Chris PeBenito b2b38c
if (use_samba_home_dirs) {
Chris PeBenito b2b38c
create_dir_file($1_gpg_agent_t, cifs_t)
Chris PeBenito b2b38c
}
Chris PeBenito b2b38c
Chris PeBenito b2b38c
# gpg connect
Chris PeBenito b2b38c
allow $1_gpg_t $1_gpg_agent_tmp_t:dir search;
Chris PeBenito b2b38c
allow $1_gpg_t $1_gpg_agent_tmp_t:sock_file write;
Chris PeBenito b2b38c
can_unix_connect($1_gpg_t, $1_gpg_agent_t)
Chris PeBenito b2b38c
') dnl endif TODO
Chris PeBenito b2b38c
Chris PeBenito b2b38c
##############################
Chris PeBenito b2b38c
#
Chris PeBenito b2b38c
# Pinentry local policy
Chris PeBenito b2b38c
#
Chris PeBenito b2b38c
Chris PeBenito b2b38c
# we need to allow gpg-agent to call pinentry so it can get the passphrase 
Chris PeBenito b2b38c
# from the user.
Chris PeBenito b2b38c
allow $1_gpg_agent_t $1_gpg_pinentry_t:process transition;
Chris PeBenito b2b38c
allow $1_gpg_agent_t pinentry_exec_t:file { getattr read execute };
Chris PeBenito b2b38c
type_transition $1_gpg_agent_t pinentry_exec_t:process $1_gpg_pinentry_t;
Chris PeBenito b2b38c
Chris PeBenito b2b38c
allow $1_gpg_pinentry_t self:unix_stream_socket { connect create getattr read shutdown write };
Chris PeBenito b2b38c
allow $1_gpg_pinentry_t self:fifo_file { getattr read write };
Chris PeBenito b2b38c
Chris PeBenito b2b38c
# read /proc/meminfo
Chris PeBenito b2b38c
kernel_read_system_state($1_gpg_pinentry_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
files_read_general_application_resources($1_gpg_pinentry_t)
Chris PeBenito b2b38c
# read /etc/X11/qtrc
Chris PeBenito b2b38c
files_read_general_system_config($1_gpg_pinentry_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
libraries_use_dynamic_loader($1_gpg_pinentry_t)
Chris PeBenito b2b38c
libraries_read_shared_libraries($1_gpg_pinentry_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
miscfiles_read_fonts($1_gpg_pinentry_t)
Chris PeBenito b2b38c
miscfiles_read_localization($1_gpg_pinentry_t)
Chris PeBenito b2b38c
Chris PeBenito b2b38c
ifdef(`TODO',`
Chris PeBenito b2b38c
Chris PeBenito b2b38c
allow $1_gpg_agent_t bin_t:dir search;
Chris PeBenito b2b38c
Chris PeBenito b2b38c
ifdef(`xdm.te', `
Chris PeBenito b2b38c
allow $1_gpg_pinentry_t xdm_xserver_tmp_t:dir search;
Chris PeBenito b2b38c
allow $1_gpg_pinentry_t xdm_xserver_tmp_t:sock_file { read write };
Chris PeBenito b2b38c
can_unix_connect($1_gpg_pinentry_t, xdm_xserver_t)
Chris PeBenito b2b38c
allow $1_gpg_pinentry_t xdm_t:fd use;
Chris PeBenito b2b38c
')dnl end ig xdm.te
Chris PeBenito b2b38c
Chris PeBenito b2b38c
allow $1_gpg_pinentry_t { tmp_t home_root_t }:dir { getattr search };
Chris PeBenito b2b38c
Chris PeBenito b2b38c
# for .Xauthority
Chris PeBenito b2b38c
allow $1_gpg_pinentry_t $1_home_dir_t:dir { getattr search };
Chris PeBenito b2b38c
allow $1_gpg_pinentry_t $1_home_t:file { getattr read };
Chris PeBenito b2b38c
# wants to put some lock files into the user home dir, seems to work fine without
Chris PeBenito b2b38c
dontaudit $1_gpg_pinentry_t $1_home_t:dir { read write };
Chris PeBenito b2b38c
dontaudit $1_gpg_pinentry_t $1_home_t:file write;
Chris PeBenito b2b38c
Chris PeBenito b2b38c
if (use_nfs_home_dirs) {
Chris PeBenito b2b38c
allow $1_gpg_pinentry_t nfs_t:dir { getattr search };
Chris PeBenito b2b38c
allow $1_gpg_pinentry_t nfs_t:file { getattr read };
Chris PeBenito b2b38c
dontaudit $1_gpg_pinentry_t nfs_t:dir { read write };
Chris PeBenito b2b38c
dontaudit $1_gpg_pinentry_t nfs_t:file write;
Chris PeBenito b2b38c
}
Chris PeBenito b2b38c
Chris PeBenito b2b38c
if (use_samba_home_dirs) {
Chris PeBenito b2b38c
allow $1_gpg_pinentry_t cifs_t:dir { getattr search };
Chris PeBenito b2b38c
allow $1_gpg_pinentry_t cifs_t:file { getattr read };
Chris PeBenito b2b38c
dontaudit $1_gpg_pinentry_t cifs_t:dir { read write };
Chris PeBenito b2b38c
dontaudit $1_gpg_pinentry_t cifs_t:file write;
Chris PeBenito b2b38c
}
Chris PeBenito b2b38c
Chris PeBenito b2b38c
dontaudit $1_gpg_pinentry_t { sysctl_t sysctl_kernel_t }:dir { getattr search };
Chris PeBenito b2b38c
') dnl end TODO
Chris PeBenito b2b38c
') dnl end gpg_per_userdomain_template