Skip to content
This repository has been archived by the owner on Jul 2, 2018. It is now read-only.

Add a policy for ejabberd. #57

Closed
wants to merge 1 commit into from

Conversation

bowlofeggs
Copy link

This pull request may depend on OwlCyberDefense/refpolicy#114 being fixed to work effectively, but I wanted to go ahead and get the code upstream. I've also send a PR with this code to Fedora's contrib policy:

fedora-selinux/selinux-policy-contrib#8

Signed-off-by: Randy Barlow [email protected]

Copy link
Contributor

@cgzones cgzones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just some thoughts, although i do not have any experience with ejabberd

ejabberd.fc Outdated

/usr/lib/systemd/system/ejabberd.* -- gen_context(system_u:object_r:ejabberd_unit_file_t,s0)

/var/lib/ejabberd.* gen_context(system_u:object_r:ejabberd_var_lib_t,s0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better regex might be /var/lib/ejabberd(/.*)?; there shouldn't be files in /var/lib

ejabberd.if Outdated
')

allow $1 { ejabberd_t }:process { ptrace signal_perms };
ps_process_pattern($1, ejabberd_t)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two line can be combined into admin_process_pattern($1, ejabberd_t)

ejabberd.if Outdated

domain_system_change_exemption($1)
role_transition $2 ejabberd_exec_t system_r;
allow $2 system_r;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these three line should be replaced by init_startstop_service($1, $2, ejabberd_t, ejabberd_initrc_exec_t, ejabberd_unit_t) for restarting the service as root

ejabberd.te Outdated
class tcp_socket { accept bind connect create getattr getopt listen read setopt write };
class udp_socket { bind connect create getattr getopt read setopt write };
class unix_dgram_socket { connect create getopt setopt write };
')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gen_require should not be used: class ones are not necessary and the net_conf_t should be include in a macro call

ejabberd.te Outdated
type ejabberd_var_lib_t;
type ejabberd_var_log_t;

files_type(ejabberd_var_lib_t)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

macro calls describing a type, like this, should be next to the type definition

ejabberd.te Outdated
corecmd_exec_bin(ejabberd_t)
corecmd_exec_shell(ejabberd_t)
corecmd_mmap_bin_files(ejabberd_t)
corecmd_shell_entry_type(ejabberd_t)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is only needed when the entrypoint of the domain is a shell script.
As ejabberd_t's entrypoint is /usr/bin/ejabberdctl this should not be necessary

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/usr/bin/ejabberdctl is a shell script. Does that make this necessary?

ejabberd.te Outdated

corenet_udp_bind_generic_node(ejabberd_t)

dev_list_sysfs(ejabberd_t)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dev_list_sysfs(ejabberd_t) is superseded by dev_read_sysfs(ejabberd_t)

ejabberd.te Outdated
dev_read_sysfs(ejabberd_t)

files_rw_etc_files(ejabberd_t)
files_var_lib_filetrans(ejabberd_t, ejabberd_var_lib_t, dir)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in my opinion application should not be able to create /var/lib entries, the package manager or installation script should handle this
so this might be replaced by files_search_var_lib

ejabberd.te Outdated

kernel_dgram_send(ejabberd_t)

logging_create_devlog_dev(ejabberd_t)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a fedora specific interface, maybe logging_send_syslog_msg could fit

ejabberd.te Outdated

sysnet_read_config(ejabberd_t)

fs_associate(ejabberd_var_lib_t)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is superseded by files_type(ejabberd_var_lib_t)

@ghost
Copy link

ghost commented Apr 9, 2017 via email

@ghost
Copy link

ghost commented Apr 9, 2017 via email

@bowlofeggs bowlofeggs force-pushed the ejabberd branch 2 times, most recently from 5d4daca to fa1893b Compare April 9, 2017 18:55
@bowlofeggs
Copy link
Author

@cgzones and @doverride,

Thanks for all the helpful tips! As you can probably tell, this is my first SELinux policy so I lack a lot of familiarity with all the macros. I believe I now have all of your suggestions in place, and I've sent this same policy to the Fedora-specific policy with the exception of keeping the Fedora-specific logging statement in that one.

The Fedora version of this seems to work well on my ejabberd system.

Let me know if there are other changes I should make, and thanks again!

Copy link
Contributor

@pebenito pebenito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question about rules, otherwise it needs some style cleanup. https://github.com/TresysTechnology/refpolicy/wiki/StyleGuide

ejabberd.te Outdated

miscfiles_read_generic_certs(ejabberd_t)

networkmanager_read_pid_files(ejabberd_t)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work without networkmanager (is networkmanager a hard dependency?)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @pebenito,

I don't believe that networkmanager is a hard dependency of ejabberd. It sounds like @doverride is recommending that I use sysnet_read_config() instead, so I'll make that change.

@ghost
Copy link

ghost commented Apr 27, 2017 via email

@bowlofeggs
Copy link
Author

bowlofeggs commented Apr 30, 2017

I have made the requested changes:

$ git diff
diff --git a/ejabberd.te b/ejabberd.te
index 4e4088b..966bb0d 100644
--- a/ejabberd.te
+++ b/ejabberd.te
@@ -42,8 +42,6 @@ dev_read_sysfs(ejabberd_t)
 
 files_search_var_lib(ejabberd_t, ejabberd_var_lib_t, dir)
 
-kernel_dgram_send(ejabberd_t)
-
 logging_send_syslog_msg(ejabberd_t)
 logging_log_filetrans(ejabberd_t, ejabberd_var_log_t, { dir file })
 
@@ -54,4 +52,4 @@ manage_files_pattern(ejabberd_t, ejabberd_var_log_t, ejabberd_var_log_t)
 
 miscfiles_read_generic_certs(ejabberd_t)
 
-networkmanager_read_pid_files(ejabberd_t)
+sysnet_read_config(ejabberd_t)

@bowlofeggs
Copy link
Author

@doverride I think dropping the kernel_dgram_send() might not work. At least, it doesn't work on my Fedora Rawhide system as ejabberd hangs during startup, and audit2allow show this:

sudo audit2allow -Rbl

require {
        type ejabberd_t;
}

#============= ejabberd_t ==============
kernel_dgram_send(ejabberd_t)

Thus, I am going to add it back.

@ghost
Copy link

ghost commented Apr 30, 2017 via email

Signed-off-by: Randy Barlow <[email protected]>
@bowlofeggs
Copy link
Author

bowlofeggs commented Apr 30, 2017

@doverride if we are confident that it is part of logging_send_syslog_msg() in refpol, I'm happy to switch it back but I don't have a setup I can use to verify that it works.

@ghost
Copy link

ghost commented Apr 30, 2017 via email

@bowlofeggs
Copy link
Author

Ah. Thanks for the review!

@pebenito
Copy link
Contributor

Closing stale PR. Please reopen when/if you will be providing updates.

@pebenito pebenito closed this Aug 14, 2017
@bowlofeggs
Copy link
Author

@pebenito I wasn't aware that updates were required from me. From my perspective, I thought I was just waiting for further review or a merge. Can you clarify what I should do to get this merged?

Copy link
Contributor

@pebenito pebenito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly stylistic fixes needed.

@@ -0,0 +1,33 @@
########################################
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing module summary tag


admin_process_pattern($1, ejabberd_t)

init_startstop_service($1, $2, ejabberd_t, ejabberd_initrc_exec_t, ejabberd_unit_t)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indents should be tabs

@@ -0,0 +1,57 @@
policy_module(ejabberd,0.0)

Copy link
Contributor

@pebenito pebenito Aug 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be ordered and commented per the Style Guide, including the header comment blocks like in other modules. Also module version 1.0.0.

# What will we allow
allow ejabberd_t self:tcp_socket { accept bind connect create getattr getopt listen read setopt write };
allow ejabberd_t self:udp_socket { bind connect create getattr getopt read setopt write };
allow ejabberd_t self:unix_dgram_socket { connect create getopt setopt write };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review the existing permission set macros to see if they can be used instead of the verbose permission lists here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants