Як запустити PhantomJS на CentOS за допомогою SELinux?


9

Я намагаюся зробити скріншот за допомогою PhantomJS на моїй машині CentOS 5, але я не можу змусити його працювати разом із SELinux. Він працює на ідентичній машині з відключеною SELinux, тому я дуже підозрюю, що за це відповідає SELinux.

Ось що я спробував (усі команди запускалися як root), і помилки, які я отримав:

$ ls -Z /usr/local/phantomjs/phantomjs-1.6.2-linux-x86_64-dynamic/bin

-rwxr-xr-x  myusername myusername system_u:object_r:bin_t          phantomjs

Спробуваний скріншот - не вдалося

$ cat /var/log/messages | grep avc

Sep 13 12:21:18 myserver kernel: type=1400 audit(1347531678.014:398): avc:  denied  { getattr } for  pid=6842 comm="sh" path="/sbin/ldconfig" dev=dm-0 ino=3097762 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:ldconfig_exec_t:s0 tclass=file
Sep 13 12:21:18 myserver kernel: type=1400 audit(1347531678.014:399): avc:  denied  { getattr } for  pid=6842 comm="sh" path="/sbin/ldconfig" dev=dm-0 ino=3097762 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:ldconfig_exec_t:s0 tclass=file
Sep 13 12:21:18 myserver kernel: type=1400 audit(1347531678.054:400): avc:  denied  { getattr } for  pid=6852 comm="sh" path="/sbin/ldconfig" dev=dm-0 ino=3097762 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:ldconfig_exec_t:s0 tclass=file
Sep 13 12:21:18 myserver kernel: type=1400 audit(1347531678.054:401): avc:  denied  { getattr } for  pid=6852 comm="sh" path="/sbin/ldconfig" dev=dm-0 ino=3097762 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:ldconfig_exec_t:s0 tclass=file
Sep 13 12:21:19 myserver kernel: type=1400 audit(1347531679.866:402): avc:  denied  { getattr } for  pid=6864 comm="sh" path="/sbin/ldconfig" dev=dm-0 ino=3097762 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:ldconfig_exec_t:s0 tclass=file
Sep 13 12:21:19 myserver kernel: type=1400 audit(1347531679.867:403): avc:  denied  { getattr } for  pid=6864 comm="sh" path="/sbin/ldconfig" dev=dm-0 ino=3097762 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:ldconfig_exec_t:s0 tclass=file
Sep 13 12:21:19 myserver kernel: type=1400 audit(1347531679.920:404): avc:  denied  { getattr } for  pid=6874 comm="sh" path="/sbin/ldconfig" dev=dm-0 ino=3097762 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:ldconfig_exec_t:s0 tclass=file
Sep 13 12:21:19 myserver kernel: type=1400 audit(1347531679.920:405): avc:  denied  { getattr } for  pid=6874 comm="sh" path="/sbin/ldconfig" dev=dm-0 ino=3097762 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:ldconfig_exec_t:s0 tclass=file
Sep 13 12:21:27 myserver kernel: type=1400 audit(1347531687.025:406): avc:  denied  { read } for  pid=6890 comm="phantomjs" name="3830d5c3ddfd5cd38a049b759396e72e-x86-64.cache-2" dev=dm-0 ino=2021753 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:var_t:s0 tclass=file
Sep 13 12:21:27 myserver kernel: type=1400 audit(1347531687.035:407): avc:  denied  { write } for  pid=6890 comm="phantomjs" name="myusername" dev=dm-0 ino=619658 scontext=system_u:system_r:httpd_t:s0 tcontext=user_u:object_r:user_home_dir_t:s0 tclass=dir
Sep 13 12:21:27 myserver kernel: type=1400 audit(1347531687.061:408): avc:  denied  { read } for  pid=6890 comm="phantomjs" name="e3ead4b767b8819993a6fa3ae306afa9-x86-64.cache-2" dev=dm-0 ino=2021752 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:var_t:s0 tclass=file
Sep 13 12:21:28 myserver kernel: type=1400 audit(1347531688.720:410): avc:  denied  { execmem } for  pid=6890 comm="phantomjs" scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:system_r:httpd_t:s0 tclass=process

Спробував змінити тип Phantomjs на httpd_sys_script_exec_t

$ chcon -v -t httpd_sys_script_exec_t /usr/local/phantomjs/phantomjs-1.6.2-linux-x86_64-dynamic/bin/phantomjs

$ ls -Z /usr/local/phantomjs/phantomjs-1.6.2-linux-x86_64-dynamic/bin

-rwxr-xr-x  myusername myusername system_u:object_r:httpd_sys_script_exec_t phantomjs

Повторний скріншот - не вдалося

$ cat /var/log/messages | grep avc

Sep 13 12:26:05 myserver kernel: type=1400 audit(1347531965.891:414): avc:  denied  { read } for  pid=6962 comm="phantomjs" path="eventpoll:[9737788]" dev=eventpollfs ino=9737788 scontext=system_u:system_r:httpd_sys_script_t:s0 tcontext=system_u:system_r:httpd_t:s0 tclass=file
Sep 13 12:26:05 myserver kernel: type=1400 audit(1347531965.892:415): avc:  denied  { write } for  pid=6962 comm="phantomjs" path=2F7661722F72756E2F777367692E363535352E302E312E6C6F636B202864656C6574656429 dev=dm-0 ino=2022252 scontext=system_u:system_r:httpd_sys_script_t:s0 tcontext=system_u:object_r:httpd_var_run_t:s0 tclass=file
Sep 13 12:26:05 myserver kernel: type=1400 audit(1347531965.892:416): avc:  denied  { write } for  pid=6962 comm="phantomjs" path=2F7661722F72756E2F777367692E363535352E302E322E6C6F636B202864656C6574656429 dev=dm-0 ino=2022255 scontext=system_u:system_r:httpd_sys_script_t:s0 tcontext=system_u:object_r:httpd_var_run_t:s0 tclass=file
Sep 13 12:26:05 myserver kernel: type=1400 audit(1347531965.892:417): avc:  denied  { write } for  pid=6962 comm="phantomjs" path=2F7661722F72756E2F777367692E363535352E302E332E6C6F636B202864656C6574656429 dev=dm-0 ino=2022257 scontext=system_u:system_r:httpd_sys_script_t:s0 tcontext=system_u:object_r:httpd_var_run_t:s0 tclass=file
Sep 13 12:26:05 myserver kernel: type=1400 audit(1347531965.893:418): avc:  denied  { write } for  pid=6962 comm="phantomjs" path=2F7661722F72756E2F777367692E363535352E302E342E6C6F636B202864656C6574656429 dev=dm-0 ino=2022266 scontext=system_u:system_r:httpd_sys_script_t:s0 tcontext=system_u:object_r:httpd_var_run_t:s0 tclass=file

Спробував змінити тип Phantomjs на httpd_t

$ chcon -v -t httpd_t /usr/local/phantomjs/phantomjs-1.6.2-linux-x86_64-dynamic/bin/phantomjs

failed to change context of /usr/local/phantomjs/phantomjs-1.6.2-linux-x86_64-dynamic/bin/phantomjs to system_u:object_r:httpd_t
chcon: failed to change context of /usr/local/phantomjs/phantomjs-1.6.2-linux-x86_64-dynamic/bin/phantomjs to system_u:object_r:httpd_t: Permission denied

Спробував змінити тип Phantomjs на httpd_var_run_t

$ chcon -v -t httpd_var_run_t /usr/local/phantomjs/phantomjs-1.6.2-linux-x86_64-dynamic/bin/phantomjs

$ ls -Z /usr/local/phantomjs/phantomjs-1.6.2-linux-x86_64-dynamic/bin

-rwxr-xr-x  myusername myusername system_u:object_r:httpd_var_run_t phantomjs

Повторний скріншот - не вдалося

$ cat /var/log/messages | grep avc

Sep 13 12:29:36 myserver kernel: type=1400 audit(1347532176.754:420): avc:  denied  { execute } for  pid=7002 comm="httpd" name="phantomjs" dev=dm-0 ino=3032985 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:httpd_var_run_t:s0 tclass=file

Спробував змінити тип Phantomjs на httpd_sys_script_t

$ chcon -v -t httpd_sys_script_t /usr/local/phantomjs/phantomjs-1.6.2-linux-x86_64-dynamic/bin/phantomjs

