Use it when a service cannot access files that have the wrong type.
Contexts
An SELinux context (label) has user:role:type:level, e.g. system_u:object_r:httpd_sys_content_t:s0. The type is what most policy rules use.
1. ls -Z <path> — type?
2. Expected type: semanage fcontext -l | grep <path> or matchpathcon <path>.
3. Fix: restorecon -Rv <path>.
4. Custom path: semanage fcontext -a -t <type> '<path>(/.*)?' + restorecon.
5. Retest the service.
file label (type) and process domain → policy allows the domain to access the type
For SELinux → Contexts, continue with the first unproven Topic check: Record exact host, distribution/kernel, boot ID, time window, workload, identity and the authoritative configuration/policy source for Contexts. If that boundary is healthy, advance to the adjacent check: Read back the effective runtime state and precedence rather than assuming an edited file, package state or service status is active. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.
Continue only after interpreting the current observation.Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
process domain + file/socket/port context → policy type rules/transition → AVC decision → operation → workload
Healthy evidence: processes and objects carry expected persistent contexts, transitions occur as designed and workload operations match policy
Step 2 Verification and output interpretation Verify boundary
Verification chain. process domain + file/socket/port context → policy type rules/transition → AVC decision → operation → workload
Step 3 Specialized verification Verify boundary
Display contexts on the process and every relevant file/path component, then compare file labels with the expected policy mapping. Use restorecon in check/verbose mode to find drift before changing it. For a denial, match source domain and target type from the AVC to the observed objects. After applying a persistent mapping and relabel, repeat the real access under the original service domain. A correct-looking label alone is not evidence the policy permits the requested class/permission.
Step 4 Commands Verify boundary
ls -Z /var/www/html
ps -eZ | grep httpd
id -Z
Step 5 Failure modes and next checks Narrow the fault
Suspicious evidence: wrong type/domain, unexpected transition, unlabeled/default context, context differs across paths or labels are modified without persistent mapping
Step 6 Special cases and limits Narrow the fault
Pathnames do not determine access directly; the resolved object’s label participates in policy. Two files with the same Unix owner/mode can have different SELinux outcomes. Moving content between filesystems or restoring from backup can alter xattrs. Context correctness does not override DAC or application policy. Keep persistent mapping, actual xattr, process domain and requested permission as separate evidence.
Step 7 Common mistakes Narrow the fault
- Moving files with
mvand keeping the old context.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
Files moved with mv keep their old label; copied files get the target directory's label. Set permanent rules with semanage fcontext -a -t <type> '<path>(/.*)?' then restorecon -Rv <path>. chcon changes are lost on relabel.
getenforce / sestatus— mode and policyls -Z <path>— file contextps -eZ | grep <proc>— process contextausearch -m AVC -ts recent— recent denialssemanage fcontext -l | grep <path>— context rules for a path
ReferenceImportant terms & boundaries6 sections · depth on demand
What this shows and what it does not
Context diagnosis is resolved when the exact subject/object contexts are resolved and matched to policy expectations for the failing operation.
In depth
SELinux contexts: user, role, type and level
Every process and every object (file, port, socket) has an SELinux context. Red Hat's SELinux guide says it has four fields: user, role, type and security level. In the targeted policy, the type does almost all the work: policy rules decide which process types (domains) may access which object types. Types end in _t. For example, httpd_t (the web server domain) may read httpd_sys_content_t (web content).
The four fields
| Field | Example | Role in the targeted policy |
|---|---|---|
| SELinux user | system_u, unconfined_u, staff_u | Maps Linux users to allowed roles |
| Role | system_r, object_r | object_r for files; roles for processes |
| Type | httpd_t, httpd_sys_content_t | The main access control decision |
| Level | s0, s0:c1,c5 | MLS/MCS: sensitivity and categories (used by containers and VMs) |
Seeing contexts
| Object | Command |
|---|---|
| Files | ls -Z, stat -c %C |
| Processes | ps -eZ, id -Z (your own) |
| Ports | semanage port -l |
| Network connections | ss -Z |
Process and file types together
| Service | Process type | Files it may read or write |
|---|---|---|
| Apache, nginx | httpd_t | httpd_sys_content_t (read), httpd_sys_rw_content_t (write), httpd_log_t |
| sshd | sshd_t | ssh_home_t (~/.ssh), sshd_key_t |
| PostgreSQL | postgresql_t | postgresql_db_t |
| Containers (podman) | container_t | container_file_t, with unique MCS categories per container |
MCS categories
Container engines and libvirt give each container or VM a unique pair of categories, such as s0:c112,c907. Even with the same type, one container can't access another's files, because their categories differ.
host$ ps -eZ | grep -E "nginx|sshd" | head -3
system_u:system_r:httpd_t:s0 1203 ? 00:00:00 nginx
system_u:system_r:sshd_t:s0-s0:c0.c1023 842 ? 00:00:00 sshd
host$ id -Z
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
host$ ls -Zd /var/www/html /home/alice/.ssh /var/lib/pgsql/data
system_u:object_r:httpd_sys_content_t:s0 /var/www/html
unconfined_u:object_r:ssh_home_t:s0 /home/alice/.ssh
system_u:object_r:postgresql_db_t:s0 /var/lib/pgsql/data
host$ podman run -d --name web1 nginx && ps -eZ | grep container_t | head -2
system_u:system_r:container_t:s0:c112,c907 22011 ? 00:00:00 nginx
host$ sudo semanage port -l | grep -w http_port_t
http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000
Reading the port list
http_port_t covers the ports httpd_t may bind to. A web server configured for port 8081 would be denied, until that port is added with semanage port -a.
Documented example, not captured output.
How it works at runtime
Contexts is part of SELinux → Contexts. SELinux Contexts are security labels associated with subjects and objects, typically represented as user:role:type:level, with type/domain commonly driving targeted-policy access decisions.
Topic-specific state model. SELinux Contexts are security labels associated with subjects and objects, typically represented as user:role:type:level, with type/domain commonly driving targeted-policy access decisions.
Interpretation rule. - A context string exists ≠ it is the expected policy context for that path/process.
- Matching Unix owner/mode ≠ matching SELinux type or domain.
Specialized mechanics
An SELinux security context is commonly represented as user:role:type:level, with type usually driving type-enforcement decisions for files and processes. Process domains are types applied to processes; file types label objects. Current file context is stored as extended metadata, while the policy’s file-context database defines the expected default label for path patterns. A copied/moved file can retain or acquire labels differently depending on operation and destination semantics.
Quick reference
SELinux contexts have four fields: user:role:type:level, e.g. system_u:object_r:httpd_sys_content_t:s0. Type enforcement uses mostly the type; MLS/MCS uses the level (containers get unique categories like s0:c123,c456 to isolate them from each other).
id -Z
ps -eZ | grep sshd
ls -Z /etc/shadow
seinfo -t | grep httpd # setools-console
sesearch -A -s httpd_t -t httpd_sys_content_t -c file
Process types transition on exec according to policy (e.g. init_t executing httpd_exec_t becomes httpd_t).
Limits and how it fails
Primary failure point. Context diagnosis is resolved when the exact subject/object contexts are resolved and matched to policy expectations for the failing operation.
ReferenceConfiguration & state2 sections · depth on demand
Configuration, persistence and lifecycle
Distribution/platform context. Contexts owns interpretation of SELinux subject/object security contexts.
Specialized lifecycle
Use policy-aware tools to define persistent path-to-type mappings and apply them. semanage fcontext adds local mappings; restorecon reconciles object labels against the policy mapping. Avoid relying on chcon for durable configuration because relabel operations can restore policy defaults. When designing service content paths outside standard locations, select the documented type for the service rather than granting broad access to a generic type. Account for mount labeling options on filesystems that cannot store normal xattrs.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in SELinux → Contexts. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://selinuxproject.org/page/Main_Page · confidence 94%Authoritative Linux project/vendor documentation reviewed for bounded reference claims: SELinux security contexts, file labeling and policy applicability. Documentation-based technical verification only; not lab or production-runtime proof. The schema vendor_doc method is used for authoritative project/vendor documentation; deployment applicability remains separate evidence.
Basis: https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/using_selinux/ · confidence 93%What changed and what may be affected
Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
Contexts operational reference
Topic-specific lookup boundaries, proof limits and next-step Evidence for Contexts.
| Lookup boundary | Topic-specific reference | Operational use |
|---|---|---|
| Scope / effective state | SELinux Contexts are security labels associated with subjects and objects, typically represented as user:role:type:level, with type/domain commonly driving targeted-policy access decisions. | Establish exactly what this Topic owns before crossing into another subsystem. |
| Fast verification | Pin host + boot/time + real identity/workload → identify authoritative policy/key/trust source → read back loaded/effective runtime state → reproduce one safe allow/deny/handshake test → correlate audit/service/kernel evidence → locate first failed boundary → make the smallest persistent change → repeat original workload + regression/recovery check. | Use the shortest evidence path first; a fast check is a boundary test, not blanket proof. |
| Verification chain | process domain + file/socket/port context → policy type rules/transition → AVC decision → operation → workload | Trace requested/configured state through effective state to the observed workload result. |
| Failure boundary | Context diagnosis closes when the exact subject/object contexts are resolved and matched to policy expectations for the failing operation. | Stop broad troubleshooting at the first boundary that is not supported by evidence. |
| Positive evidence | Correlated Linux security/trust evidence can establish this proof path: process domain + file/socket/port context → policy type rules/transition → AVC decision → operation → workload | Use this observation only for the specific claim it actually supports. |
| Evidence limit | It does not independently prove unobserved identities, objects, policies, namespaces, endpoints or time periods. Context diagnosis closes when the exact subject/object contexts are resolved and matched to policy expectations for the failing operation. | Do not promote a local success signal into end-to-end or adjacent-dependency proof. |
| Next troubleshooting check | Continue from the first unproven security/trust boundary, capture the adjacent effective state and audit/handshake evidence, make only the demonstrated persistent change, then repeat the original workload plus recovery/regression checks. | Continue to the next unresolved boundary while preserving the original test condition. |
Contexts · operational reference
Compact Linux state, persistence, verification and boundary reference for fast lookup.
| Reference boundary | Contexts |
|---|---|
| Topic path | SELinux → Contexts |
| Runtime state | SELinux Contexts are security labels associated with subjects and objects, typically represented as user:role:type:level, with type/domain commonly driving targeted-policy access decisions. |
| Fast checks | - Record exact host, distribution/kernel, boot ID, time window, workload, identity and the authoritative configuration/policy source for Contexts. - Read back the effective runtime state and precedence rather than assuming an edited file, package state or service status is active. - Reproduce one safe allowed/denied or handshake/access test and correlate kernel/service/audit evidence at the first relevant boundary. - Apply the smallest persistent cause-specific change, then repeat the original test plus an adjacent regression/recovery check. |
| Verification chain | process domain + file/socket/port context → policy type rules/transition → AVC decision → operation → workload Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary. |
| Failure boundary | Context diagnosis closes when the exact subject/object contexts are resolved and matched to policy expectations for the failing operation. Boundary chain: process credentials/namespace → path/mount lookup → DAC/ACL/LSM → filesystem metadata → block/device/backend → completion/read-back. |
| Persistence rule | Prove which configuration source owns the state, then prove that the running consumer loaded or generated the intended state. |
Contexts · specialized operational reference
Topic-specific Linux mechanics, lifecycle, proof path and failure-boundary lookup.
| Operational boundary | Topic-specific reference |
|---|---|
| Format | SELinux user : role : type : level |
| File truth | Current xattr vs policy file-context mapping |
| Persistence | semanage fcontext; restorecon applies mapping |
| Proof | Correct process domain/target type + allowed original access |