How To

Configure Podman SELinux Context on Rocky Linux 10 / AlmaLinux 10

Most SELinux trouble with Podman on Rocky Linux and AlmaLinux has nothing to do with where images live. It shows up the moment you bind mount a host directory into a container and the process inside gets Permission denied on a file that root can plainly read. The kernel’s doing its job. The directory carries a host label such as var_t or user_home_t, and the container_t domain has no rule that lets it touch those types.

Original content from computingforgeeks.com - post 73354

We reproduced every denial in this guide, read the real AVC records, and fixed each one with the smallest change that holds up after a reboot or a restorecon. We also moved rootful and rootless storage to a second disk and labeled it the way the containers-storage man page asks. Everything below was run in November 2026 on Rocky Linux 10.2 with Podman from the 10.3 repos and on AlmaLinux 10.3, both with Podman 6.1.4 and SELinux enforcing.

Confirm SELinux is enforcing and check the policy packages

Labels behave differently across container-selinux releases, so record what you have before changing anything. The Rocky and Alma cloud images we used did not ship Podman at all, which means the tools for reading denials were not there either, so you’d be guessing at the first failure. Install all three packages together.

sudo dnf install -y podman policycoreutils-python-utils setroubleshoot-server

policycoreutils-python-utils provides semanage and audit2why, and you will lean on both below. Now check the mode and versions.

sestatus | head -6
cat /etc/redhat-release
podman --version
rpm -q container-selinux

On the Rocky host the output read as follows.

SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Rocky Linux release 10.2 (Red Quartz)
podman version 6.1.4
container-selinux-2.246.0-1.el10.noarch

The AlmaLinux 10.3 host had the same Podman build with the newer container-selinux-2.250.0-1.el10 and selinux-policy-42.1.27-2.el10_3.2. Both behaved identically in every test below. If Current mode says permissive, nothing here will reproduce, because SELinux only logs in that mode. If someone set it that way to “fix” containers, our guide on switching SELinux modes on Rocky Linux 10 shows how to put it back to enforcing.

Reproduce the bind mount denial and read the AVC

A plain bind mount of a new directory under /srv fails for reads and writes alike. Create a small test tree and look at its label before you mount it.

sudo mkdir -p /srv/web
echo "served from the host" | sudo tee /srv/web/index.html
ls -Zd /srv/web /srv/web/index.html

Anything created under /srv without a matching rule inherits var_t, and that’s the type containers can’t touch.

unconfined_u:object_r:var_t:s0 /srv/web
unconfined_u:object_r:var_t:s0 /srv/web/index.html

Mount it into an Alpine container and try to read the file.

sudo podman run --rm -v /srv/web:/usr/share/web docker.io/library/alpine cat /usr/share/web/index.html

The container runs as root, the file is world readable, and it still fails. Pull the matching audit record straight after with sudo ausearch -m avc -ts recent, since recent only covers the last ten minutes.

Podman bind mount read denied with ausearch AVC showing container_t denied read on var_t file on AlmaLinux 10

That one AVC line tells you everything you need, so learn to read it once and you won’t need sealert for container work.

  • scontext: the container process, container_t with categories c515,c1010
  • tcontext: the file, still var_t
  • { read } and tclass=file: the access that was refused
  • permissive=0: SELinux blocked it, not just logged it

Don’t answer this by allowing container_t to read var_t. That rule would hand every container on the host read access to every var_t path, so the right move is to give this one directory a type containers are meant to use.

cat: can’t open ‘/usr/share/web/index.html’: Permission denied

This is the read form of the denial, denied { read } on tclass=file, and the target is whatever host type the directory had. Relabel the directory to container_file_t, either once with a volume flag or permanently with semanage fcontext. The flag is quicker, but it’s the policy rule that survives a forced relabel, so production hosts want the second option. Both are covered in the next two sections.

touch: /uploads/report.csv: Permission denied

Create a second directory and mount it at /uploads to try a write, then pipe the record through audit2why.

sudo mkdir -p /srv/uploads
sudo podman run --rm -v /srv/uploads:/uploads docker.io/library/alpine touch /uploads/report.csv
sudo ausearch -m avc -ts recent -c touch | audit2why

Writes fail the same way, and the record says { write } on tclass=dir because creating a file needs write access to the parent directory. The audit2why output is the explanation most people reach for next.

