selinux_mode
The host’s SELinux mode, enforcing or permissive, in /etc/selinux/config and, while SELinux is on, now. Removing it leaves the mode as it is.
Use selinux_mode to put a host in enforcing or permissive mode and keep it there across reboots. It’s the switch most teams flip with setenforce and an edit to /etc/selinux/config, done once and then forgotten on half the fleet. SELinux is on by default across the Red Hat family, such as Rocky Linux and RHEL.
Example usage
Section titled “Example usage”Keep a host enforcing:
step "selinux" { selinux_mode { mode = "enforcing" }}Run permissive while you write the policy for a new app, then switch back by changing one word:
step "selinux" { selinux_mode { mode = "permissive" }}Arguments
Section titled “Arguments”| Name | Type | Required | Description |
|---|---|---|---|
mode |
string | Yes | “enforcing” or “permissive”. Switching between them takes effect at once. Disabling SELinux isn’t a mode here yet. |
Read-only attributes
Section titled “Read-only attributes”Conn3x sets these; reference them as conn3x_selinux_mode.<circuit>__<step>["<host>"].<name>.
| Name | Type | Description |
|---|---|---|
in_sync |
bool | Whether the config file has mode and, while SELinux is on, it’s running in it. |
reboot_required |
bool | Whether the host needs a reboot to run in mode: true when SELinux is off now, since only a boot turns it on. Pair it with a reboot step. |
revision |
string | Changes each time Conn3x changes this on the host. Handlers watch it. |
A step lowers to the conn3x_selinux_mode resource, one instance per host, and connects with its circuit’s ssh block.
How it works
Section titled “How it works”Reading. On every plan, Conn3x reads the SELINUX= line in /etc/selinux/config and the running mode from /sys/fs/selinux/enforce. in_sync is true when the file has mode and, while SELinux is on, the host is running in it. If the host has no /etc/selinux/config, the step fails, since SELinux isn’t installed there.
Applying. Conn3x sets the SELINUX= line and keeps the rest of the file, SELINUXTYPE included. The file keeps its mode, and its SELinux label is restored after the write. While SELinux is on, setenforce switches the running mode too, so the change takes effect without a reboot.
When SELinux is off. setenforce can’t turn SELinux on, so on a host where it’s disabled Conn3x writes the file and sets reboot_required to true. The mode takes effect at the next boot. Pair the step with a reboot step for those hosts.
Disabling. mode takes enforcing or permissive. Turning SELinux off isn’t here yet. Permissive logs what it would deny and blocks nothing, which is usually what you’re after.
Changes. Changing mode updates the host in place. There’s one selinux_mode per host.
Removal
Section titled “Removal”A selinux_mode step has no on_remove. When you delete it, Conn3x stops managing the mode and leaves it as it is.
From Ansible
Section titled “From Ansible”conn3x convert ansible turns ansible.posix.selinux tasks with state: enforcing or permissive into selinux_mode steps. policy is dropped with a note, since the step leaves SELINUXTYPE as it is. state: disabled, update_kernel_param and a configfile other than /etc/selinux/config stay TODOs.