failed to change context of /usr/local/phantomjs/phantomjs-1.6.2-linux-x86_64-dynamic/bin/phantomjs to system_u:object_r:httpd_sys_script_t
chcon: failed to change context of /usr/local/phantomjs/phantomjs-1.6.2-linux-x86_64-dynamic/bin/phantomjs to system_u:object_r:httpd_sys_script_t: Permission denied

Ось додаткова інформація щодо моєї установки SELinux:

$ sestatus

SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          enforcing
Policy version:                 21
Policy from config file:        targeted

...

$ getsebool -a | grep http

allow_httpd_anon_write --> off
allow_httpd_bugzilla_script_anon_write --> off
allow_httpd_cvs_script_anon_write --> off
allow_httpd_mod_auth_pam --> off
allow_httpd_nagios_script_anon_write --> off
allow_httpd_prewikka_script_anon_write --> off
allow_httpd_squid_script_anon_write --> off
allow_httpd_sys_script_anon_write --> off
httpd_builtin_scripting --> on
httpd_can_network_connect --> off
httpd_can_network_connect_db --> off
httpd_can_network_relay --> off
httpd_can_sendmail --> on
httpd_disable_trans --> off
httpd_enable_cgi --> on
httpd_enable_ftp_server --> off
httpd_enable_homedirs --> on
httpd_execmem --> off
httpd_read_user_content --> off
httpd_rotatelogs_disable_trans --> off
httpd_setrlimit --> off
httpd_ssi_exec --> off
httpd_suexec_disable_trans --> off
httpd_tty_comm --> on
httpd_unified --> on
httpd_use_cifs --> off
httpd_use_nfs --> off

...

$ uname -r

2.6.18-308.1.1.el5

Хтось із досвідом SELinux / httpd знає, чи є контекст, який підходить для того, що я намагаюся зробити? Чи, можливо, я повинен кусати кулю і створити для цього певну політику?


Вимкнути selinux?

Це не звучить як дуже конструктивне рішення. Таким чином я викинув би дитину водою з ванни, ти не думаєш?
Dennis Bunskoek

"тому я дуже підозрюю, що SELinux несе відповідальність за це" -> Ви б переконалися в цьому, відключивши selinux.

Ага, це те, що ти мав на увазі :) Я спробую це
Денніс Бунскок

1
Я спробував відключити SELinux за допомогою "setenforce 0", і тоді він працює, тож SELinux, безумовно, причина
Денніс Бунськек,

Відповіді:


5

Ось деякі фрагменти з http://wiki.centos.org/HowTos/SELinux#7 про те, як створити модуль власної політики за допомогою allow2audit.

Спробуй це

setenforce 0
grep phantomjs /var/log/audit/audit.log | audit2allow -m httpd_phantomjs > httpd_phantomjs.te
cat httpd_phantomjs.te

Встановіть його

grep phantomjs /var/log/audit/audit.log | audit2allow -M httpd_phantomjs
semodule -i httpd_phantomjs.pp
ls /etc/selinux/targeted/modules/active/modules/ | grep httpd

Перевірте це

setenforce 1
tail -f /var/log/audit/audit.log

Це не перевірено, тому, будь ласка, оновіть по мірі необхідності. Сподіваюся, це працює для вас


1
І якщо у вас немає аудиторії2, можливо, вам доведеться встановити його .
єпископ

0

Просто виникли ті самі проблеми, і вдалося змусити фантома працювати над Centos 7.4, не створюючи спеціальної політики. Ось як я це зробив.

Оновіть політику selinux, змінивши файл phantomjs на bin_tтип
semanage fcontext -a -t bin_t '/opt/phantomjs/bin/phantomjs'

Після додавання нового типу до політики selinux потрібно оновити дозволи файлів
sudo /sbin/restorecon -v /opt/phantomjs/bin/phantomjs

Тепер вам потрібно дозволити демону httpd змінити свої ліміти ресурсів, встановивши булеву

sudo setsebool -P httpd_setrlimit 1

Сподіваюся, це допомагає :)

Використовуючи наш веб-сайт, ви визнаєте, що прочитали та зрозуміли наші Політику щодо файлів cookie та Політику конфіденційності.
Licensed under cc by-sa 3.0 with attribution required.