Podman volume write denied and audit2why explaining the missing type enforcement rule for container_t on var_t

Ignore the audit2allow hint here. It is technically correct, because a rule really is missing, but a module that lets container_t write var_t opens every var_t path on the host to every container, which defeats the point of running confined. The missing piece is the label on /srv/uploads, not a rule. For the wider toolbox (sealert, booleans, audit2allow when it really is the right answer), see our guide to troubleshooting SELinux denials on Rocky Linux 10.

Relabel a bind mount with :z or :Z

Add :z when more than one container shares the directory and :Z when only one container should ever touch it. Podman relabels the source tree to container_file_t before starting the container, and the two flags differ only in the MCS categories they set.

FlagLabel we gotWho can read it
:zcontainer_file_t:s0Any container
:Zcontainer_file_t:s0:c22,c366Only the container running with c22,c366
noneunchanged (var_t)No container

The capture below runs the shared case on /srv/web, then starts a long running db1 container with a private /srv/appdb and tries to read that directory from a second container.

Podman :z shared container_file_t label versus :Z private MCS categories on Rocky Linux 10

The directory label and the db1 process label share c22,c366, so db1 gets in and the second container, started with its own random pair, does not. That isolation is what you want for a database volume, because a compromised web container can’t reach the database files even though both run as container_t. Here are the commands, if you are copying them.

sudo podman run --rm -v /srv/web:/usr/share/web:z docker.io/library/alpine cat /usr/share/web/index.html
sudo mkdir -p /srv/appdb
echo seed | sudo tee /srv/appdb/seed.txt
sudo podman run -d --name db1 -v /srv/appdb:/var/lib/data:Z docker.io/library/alpine tail -f /dev/null
ls -Zd /srv/appdb
sudo podman inspect db1 --format "{{.ProcessLabel}}"

The same flags work in Volume= lines of a Quadlet unit, so containers you run under systemd with Quadlet take Volume=/srv/appdb:/var/lib/data:Z unchanged.

ls: can’t open ‘/var/lib/data’: Permission denied after another container used :Z

This one cost us the most time, because nothing shows up in the audit log. We captured it on the AlmaLinux host, so db1 has different categories there (c217,c279) than in the Rocky capture above. :Z relabels on every start. A second container that mounts the same directory with :Z steals the label, and the original container loses access while it is still running. Worse, a dontaudit rule in the policy hides this denial, so ausearch returns <no matches>. Rebuilding the policy with semodule -DB turns those silent rules off long enough to see the denial. With db1 from the previous section still running, start a second :Z container on the same directory and follow the denial.

sudo podman run --rm --name thief -v /srv/appdb:/var/lib/data:Z docker.io/library/alpine ls /var/lib/data
ls -Zd /srv/appdb
sudo podman exec db1 ls /var/lib/data
sudo semodule -DB
sudo podman exec db1 ls /var/lib/data
sudo ausearch -m avc -ts recent -c ls
sudo semodule -B

The first exec fails with no AVC on record. The second one, run after semodule -DB, leaves the full denial in the log.

Silent MCS denial after a second :Z container relabels a volume, revealed with semodule -DB and ausearch

Both sides are container_t and container_file_t, so the type rules pass; only the categories differ (c217,c279 against c123,c962). Always finish with sudo semodule -B to restore the default policy, or the audit log fills with noise from every service on the box. Restarting the owner relabels the directory back to its categories, which is the quick way out at 2 a.m.

sudo podman restart db1
ls -Zd /srv/appdb
sudo podman exec db1 ls /var/lib/data

The WARN line is only tail ignoring SIGTERM. After the restart the label matches db1 again and the file is readable.

WARN[0010] StopSignal SIGTERM failed to stop container db1 in 10 seconds, resorting to SIGKILL
system_u:object_r:container_file_t:s0:c217,c279 /srv/appdb
seed.txt

The lasting fix is a rule, not a restart. Use :z on directories that several containers share, and keep :Z for a directory that belongs to exactly one container.

Error: SELinux relabeling of /usr is not allowed

Podman refuses to relabel system trees, which stops a stray :Z from breaking the host. We tried /usr, /home and /etc as volume sources and got the same refusal each time.

Error: SELinux relabeling of /usr is not allowed
Error: SELinux relabeling of /home is not allowed
Error: SELinux relabeling of /etc is not allowed

