Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

How SELinux deny rules improve system security

June 4, 2025
Petr Lautrbach
Related topics:
LinuxSecurity
Related products:
Red Hat Enterprise Linux

    SELinux userspace release 3.6 introduces deny rules. SELinux is designed as an additional layer of system security. SELinux policy defines the access and operations (e.g., read or write) allowed for certain resources. SELinux stops all access unless allowed by policy.

    Before the SELinux 3.6 userspace version, it was not possible to drop any access already allowed in the base SELinux policy or in a module. When you wanted to remove access, you had to rewrite the base policy or the module. This would mean maintaining your own policy or module and overriding the distribution policies. While it’s feasible, it costs resources and could be error-prone, because you would need to merge distribution changes with your own.

    How deny rules work

    The changes in the latest SELinux userspace release 3.6 introduced support for deny rules. They are documented in Access Vector Rules: "Remove the access rights defined from any matching allow rules. These rules are processed before neverallow checking."

    Rule definition:

    (deny source_id target_id|self classpermissionset_id ...)

    A deny rule is like a neverallow rule, except it removes permissions rather than reporting errors.

    Let’s consider the following use cases.

    Restricted users

    As an administrator, I need to limit confined users so that they cannot run the ssh command.

    The /usr/bin/ssh is labeled with the ssh_exec_t file context. By default, user_u users are allowed to execute files with this context:

    # sesearch -A -s user_t -t ssh_exec_t
    ...
    allow user_usertype application_exec_type:file { execute execute_no_trans getattr ioctl lock map open read };

    In order to block user_u users to execute them, we need to deny these permissions:

    # cat > deny_user_t_ssh_exec_t.cil <<EOF
    (deny user_t ssh_exec_t (file (execute execute_no_trans getattr ioctl lock map open read)))
    EOF
    # semodule -i deny_user_t_ssh_exec_t.cil

    If a user tries to use ssh now they get Permission denied:

    user@localhost:~$ /usr/bin/ssh localhost
    -bash: /usr/bin/ssh: Permission denied

    Restricted system admin

    As an administrator, I need to have another administrator assigned to sysadm_u who would not be able to read user homedir data.

    We’ll create a new user sysadm mapped to the SELinux user staff_u, allow them to become root by running sudo assysadm_t, and check whether they’re allowed to read homedir:

    # useradd -Z staff_u sysadm
    # passwd sysadm
    New password:
    BAD PASSWORD: The password is shorter than 8 characters
    Retype new password:
    passwd: password updated successfully
    # cat > /etc/sudoers.d/sysadm <<EOF
    sysadm ALL=(ALL) TYPE=sysadm_t ROLE=sysadm_r ALL
    EOF
    # ssh sysadm@localhost
    sysadm@localhost's password:
    sysadm@localhost:~$ id -Z
    staff_u:staff_r:staff_t:s0-s0:c0.c1023
    sysadm@localhost:~$ sudo -i
    [sudo] password for sysadm:
    root@localhost:~# id -Z
    staff_u:sysadm_r:sysadm_t:s0-s0:c0.c1023
    root@localhost:~# ls /home/
    bachradsusi  mock  plautrba  sysadm  user
    root@localhost:~# ls /home/user
    Desktop  Documents  Downloads  linux-system-roles-selinux  Music  Pictures  Public  Templates  Videos

    Apparently, sysadm can read other user homes so we need to drop permissions:

    # cat > deny_sysadm_user_home_dir_t.cil <<EOF
    (deny sysadm_t user_home_dir_t (dir ( add_name append audit_access create execmod execute getattr ioctl link lock mounton open quotaon read relabelfrom relabelto remove_name rename reparent rmdir search setattr swapon unlink watch watch_mount watch_reads watch_sb watch_with_perm write )))
    EOF
    # semodule -i deny_sysadm_user_home_dir_t.cil
    # sesearch -A -s sysadm_t -t user_home_dir_t -c dir
    #
    root@localhost:~# ls /home/user
    ls: cannot access '/home/user': Permission denied

    It looks good. But what happens if the user switches to permissive as follows:

    root@localhost:~# setenforce 0
    root@localhost:~# ls /home/user
    Desktop  Documents  Downloads  linux-system-roles-selinux  Music  Pictures  Public  Templates  Videos

    As you can see, a simple deny rule is not necessarily a good tool when used on privileged SELinux domains, which can manipulate SELinux settings on the hosts.

    Hardening the default policy

    Sometimes, the default SELinux policy allows users to hang a system. For example, when an unconfined user tries to ptrace fapolicyd. Although you could disallow ptrace for the whole system by using the deny_ptrace boolean, it’s not necessary to limit ptrace of other daemons. To limit ptrace and signals on fapolicyd, we can use a deny rule.

    This module is actually already shipped with the fapolicyd policy with PR add fapolicyd-hardening module preventing usage of sigstop, sigkill and ptrace.

    But you could do the same thing manually.

    # cat > deny_domain_fapolicyd_ptrace.cil <<EOF
    (deny domain fapolicyd_t ( process ( ptrace sigkill sigstop ) ) )
    EOF
    # semodule -i deny_domain_fapolicyd_ptrace

    Learn more

    SELinux userspace release 3.6 introduces deny rules. This article demonstrated how you can now remove SELinux permissions from the base SELinux policy or a module. This improves system security and reduces errors and costs.

    To learn more about SELinux, check out the SELinux documentation.

    Last updated: June 10, 2025

    Related Posts

    • How SELinux improves Red Hat Enterprise Linux security

    • How custom SELinux policies secure servers and containers

    • My advice on SELinux container labeling

    • How to run SQL Server with SELinux enabled on RHEL 9

    Recent Posts

    • Debugging image mode with Red Hat OpenShift 4.20: A practical guide

    • EvalHub: Because "looks good to me" isn't a benchmark

    • SQL Server HA on RHEL: Meet Pacemaker HA Agent v2 (tech preview)

    • Deploy with confidence: Continuous integration and continuous delivery for agentic AI

    • Every layer counts: Defense in depth for AI agents with Red Hat AI

    What’s up next?

    This cheat sheet provides a collection of Linux commands and executables for developers and system administrators looking to advance beyond the basics.

    Get the cheat sheet
    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Chat Support

    Please log in with your Red Hat account to access chat support.