chcon:无法更改“/usr/sbin/httpd”的上下文,权限被拒绝

chcon:无法更改“/usr/sbin/httpd”的上下文,权限被拒绝

我是 SELiunx 概念的新手,根据RHEL7 > SELinux 用户和管理员指南 > 3.2。无限制过程

审核日志

type=IPC msg=audit(1624375715.312:4225): ouid=0 ogid=0 mode=0666 obj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
type=PROCTITLE msg=audit(1624375715.312:4225): proctitle=2F7573722F7362696E2F6874747064002D44464F524547524F554E44
type=AVC msg=audit(1624375724.580:4226): avc:  denied  { unix_read unix_write } for  pid=25626 comm="httpd" key=1392707921  scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 tclass=shm permissive=0
type=SYSCALL msg=audit(1624375724.580:4226): arch=c000003e syscall=29 success=no exit=-13 a0=53030951 a1=4338 a2=1b6 a3=6b items=0 ppid=25612 pid=25626 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)

我已将 httpd 更改为在unconfind_t域中运行,但现在无法将 httpd 更改回httpd_t域。

我将 httpd 设置为unconfined_t域以使shmget函数正常工作,由 httpd 托管的一个 php 进程调用。

[user@rhel7 ~]$ sudo chcon -t bin_t /usr/sbin/httpd
[user@rhel7 ~]$ ls -Z /usr/sbin/httpd
-rwxr-xr-x. root root system_u:object_r:bin_t:s0       /usr/sbin/httpd
[user@rhel7 ~]$ systemctl start httpd.service

……

[root@rhel7 user]# chcon -r system_r -t httpd_t /usr/sbin/httpd
chcon: failed to change context of ‘/usr/sbin/httpd’ to ‘system_u:system_r:httpd_t:s0’: Permission denied
[root@rhel7 user]#

答案1

您应该能够运行restorecon -v /usr/sbin/httpd将其恢复为默认值。

如果您想手动更改它,那么您需要使用httpd_exec_t作为文件的类型。

答案2

我遇到了类似的问题,在 RH 8.5 上以 root 身份登录时,我无法将文件更改为unconfined_t.我意识到使用unconfined_t并不是“解决”问题的正确方法。正确的方法是按照上述用户的建议,使文件成为现有的正确类型的一部分,然后用于semanage fcontext使更改持久化,或者定义新的类型和安全策略。就您而言,您不需要新的政策,因为httpd_t合适。

我试图将新服务的类型更改为unconfined_t.同样,理想情况下我应该创建一个全新的类型和策略,但这超出了我能做的范围。但:

chcon -t unconfined_t my_file

正在给予许可被拒绝。

对于其他寻求解决方案的人来说,我所做的是:

# setenforce 0
# chcon -t unconfined_t my_file
# setenforce 1
# getenforce 
Enforcing

我不确定这是正确的方法,但它确实让我完成了工作,稍后我将编写一个新策略并找出用于它的类型。

相关内容