Add a SELinux Reference Policy module for the
Knot authoritative-only DNS server.
Signed-off-by: Alexander Miroshnichenko <[email protected]>
---
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
On Tue, Jul 02, 2019 at 03:55:59PM +0300, Alexander Miroshnichenko wrote:
> Add a SELinux Reference Policy module for the
> Knot authoritative-only DNS server.
Some observations in line below
>
> Signed-off-by: Alexander Miroshnichenko <[email protected]>
> ---
> 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)
redundant, fc spec below covers this
> +
> +/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>
"high-performance authoritative-only DNS server."
> +
> +########################################
> +## <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.
Manage Knot runtime (its not just files)
> +## </summary>
> +## <param name="domain">
> +## <summary>
> +## Domain allowed access.
> +## </summary>
> +## </param>
> +#
> +interface(`knot_manage_runtime_files',`
knot_manage_runtime (its not just files)
> + gen_require(`
> + type knot_runtime_t;
> + type var_run_t;
not allowed to reference external types. also its not used anyway
> + ')
> +
> + 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)
Add files_search_pids($1) to allow callers to traverse /run (you cannot "manage knot runtime" if you cannot traverse /run)
> + search_dirs_pattern($1, knot_runtime_t, knot_runtime_t)
redundant as the manage_dirs_pattern($1, knot_runtime_t, knot_runtime_t) above already covers this
> + files_pid_filetrans($1, knot_runtime_t, { file dir sock_file})
This does not belong in this interface. you would create a seperate knot_runtime_filetrans() instead. Also you can remove the "file" and "sock_file" here. Everything is inside /run/knot (as per the fc spec above)
> +')
> +
> +########################################
> +## <summary>
> +## Knot /var/lib files mamange.
cannot parse "mamange" use "Knot manage var lib."
> +## </summary>
> +## <param name="domain">
> +## <summary>
> +## Domain allowed access.
> +## </summary>
> +## </param>
> +#
> +interface(`knot_manage_var_lib_files',`
knot_manage_var_lib (its not just 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)
Add files_search_var_lib($1) because caller cannot "manage Knot var lib" if it cannot traverse /var/lib
> + allow $1 knot_var_lib_t:file map;
this (probably) does not belong here: you would create a knot_mmap_var_lib_files() instead, i suppose)
> + files_var_lib_filetrans($1, knot_var_lib_t, { file dir })
This does not belong here. you would create a knot_var_lib_filetrans() instead.
> +')
> +
> +########################################
> +## <summary>
> +## Knot /etc/knot files read.
knot_read_config_files (as read_files_pattern($1, knot_conf_t, knot_conf_t) only allows for reading files)
> +## </summary>
> +## <param name="domain">
> +## <summary>
> +## Domain allowed access.
> +## </summary>
> +## </param>
> +#
> +interface(`knot_read_conf',`
knot_read_config_files (because this interface allows callers to only "read" knot_conf_t files (not dirs or anything else)
> + gen_require(`
> + type knot_conf_t;
> + type initrc_t;
This does not belong here. not allowed to reference external types directly
> + ')
> +
> + mmap_read_files_pattern($1, knot_conf_t, knot_conf_t)
this does not belong here, if you need map then create a knot_mmap_config_file()
> + read_files_pattern(initrc_t, knot_conf_t, knot_conf_t)
Youre not allowed to reference initrc_t here. Use instead: read_files_pattern($1, knot_conf_t, knot_conf_t)
Add files_search_etc($1) to allow callers to traverse /etc
> +')
> +
> +########################################
> +## <summary>
> +## Manage knot temporary files.
Manage Knot tmp (this interface also allows caller to manage knot_tmp_t dirs, so "files" is not accurate)
> +## </summary>
> +## <param name="domain">
> +## <summary>
> +## Domain allowed access.
> +## </summary>
> +## </param>
> +#
> +interface(`knot_manage_tmpfs_files',`
knot_manage_tmp (this also allows managing dirs)
> + gen_require(`
> + type knot_tmp_t;
> + ')
> +
> + files_tmp_filetrans($1, knot_tmp_t, { file dir })
You would create a knot_tmp_filetrans for the above, and "file" can be removed as everything is in the dir.
> + allow $1 knot_tmp_t:file map;
This probably does not belong here you would create a knot_mmap_tmp_files() instead.
> + 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.
"Execute knotc in the knotc domain". Ones does not "execute" types
> +## </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)
init_system_domain() as knotc is short-running not long-running
> +role knotc_roles types knotc_t;
> +
> +attribute_role knotc_roles;
> +roleattribute system_r knotc_roles;
redundant as init_system_domain() already authorizes system_r to knotc_t
> +
> +type knot_conf_t;
> +files_type(knot_conf_t)
files_config_file(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 };
You might need dac_override here as indicated by setuid/setgid
> +allow knotd_t self:process { fork signal_perms getcap getsched setsched };
fork is probably redundant since all "domain" is allowed to fork
> +allow knotd_t self:tcp_socket create_stream_socket_perms;
> +allow knotd_t self:udp_socket create_stream_socket_perms;
udp is not connection based, use create_socket_perms for udp
> +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)
you probably want sysnet_dns_name_resolve() for slave replication (ie when you use dns names instead of ip addresses to connect to master
> +
> +fs_dontaudit_getattr_xattr_fs(knotd_t)
> +
> +fs_dontaudit_getattr_tmpfs(knotd_t)
I would probably just allow the above two. Use dontaudit rules conservatively
> +
> +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)
This can be removed when you fix knot_manage_var_lib() It did not make sense. knotc can never get to /var/lib/knot if its not allowed to traverse /var/lib
> +
> +fs_dontaudit_getattr_tmpfs(knotc_t)
I would just allow this
> +
> +domain_use_interactive_fds(knotc_t)
> +
> +miscfiles_read_localization(knotc_t)
> +
> +userdom_use_user_ptys(knotc_t)
> --
> 2.21.0
>
--
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02
https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02
Dominick Grift
Add a SELinux Reference Policy module for the
Knot authoritative-only DNS server.
Signed-off-by: Alexander Miroshnichenko <[email protected]>
---
policy/modules/roles/sysadm.te | 4 +
policy/modules/services/knot.fc | 9 ++
policy/modules/services/knot.if | 219 ++++++++++++++++++++++++++++++++
policy/modules/services/knot.te | 104 +++++++++++++++
policy/modules/system/init.te | 4 +
5 files changed, 340 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..02a1c2022661
--- /dev/null
+++ b/policy/modules/services/knot.fc
@@ -0,0 +1,9 @@
+/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(/.*)? 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..fef08da46a79
--- /dev/null
+++ b/policy/modules/services/knot.if
@@ -0,0 +1,219 @@
+## <summary>high-performance authoritative-only DNS server.</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.
+## </summary>
+## <param name="domain">
+## <summary>
+## Domain allowed access.
+## </summary>
+## </param>
+#
+interface(`knot_manage_runtime',`
+ gen_require(`
+ type knot_runtime_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)
+ files_search_pids($1)
+')
+
+########################################
+## <summary>
+## Manage knot var lib.
+## </summary>
+## <param name="domain">
+## <summary>
+## Domain allowed access.
+## </summary>
+## </param>
+#
+interface(`knot_manage_var_lib',`
+ 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)
+ files_search_var_lib($1)
+')
+
+########################################
+## <summary>
+## Mmap knot var lib files.
+## </summary>
+## <param name="domain">
+## <summary>
+## Domain allowed access.
+## </summary>
+## </param>
+#
+interface(`knot_mmap_var_lib_files',`
+ gen_require(`
+ type knot_var_lib_t;
+ ')
+
+ allow $1 knot_var_lib_t:file map;
+')
+
+########################################
+## <summary>
+## Read, mmap knot config files.
+## </summary>
+## <param name="domain">
+## <summary>
+## Domain allowed access.
+## </summary>
+## </param>
+#
+interface(`knot_mmap_config_file',`
+ gen_require(`
+ type knot_conf_t;
+ ')
+
+ mmap_read_files_pattern($1, knot_conf_t, knot_conf_t)
+ files_search_etc($1)
+')
+
+########################################
+## <summary>
+## Manage knot tmp.
+## </summary>
+## <param name="domain">
+## <summary>
+## Domain allowed access.
+## </summary>
+## </param>
+#
+interface(`knot_manage_tmp',`
+ gen_require(`
+ type knot_tmp_t;
+ ')
+
+ allow $1 knot_tmp_t:file manage_file_perms;
+ allow $1 knot_tmp_t:dir manage_dir_perms;
+')
+
+########################################
+## <summary>
+## Mmap knot tmp.
+## </summary>
+## <param name="domain">
+## <summary>
+## Domain allowed access.
+## </summary>
+## </param>
+#
+interface(`knot_mmap_tmp_files',`
+ gen_require(`
+ type knot_tmp_t;
+ ')
+
+ allow $1 knot_tmp_t:file map;
+')
+
+########################################
+## <summary>
+## Create knot tmp files, directories in
+## temporary directory.
+## </summary>
+## <param name="domain">
+## <summary>
+## Domain allowed access.
+## </summary>
+## </param>
+## <param name="file_type">
+## <summary>
+## The type of the object to be created
+## </summary>
+## </param>
+## <param name="object_class">
+## <summary>
+## The object class.
+## </summary>
+## </param>
+## <param name="name" optional="true">
+## <summary>
+## The name of the object being created.
+## </summary>
+## </param>
+#
+interface(`knot_tmp_filetrans',`
+ gen_require(`
+ type knot_tmp_t;
+ ')
+
+ files_tmp_filetrans($1, knot_tmp_t, { file dir })
+')
+
+########################################
+## <summary>
+## Execute knotc 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..780535759cf5
--- /dev/null
+++ b/policy/modules/services/knot.te
@@ -0,0 +1,104 @@
+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;
+
+type knot_conf_t;
+files_config_file(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_override dac_read_search setgid setpcap setuid };
+allow knotd_t self:process { signal_perms getcap getsched setsched };
+allow knotd_t self:tcp_socket create_stream_socket_perms;
+allow knotd_t self:udp_socket create_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_mmap_config_file(knotd_t)
+
+knot_manage_runtime(knotd_t)
+files_pid_filetrans(knotd_t, knot_runtime_t, dir)
+
+knot_manage_var_lib(knotd_t)
+knot_mmap_var_lib_files(knotd_t)
+files_var_lib_filetrans(knotd_t, knot_var_lib_t, dir)
+
+knot_manage_tmp(knotd_t)
+knot_mmap_tmp_files(knotd_t)
+knot_tmp_filetrans(knotd_t)
+
+files_map_etc_files(knotd_t)
+
+fs_getattr_xattr_fs(knotd_t)
+
+fs_getattr_tmpfs(knotd_t)
+
+auth_use_nsswitch(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 };
+allow knotc_t self:process signal;
+
+stream_connect_pattern(knotc_t, knot_runtime_t, knot_runtime_t, knotd_t)
+
+knot_mmap_config_file(knotc_t)
+
+knot_manage_tmp(knotc_t)
+knot_mmap_tmp_files(knotc_t)
+knot_tmp_filetrans(knotc_t)
+
+knot_manage_var_lib(knotc_t)
+knot_mmap_var_lib_files(knotc_t)
+
+files_read_etc_files(knotc_t)
+
+fs_getattr_tmpfs(knotc_t)
+
+domain_use_interactive_fds(knotc_t)
+
+miscfiles_read_localization(knotc_t)
+
+userdom_use_user_ptys(knotc_t)
diff --git a/policy/modules/system/init.te b/policy/modules/system/init.te
index f4d27bff3ea2..d38a0a8549d3 100644
--- a/policy/modules/system/init.te
+++ b/policy/modules/system/init.te
@@ -1158,6 +1158,10 @@ optional_policy(`
kerberos_use(initrc_t)
')
+optional_policy(`
+ knot_mmap_config_file(initrc_t)
+')
+
optional_policy(`
ldap_read_config(initrc_t)
ldap_list_db(initrc_t)
--
2.21.0
On 7/5/19 8:02 AM, Alexander Miroshnichenko wrote:
> Add a SELinux Reference Policy module for the
> Knot authoritative-only DNS server.
>
> Signed-off-by: Alexander Miroshnichenko <[email protected]>
> ---
> policy/modules/roles/sysadm.te | 4 +
> policy/modules/services/knot.fc | 9 ++
> policy/modules/services/knot.if | 219 ++++++++++++++++++++++++++++++++
> policy/modules/services/knot.te | 104 +++++++++++++++
> policy/modules/system/init.te | 4 +
> 5 files changed, 340 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
I think the rules are probably ok, but the interface names need work.
They should all start with knot_*, for starters. See below.
> 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..02a1c2022661
> --- /dev/null
> +++ b/policy/modules/services/knot.fc
> @@ -0,0 +1,9 @@
> +/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(/.*)? 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..fef08da46a79
> --- /dev/null
> +++ b/policy/modules/services/knot.if
> @@ -0,0 +1,219 @@
> +## <summary>high-performance authoritative-only DNS server.</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)
> +')
This doesn't seem needed, since a service is usually started by init.
If it is needed, then it should be something like knot_domtrans(), and
then the latter knotc_domtrans should be something like
knot_domtrans_client().
> +########################################
> +## <summary>
> +## Manage Knot runtime.
> +## </summary>
> +## <param name="domain">
> +## <summary>
> +## Domain allowed access.
> +## </summary>
> +## </param>
> +#
> +interface(`knot_manage_runtime',`
> + gen_require(`
> + type knot_runtime_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)
> + files_search_pids($1)
While there are a few interfaces that have this, I don't want this to be
the standard. This should either be split into 4 different interfaces
or put the rules directly in knot.te.
> +')
> +
> +########################################
> +## <summary>
> +## Manage knot var lib.
> +## </summary>
> +## <param name="domain">
> +## <summary>
> +## Domain allowed access.
> +## </summary>
> +## </param>
> +#
> +interface(`knot_manage_var_lib',`
> + 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)
> + files_search_var_lib($1)
> +')
Same thing as above.
> +########################################
> +## <summary>
> +## Mmap knot var lib files.
> +## </summary>
> +## <param name="domain">
> +## <summary>
> +## Domain allowed access.
> +## </summary>
> +## </param>
> +#
> +interface(`knot_mmap_var_lib_files',`
"map" not "mmap"
> + gen_require(`
> + type knot_var_lib_t;
> + ')
> +
> + allow $1 knot_var_lib_t:file map;
> +')
> +
> +########################################
> +## <summary>
> +## Read, mmap knot config files.
> +## </summary>
> +## <param name="domain">
> +## <summary>
> +## Domain allowed access.
> +## </summary>
> +## </param>
> +#
> +interface(`knot_mmap_config_file',`
In this case, mmap_read, not just mmap. Or split map perm to another
interface.
> + gen_require(`
> + type knot_conf_t;
> + ')
> +
> + mmap_read_files_pattern($1, knot_conf_t, knot_conf_t)
> + files_search_etc($1)
> +')
> +
> +########################################
> +## <summary>
> +## Manage knot tmp.
> +## </summary>
> +## <param name="domain">
> +## <summary>
> +## Domain allowed access.
> +## </summary>
> +## </param>
> +#
> +interface(`knot_manage_tmp',`
> + gen_require(`
> + type knot_tmp_t;
> + ')
> +
> + allow $1 knot_tmp_t:file manage_file_perms;
> + allow $1 knot_tmp_t:dir manage_dir_perms;
Needs 2 interfaces.
> +')
> +
> +########################################
> +## <summary>
> +## Mmap knot tmp.
> +## </summary>
> +## <param name="domain">
> +## <summary>
> +## Domain allowed access.
> +## </summary>
> +## </param>
> +#
> +interface(`knot_mmap_tmp_files',`
Similar comment to above.
> + gen_require(`
> + type knot_tmp_t;
> + ')
> +
> + allow $1 knot_tmp_t:file map;
> +')
> +
> +########################################
> +## <summary>
> +## Create knot tmp files, directories in
> +## temporary directory.
> +## </summary>
> +## <param name="domain">
> +## <summary>
> +## Domain allowed access.
> +## </summary>
> +## </param>
> +## <param name="file_type">
> +## <summary>
> +## The type of the object to be created
> +## </summary>
> +## </param>
> +## <param name="object_class">
> +## <summary>
> +## The object class.
> +## </summary>
> +## </param>
> +## <param name="name" optional="true">
> +## <summary>
> +## The name of the object being created.
> +## </summary>
> +## </param>
> +#
> +interface(`knot_tmp_filetrans',`
> + gen_require(`
> + type knot_tmp_t;
> + ')
> +
> + files_tmp_filetrans($1, knot_tmp_t, { file dir })
> +')
> +
> +########################################
> +## <summary>
> +## Execute knotc 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..780535759cf5
> --- /dev/null
> +++ b/policy/modules/services/knot.te
> @@ -0,0 +1,104 @@
> +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;
> +
> +type knot_conf_t;
> +files_config_file(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_override dac_read_search setgid setpcap setuid };
> +allow knotd_t self:process { signal_perms getcap getsched setsched };
> +allow knotd_t self:tcp_socket create_stream_socket_perms;
> +allow knotd_t self:udp_socket create_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_mmap_config_file(knotd_t)
> +
> +knot_manage_runtime(knotd_t)
> +files_pid_filetrans(knotd_t, knot_runtime_t, dir)
> +
> +knot_manage_var_lib(knotd_t)
> +knot_mmap_var_lib_files(knotd_t)
> +files_var_lib_filetrans(knotd_t, knot_var_lib_t, dir)
> +
> +knot_manage_tmp(knotd_t)
> +knot_mmap_tmp_files(knotd_t)
> +knot_tmp_filetrans(knotd_t)
> +
> +files_map_etc_files(knotd_t)
> +
> +fs_getattr_xattr_fs(knotd_t)
> +
> +fs_getattr_tmpfs(knotd_t)
> +
> +auth_use_nsswitch(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 };
> +allow knotc_t self:process signal;
> +
> +stream_connect_pattern(knotc_t, knot_runtime_t, knot_runtime_t, knotd_t)
> +
> +knot_mmap_config_file(knotc_t)
> +
> +knot_manage_tmp(knotc_t)
> +knot_mmap_tmp_files(knotc_t)
> +knot_tmp_filetrans(knotc_t)
> +
> +knot_manage_var_lib(knotc_t)
> +knot_mmap_var_lib_files(knotc_t)
> +
> +files_read_etc_files(knotc_t)
> +
> +fs_getattr_tmpfs(knotc_t)
> +
> +domain_use_interactive_fds(knotc_t)
> +
> +miscfiles_read_localization(knotc_t)
> +
> +userdom_use_user_ptys(knotc_t)
> diff --git a/policy/modules/system/init.te b/policy/modules/system/init.te
> index f4d27bff3ea2..d38a0a8549d3 100644
> --- a/policy/modules/system/init.te
> +++ b/policy/modules/system/init.te
> @@ -1158,6 +1158,10 @@ optional_policy(`
> kerberos_use(initrc_t)
> ')
>
> +optional_policy(`
> + knot_mmap_config_file(initrc_t)
> +')
> +
> optional_policy(`
> ldap_read_config(initrc_t)
> ldap_list_db(initrc_t)
>
--
Chris PeBenito
Add a SELinux Reference Policy module for the
Knot authoritative-only DNS server.
Signed-off-by: Alexander Miroshnichenko <[email protected]>
---
policy/modules/roles/sysadm.te | 5 ++
policy/modules/services/knot.fc | 11 +++
policy/modules/services/knot.if | 108 ++++++++++++++++++++++++++++
policy/modules/services/knot.te | 121 ++++++++++++++++++++++++++++++++
policy/modules/system/init.te | 4 ++
5 files changed, 249 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..1f986432e2af 100644
--- a/policy/modules/roles/sysadm.te
+++ b/policy/modules/roles/sysadm.te
@@ -550,6 +550,11 @@ optional_policy(`
keystone_admin(sysadm_t, sysadm_r)
')
+optional_policy(`
+ knot_admin(sysadm_t, sysadm_r)
+ knot_run_client(sysadm_t, sysadm_r)
+')
+
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..bbf8a3526aeb
--- /dev/null
+++ b/policy/modules/services/knot.fc
@@ -0,0 +1,11 @@
+/etc/rc\.d/init\.d/knot -- gen_context(system_u:object_r:knot_initrc_exec_t,s0)
+
+/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(/.*)? 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..93285a91a5da
--- /dev/null
+++ b/policy/modules/services/knot.if
@@ -0,0 +1,108 @@
+## <summary>high-performance authoritative-only DNS server.</summary>
+
+########################################
+## <summary>
+## Execute knotc in the knotc domain.
+## </summary>
+## <param name="domain">
+## <summary>
+## Domain allowed to transition.
+## </summary>
+## </param>
+#
+interface(`knot_domtrans_client',`
+ gen_require(`
+ type knotc_t, knotc_exec_t;
+ ')
+
+ corecmd_search_bin($1)
+ domtrans_pattern($1, knotc_exec_t, knotc_t)
+')
+
+########################################
+## <summary>
+## Execute knotc in the knotc domain, and
+## allow the specified role the knotc domain.
+## </summary>
+## <param name="domain">
+## <summary>
+## Domain allowed to transition.
+## </summary>
+## </param>
+## <param name="role">
+## <summary>
+## Role allowed access.
+## </summary>
+## </param>
+## <rolecap/>
+#
+interface(`knot_run_client',`
+ gen_require(`
+ attribute_role knot_roles;
+ ')
+
+ knot_domtrans_client($1)
+ roleattribute $2 knot_roles;
+')
+
+########################################
+## <summary>
+## Read knot config files.
+## </summary>
+## <param name="domain">
+## <summary>
+## Domain allowed access.
+## </summary>
+## </param>
+#
+interface(`knot_read_config_file',`
+ gen_require(`
+ type knot_conf_t;
+ ')
+
+ read_files_pattern($1, knot_conf_t, knot_conf_t)
+ files_search_etc($1)
+')
+
+########################################
+## <summary>
+## All of the rules required to
+## administrate an knot environment.
+## </summary>
+## <param name="domain">
+## <summary>
+## Domain allowed access.
+## </summary>
+## </param>
+## <param name="role">
+## <summary>
+## Role allowed access.
+## </summary>
+## </param>
+## <rolecap/>
+#
+interface(`knot_admin',`
+ gen_require(`
+ type knotc_t, knotd_t, knot_conf_t, knot_initrc_exec_t;
+ type knot_runtime_t, knot_tmp_t, knot_var_lib_t;
+ ')
+
+ allow $1 knotc_t:process signal_perms;
+ allow $1 knotd_t:process { ptrace signal_perms };
+ ps_process_pattern($1, knotc_t)
+ ps_process_pattern($1, knotd_t)
+
+ init_startstop_service($1, $2, knotd_t, knot_initrc_exec_t)
+
+ files_search_etc($1)
+ admin_pattern($1, knot_conf_t)
+
+ files_search_pids($1)
+ admin_pattern($1, knot_runtime_t)
+
+ files_search_tmp($1)
+ admin_pattern($1, knot_tmp_t)
+
+ files_search_var_lib($1)
+ admin_pattern($1, knot_var_lib_t)
+')
diff --git a/policy/modules/services/knot.te b/policy/modules/services/knot.te
new file mode 100644
index 000000000000..8749bed5c53d
--- /dev/null
+++ b/policy/modules/services/knot.te
@@ -0,0 +1,121 @@
+policy_module(knot, 1.0.0)
+
+########################################
+#
+# Declarations
+#
+
+attribute_role knot_roles;
+
+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 knot_roles types knotc_t;
+
+type knot_conf_t;
+files_config_file(knot_conf_t)
+
+type knot_initrc_exec_t;
+init_script_file(knot_initrc_exec_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_override dac_read_search setgid setpcap setuid };
+allow knotd_t self:process { signal_perms getcap getsched setsched };
+allow knotd_t self:tcp_socket create_stream_socket_perms;
+allow knotd_t self:udp_socket create_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)
+
+allow knotd_t knot_conf_t:file map;
+knot_read_config_file(knotd_t)
+
+manage_dirs_pattern(knotd_t, knot_runtime_t, knot_runtime_t)
+manage_files_pattern(knotd_t, knot_runtime_t, knot_runtime_t)
+manage_lnk_files_pattern(knotd_t, knot_runtime_t, knot_runtime_t)
+manage_sock_files_pattern(knotd_t, knot_runtime_t, knot_runtime_t)
+files_pid_filetrans(knotd_t, knot_runtime_t, dir)
+
+allow knotd_t knot_tmp_t:file map;
+allow knotd_t knot_tmp_t:file manage_file_perms;
+allow knotd_t knot_tmp_t:dir manage_dir_perms;
+files_tmp_filetrans(knotd_t, knot_tmp_t, { file dir })
+
+allow knotd_t knot_var_lib_t:file map;
+manage_dirs_pattern(knotd_t, knot_var_lib_t, knot_var_lib_t)
+manage_files_pattern(knotd_t, knot_var_lib_t, knot_var_lib_t)
+manage_lnk_files_pattern(knotd_t, knot_var_lib_t, knot_var_lib_t)
+files_var_lib_filetrans(knotd_t, knot_var_lib_t, dir)
+
+files_map_etc_files(knotd_t)
+files_search_var_lib(knotd_t)
+
+fs_getattr_xattr_fs(knotd_t)
+
+fs_getattr_tmpfs(knotd_t)
+
+auth_use_nsswitch(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 };
+allow knotc_t self:process signal;
+
+stream_connect_pattern(knotc_t, knot_runtime_t, knot_runtime_t, knotd_t)
+
+allow knotc_t knot_conf_t:file map;
+knot_read_config_file(knotc_t)
+
+allow knotc_t knot_tmp_t:file map;
+allow knotc_t knot_tmp_t:file manage_file_perms;
+allow knotc_t knot_tmp_t:dir manage_dir_perms;
+files_tmp_filetrans(knotc_t, knot_tmp_t, { file dir })
+
+allow knotc_t knot_var_lib_t:file map;
+manage_dirs_pattern(knotc_t, knot_var_lib_t, knot_var_lib_t)
+manage_files_pattern(knotc_t, knot_var_lib_t, knot_var_lib_t)
+manage_lnk_files_pattern(knotc_t, knot_var_lib_t, knot_var_lib_t)
+
+files_read_etc_files(knotc_t)
+files_search_pids(knotc_t)
+files_search_var_lib(knotc_t)
+
+fs_getattr_tmpfs(knotc_t)
+
+domain_use_interactive_fds(knotc_t)
+
+miscfiles_read_localization(knotc_t)
+
+userdom_use_user_ptys(knotc_t)
diff --git a/policy/modules/system/init.te b/policy/modules/system/init.te
index f4d27bff3ea2..5824281090ee 100644
--- a/policy/modules/system/init.te
+++ b/policy/modules/system/init.te
@@ -1158,6 +1158,10 @@ optional_policy(`
kerberos_use(initrc_t)
')
+optional_policy(`
+ knot_read_config_file(initrc_t)
+')
+
optional_policy(`
ldap_read_config(initrc_t)
ldap_list_db(initrc_t)
--
2.21.0
On Wed, Jul 10, 2019 at 11:55:20AM +0300, Alexander Miroshnichenko wrote:
> Add a SELinux Reference Policy module for the
> Knot authoritative-only DNS server.
You forgot to make knotc init_system_domain() instead of init_daemon_domain()
also "file" should be plural "files": knot_read_config_files()
>
> Signed-off-by: Alexander Miroshnichenko <[email protected]>
> ---
> policy/modules/roles/sysadm.te | 5 ++
> policy/modules/services/knot.fc | 11 +++
> policy/modules/services/knot.if | 108 ++++++++++++++++++++++++++++
> policy/modules/services/knot.te | 121 ++++++++++++++++++++++++++++++++
> policy/modules/system/init.te | 4 ++
> 5 files changed, 249 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..1f986432e2af 100644
> --- a/policy/modules/roles/sysadm.te
> +++ b/policy/modules/roles/sysadm.te
> @@ -550,6 +550,11 @@ optional_policy(`
> keystone_admin(sysadm_t, sysadm_r)
> ')
>
> +optional_policy(`
> + knot_admin(sysadm_t, sysadm_r)
> + knot_run_client(sysadm_t, sysadm_r)
> +')
> +
> 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..bbf8a3526aeb
> --- /dev/null
> +++ b/policy/modules/services/knot.fc
> @@ -0,0 +1,11 @@
> +/etc/rc\.d/init\.d/knot -- gen_context(system_u:object_r:knot_initrc_exec_t,s0)
> +
> +/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(/.*)? 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..93285a91a5da
> --- /dev/null
> +++ b/policy/modules/services/knot.if
> @@ -0,0 +1,108 @@
> +## <summary>high-performance authoritative-only DNS server.</summary>
> +
> +########################################
> +## <summary>
> +## Execute knotc in the knotc domain.
> +## </summary>
> +## <param name="domain">
> +## <summary>
> +## Domain allowed to transition.
> +## </summary>
> +## </param>
> +#
> +interface(`knot_domtrans_client',`
> + gen_require(`
> + type knotc_t, knotc_exec_t;
> + ')
> +
> + corecmd_search_bin($1)
> + domtrans_pattern($1, knotc_exec_t, knotc_t)
> +')
> +
> +########################################
> +## <summary>
> +## Execute knotc in the knotc domain, and
> +## allow the specified role the knotc domain.
> +## </summary>
> +## <param name="domain">
> +## <summary>
> +## Domain allowed to transition.
> +## </summary>
> +## </param>
> +## <param name="role">
> +## <summary>
> +## Role allowed access.
> +## </summary>
> +## </param>
> +## <rolecap/>
> +#
> +interface(`knot_run_client',`
> + gen_require(`
> + attribute_role knot_roles;
> + ')
> +
> + knot_domtrans_client($1)
> + roleattribute $2 knot_roles;
> +')
> +
> +########################################
> +## <summary>
> +## Read knot config files.
> +## </summary>
> +## <param name="domain">
> +## <summary>
> +## Domain allowed access.
> +## </summary>
> +## </param>
> +#
> +interface(`knot_read_config_file',`
> + gen_require(`
> + type knot_conf_t;
> + ')
> +
> + read_files_pattern($1, knot_conf_t, knot_conf_t)
> + files_search_etc($1)
> +')
> +
> +########################################
> +## <summary>
> +## All of the rules required to
> +## administrate an knot environment.
> +## </summary>
> +## <param name="domain">
> +## <summary>
> +## Domain allowed access.
> +## </summary>
> +## </param>
> +## <param name="role">
> +## <summary>
> +## Role allowed access.
> +## </summary>
> +## </param>
> +## <rolecap/>
> +#
> +interface(`knot_admin',`
> + gen_require(`
> + type knotc_t, knotd_t, knot_conf_t, knot_initrc_exec_t;
> + type knot_runtime_t, knot_tmp_t, knot_var_lib_t;
> + ')
> +
> + allow $1 knotc_t:process signal_perms;
> + allow $1 knotd_t:process { ptrace signal_perms };
> + ps_process_pattern($1, knotc_t)
> + ps_process_pattern($1, knotd_t)
> +
> + init_startstop_service($1, $2, knotd_t, knot_initrc_exec_t)
> +
> + files_search_etc($1)
> + admin_pattern($1, knot_conf_t)
> +
> + files_search_pids($1)
> + admin_pattern($1, knot_runtime_t)
> +
> + files_search_tmp($1)
> + admin_pattern($1, knot_tmp_t)
> +
> + files_search_var_lib($1)
> + admin_pattern($1, knot_var_lib_t)
> +')
> diff --git a/policy/modules/services/knot.te b/policy/modules/services/knot.te
> new file mode 100644
> index 000000000000..8749bed5c53d
> --- /dev/null
> +++ b/policy/modules/services/knot.te
> @@ -0,0 +1,121 @@
> +policy_module(knot, 1.0.0)
> +
> +########################################
> +#
> +# Declarations
> +#
> +
> +attribute_role knot_roles;
> +
> +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 knot_roles types knotc_t;
> +
> +type knot_conf_t;
> +files_config_file(knot_conf_t)
> +
> +type knot_initrc_exec_t;
> +init_script_file(knot_initrc_exec_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_override dac_read_search setgid setpcap setuid };
> +allow knotd_t self:process { signal_perms getcap getsched setsched };
> +allow knotd_t self:tcp_socket create_stream_socket_perms;
> +allow knotd_t self:udp_socket create_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)
> +
> +allow knotd_t knot_conf_t:file map;
> +knot_read_config_file(knotd_t)
> +
> +manage_dirs_pattern(knotd_t, knot_runtime_t, knot_runtime_t)
> +manage_files_pattern(knotd_t, knot_runtime_t, knot_runtime_t)
> +manage_lnk_files_pattern(knotd_t, knot_runtime_t, knot_runtime_t)
> +manage_sock_files_pattern(knotd_t, knot_runtime_t, knot_runtime_t)
> +files_pid_filetrans(knotd_t, knot_runtime_t, dir)
> +
> +allow knotd_t knot_tmp_t:file map;
> +allow knotd_t knot_tmp_t:file manage_file_perms;
> +allow knotd_t knot_tmp_t:dir manage_dir_perms;
> +files_tmp_filetrans(knotd_t, knot_tmp_t, { file dir })
> +
> +allow knotd_t knot_var_lib_t:file map;
> +manage_dirs_pattern(knotd_t, knot_var_lib_t, knot_var_lib_t)
> +manage_files_pattern(knotd_t, knot_var_lib_t, knot_var_lib_t)
> +manage_lnk_files_pattern(knotd_t, knot_var_lib_t, knot_var_lib_t)
> +files_var_lib_filetrans(knotd_t, knot_var_lib_t, dir)
> +
> +files_map_etc_files(knotd_t)
> +files_search_var_lib(knotd_t)
> +
> +fs_getattr_xattr_fs(knotd_t)
> +
> +fs_getattr_tmpfs(knotd_t)
> +
> +auth_use_nsswitch(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 };
> +allow knotc_t self:process signal;
> +
> +stream_connect_pattern(knotc_t, knot_runtime_t, knot_runtime_t, knotd_t)
> +
> +allow knotc_t knot_conf_t:file map;
> +knot_read_config_file(knotc_t)
> +
> +allow knotc_t knot_tmp_t:file map;
> +allow knotc_t knot_tmp_t:file manage_file_perms;
> +allow knotc_t knot_tmp_t:dir manage_dir_perms;
> +files_tmp_filetrans(knotc_t, knot_tmp_t, { file dir })
> +
> +allow knotc_t knot_var_lib_t:file map;
> +manage_dirs_pattern(knotc_t, knot_var_lib_t, knot_var_lib_t)
> +manage_files_pattern(knotc_t, knot_var_lib_t, knot_var_lib_t)
> +manage_lnk_files_pattern(knotc_t, knot_var_lib_t, knot_var_lib_t)
> +
> +files_read_etc_files(knotc_t)
> +files_search_pids(knotc_t)
> +files_search_var_lib(knotc_t)
> +
> +fs_getattr_tmpfs(knotc_t)
> +
> +domain_use_interactive_fds(knotc_t)
> +
> +miscfiles_read_localization(knotc_t)
> +
> +userdom_use_user_ptys(knotc_t)
> diff --git a/policy/modules/system/init.te b/policy/modules/system/init.te
> index f4d27bff3ea2..5824281090ee 100644
> --- a/policy/modules/system/init.te
> +++ b/policy/modules/system/init.te
> @@ -1158,6 +1158,10 @@ optional_policy(`
> kerberos_use(initrc_t)
> ')
>
> +optional_policy(`
> + knot_read_config_file(initrc_t)
> +')
> +
> optional_policy(`
> ldap_read_config(initrc_t)
> ldap_list_db(initrc_t)
> --
> 2.21.0
>
--
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02
https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02
Dominick Grift
Add a SELinux Reference Policy module for the
Knot authoritative-only DNS server.
Signed-off-by: Alexander Miroshnichenko <[email protected]>
---
policy/modules/roles/sysadm.te | 5 ++
policy/modules/services/knot.fc | 11 +++
policy/modules/services/knot.if | 108 ++++++++++++++++++++++++++++
policy/modules/services/knot.te | 121 ++++++++++++++++++++++++++++++++
policy/modules/system/init.te | 4 ++
5 files changed, 249 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..1f986432e2af 100644
--- a/policy/modules/roles/sysadm.te
+++ b/policy/modules/roles/sysadm.te
@@ -550,6 +550,11 @@ optional_policy(`
keystone_admin(sysadm_t, sysadm_r)
')
+optional_policy(`
+ knot_admin(sysadm_t, sysadm_r)
+ knot_run_client(sysadm_t, sysadm_r)
+')
+
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..bbf8a3526aeb
--- /dev/null
+++ b/policy/modules/services/knot.fc
@@ -0,0 +1,11 @@
+/etc/rc\.d/init\.d/knot -- gen_context(system_u:object_r:knot_initrc_exec_t,s0)
+
+/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(/.*)? 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..a3792c3d15d0
--- /dev/null
+++ b/policy/modules/services/knot.if
@@ -0,0 +1,108 @@
+## <summary>high-performance authoritative-only DNS server.</summary>
+
+########################################
+## <summary>
+## Execute knotc in the knotc domain.
+## </summary>
+## <param name="domain">
+## <summary>
+## Domain allowed to transition.
+## </summary>
+## </param>
+#
+interface(`knot_domtrans_client',`
+ gen_require(`
+ type knotc_t, knotc_exec_t;
+ ')
+
+ corecmd_search_bin($1)
+ domtrans_pattern($1, knotc_exec_t, knotc_t)
+')
+
+########################################
+## <summary>
+## Execute knotc in the knotc domain, and
+## allow the specified role the knotc domain.
+## </summary>
+## <param name="domain">
+## <summary>
+## Domain allowed to transition.
+## </summary>
+## </param>
+## <param name="role">
+## <summary>
+## Role allowed access.
+## </summary>
+## </param>
+## <rolecap/>
+#
+interface(`knot_run_client',`
+ gen_require(`
+ attribute_role knot_roles;
+ ')
+
+ knot_domtrans_client($1)
+ roleattribute $2 knot_roles;
+')
+
+########################################
+## <summary>
+## Read knot config files.
+## </summary>
+## <param name="domain">
+## <summary>
+## Domain allowed access.
+## </summary>
+## </param>
+#
+interface(`knot_read_config_files',`
+ gen_require(`
+ type knot_conf_t;
+ ')
+
+ read_files_pattern($1, knot_conf_t, knot_conf_t)
+ files_search_etc($1)
+')
+
+########################################
+## <summary>
+## All of the rules required to
+## administrate an knot environment.
+## </summary>
+## <param name="domain">
+## <summary>
+## Domain allowed access.
+## </summary>
+## </param>
+## <param name="role">
+## <summary>
+## Role allowed access.
+## </summary>
+## </param>
+## <rolecap/>
+#
+interface(`knot_admin',`
+ gen_require(`
+ type knotc_t, knotd_t, knot_conf_t, knot_initrc_exec_t;
+ type knot_runtime_t, knot_tmp_t, knot_var_lib_t;
+ ')
+
+ allow $1 knotc_t:process signal_perms;
+ allow $1 knotd_t:process { ptrace signal_perms };
+ ps_process_pattern($1, knotc_t)
+ ps_process_pattern($1, knotd_t)
+
+ init_startstop_service($1, $2, knotd_t, knot_initrc_exec_t)
+
+ files_search_etc($1)
+ admin_pattern($1, knot_conf_t)
+
+ files_search_pids($1)
+ admin_pattern($1, knot_runtime_t)
+
+ files_search_tmp($1)
+ admin_pattern($1, knot_tmp_t)
+
+ files_search_var_lib($1)
+ admin_pattern($1, knot_var_lib_t)
+')
diff --git a/policy/modules/services/knot.te b/policy/modules/services/knot.te
new file mode 100644
index 000000000000..04a9aff00be6
--- /dev/null
+++ b/policy/modules/services/knot.te
@@ -0,0 +1,121 @@
+policy_module(knot, 1.0.0)
+
+########################################
+#
+# Declarations
+#
+
+attribute_role knot_roles;
+
+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_system_domain(knotc_t, knotc_exec_t)
+role knot_roles types knotc_t;
+
+type knot_conf_t;
+files_config_file(knot_conf_t)
+
+type knot_initrc_exec_t;
+init_script_file(knot_initrc_exec_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_override dac_read_search setgid setpcap setuid };
+allow knotd_t self:process { signal_perms getcap getsched setsched };
+allow knotd_t self:tcp_socket create_stream_socket_perms;
+allow knotd_t self:udp_socket create_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)
+
+allow knotd_t knot_conf_t:file map;
+knot_read_config_files(knotd_t)
+
+manage_dirs_pattern(knotd_t, knot_runtime_t, knot_runtime_t)
+manage_files_pattern(knotd_t, knot_runtime_t, knot_runtime_t)
+manage_lnk_files_pattern(knotd_t, knot_runtime_t, knot_runtime_t)
+manage_sock_files_pattern(knotd_t, knot_runtime_t, knot_runtime_t)
+files_pid_filetrans(knotd_t, knot_runtime_t, dir)
+
+allow knotd_t knot_tmp_t:file map;
+allow knotd_t knot_tmp_t:file manage_file_perms;
+allow knotd_t knot_tmp_t:dir manage_dir_perms;
+files_tmp_filetrans(knotd_t, knot_tmp_t, { file dir })
+
+allow knotd_t knot_var_lib_t:file map;
+manage_dirs_pattern(knotd_t, knot_var_lib_t, knot_var_lib_t)
+manage_files_pattern(knotd_t, knot_var_lib_t, knot_var_lib_t)
+manage_lnk_files_pattern(knotd_t, knot_var_lib_t, knot_var_lib_t)
+files_var_lib_filetrans(knotd_t, knot_var_lib_t, dir)
+
+files_map_etc_files(knotd_t)
+files_search_var_lib(knotd_t)
+
+fs_getattr_xattr_fs(knotd_t)
+
+fs_getattr_tmpfs(knotd_t)
+
+auth_use_nsswitch(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 };
+allow knotc_t self:process signal;
+
+stream_connect_pattern(knotc_t, knot_runtime_t, knot_runtime_t, knotd_t)
+
+allow knotc_t knot_conf_t:file map;
+knot_read_config_files(knotc_t)
+
+allow knotc_t knot_tmp_t:file map;
+allow knotc_t knot_tmp_t:file manage_file_perms;
+allow knotc_t knot_tmp_t:dir manage_dir_perms;
+files_tmp_filetrans(knotc_t, knot_tmp_t, { file dir })
+
+allow knotc_t knot_var_lib_t:file map;
+manage_dirs_pattern(knotc_t, knot_var_lib_t, knot_var_lib_t)
+manage_files_pattern(knotc_t, knot_var_lib_t, knot_var_lib_t)
+manage_lnk_files_pattern(knotc_t, knot_var_lib_t, knot_var_lib_t)
+
+files_read_etc_files(knotc_t)
+files_search_pids(knotc_t)
+files_search_var_lib(knotc_t)
+
+fs_getattr_tmpfs(knotc_t)
+
+domain_use_interactive_fds(knotc_t)
+
+miscfiles_read_localization(knotc_t)
+
+userdom_use_user_ptys(knotc_t)
diff --git a/policy/modules/system/init.te b/policy/modules/system/init.te
index f4d27bff3ea2..d118290e6c19 100644
--- a/policy/modules/system/init.te
+++ b/policy/modules/system/init.te
@@ -1158,6 +1158,10 @@ optional_policy(`
kerberos_use(initrc_t)
')
+optional_policy(`
+ knot_read_config_files(initrc_t)
+')
+
optional_policy(`
ldap_read_config(initrc_t)
ldap_list_db(initrc_t)
--
2.21.0
On 7/10/19 8:54 AM, Alexander Miroshnichenko wrote:
> Add a SELinux Reference Policy module for the
> Knot authoritative-only DNS server.
>
> Signed-off-by: Alexander Miroshnichenko <[email protected]>
> ---
> policy/modules/roles/sysadm.te | 5 ++
> policy/modules/services/knot.fc | 11 +++
> policy/modules/services/knot.if | 108 ++++++++++++++++++++++++++++
> policy/modules/services/knot.te | 121 ++++++++++++++++++++++++++++++++
> policy/modules/system/init.te | 4 ++
> 5 files changed, 249 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..1f986432e2af 100644
> --- a/policy/modules/roles/sysadm.te
> +++ b/policy/modules/roles/sysadm.te
> @@ -550,6 +550,11 @@ optional_policy(`
> keystone_admin(sysadm_t, sysadm_r)
> ')
>
> +optional_policy(`
> + knot_admin(sysadm_t, sysadm_r)
> + knot_run_client(sysadm_t, sysadm_r)
> +')
> +
> 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..bbf8a3526aeb
> --- /dev/null
> +++ b/policy/modules/services/knot.fc
> @@ -0,0 +1,11 @@
> +/etc/rc\.d/init\.d/knot -- gen_context(system_u:object_r:knot_initrc_exec_t,s0)
> +
> +/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(/.*)? 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..a3792c3d15d0
> --- /dev/null
> +++ b/policy/modules/services/knot.if
> @@ -0,0 +1,108 @@
> +## <summary>high-performance authoritative-only DNS server.</summary>
> +
> +########################################
> +## <summary>
> +## Execute knotc in the knotc domain.
> +## </summary>
> +## <param name="domain">
> +## <summary>
> +## Domain allowed to transition.
> +## </summary>
> +## </param>
> +#
> +interface(`knot_domtrans_client',`
> + gen_require(`
> + type knotc_t, knotc_exec_t;
> + ')
> +
> + corecmd_search_bin($1)
> + domtrans_pattern($1, knotc_exec_t, knotc_t)
> +')
> +
> +########################################
> +## <summary>
> +## Execute knotc in the knotc domain, and
> +## allow the specified role the knotc domain.
> +## </summary>
> +## <param name="domain">
> +## <summary>
> +## Domain allowed to transition.
> +## </summary>
> +## </param>
> +## <param name="role">
> +## <summary>
> +## Role allowed access.
> +## </summary>
> +## </param>
> +## <rolecap/>
> +#
> +interface(`knot_run_client',`
> + gen_require(`
> + attribute_role knot_roles;
> + ')
> +
> + knot_domtrans_client($1)
> + roleattribute $2 knot_roles;
> +')
> +
> +########################################
> +## <summary>
> +## Read knot config files.
> +## </summary>
> +## <param name="domain">
> +## <summary>
> +## Domain allowed access.
> +## </summary>
> +## </param>
> +#
> +interface(`knot_read_config_files',`
> + gen_require(`
> + type knot_conf_t;
> + ')
> +
> + read_files_pattern($1, knot_conf_t, knot_conf_t)
> + files_search_etc($1)
> +')
> +
> +########################################
> +## <summary>
> +## All of the rules required to
> +## administrate an knot environment.
> +## </summary>
> +## <param name="domain">
> +## <summary>
> +## Domain allowed access.
> +## </summary>
> +## </param>
> +## <param name="role">
> +## <summary>
> +## Role allowed access.
> +## </summary>
> +## </param>
> +## <rolecap/>
> +#
> +interface(`knot_admin',`
> + gen_require(`
> + type knotc_t, knotd_t, knot_conf_t, knot_initrc_exec_t;
> + type knot_runtime_t, knot_tmp_t, knot_var_lib_t;
> + ')
> +
> + allow $1 knotc_t:process signal_perms;
> + allow $1 knotd_t:process { ptrace signal_perms };
> + ps_process_pattern($1, knotc_t)
> + ps_process_pattern($1, knotd_t)
> +
> + init_startstop_service($1, $2, knotd_t, knot_initrc_exec_t)
> +
> + files_search_etc($1)
> + admin_pattern($1, knot_conf_t)
> +
> + files_search_pids($1)
> + admin_pattern($1, knot_runtime_t)
> +
> + files_search_tmp($1)
> + admin_pattern($1, knot_tmp_t)
> +
> + files_search_var_lib($1)
> + admin_pattern($1, knot_var_lib_t)
> +')
> diff --git a/policy/modules/services/knot.te b/policy/modules/services/knot.te
> new file mode 100644
> index 000000000000..04a9aff00be6
> --- /dev/null
> +++ b/policy/modules/services/knot.te
> @@ -0,0 +1,121 @@
> +policy_module(knot, 1.0.0)
> +
> +########################################
> +#
> +# Declarations
> +#
> +
> +attribute_role knot_roles;
> +
> +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_system_domain(knotc_t, knotc_exec_t)
> +role knot_roles types knotc_t;
> +
> +type knot_conf_t;
> +files_config_file(knot_conf_t)
> +
> +type knot_initrc_exec_t;
> +init_script_file(knot_initrc_exec_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_override dac_read_search setgid setpcap setuid };
> +allow knotd_t self:process { signal_perms getcap getsched setsched };
> +allow knotd_t self:tcp_socket create_stream_socket_perms;
> +allow knotd_t self:udp_socket create_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)
> +
> +allow knotd_t knot_conf_t:file map;
> +knot_read_config_files(knotd_t)
> +
> +manage_dirs_pattern(knotd_t, knot_runtime_t, knot_runtime_t)
> +manage_files_pattern(knotd_t, knot_runtime_t, knot_runtime_t)
> +manage_lnk_files_pattern(knotd_t, knot_runtime_t, knot_runtime_t)
> +manage_sock_files_pattern(knotd_t, knot_runtime_t, knot_runtime_t)
> +files_pid_filetrans(knotd_t, knot_runtime_t, dir)
> +
> +allow knotd_t knot_tmp_t:file map;
> +allow knotd_t knot_tmp_t:file manage_file_perms;
> +allow knotd_t knot_tmp_t:dir manage_dir_perms;
> +files_tmp_filetrans(knotd_t, knot_tmp_t, { file dir })
> +
> +allow knotd_t knot_var_lib_t:file map;
> +manage_dirs_pattern(knotd_t, knot_var_lib_t, knot_var_lib_t)
> +manage_files_pattern(knotd_t, knot_var_lib_t, knot_var_lib_t)
> +manage_lnk_files_pattern(knotd_t, knot_var_lib_t, knot_var_lib_t)
> +files_var_lib_filetrans(knotd_t, knot_var_lib_t, dir)
> +
> +files_map_etc_files(knotd_t)
> +files_search_var_lib(knotd_t)
> +
> +fs_getattr_xattr_fs(knotd_t)
> +
> +fs_getattr_tmpfs(knotd_t)
> +
> +auth_use_nsswitch(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 };
> +allow knotc_t self:process signal;
> +
> +stream_connect_pattern(knotc_t, knot_runtime_t, knot_runtime_t, knotd_t)
> +
> +allow knotc_t knot_conf_t:file map;
> +knot_read_config_files(knotc_t)
> +
> +allow knotc_t knot_tmp_t:file map;
> +allow knotc_t knot_tmp_t:file manage_file_perms;
> +allow knotc_t knot_tmp_t:dir manage_dir_perms;
> +files_tmp_filetrans(knotc_t, knot_tmp_t, { file dir })
> +
> +allow knotc_t knot_var_lib_t:file map;
> +manage_dirs_pattern(knotc_t, knot_var_lib_t, knot_var_lib_t)
> +manage_files_pattern(knotc_t, knot_var_lib_t, knot_var_lib_t)
> +manage_lnk_files_pattern(knotc_t, knot_var_lib_t, knot_var_lib_t)
> +
> +files_read_etc_files(knotc_t)
> +files_search_pids(knotc_t)
> +files_search_var_lib(knotc_t)
> +
> +fs_getattr_tmpfs(knotc_t)
> +
> +domain_use_interactive_fds(knotc_t)
> +
> +miscfiles_read_localization(knotc_t)
> +
> +userdom_use_user_ptys(knotc_t)
> diff --git a/policy/modules/system/init.te b/policy/modules/system/init.te
> index f4d27bff3ea2..d118290e6c19 100644
> --- a/policy/modules/system/init.te
> +++ b/policy/modules/system/init.te
> @@ -1158,6 +1158,10 @@ optional_policy(`
> kerberos_use(initrc_t)
> ')
>
> +optional_policy(`
> + knot_read_config_files(initrc_t)
> +')
> +
> optional_policy(`
> ldap_read_config(initrc_t)
> ldap_list_db(initrc_t)
Merged.
--
Chris PeBenito