文章目录
Introduction to SELinux(介绍SELinux)
Security-Enhanced Linux (SELinux) is a Linux kernel security module that provides a mechanism for supporting access control security policies, including United States Department of Defense-style mandatory(强制的、义务的) access controls (MAC).
安全增强型Linux(SELinux)是一个Linux内核安全模块,它提供了一种支持访问控制安全策略的机制,包括美国国防部风格的强制访问控制(MAC)。
Understanding SELinux(理解SELinux)
SELinux is an implementation of Mandatory Access Control (MAC) in the Linux kernel. Unlike standard discretionary(自由决定的) access control (DAC), where an application or process running as a user or group has complete discretion over its files’ permissions, MAC allows administrators to define how applications and processes can access different resources.
SELinux是Linux内核中强制访问控制(MAC)的实现。与标准的自由裁量访问控制(DAC)不同,其中作为用户或组运行的应用程序或进程对其文件的权限有完全的裁量权,MAC允许管理员定义应用程序和进程如何访问不同的资源。
SELinux Modes(SELinux模式)(Enforcing 强制、Permissive 宽容、Disabled 禁用)
SELinux operates in one of three modes:
- Enforcing: SELinux policy is enforced(强制的). SELinux denies access based on SELinux policy rules.
- Permissive: SELinux policy is not enforced. SELinux does not deny access, but denials(否定) are logged for actions that would have been denied if running in enforcing mode.
- Disabled: SELinux is fully disabled.
SELinux有三种运行模式:
- 强制: 执行SELinux策略。根据SELinux策略规则拒绝访问。
- 宽容: 不执行SELinux策略。SELinux不会拒绝访问,但是如果在强制模式下运行将被拒绝的操作会被记录下来。
- 禁用: SELinux完全禁用。
SELinux Policies(SELinux策略)
Two main types of policies are used in SELinux: targeted and strict. The targeted policy, which is the default, targets(针对) and confines(限制) selected system processes. The strict policy confines all processes on the system.
SELinux主要使用两种类型的策略:目标和严格。默认的是目标策略,它针对并限制了选定的系统进程。严格策略限制了系统上的所有进程。
sestatus
The above command will display the current SELinux status, including the policy being loaded.
以上命令将显示当前的SELinux状态,包括正在加载的策略。
Configuring SELinux(配置SELinux)(targeted针对的、minimum最小化的、mls多级保护)
System administrators can manipulate(操作) the SELinux settings via the /etc/selinux/config
file. Here, you can set the SELinux mode and choose the policy to load at boot time.
系统管理员可以通过/etc/selinux/config
文件操作SELinux设置。在这里,您可以设置SELinux模式并选择在启动时加载的策略。
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
The settings in this file will take effect after a system reboot.
这个文件中的设置将在系统重启后生效。
这三种SELinux策略的范围从小到大可以理解为 “minimum” < “targeted” < “mls”。
Minimum:这是最小的范围,只保护选定的进程。这是对"targeted"策略的一种修改,比"targeted"策略有更少的受保护的进程。
Targeted:这个策略的范围比"minimum"大。它针对特定的系统进程进行保护,而其它进程则运行在传统的Discretionary
Access Control(DAC)环境下。这是默认的SELinux策略。MLS (Multi Level Security):这是范围最大的策略,它为所有的系统进程提供了多级别的安全保护。
注意:
在这里,“targeted”和“minimum”是两种不同的SELinux策略类型。
Targeted:这种策略只针对特定的系统进程进行保护,而其它进程则运行在传统的Discretionary Access Control(DAC)环境下。这是默认的SELinux策略。
Minimum:这种策略是对"targeted"策略的修改。它只保护选定的进程,但比"targeted"策略有更少的受限制的进程。
所以说,“Targeted processes are protected”和“Only selected processes are protected”虽然看起来很像,但是它们所指的保护范围和级别是不同的。
Working with SELinux Booleans(使用SELinux布尔值)
SELinux booleans allow the administrator to modify SELinux settings on the fly(即时) without any need for policy recompilation(重编译). To get a list of all available SELinux booleans, you can use:
SELinux布尔值允许管理员即时修改SELinux设置,无需重新编译策略。要获取所有可用的SELinux布尔值列表,您可以使用:
getsebool -a
To set a particular boolean value, use the setsebool
command:
要设置特定的布尔值,请使用setsebool
命令:
setsebool -P httpd_can_network_connect 1
In this example, we’re allowing the HTTPD daemon to make(建立) network connections.
在此示例中,我们允许HTTPD守护进程进行网络连接。
getsebool -a
setsebool -P httpd_can_network_connect 1
Conclusion
结论
While it might seem complex at first, SELinux is an extremely powerful tool that allows system administrators to have fine-grained(细粒的) control over their systems’ security. It offers a higher level of access control and process separation(进程隔离) than traditional Unix permissions models. Understanding how to work with SELinux can significantly enhance your system’s security posture.
虽然一开始可能看起来很复杂,但SELinux是一个非常强大的工具,它允许系统管理员对他们的系统安全性进行精细控制。它提供了比传统Unix权限模型更高级别的访问控制和进程分离。理解如何使用SELinux可以显著增强您的系统的安全态势。