Mount a narrower subdirectory instead. If a container truly needs to read a system path, drop the relabel flag and run that one container with --security-opt label=disable, which the podman-run documentation recommends over relabeling system files.

Make the label permanent with semanage fcontext

A :z label survives a plain restorecon, but not a forced one or a full filesystem relabel. That surprised us, so here is what happened on /srv/web after the :z run.

sudo restorecon -Rv /srv/web
sudo restorecon -RvF /srv/web
sudo podman run --rm -v /srv/web:/usr/share/web docker.io/library/alpine cat /usr/share/web/index.html

The first command skips the tree because container_file_t is a customizable type. The second resets it to var_t, and the container run after it fails again.

/srv/web not reset as customized by admin to system_u:object_r:container_file_t:s0
/srv/web/index.html not reset as customized by admin to system_u:object_r:container_file_t:s0
Relabeled /srv/web from system_u:object_r:container_file_t:s0 to system_u:object_r:var_t:s0
Relabeled /srv/web/index.html from system_u:object_r:container_file_t:s0 to system_u:object_r:var_t:s0
cat: can't open '/usr/share/web/index.html': Permission denied

Any forced relabel (restorecon -F or fixfiles -F) has the same effect, so a host that gets a full relabel during maintenance can come back with broken containers. Write the label into policy so every relabel agrees with you.

sudo semanage fcontext -a -t container_file_t "/srv/web(/.*)?"
sudo restorecon -RvF /srv/web

Now the volume works without any flag on the -v option, which means your compose files and Quadlet units don’t have to carry SELinux knowledge.

semanage fcontext rule for container_file_t on /srv/web applied with restorecon -RvF for a Podman bind mount

We use this for anything shared and long lived, such as web roots, config directories and upload trees. The rule gives the shared s0 label, so keep :Z for the private database case. semanage fcontext -l -C lists your local rules, which makes them easy to carry into Ansible or a kickstart.

Fix rootless bind mounts from your home directory

Rootless containers run as container_t too, so a directory in your home with the default user_home_t label is denied just like var_t. The captures below ran as user josphat with no sudo.

mkdir -p ~/site
echo "rootless page" > ~/site/index.html
ls -Zd ~/site
podman run --rm -v ~/site:/site docker.io/library/alpine cat /site/index.html
podman run --rm -v ~/site:/site:Z docker.io/library/alpine cat /site/index.html
ls -Zd ~/site

Without the flag the read fails. With :Z it works and the directory picks up private categories.

unconfined_u:object_r:user_home_t:s0 /home/josphat/site
cat: can't open '/site/index.html': Permission denied
rootless page
system_u:object_r:container_file_t:s0:c83,c746 /home/josphat/site

Relabel a project folder, never your whole home. Podman blocks the worst case anyway with Error: SELinux relabeling of /home/josphat is not allowed, and a relabeled home would take ~/.ssh away from sshd. If a dev container genuinely needs the whole home, --security-opt label=disable on that container is the safer trade, because you lose confinement on one container instead of breaking logins for the whole account.

Move rootful Podman storage to a second disk

To relocate /var/lib/containers/storage, add an equivalence rule so the new path gets exactly the labels the old one had, then point graphroot at it. One container_var_lib_t rule on the whole tree, which older guides suggest, is wrong. Image layers need container_ro_file_t, so a single type mislabels every layer, and the equivalence rule handles that split for you.

This section assumes the second disk is already formatted and mounted on /data through /etc/fstab. Ours was a 20 GB disk formatted with mkfs.xfs. Check the current paths first so you know what you’re moving.

sudo podman info --format "graphRoot: {{.Store.GraphRoot}}\nrunRoot: {{.Store.RunRoot}}\ndriver: {{.Store.GraphDriverName}}"

These are the stock values on EL10, and you only need to change the first one. Podman keeps images, layers and container state under the graph root, so that is the directory that grows and the one worth moving to a bigger disk.

graphRoot: /var/lib/containers/storage
runRoot: /run/containers/storage
driver: overlay

Leave the run root alone. It lives on tmpfs, carries container_var_run_t, and gains nothing from a faster disk. Create the new directory, add the equivalence and relabel.

sudo mkdir -p /data/containers/storage
sudo semanage fcontext -a -e /var/lib/containers /data/containers
sudo restorecon -Rv /data/containers

