sepolicy-generate(8)
π sepolicy-generate β the girlies' guide to SELinux policy modules π
okay so bestie, you found your way into sepolicy-generate(8) and honestly? iconic. this is the tool that hands you a whole starter SELinux policy module template so you don't have to stare at an empty .te file and cry. let's get into it π«Ά
β¨ NAME β¨
sepolicy-generate β Generate an initial SELinux policy module template.
like. it literally generates the template for you. no cap.
πΈ SYNOPSIS πΈ
π Common options
sepolicy generate [-h ] [-p PATH]
π Confined Applications
sepolicy generate --application [-n NAME] [-u USER ]command [-w WRITE_PATH ]
sepolicy generate --cgi [-n NAME] command [-w WRITE_PATH ]
sepolicy generate --dbus [-n NAME] command [-w WRITE_PATH ]
sepolicy generate --inetd [-n NAME] command [-w WRITE_PATH ]
sepolicy generate --init [-n NAME] command [-w WRITE_PATH ]
π¦ Confined Users
sepolicy generate --admin_user [-r TRANSITION_ROLE] -n NAME
sepolicy generate --confined_admin -n NAME [-a ADMIN_DOMAIN] [-u USER]
[-n NAME] [-w WRITE_PATH]
sepolicy generate --desktop_user -n NAME [-w WRITE_PATH]
sepolicy generate --term_user -n NAME [-w WRITE_PATH]
sepolicy generate --x_user -n NAME [-w WRITE_PATH]
π Miscellaneous Policy
sepolicy generate --customize -d DOMAIN -n NAME [-a ADMIN_DOMAIN]
sepolicy generate --newtype -t type -n NAME
sepolicy generate --sandbox -n NAME
π DESCRIPTION π
Use sepolicy generate to generate an SELinux policy Module. that's the whole assignment, and it eats every time. π
sepolicy generate will create 5 files. five. a whole little family of files, and you're their mother.
When specifying a confined application you must specify a path β no path, no policy, periodt. sepolicy generate will use the rpm payload of the application along with nm -D APPLICATION to help it generate types and policy rules for your policy files. (yes, it's doing detective work with nm -D, let her cook π₯)
π NAME.te
This file can be used to define all the types enforcement rules for a particular domain.
Note: Policy generated bysepolicy generatewill automatically add a permissive DOMAIN to your.tefile. When you are satisfied that your policy works, you need to remove the permissive line from the.tefile to run your domain in enforcing mode.
so lowkey your domain starts out in permissive mode. that's the training-wheels era. once you're confident, you delete that permissive line and boom β enforcing mode, main character energy, no safety net π
π NAME.if
This file defines the interfaces for the types generated in the .te file, which can be used by other policy domains. sharing is caring, bestie π«Ά
π NAME.fc
This file defines the default file context for the system, it takes the file types created in the .te file and associates file paths to the types. Tools like restorecon and RPM will use these paths to put down labels. it's giving matchmaker but for file paths and types π
π NAME_selinux.spec
This file is an RPM SPEC file that can be used to install the SELinux policy on to machines and setup the labeling. The spec file also installs the interface file and a man page describing the policy. You can use sepolicy manpage -d NAME to generate the man page. (manpage-ception, we love to see it β¨)
π NAME.sh
This is a helper shell script to compile, install and fix the labeling on your test system. It will also generate a man page based on the installed policy, and compile and build an RPM suitable to be installed on other machines. it's the whole pipeline in one little script, she's doing the most and we respect it π
β OPTIONS β
-h,--helpβ Display help message-d,--domainβ Enter domain type(s) which you will be extending-n,--nameβ Specify alternate name of policy. The policy will default to the executable or name specified-p,--pathβ Specify the directory to store the created policy files. (Default to current working directory )-r,--roleβ Enter role(s) to which this admin user will transition-t,--typeβ Enter type(s) for which you will generate new definition and rule(s)-u,--userβ SELinux user(s) which will transition to this domain-w,--writepathβ Path(s) which the confined processes need to write to-a,--adminβ Domain(s) which the confined admin will administrate
π§ optional arguments:
--admin_userβ Generate Policy for Administrator Login User Role--applicationβ Generate Policy for User Application--cgiβ Generate Policy for Web Application/Script (CGI)--confined_adminβ Generate Policy for Confined Root Administrator Role--customizeβ Generate Policy for Existing Domain Type--dbusβ Generate Policy for DBUS System Daemon--desktop_userβ Generate Policy for Desktop Login User Role--inetdβ Generate Policy for Internet Services Daemon--initβ Generate Policy for Standard Init Daemon (Default)--newtypeβ Generate new policy for new types to add to an existing policy--sandboxβ Generate Policy for Sandbox--term_userβ Generate Policy for Minimal Terminal Login User Role--x_userβ Generate Policy for Minimal X Windows Login User Role
π EXAMPLE π
watch her work her magic:
> sepolicy generate --init /usr/sbin/rwhod
Generating Policy for /usr/sbin/rwhod named rwhod
Created the following files:
rwhod.te # Type Enforcement file
rwhod.if # Interface file
rwhod.fc # File Contexts file
rwhod_selinux.spec # Spec file
rwhod.sh # Setup Script
five files, one command, zero tears. ate and left no crumbs π₯
π AUTHOR π
This man page was written by Daniel Walsh <dwalsh@redhat.com> β thank you king, we are obsessed π
π¦ SEE ALSO π¦
iykyk, go read those next bestie, the lore goes deep π
and that's the whole page!! this one's from the 20121005 era of sepolicy-generate(8) β vintage, nostalgic, still slaying π π go forth and generate your policies, you've got this fr fr β¨
π¦ where this page comes from
- centos-stream 10: policycoreutils-devel 3.11-1.el10 Β· GPL-2.0-or-later
- centos-stream 9: policycoreutils-devel 3.6-9.el9 Β· GPL-2.0-or-later
- centos-stream 9: policycoreutils-devel 3.6-9.el9 Β· GPL-2.0-or-later
- debian trixie: policycoreutils-dev 3.8.1-2 Β· GPL-2.0-or-later
- fedora 43: policycoreutils-devel 3.9-5.fc43 Β· GPL-2.0-or-later
- fedora 43: policycoreutils-devel 3.9-5.fc43 Β· GPL-2.0-or-later
- fedora 43: policycoreutils-devel 3.9-7.fc43 Β· GPL-2.0-or-later
- fedora 43: policycoreutils-devel 3.9-7.fc43 Β· GPL-2.0-or-later
- fedora 44: policycoreutils-devel 3.10-1.fc44 Β· GPL-2.0-or-later
- fedora 44: policycoreutils-devel 3.10-1.fc44 Β· GPL-2.0-or-later
- fedora 44: policycoreutils-devel 3.11-2.fc44 Β· GPL-2.0-or-later
- fedora 44: policycoreutils-devel 3.11-2.fc44 Β· GPL-2.0-or-later
- nixos 26.05: selinux-python 3.10
- nixpkgs unstable: selinux-python 3.10
- opensuse-leap 16.0: policycoreutils-devel 3.8.1-160000.5.1 Β· GPL-2.0-or-later
- opensuse-leap 16.0: policycoreutils-devel 3.8.1-160000.5.1 Β· GPL-2.0-or-later
- opensuse-leap 16.0: policycoreutils-devel 3.8.1-160000.5.1 Β· GPL-2.0-or-later
- opensuse-leap 16.0: policycoreutils-devel 3.8.1-160000.5.1 Β· GPL-2.0-or-later
- ubuntu questing: policycoreutils-dev 3.8.1-2
- ubuntu resolute: policycoreutils-dev 3.9-2 Β· GPL-2.0-or-later
- ubuntu stonking: policycoreutils-dev 3.11-2 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms