policyd module
Here's a module for the postfix policy server "policyd",
http://policyd.org/. It also needs the port 10031/tcp labeled as policyd_port_t, but I don't know how to code that in a module. So I've added it manually with "semanage port -a -t policyd_port_t -p tcp 10031" on my systems.
#------------ policyd.fc ---------------------------------------------------
# policyd labeling policy # file: policyd.fc /usr/sbin/policyd -- gen_context(system_u:object_r:policyd_exec_t, s0) /etc/policyd.conf -- gen_context(system_u:object_r:policyd_conf_t, s0) /var/run/policyd.pid -- gen_context(system_u:object_r:policyd_var_run_t, s0) #------------/policyd.fc ---------------------------------------------------
#------------ policyd.te ---------------------------------------------------
policy_module(policyd, 1.0)
#####################
# Type declarations #
#####################
# Policyd domain:
type policyd_t;
# executable entry point: type policyd_exec_t;
# mark policyd_t as a domain and policyd_exec_t as an entrypoint into that domain init_daemon_domain(policyd_t, policyd_exec_t)
# PID file /var/run/policyd.pid
type policyd_var_run_t;files_pid_file(policyd_var_run_t)
# configuration files type policyd_conf_t; files_config_file(policyd_conf_t)
##########################
# policyd -- core access # ##########################
# Configuration files - read
allow policyd_t policyd_conf_t : dir r_dir_perms; allow policyd_t policyd_conf_t : file r_file_perms; allow policyd_t policyd_conf_t : lnk_file { getattr read };
# PID file - create, read, and write
allow policyd_t policyd_var_run_t : dir rw_dir_perms; allow policyd_t policyd_var_run_t : file create_file_perms; files_pid_filetrans(policyd_t, policyd_var_run_t, file)
allow policyd_t self : tcp_socket create_stream_socket_perms; corenet_tcp_sendrecv_all_if(policyd_t) corenet_tcp_sendrecv_all_nodes(policyd_t) corenet_tcp_sendrecv_all_ports(policyd_t) corenet_non_ipsec_sendrecv(policyd_t) corenet_tcp_bind_all_nodes(policyd_t) sysnet_dns_name_resolve(policyd_t)
# use shared libraries libs_use_ld_so(policyd_t) libs_use_shared_libs(policyd_t)
############### Analyzed AVC denials #######
require {
class capability { setgid setuid sys_chroot sys_resource};
class chr_file { read write getattr};
class file { read getattr };
class process setrlimit;
class sock_file write;
class tcp_socket { name_bind name_connect name_connect };
class unix_dgram_socket { connect create sendto write };
type devlog_t;
type devpts_t;
type etc_t;
type locale_t;
type mysqld_port_t;
type policyd_t;
type policyd_port_t;
type postfix_smtpd_t;
type syslogd_t;
type usr_t;
role system_r;
};# Write to stdout/stderr:
allow policyd_t devpts_t:chr_file { getattr read write };
allow policyd_t policyd_port_t:tcp_socket name_bind;
allow policyd_t mysqld_port_t:tcp_socket name_connect;
allow policyd_t self:capability { sys_resource sys_chroot setgid setuid }; allow policyd_t self:process setrlimit;
allow policyd_t etc_t:file { getattr read };
allow policyd_t devlog_t:sock_file write;
allow policyd_t locale_t:file { getattr read };
allow policyd_t self:unix_dgram_socket { connect create write};
allow policyd_t syslogd_t:unix_dgram_socket sendto;
allow policyd_t usr_t:file { getattr read }; # For /usr/share/mysql/charsets/Index.xml.
# Allow postfix to connect to the policy server:
allow postfix_smtpd_t policyd_port_t:tcp_socket name_connect;
#------------/policyd.te ---------------------------------------------------
-jf
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 5 lines · Jan-Frode Myklebust
Here's a module for the postfix policy server "policyd",
http://policyd.org/. It also needs the port 10031/tcp labeled aspolicyd_port_t, but I don't know how to code that in a module. So I've added it manually with "semanage port -a -tpolicyd_port_t-p tcp 10031" on my systems.
It is a limitation of modules, ports can only be defined in the base module or via semanage.
Signature · 10 lines
Chris PeBenito Tresys Technology, LLC (410) 290-1411 x150 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): 1191416728.5843.6.camel@gorn
Quoted 8 lines · Christopher J. PeBenito
I haven't looked at the module closely but right away I see you need to follow the commenting style like in all of the other modules. Also everything under the "analyzed avc denials" comment needs to be fixed to call interfaces except for the self ones. For the last line, you would need a patch for corenetwork to define the port and to add the tcp connect to policyd port (these two changes can be in the same patch).
Here you go :-) Diffed against refpolicy-20070928.tar.bz2.
I haven't tested this module after these changes, other than seeing that it builds. But the replacement of allow rules with interfaces seemed straight forward enough.
-jf
policy/modules/kernel/corenetwork.te.in +1 -0
@@ -125,6 +125,7 @@ network_port(openvpn, tcp,1194,s0, udp,1194,s0) network_port(pegasus_http, tcp,5988,s0) network_port(pegasus_https, tcp,5989,s0) +network_port(policyd, tcp,10031,s0) network_port(pop, tcp,106,s0, tcp,109,s0, tcp,110,s0, tcp,143,s0, tcp,220,s0, tcp,993,s0, tcp,995,s0, tcp,1109,s0) network_port(portmap, udp,111,s0, tcp,111,s0) network_port(postgresql, tcp,5432,s0)
policy/modules/services/policyd.fc +3 -0
@@ -0,0 +1,3 @@ +/usr/sbin/policyd -- gen_context(system_u:object_r:policyd_exec_t, s0) +/etc/policyd.conf -- gen_context(system_u:object_r:policyd_conf_t, s0) +/var/run/policyd\.pid -- gen_context(system_u:object_r:policyd_var_run_t, s0)
policy/modules/services/policyd.te +58 -0
58 lines not on this page · raw message
policy/modules.conf +7 -0
@@ -1137,6 +1137,13 @@ perdition = module # Layer: services +# Module: policyd +# +# Postfix policy server +# +policyd = module + +# Layer: services # Module: portmap # # RPC port mapping service.
Quoted 11 lines · Jan-Frode Myklebust
Quoted 8 lines · Christopher J. PeBenito
I haven't looked at the module closely but right away I see you need to follow the commenting style like in all of the other modules. Also everything under the "analyzed avc denials" comment needs to be fixed to call interfaces except for the self ones. For the last line, you would need a patch for corenetwork to define the port and to add the tcp connect to policyd port (these two changes can be in the same patch).
Here you go :-) Diffed against refpolicy-20070928.tar.bz2.
Its not a problem in this case, since that version just went out, but in the future, the preference would be against svn HEAD.
Quoted 3 lines
I haven't tested this module after these changes, other than seeing that it builds. But the replacement of allow rules with interfaces seemed straight forward enough.
Other comments:
Quoted 15 lines
plain text
document
attachment
(policyd.patch),
"policyd.patch"policy/modules/services/policyd.te +3
-0+ +allow policyd_t policyd_conf_t:dir r_dir_perms; +allow policyd_t policyd_conf_t:file r_file_perms;
policy/modules/services/policyd.te line 35
Quoted 10 lines
policy/modules/services/policyd.te +10
-0+allow policyd_t policyd_conf_t:lnk_file { getattr read }; + +allow policyd_t policyd_var_run_t:dir rw_dir_perms; +allow policyd_t policyd_var_run_t:file create_file_perms; +files_pid_filetrans(policyd_t, policyd_var_run_t, file) + +allow policyd_t self:tcp_socket create_stream_socket_perms; +allow policyd_t self:capability { sys_resource sys_chroot setgid setuid }; +allow policyd_t self:process setrlimit; +allow policyd_t self:unix_dgram_socket { connect create write};
This set of self lines should go at the top of this section
Quoted 10 lines
policy/modules/services/policyd.te +10
-0+corenet_tcp_sendrecv_all_if(policyd_t) +corenet_tcp_sendrecv_all_nodes(policyd_t) +corenet_tcp_sendrecv_all_ports(policyd_t) +corenet_all_recvfrom_unlabeled(policyd_t) +corenet_tcp_bind_all_nodes(policyd_t) +corenet_tcp_bind_policyd_port(policyd_t) +corenet_tcp_bind_mysqld_port(policyd_t) + +corenet_tcp_connect_policyd_port(postfix_smtpd_t) +
policy/modules/services/policyd.te line 56
Quoted 10 lines
policy/modules/services/policyd.te +10
-0+sysnet_dns_name_resolve(policyd_t) + +libs_use_ld_so(policyd_t) +libs_use_shared_libs(policyd_t) +term_use_generic_ptys(policyd_t) +files_read_etc_files(policyd_t) +logging_send_syslog_msg(policyd_t) + + +# No existing interface for these:
They do exist:
Quoted 1 line
+allow
policyd_tlocale_t:file { getattr read };
This one is is miscfiles.
Quoted 1 line
+allow
policyd_tusr_t:file { getattr read };
this one is in files.
Quoted 7 lines
diff -ruN
refpolicy.old/policy/modules.confrefpolicy/policy/modules.confpolicy/modules.conf 2007-10-03 16:06:52.000000000 +0200 renamed from policy/modules.conf 2007-09-28 15:57:26.000000000 +0200 +0
-0@@ -1137,6 +1137,13 @@ perdition = module # Layer: services
policy/modules.conf 2007-10-03 16:06:52.000000000 +0200 line 1149
Quoted 10 lines
policy/modules.conf 2007-10-03 16:06:52.000000000 +0200 renamed from policy/modules.conf 2007-09-28 15:57:26.000000000 +0200 +7
-0+# Module: policyd +# +# Postfix policy server +# +policyd = module + +# Layer: services # Module: portmap # # RPC port mapping service.
This isn't needed. A modules.conf is included in the release tarball so that users can just configure it and build it, but is not in the repository as it is a generated file.
Signature · 9 lines
Chris PeBenito Tresys Technology, LLC (410) 290-1411 x150 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 3 lines · Christopher J. PeBenito
Its not a problem in this case, since that version just went out, but in the future, the preference would be against svn HEAD.
OK, attached patch is against svn HEAD.
Quoted 6 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+allow policyd_t self:tcp_socket create_stream_socket_perms; +allow policyd_t self:capability { sys_resource sys_chroot setgid setuid }; +allow policyd_t self:process setrlimit; +allow policyd_t self:unix_dgram_socket { connect create write};This set of self lines should go at the top of this section
Done.
Quoted 5 lines
Quoted 1 line
+# No existing interface for these:
They do exist:
Quoted 1 line
+allow
policyd_tlocale_t:file { getattr read };
miscfiles_read_localization(policyd_t)
Quoted 4 lines
Quoted 2 lines
+allow
policyd_tusr_t:file { getattr read };this one is in files.
files_read_usr_files(policyd_t)
Quoted 3 lines
This isn't needed. A modules.conf is included in the release tarball so that users can just configure it and build it, but is not in the repository as it is a generated file.
OK.
-jf
policy/modules/kernel/corenetwork.te.in +1 -0
@@ -125,6 +125,7 @@ network_port(openvpn, tcp,1194,s0, udp,1194,s0) network_port(pegasus_http, tcp,5988,s0) network_port(pegasus_https, tcp,5989,s0) +network_port(policyd, tcp,10031,s0) network_port(pop, tcp,106,s0, tcp,109,s0, tcp,110,s0, tcp,143,s0, tcp,220,s0, tcp,993,s0, tcp,995,s0, tcp,1109,s0) network_port(portmap, udp,111,s0, tcp,111,s0) network_port(postgresql, tcp,5432,s0)
policy/modules/services/policyd.fc +3 -0
@@ -0,0 +1,3 @@ +/usr/sbin/policyd -- gen_context(system_u:object_r:policyd_exec_t, s0) +/etc/policyd.conf -- gen_context(system_u:object_r:policyd_conf_t, s0) +/var/run/policyd\.pid -- gen_context(system_u:object_r:policyd_var_run_t, s0)
policy/modules/services/policyd.te +56 -0
56 lines not on this page · raw message
Quoted 39 lines · Jan-Frode Myklebust
diff -ruN refpolicy.old/policy/modules/services/policyd.te refpolicy/policy/modules/services/policyd.te
policy/modules/services/policyd.te 2007-10-06 01:46:26.000000000 +0200 renamed from policy/modules/services/policyd.te 1970-01-01 01:00:00.000000000 +0100 +35
-0@@ -0,0 +1,56 @@ + +policy_module(policyd, 1.0.0) + +######################################## +# +# Declarations +# + +type policyd_t; +type policyd_exec_t; +init_daemon_domain(policyd_t, policyd_exec_t) + +type policyd_conf_t; +files_config_file(policyd_conf_t) + +type policyd_var_run_t; +files_pid_file(policyd_var_run_t) + +######################################## +# +# Local Policy +# + +allow policyd_t self:tcp_socket create_stream_socket_perms; +allow policyd_t self:capability { sys_resource sys_chroot setgid setuid }; +allow policyd_t self:process setrlimit; +allow policyd_t self:unix_dgram_socket { connect create write}; + +allow policyd_t policyd_conf_t:dir r_dir_perms; +allow policyd_t policyd_conf_t:file r_file_perms; +allow policyd_t policyd_conf_t:lnk_file { getattr read }; + +allow policyd_t policyd_var_run_t:dir rw_dir_perms; +allow policyd_t policyd_var_run_t:file create_file_perms; +files_pid_filetrans(policyd_t, policyd_var_run_t, file)
policy/modules/services/policyd.te 2007-10-06 01:46:26.000000000 +0200 line 45
Quoted 10 lines
policy/modules/services/policyd.te 2007-10-06 01:46:26.000000000 +0200 renamed from policy/modules/services/policyd.te 1970-01-01 01:00:00.000000000 +0100 +10
-0+ +corenet_tcp_sendrecv_all_if(policyd_t) +corenet_tcp_sendrecv_all_nodes(policyd_t) +corenet_tcp_sendrecv_all_ports(policyd_t) +corenet_all_recvfrom_unlabeled(policyd_t) +corenet_tcp_bind_all_nodes(policyd_t) +corenet_tcp_bind_policyd_port(policyd_t) +corenet_tcp_bind_mysqld_port(policyd_t) + +corenet_tcp_connect_policyd_port(postfix_smtpd_t)
This line needs to be moved to the postfix module, as postfix_smtpd_t isn't owned by this module.
policy/modules/services/policyd.te 2007-10-06 01:46:26.000000000 +0200 line 55
Quoted 10 lines
policy/modules/services/policyd.te 2007-10-06 01:46:26.000000000 +0200 renamed from policy/modules/services/policyd.te 1970-01-01 01:00:00.000000000 +0100 +10
-0+sysnet_dns_name_resolve(policyd_t) + +libs_use_ld_so(policyd_t) +libs_use_shared_libs(policyd_t) +term_use_generic_ptys(policyd_t) +files_read_etc_files(policyd_t) +logging_send_syslog_msg(policyd_t) + +miscfiles_read_localization(policyd_t) +files_read_usr_files(policyd_t)
I didn't notice this before, but you are missing a .if file. Even if there aren't currently any interfaces, there needs to be a .if file with at least the XML summary.
Signature · 10 lines
Chris PeBenito Tresys Technology, LLC (410) 290-1411 x150 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 5 lines · Christopher J. PeBenito
Review
Quoted 2 lines
(quoted diff) +2
-0+ +corenet_tcp_connect_policyd_port(postfix_smtpd_t)This line needs to be moved to the postfix module, as
postfix_smtpd_tisn't owned by this module.
OK, done.
Quoted 4 lines
I didn't notice this before, but you are missing a .if file. Even if there aren't currently any interfaces, there needs to be a .if file with at least the XML summary.
Fixed one liner xml summary.
-jf
policy/modules/kernel/corenetwork.te.in +1 -0
@@ -125,6 +125,7 @@ network_port(openvpn, tcp,1194,s0, udp,1194,s0) network_port(pegasus_http, tcp,5988,s0) network_port(pegasus_https, tcp,5989,s0) +network_port(policyd, tcp,10031,s0) network_port(pop, tcp,106,s0, tcp,109,s0, tcp,110,s0, tcp,143,s0, tcp,220,s0, tcp,993,s0, tcp,995,s0, tcp,1109,s0) network_port(portmap, udp,111,s0, tcp,111,s0) network_port(postgresql, tcp,5432,s0)
policy/modules/services/policyd.fc +3 -0
@@ -0,0 +1,3 @@ +/usr/sbin/policyd -- gen_context(system_u:object_r:policyd_exec_t, s0) +/etc/policyd.conf -- gen_context(system_u:object_r:policyd_conf_t, s0) +/var/run/policyd\.pid -- gen_context(system_u:object_r:policyd_var_run_t, s0)
policy/modules/services/policyd.if +2 -0
@@ -0,0 +1,2 @@ +## <summary>Postfix policy server</summary> +
policy/modules/services/policyd.te +54 -0
54 lines not on this page · raw message
policy/modules/services/postfix.te +3 -0
@@ -547,6 +547,9 @@ # connect to master process stream_connect_pattern(postfix_smtpd_t,{ postfix_private_t postfix_public_t },{ postfix_private_t postfix_public_t },postfix_master_t) +# Connect to policy server +corenet_tcp_connect_policyd_port(postfix_smtpd_t) + # for prng_exch allow postfix_smtpd_t postfix_spool_t:file rw_file_perms; allow postfix_smtpd_t postfix_prng_t:file rw_file_perms;
Resending this one, as it seems to have dropped of your radar. Still applies to refpolicy-head.
-jf
policy/modules/kernel/corenetwork.te.in +1 -0
@@ -125,6 +125,7 @@ network_port(openvpn, tcp,1194,s0, udp,1194,s0) network_port(pegasus_http, tcp,5988,s0) network_port(pegasus_https, tcp,5989,s0) +network_port(policyd, tcp,10031,s0) network_port(pop, tcp,106,s0, tcp,109,s0, tcp,110,s0, tcp,143,s0, tcp,220,s0, tcp,993,s0, tcp,995,s0, tcp,1109,s0) network_port(portmap, udp,111,s0, tcp,111,s0) network_port(postgresql, tcp,5432,s0)
policy/modules/services/policyd.fc +3 -0
@@ -0,0 +1,3 @@ +/usr/sbin/policyd -- gen_context(system_u:object_r:policyd_exec_t, s0) +/etc/policyd.conf -- gen_context(system_u:object_r:policyd_conf_t, s0) +/var/run/policyd\.pid -- gen_context(system_u:object_r:policyd_var_run_t, s0)
policy/modules/services/policyd.if +2 -0
@@ -0,0 +1,2 @@ +## <summary>Postfix policy server</summary> +
policy/modules/services/policyd.te +54 -0
54 lines not on this page · raw message
policy/modules/services/postfix.te +3 -0
@@ -547,6 +547,9 @@ # connect to master process stream_connect_pattern(postfix_smtpd_t,{ postfix_private_t postfix_public_t },{ postfix_private_t postfix_public_t },postfix_master_t) +# Connect to policy server +corenet_tcp_connect_policyd_port(postfix_smtpd_t) + # for prng_exch allow postfix_smtpd_t postfix_spool_t:file rw_file_perms; allow postfix_smtpd_t postfix_prng_t:file rw_file_perms;
Quoted 2 lines · Jan-Frode Myklebust
Resending this one, as it seems to have dropped of your radar. Still applies to refpolicy-head.
I'm wrestling with the naming. Policyd, while its the name of the server, seems far too generic. It seems like postfix_policyd would be better.
Signature · 9 lines
Chris PeBenito Tresys Technology, LLC (410) 290-1411 x150 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 7 lines · Christopher J. PeBenito
Quoted 2 lines · Jan-Frode Myklebust
Resending this one, as it seems to have dropped of your radar. Still applies to refpolicy-head.
I'm wrestling with the naming. Policyd, while its the name of the server, seems far too generic. It seems like
postfix_policydwould be better.
Or maybe even a more generic mta_policyd. If you make a policy that's generic enough for the majority of Postfix policy server modules then getting it to also work for Sendmail milters etc should not be difficult.
Signature · 10 lines
[email protected] http://etbe.coker.com.au/ My Blog http://www.coker.com.au/sponsorship.html Sponsoring Free Software development -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 7 lines · Christopher J. PeBenito
Quoted 2 lines · Jan-Frode Myklebust
Resending this one, as it seems to have dropped of your radar. Still applies to refpolicy-head.
I'm wrestling with the naming. Policyd, while its the name of the server, seems far too generic. It seems like
postfix_policydwould be better.
Here's an updated patch against HEAD with name changed to postfix_policyd, and r_dir_perms/r_file_perms changed to list_dir_perms/read_file_perms.
Re: Russels comment "If you make a policy that's generic
enough for the majority of Postfix policy server modules then getting it to also work for Sendmail milters etc should not be difficult."
This is not meant as a generic postfix policy policy.. but a specific policy for the policyd postfix policy daemon :-)
-jf
policy/modules/kernel/corenetwork.te.in +1 -0
@@ -132,6 +132,7 @@ network_port(openvpn, tcp,1194,s0, udp,1194,s0) network_port(pegasus_http, tcp,5988,s0) network_port(pegasus_https, tcp,5989,s0) +network_port(postfix_policyd, tcp,10031,s0) network_port(pop, tcp,106,s0, tcp,109,s0, tcp,110,s0, tcp,143,s0, tcp,220,s0, tcp,993,s0, tcp,995,s0, tcp,1109,s0) network_port(portmap, udp,111,s0, tcp,111,s0) network_port(postgresql, tcp,5432,s0)
policy/modules/kernel/corenetwork.te.in.orig +242 -0
242 lines not on this page · raw message
policy/modules/services/postfix_policyd.fc +3 -0
@@ -0,0 +1,3 @@ +/usr/sbin/policyd -- gen_context(system_u:object_r:postfix_policyd_exec_t, s0) +/etc/policyd.conf -- gen_context(system_u:object_r:postfix_policyd_conf_t, s0) +/var/run/policyd\.pid -- gen_context(system_u:object_r:postfix_policyd_var_run_t, s0)
policy/modules/services/postfix_policyd.if +2 -0
@@ -0,0 +1,2 @@ +## <summary>Postfix policy server</summary> +
policy/modules/services/postfix_policyd.te +54 -0
54 lines not on this page · raw message
policy/modules/services/postfix.te +3 -0
@@ -547,6 +547,9 @@ # connect to master process stream_connect_pattern(postfix_smtpd_t,{ postfix_private_t postfix_public_t },{ postfix_private_t postfix_public_t },postfix_master_t) +# Connect to policy server +corenet_tcp_connect_postfix_policyd_port(postfix_smtpd_t) + # for prng_exch allow postfix_smtpd_t postfix_spool_t:file rw_file_perms; allow postfix_smtpd_t postfix_prng_t:file rw_file_perms;
Quoted 5 lines · Jan-Frode Myklebust
Quoted 4 lines · Christopher J. PeBenito
Quoted 2 lines · Jan-Frode Myklebust
Resending this one, as it seems to have dropped of your radar. Still applies to refpolicy-head.
Quoted 7 lines
Quoted 3 lines
I'm wrestling with the naming. Policyd, while its the name of the server, seems far too generic. It seems like
postfix_policydwould be better.Here's an updated patch against HEAD with name changed to
postfix_policyd, and r_dir_perms/r_file_perms changed to list_dir_perms/read_file_perms.
Merged.
Signature · 9 lines
Chris PeBenito Tresys Technology, LLC (410) 290-1411 x150 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.