Lesson 014 · Linux Administration Learning Path

RHEL SELinux Administration and Troubleshooting

· Published · 7 min read

Labelled RHEL Linux administration path highlighting SELinux subject object labels policy AVC evidence durable correction and enforcing validation

SELinux evaluates a mandatory policy decision in addition to ordinary Unix permissions. A denial is evidence that a subject type attempted an operation on an object type that policy did not allow. Disabling enforcement may hide that evidence while exposing the service. The correct response is to confirm the application path, read the AVC, decide whether the behavior is intended and choose a supported boolean, durable label or narrowly reviewed policy change.

Treat SELinux as a separate access-control decision

Discretionary owner/group/mode and ACL checks remain relevant, but passing them does not override SELinux. Labels normally contain user, role, type and level fields; service policy most often depends on types. A temporary chcon change can be lost during relabel. Use semanage fcontext for a durable local mapping and apply it with restorecon.

Booleans expose supported policy choices and can be persistent. Do not toggle a boolean because its name sounds relevant; inspect its description and scope, then test the specific application behavior and unintended access.

Read the complete SELinux decision

LayerQuestion to answerEvidence
SubjectWhich process type made the request?PID, executable, unit and source context
ObjectWhich path/socket/port and target type?Object context and real resolved target
OperationWhich class and permission were requested?AVC fields and application action
Policy choiceIs behavior expected and supported?Documentation, boolean, standard label or reviewed module
VerificationDoes intended access work while unrelated access remains denied?Positive/negative tests with enforcement active

Diagnose an AVC without weakening the host

  1. Reproduce one authorized request and record UTC time, service and path.
  2. Confirm enforcing mode, process context and object context.
  3. Query the audit log for the matching AVC and read source type, target type, class and permission.
  4. Verify ordinary permissions, resolved paths, mounts and application configuration.
  5. Choose the documented standard location/label or supported boolean where it represents intended design.
  6. Create a durable local file-context mapping only for the exact custom path, apply and retest.
  7. Consider a custom policy module only after review proves the behavior is necessary and narrowly scoped.

Collect SELinux evidence and apply a durable label

getenforce
sestatus
ps -eZ | grep httpd
ls -ldZ /srv/example /srv/example/index.html
ausearch -m AVC,USER_AVC -ts recent
sealert -a /var/log/audit/audit.log 2>/dev/null
getsebool -a | grep httpd
semanage boolean -l | grep httpd
semanage fcontext -a -t httpd_sys_content_t '/srv/example(/.*)?'
restorecon -RFv /srv/example
matchpathcon /srv/example/index.html
  • The example label makes content readable to an HTTP service; it does not grant write access. Select the documented type for the real purpose.
  • Generated policy suggestions are diagnostic input, not automatically safe policy. Review every allowed class and permission.
  • Avoid broad recursive relabeling outside the exact approved path.
  • Keep enforcement active during final positive and negative acceptance tests.

Evidence and acceptance criteria

EvidenceHealthy resultFailure meaning
ModeEnforcing with policy loadedPermissive test may hide production denial
AVC correlationTimestamp, subject, object, class and permission match requestUnrelated denial can lead to wrong correction
Path labelmatchpathcon and actual context agreeTemporary or incorrect label
Policy decisionBoolean/label/module has documented narrow purposeOverbroad access or wrong application behavior
AcceptanceIntended request succeeds and denied boundary remainsCorrection weakened more than required

Worked scenario: custom web root works only after disabling SELinux

An Apache virtual host moves content under /srv/customer. Unix permissions permit access, but the files carry a generic type and AVCs show the HTTP process denied read access. Disabling SELinux makes the page load but removes confinement for every service decision.

The administrator confirms the custom path is intended read-only web content, adds a durable httpd_sys_content_t mapping for that exact tree, runs restorecon and retests while enforcing. A separate upload directory receives a purpose-specific writable type only if the application design requires it.

Practical how-to cases

Case 1: Publish content from /srv

Define a persistent file-context rule and apply it rather than copying a transient label. Keep enforcing mode and identify subject type, object type, operation and policy decision from AVC evidence.

sudo mkdir -p /srv/site
sudo semanage fcontext -a -t httpd_sys_content_t '/srv/site(/.*)?'
sudo restorecon -RFv /srv/site
ls -ldZ /srv/site
matchpathcon /srv/site
CheckpointWhat to establish
Expected resultActual and expected labels match and relabeling the filesystem preserves the rule.
If it failschcon alone can be overwritten by restorecon or a full relabel.
Safe recoveryRestore the saved configuration and default labels with restorecon; remove only the custom semanage rule or Boolean change introduced by the lab.

Case 2: Allow a non-default port

