SELinux httpd 对目录的写访问权限

Nee*_*asu 9 fedora rhel selinux apache-httpd

我是 SELinux 的新手。来自 debian。我想授予httpd对目录的访问权限。

SELinux 警报浏览器建议:

# grep httpd /var/log/audit/audit.log | audit2allow -M mypol
# semodule -i mypol.pp 
Run Code Online (Sandbox Code Playgroud)

我无法理解这个命令是如何工作的。我没有在任何地方指定目录路径。它如何知道哪个目录允许 httpd ?

以前我使用 grep 从输出或文件中提取文本。但是这里 grep 被用于一个进程。我没有得到的。

还有什么是实际的解决方案。如果我想授予 httpd 对目录的写访问权限?

Gre*_*reg 18

以下是永久更改目录上下文的方法:

# install semanage if you don't already have it. It'll be one of:
yum install policycoreutils-python
dnf install policycoreutils-python-utils

# give the directory a new default context. The part at the end is a regex.
semanage fcontext -a -t httpd_sys_rw_content_t "/path/to/directory(/.*)?"

# apply the default context to the directory
restorecon -R /path/to/directory
Run Code Online (Sandbox Code Playgroud)

以下是有关 httpd 不同上下文的更多文档:

RHEL 8:https : //access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/using_selinux/configuring-selinux-for-applications-and-services-with-non-standard-configurations_using-selinux#customizing -the-selinux-policy-for-the-apache-http-server-in-a-non-standard-configuration_configuring-selinux-for-applications-and-services-with-non-standard-configurations

RHEL 7:https : //access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/SELinux_Users_and_Administrators_Guide/sect-Managing_Confined_Services-The_Apache_HTTP_Server-Types.html

RHEL 6:https : //access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Managing_Confined_Services/sect-Managing_Confined_Services-The_Apache_HTTP_Server-Types.html


slm*_*slm 5

SELinux 利用可以附加到磁盘上的目录结构的扩展属性。将这些视为元数据。访问控制列表 (ACL) 是另一个。

您需要附加到目录的扩展属性称为上下文,而 SELinux 就像一个交通警察,确保允许具有特定上下文的可执行文件基于这些上下文访问文件系统。您可以使用-Z切换到ls.

$ sudo ls -Z /var/www
drwxr-xr-x. root root system_u:object_r:httpd_sys_script_exec_t:s0 cgi-bin
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 html
Run Code Online (Sandbox Code Playgroud)

在这里,你可以看到,这些目录有上下文httpd_sys_script_exec_t:s0cgi-bin目录。和html目录。有httpd_sys_content_t:s0.

您可以使用以下chcon命令添加这些:

$ sudo chcon -t httpd_sys_content_t public_html
Run Code Online (Sandbox Code Playgroud)

你问的命令只会加载模块mypoll.pp我不相信它会授予任何权限audit.log,你的命令中可能有更多的消息,这将更详细地告诉你你需要什么允许访问。

我鼓励您花一些时间熟悉 SELinux。起初令人困惑,但在花了一些时间之后通常很简单。请参阅以下资源以帮助您入门。

参考