【发布时间】:2017-03-17 12:25:21
【问题描述】:
我已使用 PHP exec 命令发出 lpr -P printer_name /var/www/html/somefile.pdf,但在 RHEL 系统更新(7.2 到 7.3)之后,selinux 决定开始阻止这些请求。
发送打印文件的selinux权限:
ls -lZ /var/www/html/somefile.pdf
-rw-r-----. apache webdev system_u:object_r:httpd_sys_rw_content_t:s0 /var/www/html/somefile.pdf
审计日志中出现以下内容,对应于上面来自PHP的exec命令:
时间->2016 年 11 月 3 日星期四 15:07:02
type=PATH msg=audit(1478200022.446:5151): item=0 name="/etc/cups/lpoptions" inode=134317708 dev=fd:03 mode=0100644 ouid=0 ogid=7 rdev=00:00 obj=system_u:object_r:cupsd_rw_etc_t:s0 objtype=正常
type=CWD msg=audit(1478200022.446:5151): cwd="/var/www/html"
type=SYSCALL msg=audit(1478200022.446:5151):arch=c000003e syscall=2 成功=是退出=5 a0=7fff26837c70 a1=0 a2=0 a3=9 项=1 ppid=19397 pid=46644 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(无) ses=4294967295 comm="lpr" exe="/usr/bin/lpr.cups" subj=system_u:system_r:httpd_t:s0 key=(null)
type=AVC msg=audit(1478200022.446:5151): avc: denied { open } for pid=46644 comm="lpr" path="/etc/cups/lpoptions" dev="dm-3" ino=134317708 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:cupsd_rw_etc_t:s0 tclass=文件
type=AVC msg=audit(1478200022.446:5151): avc: denied { read } for pid=46644 comm="lpr" name="lpoptions" dev="dm-3" ino=134317708 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:cupsd_rw_etc_t:s0 tclass=文件
对wkhtmltopdf 使用另一个exec 命令时出现类似错误。
这是当前的 selinux 配置:
# getsebool -a | grep httpd
httpd_anon_write --> off
httpd_builtin_scripting --> on
httpd_can_check_spam --> off
httpd_can_connect_ftp --> off
httpd_can_connect_ldap --> off
httpd_can_connect_mythtv --> off
httpd_can_connect_zabbix --> off
httpd_can_network_connect --> on
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> off
httpd_can_network_memcache --> off
httpd_can_network_relay --> off
httpd_can_sendmail --> on
httpd_dbus_avahi --> off
httpd_dbus_sssd --> off
httpd_dontaudit_search_dirs --> off
httpd_enable_cgi --> on
httpd_enable_ftp_server --> off
httpd_enable_homedirs --> off
httpd_execmem --> off
httpd_graceful_shutdown --> on
httpd_manage_ipa --> off
httpd_mod_auth_ntlm_winbind --> off
httpd_mod_auth_pam --> off
httpd_read_user_content --> off
httpd_run_ipa --> off
httpd_run_preupgrade --> off
httpd_run_stickshift --> off
httpd_serve_cobbler_files --> off
httpd_setrlimit --> off
httpd_ssi_exec --> on
httpd_sys_script_anon_write --> off
httpd_tmp_exec --> off
httpd_tty_comm --> off
httpd_unified --> off
httpd_use_cifs --> off
httpd_use_fusefs --> off
httpd_use_gpg --> off
httpd_use_nfs --> on
httpd_use_openstack --> off
httpd_use_sasl --> off
httpd_verify_dns --> off
这一切都是在 yum 将我的系统从 RHEL 7.2 更新到 7.3 之后立即开始的。
拒绝的原因是什么?
【问题讨论】:
-
您要打印的文件类型是什么?
-
我正在发送一个 pdf。例如:
lpr -P printer_name /var/www/html/somefile.pdf。如果我在命令行上以 root 身份运行该文件,则会打印该文件。如果我使用exec函数通过 PHP 脚本运行它。它会因上述日志数据而失败。 -
我怀疑您的 Apache 守护程序没有应用
lpr_exec_t上下文(与例如 sendmail 不同,没有单个布尔值)。最快(最不安全)的修复可能是sudo semanage permissive -a lpr_t。另请参阅 this post 了解详细信息(以及如何应用上下文)。 -
我已在问题中添加了 getsebool 输出。
-
@bishop,不确定这是否会有所帮助,因为 selinux 现在也阻止了我通过 php 的
exec函数发出的所有内容。