Add a reviewed port label and align the application and firewall configuration. Keep enforcing mode and identify subject type, object type, operation and policy decision from AVC evidence.

sudo semanage port -l | grep http_port_t
sudo semanage port -a -t http_port_t -p tcp 8088
sudo semanage port -l | grep 8088
sudo httpd -t
sudo systemctl restart httpd
CheckpointWhat to establish
Expected resultThe port maps to http_port_t and the service binds after its own configuration validates.
If it failsAddress in use and firewall denial are not SELinux denials; inspect the actual evidence.
Safe recoveryRestore the saved configuration and default labels with restorecon; remove only the custom semanage rule or Boolean change introduced by the lab.

Case 3: Choose a Boolean deliberately

Read the Boolean description and enable only the capability the workload requires. Keep enforcing mode and identify subject type, object type, operation and policy decision from AVC evidence.

getsebool httpd_can_network_connect_db
semanage boolean -l | grep httpd_can_network_connect_db
sudo setsebool -P httpd_can_network_connect_db on
getsebool httpd_can_network_connect_db
CheckpointWhat to establish
Expected resultThe persistent state matches a documented application requirement.
If it failsEnabling a broad Boolean without knowing the permitted interactions expands access unnecessarily.
Safe recoveryRestore the saved configuration and default labels with restorecon; remove only the custom semanage rule or Boolean change introduced by the lab.

Case 4: Analyze an AVC

Reproduce one denied lab request, correlate audit time and correct label or configuration cause. Keep enforcing mode and identify subject type, object type, operation and policy decision from AVC evidence.

sudo ausearch -m AVC,USER_AVC -ts recent -i
sudo sealert -a /var/log/audit/audit.log 2>/dev/null
ps -eZ | grep httpd
ls -lZ /srv/site
namei -om /srv/site/index.html
CheckpointWhat to establish
Expected resultThe denial identifies a specific domain, type, class and permission and the correction matches application intent.
If it failsaudit2allow output is a hypothesis, not automatic proof that custom policy is appropriate.
Safe recoveryRestore the saved configuration and default labels with restorecon; remove only the custom semanage rule or Boolean change introduced by the lab.

Independent practice tasks

  1. Fix mislabeled web content without disabling SELinux.
  2. Configure and remove a custom port type mapping.
  3. Compare permissive-domain debugging with global permissive mode.
  4. Explain an AVC where Unix permissions, not SELinux, fail first.

For this lesson on RHEL SELinux Troubleshooting, complete each task without copying the worked command sequence. Record the initial state, exact change, verification, negative test and recovery command. A task is unfinished if it works now but does not survive a reboot where persistence is required.

Troubleshooting by symptom

SymptomInspect firstDefensible next action
No AVC but permission deniedDAC/ACL, application, mount and correct audit source/timeDiagnose other access layers
chcon fix disappearsPersistent file-context database and relabelDefine exact semanage fcontext rule
Boolean fixes too muchBoolean description and affected policy pathsUse standard label/design or narrower reviewed policy
Module suggestion allows many permissionsRaw AVC set and application behaviorDo not install automatically; reduce and review
Service works permissive onlyCorrelated AVC plus process/object contextCorrect intended behavior and retest enforcing

Unsafe operations and recovery boundaries

  • Unsafe: setenforce 0 on production removes enforcement as a diagnostic shortcut and can expose unrelated services.
  • Unsafe: automatically installing audit2allow output may authorize compromised or misconfigured behavior.
  • Unsafe: broad recursive relabeling can break multiple services; define and apply the exact path mapping.

Rewritten knowledge checks

What does SELinux add to Unix permissions?
A mandatory policy decision based on security contexts, classes and permissions.
Which label field commonly drives service policy?
The type field, though the complete context and policy matter.
Why is <code>chcon</code> usually not durable?
A relabel or restorecon can restore the policy-defined context.
How is a durable custom path label defined?
With semanage fcontext, then applied using restorecon.
What is an AVC?
An audit record describing an SELinux access decision, often a denial.
Should audit2allow output be installed automatically?
No. It can encode unintended or malicious behavior and requires policy review.
What is a SELinux boolean?
A supported switch for a defined optional policy behavior, optionally made persistent.
What proves the correction?
Enforcing-mode positive and negative tests plus matching contexts and absence of relevant AVCs.

Guided lab and acceptance test

  1. Install/start a lab HTTP service and serve its default path.
  2. Create a custom read-only web root under /srv with correct Unix permissions.
  3. Observe and correlate the SELinux denial without disabling enforcement.
  4. Add the exact durable file-context mapping and apply it.
  5. Prove the page works and that an unrelated path remains unavailable.
  6. Remove the custom mapping/content and restore the original service configuration.

Primary references

Advertisement