A fresh EL10 install has no /etc/containers/storage.conf, and the defaults sit in /usr/share/containers/storage.conf. A host upgraded from Podman 5 may still carry the old file in /etc, which then acts as the main config, so check for it before you add a drop-in. Put the override in the root only drop-in directory, because the plain storage.conf.d also applies to rootless users (the error that causes is shown just below).

sudo mkdir -p /etc/containers/storage.rootful.conf.d
sudo vim /etc/containers/storage.rootful.conf.d/50-graphroot.conf

Add these two lines and save.

[storage]
graphroot = "/data/containers/storage"

Do this before the first pull, because Podman does not move existing images and the old /var/lib/containers/storage simply stays behind as orphaned data. On a host that already has containers, think twice before reaching for sudo podman system reset, and if you do, run it before you add the drop-in, because it wipes whichever graphroot is configured at the time: it deletes every container, pod, image, network and named volume in rootful storage, so export volumes you care about with podman volume export first and expect to pull images again. After pulling Alpine and running a container, the new tree carries the same split of labels as the stock location.

Rootful Podman graphroot moved to /data with a semanage fcontext equivalence rule and the resulting storage labels

A dry run with sudo restorecon -Rnv /data/containers | wc -l returned 0, so nothing disagreed with policy. The same steps on AlmaLinux 10.3 gave container_ro_file_t on /data/containers/storage/overlay.

Here is the honest part. We also ran Podman 6.1.4 on graphroots left as unlabeled_t and default_t. Pull, run, build and named volumes all worked, rootful and rootless, with no container AVCs. Podman runs as container_runtime_t, an unconfined domain, and it mounts each container’s root filesystem with a context="system_u:object_r:container_file_t:s0:c141,..." option, so the container never sees the label on disk. Label the storage anyway. The containers-storage.conf man page tells you to, a later policy can tighten container_runtime_t, and a consistent tree is one less thing to rule out when a real denial turns up.

RunRoot is pointing to a path (/run/containers/storage) which is not writable

Our first attempt put the drop-in in /etc/containers/storage.conf.d/. Root was fine, but every rootless command broke.

WARN[0000] RunRoot is pointing to a path (/run/containers/storage) which is not writable. Most likely podman will fail.: permission denied
Error: cannot evaluate symlinks on DB run root path "/run/containers/storage": lstat /run/containers/storage: permission denied

Files in storage.conf.d load for every user, so the rootless user picked up the system configuration and tried the root owned run root. Move the file to storage.rootful.conf.d, which loads only when the UID is 0.

sudo mkdir -p /etc/containers/storage.rootful.conf.d
sudo mv /etc/containers/storage.conf.d/50-graphroot.conf /etc/containers/storage.rootful.conf.d/
sudo podman info --format "root graphRoot: {{.Store.GraphRoot}}"
podman info --format "rootless graphRoot: {{.Store.GraphRoot}}  runRoot: {{.Store.RunRoot}}"

Each side now gets its own paths.

root graphRoot: /data/containers/storage
rootless graphRoot: /home/josphat/.local/share/containers/storage  runRoot: /run/user/1000/containers

The drop-in directories and their load order are listed in the containers-storage.conf man page.

Move rootless storage off your home directory

Rootless storage follows the same pattern, but the equivalence points at your own ~/.local/share/containers, where policy assigns data_home_t to the top and container_ro_file_t to the overlay directories. Root creates the directory and the rule, and everything after that runs as the user. Your shell expands $USER and $HOME before sudo runs, so the paths are yours, not root’s.

sudo mkdir -p /data/$USER/containers/storage
sudo chown -R $USER:$USER /data/$USER
sudo semanage fcontext -a -e $HOME/.local/share/containers /data/$USER/containers
sudo restorecon -Rv /data/$USER

The new directories move from default_t to the home data type (our user was josphat).

Relabeled /data/josphat/containers from unconfined_u:object_r:default_t:s0 to unconfined_u:object_r:data_home_t:s0
Relabeled /data/josphat/containers/storage from unconfined_u:object_r:default_t:s0 to unconfined_u:object_r:data_home_t:s0

Then set graphroot in the per user config file.

mkdir -p ~/.config/containers
vim ~/.config/containers/storage.conf

We used this content.

[storage]
driver = "overlay"
graphroot = "/data/josphat/containers/storage"

