Gus*_*uss 8 selinux rhel7 centos7
在 RHEL/CentOS 7 上,我试图为文件创建一个新的 SELinux 安全上下文,以支持我正在编写的新服务。
我已经为我的新服务创建了一个类型强制文件,但我无法创建一个系统将识别为文件类型的新类型。
我正在基于此CentOS 5“构建本地策略模块”文档工作,该文档指示我创建一个 TE 文件,然后使用checkmodule
并semodule_package
编译它。
如果我只是在我的 TE 文件中写入:
type myservice_spool_t;
Run Code Online (Sandbox Code Playgroud)
然后 TE 编译得很好,但是当我尝试时,semanage fcontext
我得到了这个:
$ sudo semanage fcontext -a -t myservice_spool_t "/var/spool/myservice(/.*)?"
ValueError: Type myservice_spool_t is invalid, must be a file or device type
Run Code Online (Sandbox Code Playgroud)
我已经阅读了各种教程,但没有找到一个有效的例子——我所看到的一切都是:
type myservice_spool_t, file_type;
但checkmodule
说:ERROR 'attribute file_type is not declared'
file_type()
但checkmodule
说:ERROR 'This block has no require section.' at token 'files_type'
audit2allow
.该SELinux项目的网站是完全无用的,因为我没能找到一个工作示例
我很欣赏一个简单的例子,说明如何编写一个引入新类型的 TE 文件,该文件semanage fcontext
将被批准。
[更新]
我找到了这个用于创建策略文件的 Gentoo 文档,其中有一些有用的解释和示例。
我发现我遇到的问题是因为我没有正确编译模块。因此,宏可能没有“接受”,并且checkmodule
策略编译器错误消息并不能真正帮助理解这一点。
为了让所有这些宏正确扩展,需要使用 SELinux 提供的 Makefile 来编译策略 - 使用名为 myservice_spool.te 的 TE 文件,应该执行:
make -f /usr/share/selinux/devel/Makefile myservice_spool.pp
Run Code Online (Sandbox Code Playgroud)
这将创建一个扩展了所有宏的临时 TE 文件,然后调用相关编译器来创建myservice_spool.pp
.
OP 中链接的 Gentoo 文档提供了更多信息,但 CentOS 系统的文件路径不正确。
如果您查看目录中生成的 TE 模板tmp
(SELinux makefile 有助于保留该模板),您可以看到“属性”确实是处理将类型指定为文件的正确方法,但我们必须使用require
它们才能使它们工作- SELinux TE 文件的工作方式似乎是您不会将任何符号神奇地导入到配置文件中 - 您必须require
使用任何您使用的东西。
因此,设置新文件类型的正确非宏化方法如下(从 TE 生成的模板复制):
type myservice_spool_t;
require {
attribute spoolfile;
attribute file_type, non_security_file_type, non_auth_file_type;
} # end require
typeattribute myservice_spool_t file_type, non_security_file_type, non_auth_file_type, spoolfile;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4060 次 |
最近记录: |