policy_module(kerberos, 1.12.0)

########################################
#
# Declarations
#

## <desc>
## <p>
## Allow confined applications to run with kerberos.
## </p>
## </desc>
gen_tunable(kerberos_enabled, false)

type kadmind_t;
type kadmind_exec_t;
init_daemon_domain(kadmind_t, kadmind_exec_t)
domain_obj_id_change_exemption(kadmind_t)

type kadmind_log_t;
logging_log_file(kadmind_log_t)

type kadmind_tmp_t;
files_tmp_file(kadmind_tmp_t)

type kadmind_var_run_t;
files_pid_file(kadmind_var_run_t)

type kerberos_initrc_exec_t;
init_script_file(kerberos_initrc_exec_t)

type kpropd_t;
type kpropd_exec_t;
init_daemon_domain(kpropd_t, kpropd_exec_t)
domain_obj_id_change_exemption(kpropd_t)

type krb5_conf_t;
files_config_file(krb5_conf_t)

type krb5_home_t;
userdom_user_home_content(krb5_home_t)

type krb5_host_rcache_t alias saslauthd_tmp_t;
files_tmp_file(krb5_host_rcache_t)

# types for general configuration files in /etc
type krb5_keytab_t;
files_security_file(krb5_keytab_t)

# types for KDC configs and principal file(s)
type krb5kdc_conf_t;
files_config_file(krb5kdc_conf_t)

type krb5kdc_lock_t;
files_lock_file(krb5kdc_lock_t)

type krb5kdc_var_lib_t;
files_type(krb5kdc_var_lib_t)

# types for KDC principal file(s)
type krb5kdc_principal_t;
files_type(krb5kdc_principal_t)

type krb5kdc_t;
type krb5kdc_exec_t;
init_daemon_domain(krb5kdc_t, krb5kdc_exec_t)
domain_obj_id_change_exemption(krb5kdc_t)

type krb5kdc_log_t;
logging_log_file(krb5kdc_log_t)

type krb5kdc_tmp_t;
files_tmp_file(krb5kdc_tmp_t)

type krb5kdc_var_run_t;
files_pid_file(krb5kdc_var_run_t)

########################################
#
# kadmind local policy
#

# Use capabilities. Surplus capabilities may be allowed.
allow kadmind_t self:capability { setuid setgid chown fowner dac_read_search  sys_nice };
allow kadmind_t self:capability2 block_suspend;
dontaudit kadmind_t self:capability sys_tty_config;
allow kadmind_t self:process { setfscreate setsched getsched signal_perms };
allow kadmind_t self:netlink_route_socket r_netlink_socket_perms;
allow kadmind_t self:unix_dgram_socket { connect create write };
allow kadmind_t self:tcp_socket connected_stream_socket_perms;
allow kadmind_t self:udp_socket create_socket_perms;

allow kadmind_t kadmind_log_t:file manage_file_perms;
logging_log_filetrans(kadmind_t, kadmind_log_t, file)

allow kadmind_t krb5_conf_t:file read_file_perms;
dontaudit kadmind_t krb5_conf_t:file write;

manage_files_pattern(kadmind_t, krb5kdc_conf_t, krb5kdc_conf_t)

allow kadmind_t krb5kdc_lock_t:file { rw_file_perms setattr_file_perms };

allow kadmind_t krb5kdc_principal_t:file { manage_file_perms map };
filetrans_pattern(kadmind_t, krb5kdc_conf_t, krb5kdc_principal_t, file)

allow kadmind_t krb5_keytab_t:file read_file_perms;

can_exec(kadmind_t, kadmind_exec_t)

manage_files_pattern(kadmind_t, krb5_host_rcache_t, krb5_host_rcache_t)
files_tmp_filetrans(kadmind_t, krb5_host_rcache_t, file, "krb5_0.rcache2")

