SELinux访问控制策略配置实践
在Linux系统安全防护中,基于用户角色的SELinux访问控制是核心安全策略之一。本文将通过具体案例演示如何配置基于用户角色的SELinux策略。
策略目标
为不同用户角色分配相应的访问权限,实现最小权限原则。
配置步骤
- 创建用户角色和类型
# 创建用户角色定义文件 /etc/selinux/targeted/contexts/users/user_roles.te
user roles user_r;
user roles admin_r;
user roles guest_r;
- 配置用户类型映射
# 在 /etc/selinux/targeted/contexts/users/usermap 中添加
# 用户映射到角色
john user_r
alice admin_r
bob guest_r
- 定义文件类型策略
# 创建自定义策略模块
module custom_access 1.0;
require {
type user_t;
type admin_t;
type guest_t;
class file { read write execute };
}
# 允许用户读取配置文件
allow user_t self:file { read };
allow admin_t self:file { read write execute };
- 编译并加载策略
# 编译策略模块
checkmodule -M -m -o custom_access.mod custom_access.te
semodule_package -o custom_access.pp -i custom_access.mod
semodule -i custom_access.pp
验证配置
通过以下命令验证用户角色是否生效:
# 检查用户上下文
id -Z
# 查看SELinux状态
sestatus
该策略确保了不同角色用户只能访问其权限范围内的资源,有效降低系统攻击面。

讨论