Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 452166 - Please extend the policy for sysadm_t, by adding asterisk_exec(sysadm_t)
Summary: Please extend the policy for sysadm_t, by adding asterisk_exec(sysadm_t)
Status: VERIFIED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: SELinux (show other bugs)
Hardware: x86 Linux
: Normal normal (vote)
Assignee: Sven Vermeulen (RETIRED)
URL:
Whiteboard: sec-policy r12
Keywords:
Depends on:
Blocks:
 
Reported: 2013-01-15 01:08 UTC by Ilias
Modified: 2013-03-29 10:54 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Add asterisk_exec interface, add it to asterisk admin (asterisk_run.patch,715 bytes, patch)
2013-01-17 11:17 UTC, Vincent Brillault
Details | Diff
Add asterisk_exec interface, add it to asterisk admin (asterisk_run.patch,711 bytes, patch)
2013-01-21 13:14 UTC, Vincent Brillault
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ilias 2013-01-15 01:08:35 UTC
when starting asterisk in selinux / hardened environement with enforcing/setenforce 1, I get permission denied message

Reproducible: Always

Steps to Reproduce:
1.selinux -> setenforce 1
2.asterisk -r or /etc/init.d/asterisk start/stop
Actual Results:  
permission denied
Comment 1 Ilias 2013-01-15 01:11:47 UTC
emerge --info

http://bpaste.net/show/70244/
Comment 2 Vincent Brillault 2013-01-17 11:17:07 UTC
Created attachment 335894 [details, diff]
Add asterisk_exec interface, add it to asterisk admin

mmmm, the init script should work without asterisk_exec(sysadm_t): there is asterisk_admin(sysadm_t, sysadm_r) in roles/sysadm.te and asterisk_admin gives the rights to sysadm_t to run the init script. Does your /etc/init.d/asterisk have the correct context (system_u:object_r:asterisk_initrc_exec_t ) ?

I can confirm that 'asterisk -r' doesn't work:
[207086.025116] type=1400 audit(1358418922.444:456): avc:  denied  { execute } for  pid=23640 comm="zsh" name="asterisk" dev="sda1" ino=38941 scontext=staff_u:sysadm_r:sysadm_t tcontext=system_u:object_r:asterisk_exec_t tclass=file

Here is a simple patch against the 2.20120725-r9 policy that make it works on my system. Not sure if it really need a whole interface, but perhaps someone could want to uncouple it from asterisk_admin. I'm not using this interface like that, I simply use a asterisk_fix module with this interface in asterisk_fix.if and the following asterisk_fix.te:
'''
policy_module(asterisk_fix,1.0.0)
require {
  type sysadm_t;
}
asterisk_exec(sysadm_t)
'''
Comment 3 meteora 2013-01-21 11:13:04 UTC
Context seems to be correct. 

ls -Z /etc/init.d/asterisk
system_u:object_r:asterisk_initrc_exec_t /etc/init.d/asterisk

But when I setenforce 1 and try to start/stop asterisk service it gives out: 

/etc/init.d/asterisk stop
bash: /etc/init.d/asterisk: /sbin/runscript: bad interpreter: Permission denied

May I ask for some help on how to test the provided fix?
Comment 4 Vincent Brillault 2013-01-21 13:08:55 UTC
mmm, strange. It definitely works here :'(
What version of the selinux policy are you using ?

Do you see any related deny in you avc/kernel logs ?
Could you stop asterisk in non enforcing mode, then try starting it in enforcing and look for denies just during this start ?
Could you run 'semanage dontaudit off' and 'semodule -DB' before testing ? (It enables more verbose logs, you can turn it back by running 'semanage dontaudit on' and 'semodule -B')

For applying the fix (that should enables you to run asterisk -r):
- Create a new directory (e.g asterisk_fix), enter it
- Create a new file, asterisk_fix.te and put the following inside:
'''
policy_module(fix_asterisk,1.0.0)
require {
  type asterisk_exec_t, sysadm_t;
}
can_exec(sysadm_t, asterisk_exec_t);
'''
- Run 'make -f /usr/share/selinux/strict/include/Makefile fix_asterisk.pp' to compile a new policy (if you are not under strict selinux, replace strict by the type your are using (targeted, mls or mcs)).
- Run 'semodule -i fix_asterisk.pp' to install it

