policy_module(iptables, 1.14.0)

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

attribute_role iptables_roles;
roleattribute system_r iptables_roles;

type iptables_t;
type iptables_exec_t;
init_system_domain(iptables_t, iptables_exec_t)
role iptables_roles types iptables_t;

type iptables_initrc_exec_t;
init_script_file(iptables_initrc_exec_t)

type iptables_tmp_t;
files_tmp_file(iptables_tmp_t)

type iptables_var_run_t;
files_pid_file(iptables_var_run_t)

type iptables_var_lib_t;
files_pid_file(iptables_var_lib_t)

type iptables_lock_t;
files_lock_file(iptables_lock_t)

type iptables_unit_file_t;
systemd_unit_file(iptables_unit_file_t)

########################################
#
# Iptables local policy
#

allow iptables_t self:capability { dac_read_search  net_admin net_raw };
allow iptables_t self:cap_userns { dac_read_search  net_admin net_raw };
dontaudit iptables_t self:capability { sys_admin sys_tty_config };
dontaudit iptables_t self:capability2 block_suspend;
allow iptables_t self:fifo_file rw_fifo_file_perms;
allow iptables_t self:process { sigchld sigkill sigstop signull signal };
allow iptables_t self:netlink_socket create_socket_perms;
allow iptables_t self:netlink_generic_socket create_socket_perms;
allow iptables_t self:netlink_netfilter_socket create_socket_perms;
allow iptables_t self:rawip_socket create_socket_perms;

files_manage_system_conf_files(iptables_t)
files_etc_filetrans_system_conf(iptables_t)
files_etc_filetrans(iptables_t, system_conf_t, dir)

manage_files_pattern(iptables_t, iptables_var_run_t, iptables_var_run_t)
files_pid_filetrans(iptables_t, iptables_var_run_t, file)

manage_dirs_pattern(iptables_t, iptables_var_lib_t, iptables_var_lib_t)
manage_files_pattern(iptables_t, iptables_var_lib_t, iptables_var_lib_t)
manage_lnk_files_pattern(iptables_t, iptables_var_lib_t, iptables_var_lib_t)
files_var_lib_filetrans(iptables_t, iptables_var_lib_t, { file dir lnk_file })

can_exec(iptables_t, iptables_exec_t)

manage_files_pattern(iptables_t, iptables_lock_t, iptables_lock_t)
files_lock_filetrans(iptables_t, iptables_lock_t, file)

allow iptables_t iptables_tmp_t:dir manage_dir_perms;
allow iptables_t iptables_tmp_t:file manage_file_perms;
files_tmp_filetrans(iptables_t, iptables_tmp_t, { file dir })

kernel_getattr_proc(iptables_t)
kernel_request_load_module(iptables_t)
kernel_read_system_state(iptables_t)
kernel_read_network_state(iptables_t)
kernel_read_kernel_sysctls(iptables_t)
kernel_read_usermodehelper_state(iptables_t)
kernel_use_fds(iptables_t)
kernel_rw_net_sysctls(iptables_t)
kernel_search_network_sysctl(iptables_t)


# needed by ipvsadm
corecmd_exec_bin(iptables_t)
corecmd_exec_shell(iptables_t)

corenet_relabelto_all_packets(iptables_t)
corenet_dontaudit_rw_tun_tap_dev(iptables_t)

dev_read_sysfs(iptables_t)
dev_read_urand(iptables_t)
dev_read_rand(iptables_t)

fs_getattr_xattr_fs(iptables_t)
fs_search_auto_mountpoints(iptables_t)
fs_list_inotifyfs(iptables_t)
fs_read_nsfs_files(iptables_t)

mls_file_read_all_levels(iptables_t)

term_dontaudit_use_console(iptables_t)
term_use_all_inherited_terms(iptables_t)

domain_use_interactive_fds(iptables_t)

files_rw_etc_runtime_files(iptables_t)
files_rw_inherited_tmp_file(iptables_t)
files_read_kernel_modules(iptables_t)

auth_use_nsswitch(iptables_t)

init_use_fds(iptables_t)
init_use_script_ptys(iptables_t)
# to allow rules to be saved on reboot:
init_rw_script_tmp_files(iptables_t)
init_rw_script_stream_sockets(iptables_t)
init_dontaudit_script_leaks(iptables_t)

logging_send_syslog_msg(iptables_t)

sysnet_run_ifconfig(iptables_t, iptables_roles)
sysnet_dns_name_resolve(iptables_t)

userdom_use_inherited_user_terminals(iptables_t)
userdom_use_all_users_fds(iptables_t)

ifdef(`hide_broken_symptoms',`
	dev_dontaudit_write_mtrr(iptables_t)
')

optional_policy(`
	container_read_state(iptables_t)
')

optional_policy(`
	fail2ban_append_log(iptables_t)
    fail2ban_read_log(iptables_t)
	fail2ban_dontaudit_leaks(iptables_t)
	fail2ban_rw_inherited_tmp_files(iptables_t)
')

optional_policy(`
	firstboot_use_fds(iptables_t)
	firstboot_rw_pipes(iptables_t)
')

optional_policy(`
	firewalld_read_config(iptables_t)
	firewalld_read_pid_files(iptables_t)
	firewalld_dontaudit_write_tmp_files(iptables_t)
	firewalld_dontaudit_leaks(iptables_t)
')

optional_policy(`
	modutils_run_kmod(iptables_t, iptables_roles)
    modutils_list_module_config(iptables_t)
    modutils_read_module_config(iptables_t)
')

optional_policy(`
    NetworkManager_read_state(iptables_t)
')

optional_policy(`
	# for iptables -L
	nis_use_ypbind(iptables_t)
')

optional_policy(`
    plymouthd_exec_plymouth(iptables_t)
')

optional_policy(`
	ppp_dontaudit_use_fds(iptables_t)
')

optional_policy(`
	psad_rw_tmp_files(iptables_t)
	psad_write_log(iptables_t)
')

optional_policy(`
	ctdbd_read_lib_files(iptables_t)
')

optional_policy(`
    neutron_rw_inherited_pipes(iptables_t)
    neutron_sigchld(iptables_t)
')

optional_policy(`
	rhgb_dontaudit_use_ptys(iptables_t)
')

optional_policy(`
	seutil_sigchld_newrole(iptables_t)
    seutil_run_setfiles(iptables_t, iptables_roles)
')

optional_policy(`
	shorewall_read_config(iptables_t)
	shorewall_read_tmp_files(iptables_t)
	shorewall_rw_lib_files(iptables_t)
')

optional_policy(`
	udev_read_db(iptables_t)
')