manage_dirs_pattern(kadmind_t, kadmind_tmp_t, kadmind_tmp_t)
manage_files_pattern(kadmind_t, kadmind_tmp_t, kadmind_tmp_t)
files_tmp_filetrans(kadmind_t, kadmind_tmp_t, { file dir })

manage_files_pattern(kadmind_t, kadmind_var_run_t, kadmind_var_run_t)
files_pid_filetrans(kadmind_t, kadmind_var_run_t, file)

kernel_read_kernel_sysctls(kadmind_t)
kernel_list_proc(kadmind_t)
kernel_read_network_state(kadmind_t)
kernel_read_proc_symlinks(kadmind_t)
kernel_read_system_state(kadmind_t)

corecmd_exec_bin(kadmind_t)
corecmd_exec_shell(kadmind_t)

corenet_all_recvfrom_netlabel(kadmind_t)
corenet_tcp_sendrecv_generic_if(kadmind_t)
corenet_udp_sendrecv_generic_if(kadmind_t)
corenet_tcp_sendrecv_generic_node(kadmind_t)
corenet_udp_sendrecv_generic_node(kadmind_t)
corenet_tcp_sendrecv_all_ports(kadmind_t)
corenet_udp_sendrecv_all_ports(kadmind_t)
corenet_tcp_bind_generic_node(kadmind_t)
corenet_udp_bind_generic_node(kadmind_t)
corenet_tcp_bind_kerberos_admin_port(kadmind_t)
corenet_tcp_bind_kerberos_password_port(kadmind_t)
corenet_udp_bind_kerberos_admin_port(kadmind_t)
corenet_udp_bind_kerberos_password_port(kadmind_t)
corenet_tcp_bind_reserved_port(kadmind_t)
corenet_dontaudit_tcp_bind_all_reserved_ports(kadmind_t)
corenet_sendrecv_kerberos_admin_server_packets(kadmind_t)
corenet_sendrecv_kerberos_password_server_packets(kadmind_t)
corenet_tcp_bind_kprop_port(kadmind_t)
corenet_tcp_connect_kprop_port(kadmind_t)

dev_read_sysfs(kadmind_t)
dev_read_rand(kadmind_t)
dev_read_urand(kadmind_t)

fs_getattr_all_fs(kadmind_t)
fs_search_auto_mountpoints(kadmind_t)
fs_rw_anon_inodefs_files(kadmind_t)

domain_use_interactive_fds(kadmind_t)

files_read_etc_files(kadmind_t)
files_read_usr_symlinks(kadmind_t)
files_read_var_files(kadmind_t)

kerberos_manage_host_rcache(kadmind_t)

selinux_validate_context(kadmind_t)

auth_read_passwd(kadmind_t)

logging_send_syslog_msg(kadmind_t)

miscfiles_read_generic_certs(kadmind_t)
miscfiles_read_localization(kadmind_t)
miscfiles_read_pkcs11_modules(kadmind_t)

seutil_read_config(kadmind_t)
seutil_read_file_contexts(kadmind_t)

sysnet_read_config(kadmind_t)
sysnet_use_ldap(kadmind_t)

userdom_dontaudit_use_unpriv_user_fds(kadmind_t)
userdom_dontaudit_search_user_home_dirs(kadmind_t)

