Linux Tutorial

Linux File/Directory Management

Linux Packaging And Compression

Vim Text Editor

Linux Text Processing

Linux Software Installation

Linux User/User Group Management

Linux Permission Management

Linux Filesystem Management

Linux Advanced Filesystem Management

Linux System Management

Linux Backup and Recovery

Linux System Service Management

Linux System Log Management

Linux Boot Management

LAMP/LNMP Environment

SELinux Management

How To Display SELinux Strategy Rules (seinfo And sesearch)

SELinux uses policy rules to define access control and enforce security for a system. You can display and analyze these policy rules using the seinfo and sesearch command-line utilities. In this tutorial, we will discuss how to display SELinux policy rules using these tools.

  • Installing policy utilities:

First, ensure that the policycoreutils-python-utils package is installed on your system. This package contains the necessary utilities to work with SELinux policies, including seinfo and sesearch.

  • For Debian/Ubuntu-based systems:

    sudo apt-get update
    sudo apt-get install policycoreutils-python-utils
    
  • For RHEL/CentOS-based systems:

    sudo yum install policycoreutils-python-utils
    
  • For openSUSE-based systems:

    sudo zypper install policycoreutils-python-utils
    
  • Displaying policy information using seinfo:

The seinfo command provides an overview of the policy components, such as users, roles, types, attributes, and booleans.

To display a summary of the policy components, run:

seinfo

To display information about a specific policy component, use the -x and -t options:

  • List all users:

    seinfo -xu
    
  • List all roles:

    seinfo -xr
    
  • List all types:

    seinfo -xt
    
  • List all booleans:

    seinfo -xb
    
  • Displaying policy rules using sesearch:

The sesearch command is used to search for specific policy rules in the SELinux policy. To search for a rule, use the following syntax:

sesearch [options] /path/to/policy/file

Some useful options for sesearch include:

  • --allow: Search for allow rules.
  • --type: Search for type enforcement rules.
  • --role_allow: Search for role allow rules.
  • -s source_type: Specify the source type.
  • -t target_type: Specify the target type.
  • -p permission: Specify the permission.

By default, the active policy is located at /etc/selinux/targeted/policy/policy.##.

Examples:

  • Search for allow rules involving the httpd_t type:

    sesearch --allow -s httpd_t /etc/selinux/targeted/policy/policy.##
    
  • Search for allow rules involving the httpd_t type and file_t type with the read permission:

    sesearch --allow -s httpd_t -t file_t -p read /etc/selinux/targeted/policy/policy.##
    
  • Search for role allow rules involving the user_r role:

    sesearch --role_allow -s user_r /etc/selinux/targeted/policy/policy.##
    

In this tutorial, we have discussed how to display SELinux policy rules using the seinfo and sesearch command-line utilities. Understanding and analyzing policy rules is essential for maintaining a secure and well-managed system, especially when troubleshooting or customizing SELinux policies.

  1. Querying SELinux policy rules with seinfo and sesearch: Query specific SELinux policy rules using seinfo and sesearch. Example:

    seinfo -aunconditional_access
    
  2. How to extract policy details with seinfo and sesearch: Extract detailed information about SELinux policy components. Example:

    seinfo -x /usr/bin/myapp
    
  3. SESearch examples for searching SELinux policies: Use sesearch to search for specific policy rules. Example:

    sesearch -Ad -s targeted -t httpd_t