Swap josphat for your own user name. This file replaces the vendor storage.conf as the main file for your account, while the vendor drop-in that sets the overlay driver still loads after it, so the driver line is only there to be explicit. Pull an image, start a container, then run one relabel pass over the new tree.

podman pull docker.io/library/alpine
podman run --rm docker.io/library/alpine echo rootless storage on /data works
restorecon -Rv /data/$USER/containers

In our run that restorecon pass corrected three files that Podman created under overlay-containers.

Rootless Podman storage moved to /data with storage.conf and restorecon fixing overlay-containers labels

Run that restorecon -Rv once after the first container starts, then leave it, because those files only get created on first use. If a later denial names default_t under that tree, the same command fixes it. The run root stays on /run/user/1000/containers, which is what you want. If the account is new to Podman, our walkthrough on installing Podman and Buildah on Rocky Linux 10 covers the base install.

Get AVC records when ausearch prints <no matches>

An empty ausearch result has two common causes, and only one of them is dontaudit. The other is stdin. When stdin is a pipe (cron, CI runners, ssh without a terminal, Ansible), ausearch reads stdin instead of the audit logs, and the man page says --input-logs is needed from a cron job. We ran the same query both ways against a known write denial.

sudo ausearch --input-logs -m avc -ts recent -c touch | grep ^type=AVC

Without the flag the non interactive run printed <no matches>. With it the record came back.

type=AVC msg=audit(1796044157.748:635): avc:  denied  { write } for  pid=4179 comm="touch" name="uploads" dev="sda2" ino=17065814 scontext=system_u:system_r:container_t:s0:c559,c677 tcontext=unconfined_u:object_r:var_t:s0 tclass=dir permissive=0

Add --input-logs to any scripted check, because a monitoring job that always reports zero denials is worse than no job at all. If it still prints nothing and the container is denied, suspect an MCS mismatch and use the semodule -DB round trip shown earlier.

Match each path to the SELinux type Podman expects

These are the labels Podman storage carries and where each belongs. When a denial names one of the bottom row’s types as tcontext, you’re looking at a labeling fix.

TypeWhere we saw itWhat it means
container_tProcess inside every containerThe confined domain doing the reads and writes
container_file_tBind mounts after :z, :Z or a semanage rule; named volumesContent containers may read and write
container_ro_file_toverlay, overlay-images, overlay-layersImage layers
container_var_lib_tlibpod, db.sql, volumes, lock filesRootful runtime state
container_var_run_t/run/containers/storageRootful run root on tmpfs
data_home_tRootless storage top directoriesRootless runtime state
var_t, user_home_t, default_tNew directories with no ruleDenied to containers

On a production host we keep it to four habits, and you can copy them into your build as they are.

  1. Shared host directories get a semanage fcontext rule to container_file_t
  2. Single owner data, such as a database directory, uses :Z
  3. Relocated storage gets the -e equivalence rule before the first pull
  4. No audit2allow modules or permissive mode to make a container start

The fourth one matters most, because every denial in this guide was a labeling problem with a labeling fix. If you catch yourself writing a policy module for a bind mount, stop and check tcontext first, since the answer is almost always a missing container_file_t label. If you run these containers as services, running Podman containers as systemd services uses the same volume flags, and the Podman cheat sheet lists them next to the rest of the rootless commands.

Keep reading

Java4Shell (CVE-2026-114938): Find and Patch Vulnerable JVMs Security Java4Shell (CVE-2026-114938): Find and Patch Vulnerable JVMs UFW Firewall Commands with Examples on Ubuntu 26.04 / 24.04 Security UFW Firewall Commands with Examples on Ubuntu 26.04 / 24.04 nginx HTTP/2 RCE CVE-2026-123007: Check, Disable HTTP/2, Patch Security nginx HTTP/2 RCE CVE-2026-123007: Check, Disable HTTP/2, Patch Encapsule on Fedora 45: Isolated Dev Containers vs Toolbx Containers Encapsule on Fedora 45: Isolated Dev Containers vs Toolbx Join Fedora 45 / 44 to FreeIPA: ipa-client-install, SSSD, sudo Fedora Join Fedora 45 / 44 to FreeIPA: ipa-client-install, SSSD, sudo How To Install Podman on Ubuntu 24.04|22.04|20.04 Containers How To Install Podman on Ubuntu 24.04|22.04|20.04

Leave a Comment

Press ESC to close