optional_policy(`
	bind_read_cache(kadmind_t)
')

optional_policy(`
	ldap_stream_connect(kadmind_t)
')

optional_policy(`
	dirsrv_stream_connect(kadmind_t)
')

optional_policy(`
    gnome_read_home_config(kadmind_t)
')

optional_policy(`
	nis_use_ypbind(kadmind_t)
')

optional_policy(`
	sssd_read_public_files(kadmind_t)
    sssd_stream_connect(kadmind_t)
')

optional_policy(`
	seutil_sigchld_newrole(kadmind_t)
')

optional_policy(`
	udev_read_db(kadmind_t)
')

########################################
#
# Krb5kdc local policy
#

# Use capabilities. Surplus capabilities may be allowed.
allow krb5kdc_t self:capability { setuid setgid net_admin chown fowner dac_read_search  sys_nice };
allow krb5kdc_t self:capability2 block_suspend;
dontaudit krb5kdc_t self:capability sys_tty_config;
allow krb5kdc_t self:process { setfscreate setsched getsched signal_perms };
allow krb5kdc_t self:netlink_route_socket r_netlink_socket_perms;
allow krb5kdc_t self:tcp_socket create_stream_socket_perms;
allow krb5kdc_t self:udp_socket create_socket_perms;
allow krb5kdc_t self:fifo_file rw_fifo_file_perms;

allow krb5kdc_t krb5_conf_t:file read_file_perms;
dontaudit krb5kdc_t krb5_conf_t:file write;

can_exec(krb5kdc_t, krb5kdc_exec_t)

list_dirs_pattern(krb5kdc_t, krb5kdc_conf_t, krb5kdc_conf_t)
read_files_pattern(krb5kdc_t, krb5kdc_conf_t, krb5kdc_conf_t)
dontaudit krb5kdc_t krb5kdc_conf_t:file write;

allow krb5kdc_t krb5kdc_lock_t:file { rw_file_perms setattr_file_perms };

allow krb5kdc_t krb5kdc_log_t:file manage_file_perms;
logging_log_filetrans(krb5kdc_t, krb5kdc_log_t, file)

allow krb5kdc_t krb5kdc_principal_t:file rw_file_perms;

manage_dirs_pattern(krb5kdc_t, krb5kdc_tmp_t, krb5kdc_tmp_t)
manage_files_pattern(krb5kdc_t, krb5kdc_tmp_t, krb5kdc_tmp_t)
files_tmp_filetrans(krb5kdc_t, krb5kdc_tmp_t, { file dir })

manage_files_pattern(krb5kdc_t, krb5kdc_var_run_t, krb5kdc_var_run_t)
manage_sock_files_pattern(krb5kdc_t, krb5kdc_var_run_t, krb5kdc_var_run_t)
manage_dirs_pattern(krb5kdc_t, krb5kdc_var_run_t, krb5kdc_var_run_t)
files_pid_filetrans(krb5kdc_t, krb5kdc_var_run_t, { dir file sock_file })

manage_files_pattern(krb5kdc_t, krb5kdc_var_lib_t, krb5kdc_var_lib_t)
manage_dirs_pattern(krb5kdc_t, krb5kdc_var_lib_t, krb5kdc_var_lib_t)

kernel_read_system_state(krb5kdc_t)
kernel_read_kernel_sysctls(krb5kdc_t)
kernel_list_proc(krb5kdc_t)
kernel_read_proc_symlinks(krb5kdc_t)
kernel_read_network_state(krb5kdc_t)
kernel_search_network_sysctl(krb5kdc_t)

corecmd_exec_bin(krb5kdc_t)

corenet_all_recvfrom_netlabel(krb5kdc_t)
corenet_tcp_sendrecv_generic_if(krb5kdc_t)
corenet_udp_sendrecv_generic_if(krb5kdc_t)
corenet_tcp_sendrecv_generic_node(krb5kdc_t)
corenet_udp_sendrecv_generic_node(krb5kdc_t)
corenet_tcp_sendrecv_all_ports(krb5kdc_t)
corenet_udp_sendrecv_all_ports(krb5kdc_t)
corenet_tcp_bind_generic_node(krb5kdc_t)
corenet_udp_bind_generic_node(krb5kdc_t)
corenet_tcp_bind_kerberos_port(krb5kdc_t)
corenet_udp_bind_kerberos_port(krb5kdc_t)
corenet_tcp_connect_ocsp_port(krb5kdc_t)
corenet_sendrecv_kerberos_server_packets(krb5kdc_t)
corenet_sendrecv_ocsp_client_packets(krb5kdc_t)

dev_read_sysfs(krb5kdc_t)
dev_read_urand(krb5kdc_t)

fs_getattr_all_fs(krb5kdc_t)
fs_search_auto_mountpoints(krb5kdc_t)
fs_rw_anon_inodefs_files(krb5kdc_t)

domain_use_interactive_fds(krb5kdc_t)

files_read_usr_symlinks(krb5kdc_t)
files_read_var_files(krb5kdc_t)

selinux_validate_context(krb5kdc_t)

auth_use_nsswitch(krb5kdc_t)

logging_send_syslog_msg(krb5kdc_t)

miscfiles_read_generic_certs(krb5kdc_t)

seutil_read_file_contexts(krb5kdc_t)

sysnet_read_config(krb5kdc_t)
sysnet_use_ldap(krb5kdc_t)

userdom_dontaudit_use_unpriv_user_fds(krb5kdc_t)
userdom_dontaudit_search_user_home_dirs(krb5kdc_t)

optional_policy(`
    ipa_stream_connect_otpd(krb5kdc_t)
')

optional_policy(`
	ldap_stream_connect(krb5kdc_t)
')

optional_policy(`
	dirsrv_stream_connect(krb5kdc_t)
')

optional_policy(`
	nis_use_ypbind(krb5kdc_t)
')

optional_policy(`
	realmd_read_var_lib(krb5kdc_t)
')

optional_policy(`
	seutil_sigchld_newrole(krb5kdc_t)
')

optional_policy(`
	sssd_read_public_files(krb5kdc_t)
')

optional_policy(`
	udev_read_db(krb5kdc_t)
')

########################################
#
# kpropd local policy
#

allow kpropd_t self:capability net_bind_service;
allow kpropd_t self:process setfscreate;

allow kpropd_t self:fifo_file rw_file_perms;
allow kpropd_t self:unix_stream_socket create_stream_socket_perms;
allow kpropd_t self:tcp_socket create_stream_socket_perms;

allow kpropd_t krb5_host_rcache_t:file manage_file_perms;

allow kpropd_t krb5_keytab_t:file read_file_perms;

read_files_pattern(kpropd_t, krb5kdc_conf_t, krb5kdc_conf_t)

manage_files_pattern(kpropd_t, krb5kdc_conf_t, krb5kdc_lock_t)
filetrans_pattern(kpropd_t, krb5kdc_conf_t, krb5kdc_lock_t, file)

manage_files_pattern(kpropd_t, krb5kdc_conf_t, krb5kdc_principal_t)
allow kpropd_t krb5kdc_principal_t:file map;

manage_dirs_pattern(kpropd_t, krb5kdc_tmp_t, krb5kdc_tmp_t)
manage_files_pattern(kpropd_t, krb5kdc_tmp_t, krb5kdc_tmp_t)
files_tmp_filetrans(kpropd_t, krb5kdc_tmp_t, { file dir })

kernel_read_system_state(kpropd_t)
kernel_read_network_state(kpropd_t)

can_exec(kpropd_t,kpropd_exec_t)

corecmd_exec_bin(kpropd_t)

corenet_tcp_sendrecv_generic_if(kpropd_t)
corenet_tcp_sendrecv_generic_node(kpropd_t)
corenet_tcp_sendrecv_all_ports(kpropd_t)
corenet_tcp_bind_generic_node(kpropd_t)
corenet_tcp_bind_kprop_port(kpropd_t)
corenet_tcp_connect_kprop_port(kpropd_t)

dev_read_urand(kpropd_t)

files_search_tmp(kpropd_t)

selinux_validate_context(kpropd_t)

auth_use_nsswitch(kpropd_t)

logging_send_syslog_msg(kpropd_t)

seutil_read_file_contexts(kpropd_t)

sysnet_dns_name_resolve(kpropd_t)

kerberos_tmp_filetrans_host_rcache(kpropd_t, "krb5_0.rcache2")
kerberos_use(kpropd_t)
