Podman SELinux Volume Labeling Strategy Prompt
Decide between :z, :Z, and permanent host relabeling for every Podman mount so containers get access without weakening SELinux or corrupting host directory labels.
- Target user
- Platform engineers running Podman on SELinux-enforcing hosts
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior Linux security engineer who knows exactly what Podman's volume label suffixes do. You know `:z` relabels the mount to a shared container label so any container can read it, `:Z` relabels it with a private MCS category so only that container can, and that both physically chown the SELinux context of the host path — which is why `:Z` on a shared or system directory is destructive. You know `--security-opt label=disable` turns SELinux off for that container entirely, that named Podman volumes are labeled correctly on creation without a suffix, and that permanent relabeling belongs in `semanage fcontext` plus `restorecon`, not in a run flag. I will list the mounts and the host layout. Produce a labeling strategy. Steps: 1. **Classify each mount**: for every bind mount, record the host path, which containers use it, whether it is read-only, and whether the path is container-owned data or a shared/system directory the host also uses. 2. **Pick the mechanism per mount**: choose `:z` for a path genuinely shared by multiple containers, `:Z` only for a path exclusively owned by one container, a named volume where no specific host path is required, and permanent `semanage fcontext` labeling for stable paths managed by configuration management. 3. **Flag destructive relabels explicitly**: reject any `:Z` or `:z` on paths like `/home`, `/usr`, `/etc`, or a directory the host also serves from, and explain that the relabel rewrites the host's context and can break the non-container consumers of that path. 4. **Handle the read-only case**: note that a read-only mount still needs a readable label, and prefer permanent labeling over a relabel suffix for read-only config directories that other processes depend on. 5. **Deal with multi-container access under :Z**: point out that `:Z` assigns a per-container MCS category, so a second container mounting the same path will relabel it again and lock the first one out — the classic "it worked until I added a sidecar" failure. 6. **Give the diagnostic path**: show how to confirm a denial is SELinux rather than POSIX permissions, using `ls -Z` on the host path, `podman exec` to check inside, and `ausearch -m AVC -ts recent` or `journalctl` for the actual denial record. 7. **Reserve label=disable properly**: state the narrow cases where disabling the label is defensible, what protection is given up, and require an explicit note of the accepted risk rather than treating it as a fix. 8. **Express the result durably**: give the Quadlet `Volume=` lines with suffixes, plus any `semanage fcontext -a` and `restorecon -Rv` commands that make the labeling survive a relabel of the filesystem. Fill in: - Bind mounts with host paths and containers using them: [LIST] - Which paths the host itself also uses: [LIST] - Read-only versus read-write per mount: [LIST] - Current denials or errors: [PASTE] - Is SELinux enforcing or permissive: [DESCRIBE] Output as: (a) a per-mount table of path, chosen mechanism, reasoning, and risk, (b) the Quadlet volume lines and any semanage/restorecon commands, and (c) the verification steps including how to read an AVC denial. Do not apply `:Z` to any directory outside container-owned data, and never resolve a denial with `--security-opt label=disable` without recording what protection was given up and why it was acceptable.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Why this prompt works
SELinux volume labeling is the single most common place where a working Podman setup gets “fixed” into an insecure one. The symptom is a permission denied that POSIX permissions do not explain, the internet supplies :Z and --security-opt label=disable as the two answers, and both make the error disappear. One of them can corrupt host directory labels and the other switches off mandatory access control for the container. Structuring the prompt around choosing a mechanism per mount, with an explicit rejection rule for system paths, replaces reflex with a decision that has reasoning attached.
The distinction between :z and :Z deserves the space it gets because the failure mode is delayed. :Z looks strictly better — a private category is more isolated than a shared label — and it works perfectly for a single container. The problem arrives weeks later when a sidecar or a second service mounts the same path, applies its own MCS category, and locks out the container that had been running fine. That is exactly the kind of bug that consumes an afternoon, so naming it as a design-time consideration in step five is worth more than any amount of after-the-fact debugging advice.
The diagnostic and durability steps close the loop at both ends. Confirming a denial is genuinely SELinux, via ls -Z and the actual AVC record, prevents relabeling a directory to solve what was really a UID mismatch inside a user namespace. And because a filesystem relabel can undo suffix-applied contexts, pushing stable paths toward semanage fcontext with restorecon makes the strategy survive the next relabel rather than quietly reverting and taking the containers down with it.
Related prompts
-
Podman Container Security Hardening Prompt
Harden a Podman container with dropped capabilities, no-new-privileges, a read-only rootfs, a tuned seccomp profile, and a user namespace mapping that actually fits the workload.
-
Multi-Container Podman Pod Design Prompt
Design a Podman pod with the right shared namespaces, sidecar boundaries, and port publishing so co-located containers cooperate without becoming one unsplittable blob.
-
Podman Volume Backup & Restore Prompt
Build a tested backup and restore procedure for Podman named volumes and container state that survives rootless UID mapping and SELinux relabeling.
-
Docker to Podman Team Migration Plan Prompt
Produce a phased Docker-to-Podman migration plan covering socket compatibility, CI impact, rootless gaps, and the developer workflow changes a team will actually hit.
More Podman prompts & error guides
Browse every Podman prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.