我在openstack-swift设置中使用我的几个文件'SELinux上下文时遇到了一些麻烦
设置详情:
守护程序正在运行带有以下SELinux上下文的swift-object-replicator
system_u:system_r:swift_t:s0 swift ... /usr/bin/python /usr/bin/swift-object-replicator /etc/swift/object-server.conf
此守护进程定期调用脚本。该脚本创建的文件具有以下SELinux上下文
system_u:object_r:swift_var_cache_t:s0 /var/cache/swift/object.recon
哪个是对的!!
问题
如果我从终端运行相同的脚本(该守护程序在内部调用)作为“root”,则object.recon文件SELinux上下文被修改为-rw-------. swift swift unconfined_u:object_r:var_t:s0 /var/cache/swift/object.recon
然后我开始在该守护进程的日志文件中看到错误消息
任何想法为什么上下文改变以及如何保留它,即使我希望从终端触发脚本
答案 0 :(得分:1)
我想出了两种保留上下文的方法:
使用runcon运行具有正确上下文的命令
runcon -t swift_t -r system_r swift-object-replicator /etc/swift/object-server.conf -ov
或者,定义SELinux type_transition规则,以便在执行脚本时具有unconfined_t域的用户转换到正确的域
require {
type unconfined_t;
type swift_exec_t;
type swift_t;
role unconfined_r;
class process transition;
}
role unconfined_r types swift_t;
type_transition unconfined_t swift_exec_t:process swift_t;