PS: if you are running asterisk under a hardened system, you may be interested by bug 445176: https://bugs.gentoo.org/show_bug.cgi?id=445176
Comment 5 Vincent Brillault 2013-01-21 13:14:35 UTC
Created attachment 336336 [details, diff]
Add asterisk_exec interface, add it to asterisk admin

Small typo (I though of creating a 'asterisk_run' interface, which also needs a role, but it seems it's not necessary to run in the asterisk_t domain for only 'asterisk -r' (Running in asterisk_t results in more problems as asterisk_t doesn't have the right to use users' tty))
Comment 6 Sven Vermeulen (RETIRED) gentoo-dev 2013-01-21 20:08:43 UTC
You shouldn't get the permission denied issue when calling asterisk through the init script (but check to make sure that the init script is labeled asterisk_initrc_exec_t).

However, the request for providing the ability to call asterisk directly for an asterisk administrator is equally valid (lots of asterisk documentation uses direct calls towards asterisk).
Comment 7 Sven Vermeulen (RETIRED) gentoo-dev 2013-01-21 20:10:11 UTC
It's in the repository and will be in rev 12
Comment 8 Matthew Thode ( prometheanfire ) archtester Gentoo Infrastructure gentoo-dev Security 2013-01-21 20:48:05 UTC
this is how fedora did it, I would recommend doing something similar, to track upstream.

http://pkgs.fedoraproject.org/cgit/selinux-policy.git/tree/asterisk.if?h=master_contrib#n32
Comment 9 Ilias 2013-01-21 23:26:50 UTC
emerge selinux-asterisk --search

      sec-policy/selinux-asterisk
      Latest version available: 2.20120725-r9
      Latest version installed: 2.20120725-r9
      Size of files: 996 kB
      Homepage:      http://www.gentoo.org/proj/en/hardened/selinux/
      Description:   SELinux policy for asterisk
      License:       GPL-2

/etc/init.d/asterisk stop

semanage dontaudit off
semodule -DB

setenforce 1

getenforce: 
enforcing

ls -Z /etc/init.d/asterisk
system_u:object_r:asterisk_initrc_exec_t /etc/init.d/asterisk

/etc/init.d/asterisk start
bash: /etc/init.d/asterisk: /sbin/runscript: bad interpreter: Permission denied

Maybe I have a general problem with my selinux/hardened setup? It's my first try on enabling selinux and hardened. With enforced mode, I cannot make calls with my softphone. It connects to the asterisk server but dialing anything, for example the echotest fails too. 

Following the avc.log when trying to start asterisk enforced: 
http://bpaste.net/show/71921/

For the fix I tried: 
mkdir /usr/share/selinux/strict/include/asterisk_fix
cd /usr/share/selinux/strict/include/asterisk_fix
nano asterisk_fix.te

inserted: 
policy_module(fix_asterisk,1.0.0)
require {
  type asterisk_exec_t, sysadm_t;
}
can_exec(sysadm_t, asterisk_exec_t); 

and saved file

make -f /usr/share/selinux/strict/include/Makefile fix_asterisk.pp
make: *** No rule to make target `fix_asterisk.pp'.  Stop.

I guess, I will try to get some help on irc #selinux channel, to further debug my selinux setup, and wait till the patch gets in tree?

Thank you for helping me :)
Comment 11 Ilias 2013-01-22 22:34:07 UTC
great work. 

Thanks for your great support. Specialthank for Vincent :)
Comment 12 Sven Vermeulen (RETIRED) gentoo-dev 2013-03-09 12:40:57 UTC
rev 12 in main tree, ~arch'ed
Comment 13 Sven Vermeulen (RETIRED) gentoo-dev 2013-03-29 10:54:41 UTC
stabilized