我想学习为我的自定义运动守护程序创建一个基于user_r的角色。守护进程在不受约束的情况下工作正常,但我想进一步锁定它。我戴的是38号软呢帽。
Selinux教程和文档在地面上有点薄,但我发现:
自定义角色创建:http://www.selinuxproject.org/page/RefpolicyBasicRoleCreation
限制:https://wiki.gentoo.org/wiki/SELinux/Constraints(很少有有用的selinux gentoo页面)。
因此,我已经将我的用户切换到user_u角色作为开始,但是我开始在audit.log中获得以下avc拒绝
type=AVC msg=audit(1686738596.953:155): avc: denied { relabelto } for pid=1054
comm="systemd" name="tmp" dev="tmpfs" ino=302 scontext=user_u:user_r:user_t:s0
tcontext=system_u:object_r:tmp_t:s0 tclass=dir permissive=0
audit 2allow告诉我:
#============= user_t ==============
#!!!! This avc is a constraint violation. You would need to modify the attributes of
either the source or target types to allow this access.
#Constraint rule:
# constrain dir { create relabelfrom relabelto } ((u1 == u2 -Fail-) or (t1 ==
can_change_object_identity -Fail-) ); Constraint DENIED
# Possible cause is the source user (user_u) and target user (system_u) are different.
allow user_t tmp_t:dir relabelto;
因此,有一个约束冲突,因为user_r角色的某个部分阻止了我的用户访问/tmp的某个部分(我认为)。我以为/tmp可以被user_r访问,但显然我错了。
我不想将can_change_object_identity
添加到我的user_r模板化自定义角色,即使我这样做了,我也找不到任何关于如何做到这一点的信息。我找到了这个命令:seinfo -acan_change_object_identity -x
,它列出了哪些类型具有can_change_object_identity,但是定义这些类型的文件在哪里,或者允许它们的命令是什么?
问题是,我并不真的想将can_change_object_identity
添加到我的custom_role中,那么我能做些什么来减轻这种avc拒绝呢?
最后,请让我知道,如果我完全搞错了,因为除了selinux是非常复杂的事实(似乎新手),我只是找不到权威的完整和/或容易遵循的selinux教程/信息。任何关于这个方向的建议都非常感谢...
MTIA
1条答案
按热度按时间v440hwme1#
这是我在liberachat上的#selinux irc上提出的问题。
不允许源上下文user_u:user_r:user_t:s0重新标记为system_u标识
是有原因的
该上下文意味着与(几乎从不)与root或root权限相关联的进程相关联,因此允许它没有意义,因为这将需要root访问权限,无论如何,有一个domain_obj_id_change_exemption(或类似的东西)允许您绕过它,并将avc拒绝管道到audit2allow-W应该告诉您,除其他事项外,
即:
echo '(typeattributeset can_change_object_identity user_t)' > mytest.cil && sudo semodule -i mytest.cil
要点是systemd--user在错误的上下文下运行
可能是pam的问题
或旧政策
因为它的fedora 38它可能是某种pam的问题
我不使用软呢帽,所以我不确定
无论如何,mytest.cil应该“修复”当前的问题(但是在user_t域中运行systemd--user会打开一个蠕虫罐)
不完全确定,但除非事情在Fedora中发生剧烈变化:受限用户,如user_t和staff_t等,在fedora中是一个事后的想法。主要关注的是不受限制的用户。而受限用户只能(勉强)使用最小的shell(即没有systemd--user示例、没有gui等的会话)简单的ssh登录shell
因此请考虑:
systemctl mask user@
id -u USER
.service systemctl mask user-runtime-dir@id -u USER
.service其中USER是受限登录用户的用户名
这对于受限ssh登录应该很好
或者找出systemd--user是否应该在user_t域中运行,就像在您的情况下一样,或者您是否遇到了一个bug,systemd--user应该在自己的私有user_systemd_t域中运行
如果systemd--user域在其自己的私有域中运行,则可以将使用此功能所需的规则仅与该私有域而不是user_t相关联
由kcinimod发布到#selinux(经许可转载)...