Sub topic 14
MCS Categories and How They Isolate Containers
This chapter assumes you understand Linux permissions, SELinux types, and basic Podman or Docker commands. You should also know how to read a context such as system_u:system_r:container_t:s0:c12,c45.
What MCS adds to type enforcement
SELinux type enforcement decides whether a domain may access a type. For example, a process in container_t may access files labeled container_file_t. This rule alone would allow every ordinary container process to access every matching container file.
Multi-Category Security (MCS) adds categories to the sensitivity and level portion of a context. A container process might have this context:
system_u:system_r:container_t:s0:c12,c45The type is container_t. The categories are c12 and c45. A file mounted for that container may have:
system_u:object_r:container_file_t:s0:c12,c45The container policy requires the process and object to have compatible categories. A second container with s0:c7,c19 cannot normally access the first container's categorized files, even though both processes use the container_t domain.
| Context component | Example | Purpose |
|---|---|---|
| SELinux user | `system_u` | SELinux identity, not a Linux login name |
| Role | `system_r` | Role used in the SELinux model |
| Type | `container_t` | Main type-enforcement decision |
| Level and categories | `s0:c12,c45` | MCS isolation labels |
Inspecting container labels
Use ps to inspect process contexts and ls -Z to inspect file contexts. Podman can also report the process label assigned to a container.
podman run -d --name web-a docker.io/library/nginx:alpine
podman run -d --name web-b docker.io/library/nginx:alpine
podman inspect --format '{{.ProcessLabel}}' web-a
podman inspect --format '{{.ProcessLabel}}' web-b
ps -eZ | grep '[n]ginx'The two containers should normally receive different category pairs. The exact category numbers are selected by the container runtime and can change when containers are recreated.
The :Z and :z volume suffixes tell a container runtime to relabel a bind mount:
:Zgives the content a private label for one container.:zgives the content a shared label for multiple containers.
For example:
mkdir -p "$HOME/web-data"
printf 'private content\n' > "$HOME/web-data/index.html"
podman run --rm \
--volume "$HOME/web-data:/usr/share/nginx/html:Z" \
-p 8080:80 \
docker.io/library/nginx:alpine
ls -Zd "$HOME/web-data"The runtime applies a category-aware container_file_t label. Do not replace this with a random chcon command. A manual label can be lost after relabeling, and it may not match the container that needs the data.
Category isolation and its limits
MCS isolation is useful when several containers run under the same broad container_t policy but must not share mounted data. It is a labeling mechanism, not encryption. A process that gains access to the host, runs with excessive privileges, or uses an unsafe runtime configuration may weaken the intended boundary.
Avoid sharing a private :Z volume between unrelated containers. If shared access is required, use :z deliberately and keep the data set limited. Check the resulting labels after deployment.
Exercise
Two containers both run in container_t. Why can one still be denied access to the other container's files?
Show answer
Their MCS category sets differ. SELinux requires compatible categories in addition to the allowed container type.