ubuntu

Ubuntu SELinux如何进行强制访问控制

小樊
49
2025-09-23 04:20:32
栏目: 智能运维

Preparatory Note
Ubuntu defaults to AppArmor for mandatory access control (MAC), not SELinux. To use SELinux on Ubuntu, you must first install and enable it, which may introduce compatibility considerations with existing AppArmor policies.

1. Install SELinux Packages

Before configuring SELinux, install the necessary packages to support its functionality:

sudo apt update
sudo apt install selinux-basics selinux-policy-default auditd audispd-plugins

The selinux-basics package installs core SELinux utilities, while selinux-policy-default provides a default policy. The auditd suite is required to log SELinux denial events.

2. Enable SELinux

After installation, enable SELinux to start enforcing access controls:

Verify the current mode with:

sestatus

The output should show SELinux status: enabled and Current mode: enforcing.

3. Configure SELinux Modes

SELinux operates in three modes:

Use setenforce for temporary changes and the /etc/selinux/config file for permanent adjustments.

4. Manage File Contexts for Access Control

SELinux uses security contexts (labels) to define access rules for files/directories. Use the semanage fcontext command to modify these contexts:

5. Create Custom SELinux Policies

For granular control (e.g., restricting an application’s access), create custom policies using .te (Type Enforcement) files:

6. Troubleshoot SELinux Issues

When SELinux blocks an action, it logs the event to /var/log/audit/audit.log. Use these tools to analyze and resolve issues:

By following these steps, you can implement mandatory access control on Ubuntu using SELinux. Remember to test policies thoroughly in permissive mode before enforcing them to avoid disrupting system operations.

0
看了该问题的人还看了