Add a SELinux Reference Policy module for the Knot authoritative-only DNS server. Signed-off-by: Alexander Miroshnichenko <alex@xxxxxxxxxxxxxx> --- policy/modules/roles/sysadm.te | 4 + policy/modules/services/knot.fc | 11 +++ policy/modules/services/knot.if | 156 ++++++++++++++++++++++++++++++++ policy/modules/services/knot.te | 92 +++++++++++++++++++ 4 files changed, 263 insertions(+) create mode 100644 policy/modules/services/knot.fc create mode 100644 policy/modules/services/knot.if create mode 100644 policy/modules/services/knot.te diff --git a/policy/modules/roles/sysadm.te b/policy/modules/roles/sysadm.te index 8f891c83865f..e3079ad65d17 100644 --- a/policy/modules/roles/sysadm.te +++ b/policy/modules/roles/sysadm.te @@ -550,6 +550,10 @@ optional_policy(` keystone_admin(sysadm_t, sysadm_r) ') +optional_policy(` + knotc_role(sysadm_r, sysadm_t) +') + optional_policy(` kismet_admin(sysadm_t, sysadm_r) ') diff --git a/policy/modules/services/knot.fc b/policy/modules/services/knot.fc new file mode 100644 index 000000000000..a809fbc72b14 --- /dev/null +++ b/policy/modules/services/knot.fc @@ -0,0 +1,11 @@ +/etc/knot(/.*)? gen_context(system_u:object_r:knot_conf_t,s0) + +/usr/sbin/knotd -- gen_context(system_u:object_r:knotd_exec_t,s0) + +/usr/sbin/knotc -- gen_context(system_u:object_r:knotc_exec_t,s0) + +/var/lib/knot(/.*)? gen_context(system_u:object_r:knot_var_lib_t,s0) + +/run/knot -d gen_context(system_u:object_r:knot_runtime_t,s0) + +/run/knot(/.*)? gen_context(system_u:object_r:knot_runtime_t,s0) diff --git a/policy/modules/services/knot.if b/policy/modules/services/knot.if new file mode 100644 index 000000000000..71eec0c9c1e3 --- /dev/null +++ b/policy/modules/services/knot.if @@ -0,0 +1,156 @@ + +## <summary>policy for knotc</summary> + +######################################## +## <summary> +## Execute knotd_exec_t in the knotd domain. +## </summary> +## <param name="domain"> +## <summary> +## Domain allowed to transition. +## </summary> +## </param> +# +interface(`knotd_domtrans',` + gen_require(` + type knotd_t, knotd_exec_t; + ') + + corecmd_search_bin($1) + domtrans_pattern($1, knotd_exec_t, knotd_t) +') + +######################################## +## <summary> +## Manage knot runtime files. +## </summary> +## <param name="domain"> +## <summary> +## Domain allowed access. +## </summary> +## </param> +# +interface(`knot_manage_runtime_files',` + gen_require(` + type knot_runtime_t; + type var_run_t; + ') + + manage_dirs_pattern($1, knot_runtime_t, knot_runtime_t) + manage_files_pattern($1, knot_runtime_t, knot_runtime_t) + manage_lnk_files_pattern($1, knot_runtime_t, knot_runtime_t) + manage_sock_files_pattern($1, knot_runtime_t, knot_runtime_t) + search_dirs_pattern($1, knot_runtime_t, knot_runtime_t) + files_pid_filetrans($1, knot_runtime_t, { file dir sock_file}) +') + +######################################## +## <summary> +## Knot /var/lib files mamange. +## </summary> +## <param name="domain"> +## <summary> +## Domain allowed access. +## </summary> +## </param> +# +interface(`knot_manage_var_lib_files',` + gen_require(` + type knot_var_lib_t; + ') + + manage_dirs_pattern($1, knot_var_lib_t, knot_var_lib_t) + manage_files_pattern($1, knot_var_lib_t, knot_var_lib_t) + manage_lnk_files_pattern($1, knot_var_lib_t, knot_var_lib_t) + allow $1 knot_var_lib_t:file map; + files_var_lib_filetrans($1, knot_var_lib_t, { file dir }) +') + +######################################## +## <summary> +## Knot /etc/knot files read. +## </summary> +## <param name="domain"> +## <summary> +## Domain allowed access. +## </summary> +## </param> +# +interface(`knot_read_conf',` + gen_require(` + type knot_conf_t; + type initrc_t; + ') + + mmap_read_files_pattern($1, knot_conf_t, knot_conf_t) + read_files_pattern(initrc_t, knot_conf_t, knot_conf_t) +') + +######################################## +## <summary> +## Manage knot temporary files. +## </summary> +## <param name="domain"> +## <summary> +## Domain allowed access. +## </summary> +## </param> +# +interface(`knot_manage_tmpfs_files',` + gen_require(` + type knot_tmp_t; + ') + + files_tmp_filetrans($1, knot_tmp_t, { file dir }) + allow $1 knot_tmp_t:file map; + allow $1 knot_tmp_t:file manage_file_perms; + allow $1 knot_tmp_t:dir manage_dir_perms; +') + +######################################## +## <summary> +## Execute knotc_exec_t in the knotc domain. +## </summary> +## <param name="domain"> +## <summary> +## Domain allowed to transition. +## </summary> +## </param> +# +interface(`knotc_domtrans',` + gen_require(` + type knotc_t, knotc_exec_t; + ') + + corecmd_search_bin($1) + domtrans_pattern($1, knotc_exec_t, knotc_t) +') + +######################################## +## <summary> +## Role access for knotc +## </summary> +## <param name="role"> +## <summary> +## Role allowed access +## </summary> +## </param> +## <param name="domain"> +## <summary> +## User domain for the role +## </summary> +## </param> +# +interface(`knotc_role',` + gen_require(` + type knotc_t; + attribute_role knotc_roles; + ') + + roleattribute $1 knotc_roles; + + knotc_domtrans($2) + + ps_process_pattern($2, knotc_t) + allow $2 knotc_t:process { signull signal sigkill }; +') diff --git a/policy/modules/services/knot.te b/policy/modules/services/knot.te new file mode 100644 index 000000000000..d96b7bf4ce98 --- /dev/null +++ b/policy/modules/services/knot.te @@ -0,0 +1,92 @@ +policy_module(knot, 1.0.0) + +######################################## +# +# Declarations +# + +type knotd_t; +type knotd_exec_t; +init_daemon_domain(knotd_t, knotd_exec_t) + +type knotc_t; +type knotc_exec_t; +application_domain(knotc_t, knotc_exec_t) +init_daemon_domain(knotc_t, knotc_exec_t) +role knotc_roles types knotc_t; + +attribute_role knotc_roles; +roleattribute system_r knotc_roles; + +type knot_conf_t; +files_type(knot_conf_t) + +type knot_runtime_t; +files_pid_file(knot_runtime_t) + +type knot_var_lib_t; +files_type(knot_var_lib_t) + +type knot_tmp_t; +files_tmp_file(knot_tmp_t) + +######################################## +# +# knotd local policy +# +allow knotd_t self:capability { dac_read_search setgid setpcap setuid }; +allow knotd_t self:process { fork signal_perms getcap getsched setsched }; +allow knotd_t self:tcp_socket create_stream_socket_perms; +allow knotd_t self:udp_socket create_stream_socket_perms; +allow knotd_t self:unix_stream_socket create_stream_socket_perms; + +corenet_tcp_bind_generic_node(knotd_t) +corenet_udp_bind_generic_node(knotd_t) + +corenet_sendrecv_dns_server_packets(knotd_t) +corenet_tcp_bind_dns_port(knotd_t) +corenet_udp_bind_dns_port(knotd_t) +# Slave replication +corenet_tcp_connect_dns_port(knotd_t) + +kernel_read_kernel_sysctls(knotd_t) + +knot_read_conf(knotd_t) +knot_manage_runtime_files(knotd_t) +knot_manage_tmpfs_files(knotd_t) + +# Read /etc/passwd +files_read_etc_files(knotd_t) +# Read /etc/{resolv.conf,hosts} +sysnet_read_config(knotd_t) + +fs_dontaudit_getattr_xattr_fs(knotd_t) + +fs_dontaudit_getattr_tmpfs(knotd_t) + +logging_send_syslog_msg(knotd_t) + +miscfiles_read_localization(knotd_t) + +######################################## +# +# knotc local policy +# + +allow knotc_t self:capability { dac_override dac_read_search }; + +stream_connect_pattern(knotc_t, knot_runtime_t, knot_runtime_t, knotd_t) + +knot_read_conf(knotc_t) +knot_manage_tmpfs_files(knotc_t) +knot_manage_var_lib_files(knotc_t) + +files_dontaudit_search_var_lib(knotc_t) + +fs_dontaudit_getattr_tmpfs(knotc_t) + +domain_use_interactive_fds(knotc_t) + +miscfiles_read_localization(knotc_t) + +userdom_use_user_ptys(knotc_t) -- 2.21.0