Chapter 7: Static Website Hosting (3 OSes × 2 Web Servers)
7.11 Combination 6 — CentOS Stream 9 + Apache
The last combination – CentOS Stream 9 and Apache. First inspect the assigned guest and prepare the named vhost. Compare the actual and expected SELinux labels for its files. Inspect firewalld only if the guest uses it and the exercise needs remote access. Test the selected site after validation and activation.
शेवटचं कॉम्बिनेशन – CentOS Stream 9 आणि Apache. आधी सरावाचा guest तपासा आणि named vhost तयार करा. Files चे actual आणि expected SELinux labels तपासा. Remote access लागणार असेल आणि firewalld चालू असेल तर त्याची स्थिती पहा. Configuration तपासून activate केल्यावर site चा HTTP response तपासा.
आख़िरी कॉम्बिनेशन – CentOS Stream 9 और Apache. पहले अभ्यास वाला guest जाँचो और named vhost तैयार करो। Files के actual और expected SELinux labels जाँचो। Remote access चाहिए और firewalld चल रहा है तो उसकी स्थिति देखो। Configuration की जाँच और activation के बाद site का HTTP response देखो।
Check the assigned guest and current socket owner. The expanded procedure below shows a scoped vhost, file publication, and validation.
cat /etc/os-release
sudo dnf info httpd
sudo ss -ltnp 'sport = :80'
getenforce
systemctl is-active firewalld
Ravindra Bagale's Tip
A same-filesystem move can retain a file’s prior SELinux label. A fresh copy can get destination defaults, with results depending on the options and existing objects. Read both the actual and expected contexts at the new path. Apply a scoped restorecon only when the relevant mapping is correct and the file needs it.
Ravindra Bagale's Tip – मराठी
त्याच filesystem मधील mv मध्ये file चा जुना SELinux label राहू शकतो. नवीन copy चा label हा destination, options आणि तिथे आधीपासून file आहे का यावर अवलंबून असतो. नवीन path साठी actual आणि expected context तपासा. योग्य mapping असून बदल लागेल तर त्या file साठीच restorecon वापरा.
Ravindra Bagale's Tip – हिंदी
उसी filesystem में mv करने पर पुराना SELinux label रह सकता है। नई copy का label destination, options और पहले से मौजूद file पर निर्भर हो सकता है। नए path का actual और expected context जाँचो। Mapping सही है और सुधार चाहिए तो उसी file पर restorecon लगाओ।
Lab
Chala, khalcha lab kara. Assigned hostname ne sample guide cha pahila 404 tapaasa. Mag navi file publish kara ani actual ani expected label paha. Approved mapping barobar asel ani farak asel tar fakt tya file cha label durust kara. Shevti tyach request cha 200 ani olakhichi line tapaasa.
Update a museum's official visitor guide on CentOS Stream 9
A museum volunteer publishes a homepage, a visitor guide and CSS on an Apache training host. The homepage stays available after the update, but the newly transferred guide is rejected when visitors ask for it. The volunteer can open the guide in their own shell. An administrator adds that its spelling matches the URL and that its ordinary mode looks readable. The learner now needs to prove which worker tried to open the file, which folder the vhost selected, and whether that file has the label expected at its destination.
This combination brings together Apache's virtual host and directory rules with the CentOS Stream file policy tools. We will distinguish a copy to a fresh file from replacing or moving an existing object, and we will verify the published file as the server sees it. One lab installs and checks a new synthetic guide without altering any real webpage. An offline exercise proves the underlying file operations in a scratch tree and uses an explicit model to reason about type mappings. You can use the offline exercise before obtaining a machine running SELinux.
Use an assigned CentOS Stream 9 system for privileged setup. Before switching any service, confirm that the system is dedicated to this lesson and identify its existing listener. When another site's process already owns port 80, leave it running and use a separate assigned machine or the offline exercise. An Apache package and synthetic HTML are sufficient for this release. There is no need to alter Nginx, add database components, or create a public TLS listener to study one static file's access decision.
Choose the RPM package and inspect the approved service
Check /etc/os-release for CentOS Stream and its version. Record the actual guest identity, including its assigned instance ID when using EC2. From the approved shell, confirm the state of httpd, the RPM package for Apache in this distribution, and the service using the same name under systemd. A managed web process called apache2 is common in Ubuntu. A copied command using that name on this machine may query or manipulate the wrong unit. The running service and file layout tell you which case you have.
cat /etc/os-release
id
rpm -q httpd
sudo dnf info httpd
sudo ss -ltnp 'sport = :80'
systemctl is-active httpd
systemctl is-enabled httpd
getenforce
Review the output of each check. An uninstalled package or inactive service can give a nonzero status before installation. The socket listing shows which process can receive requests at the specified port. The package queries show different states for a candidate from configured repositories and an installed RPM. The last command reports the guest's current SELinux mode. Record these facts up front. If another service binds the intended socket, the first corrective action is to choose a suitable lab placement, not to disable that service.
Install using sudo dnf install httpd on the approved guest after reading its transaction summary. Inspect the packaged unit with systemctl cat httpd. The expected configuration layout has a main file under /etc/httpd/conf, module fragments under conf.modules.d, and site fragments under an included location such as /etc/httpd/conf.d. Verify the actual include in the guest. A directory convention helps narrow the search, while the loaded configuration and virtual host map show which files influence the running service.
sudo dnf install httpd
rpm -q httpd
httpd -v
systemctl cat httpd
sudo httpd -M
sudo httpd -S
sudo apachectl configtest
The loaded modules matter because directive names are provided by Apache core or by modules activated in the configuration. The lab relies on standard directory index, authorization and logging features. Confirm the package provides those features before applying a snippet copied from another host. In a custom service check that your test and the active unit read the same configuration arguments. A valid file loaded only by a test command can't explain what a separate service produces on port 80.
Prepare an explicit public release and check its actual context
Use a fresh public root for the synthetic visitor site at /var/www/museum-hours-lab. The first three files are index.html, 404.html, and css/museum.css. Use “Museum visitor entrance” for a homepage marker, “This museum page is unavailable” in the missing-page document and a CSS class named .visitor-hours. You will add visitor-guide.html after the initial validation. Give it the marker “Visitor guide revised for this exercise”. Put only approved sample public files in the root. Use the staging and mode instructions from the earlier copying lesson for the initial three files.
Check ordinary directory and file access for the worker. A default mode such as 0755 for directories and 0644 for public sample files often suits the exercise, subject to ownership, access-control settings and the host's policy. The run user must traverse the entire path, including its parent directories. The volunteer's ordinary access to a home folder may differ from the web worker's ability to traverse it. Publishing into a dedicated site directory also avoids granting access to anyone's normal login home. Keep the site publisher's write access limited to what is needed.
ROOT=/var/www/museum-hours-lab
namei -l "$ROOT/index.html"
ls -ld "$ROOT" "$ROOT/css"
ls -Zd "$ROOT" "$ROOT/index.html" "$ROOT/css"
matchpathcon "$ROOT/index.html"
getenforce
Compare the actual SELinux labels with the expected file context for the published path. The label includes a type field used by the loaded policy to decide which processes and operations may use it. On the expected targeted policy the type for ordinary read-only public website content is commonly httpd_sys_content_t. The process context under ps -eZ varies with how the process was installed and started. Determine the actual values instead of assuming a single label covers every setup. If both expected and actual types disagree with the planned use, an approved mapping may be missing.
When matchpathcon already expects the intended type, do not add a duplicate custom mapping. Preview a scoped restore and apply it only where the files disagree. If the approved path genuinely has no suitable expected web type, inspect existing customizations with sudo semanage fcontext -l -C and ask the policy owner for a narrowly scoped site rule. On the expected package layout policycoreutils-python-utils supplies the management utility if it is absent. Once that rule is approved, the restore and verification should target this exact release.
# Only if the fresh exercise root needs a new context mapping.
sudo semanage fcontext -a -t httpd_sys_content_t '/var/www/museum-hours-lab(/.*)?'
# Preview and review before applying a scoped context repair.
sudo restorecon -nRv /var/www/museum-hours-lab
sudo restorecon -Rv /var/www/museum-hours-lab
matchpathcon -V /var/www/museum-hours-lab/index.html
The first command establishes the expected context where policy needs a new rule. The preview reports what would change, and the apply command changes the current labels to match the policy. Because normal web roots often already have a relevant rule, the exercise might need only checking, with no label writes. Keep SELinux in its assigned mode. Changing mode would alter more than this one release and would not teach you how the file acquired its current attributes.
Make the museum vhost select only the intended release
The test hostname is museum-guide.example.test. Its .test suffix is for practice, so the exercise will send that name with a local destination. A public DNS record is a separate deployment choice. The socket accepts a connection before HTTP host selection, and eligible virtual hosts can share the same port. A raw request to the instance address alone can select the default. Keep any other approved virtual host and its root protected while adding this new definition on the dedicated instance.
<VirtualHost *:80>
ServerName museum-guide.example.test
DocumentRoot "/var/www/museum-hours-lab"
<Directory "/var/www/museum-hours-lab">
Options None
AllowOverride None
AllowOverrideList None
Require all granted
DirectoryIndex disabled
DirectoryIndex index.html
</Directory>
ErrorDocument 404 /404.html
ErrorLog "/var/log/httpd/museum-hours-lab.error.log"
CustomLog "/var/log/httpd/museum-hours-lab.access.log" combined
</VirtualHost>
The Listen directive in the main service still creates the socket, and the block's port determines which requests can select it. The root and the directory rule refer to the same approved path. The authorization rule is for the public museum files. It does not grant general filesystem or SELinux access to the worker. The local error body also belongs to this site and needs readable attributes. The access log uses a configured format alias. Check the current definition of combined and the site-specific logfile paths before installing the candidate.
The ordinary site can serve its approved index and individual files without directory listings and without per-directory overrides. A file outside the declared set should not be placed into the publish tree merely because the CMS did not link to it. A direct public URL may still resolve. Inspect any paths that a different included rule might map. This fresh exercise uses regular files, so the selected path and worker-visible document are both reproducible.
(
set -eu
candidate="$PWD/museum-hours-lab.conf"
destination=/etc/httpd/conf.d/museum-hours-lab.conf
test -f "$candidate"
test ! -L "$candidate"
sudo sh -c '
set -euC
test ! -e "$2"
test ! -L "$2"
umask 022
cat "$1" > "$2"
' sh "$candidate" "$destination"
sudo apachectl configtest
sudo httpd -S
)
Save the block as the candidate in your workspace first. The helper assumes the active includes were verified, no concurrent changes are taking place, and the protected destination is new. If a destination already exists, determine which configuration owns it before continuing. If tests fail after writing the new file, fix or remove that exact file and obtain a clean parse. With an approved active service, reload using sudo systemctl reload httpd. On a dedicated lab image where the service is inactive, use the approved sudo systemctl start httpd after validation. Check the active state and listener before sending requests.
Distinguish writing bytes, moving a file, and creating a new file
File names are directory entries. On a Linux filesystem an inode is the underlying object that holds metadata about a file, including permissions and where the filesystem stores its contents. A name can change while the inode stays the same. File ownership, ordinary modes and extended attributes do not necessarily change just because the object moved. SELinux labels on ordinary supported local Linux filesystems are among those attributes. This model lets you predict what evidence to collect without memorizing a single rule about every possible copy or move command.
On the same filesystem an ordinary rename can move a file's name into the published directory while keeping the same inode. If it carried a home directory type that the web worker cannot use there, the renamed file may still have that type. A move across filesystems can require a copy and removal of the source, with attribute handling affected by the tool and destination. Copying a new file often creates a new inode in its destination. Its label reflects the creation rules or any explicit options that preserve attribute information. Verify the actual result after transfer.
Overwriting the contents of an existing destination can leave the original destination inode and its metadata in place. Other tools stage a separate file and then rename that file over the target, so its inode and attributes may change even though the full public path stays identical. Archives and backups can also preserve contexts or recreate defaults according to tool options. Learn the publication mechanism you are using. In each case the URL merely requests a named resource. The HTTP worker must resolve the name to a specific readable object and be authorized for that object in its current context.
| Operation | What often happens | Evidence to record |
|---|---|---|
| Same-filesystem rename | The file keeps its inode and existing stored label while its name changes. | Device and inode numbers before and after, actual label and expected destination type. |
| Plain copy to a new target | A new object is created and receives attributes according to its destination and creation rules. | Existence, byte comparison, actual mode and context at the published path. |
| Copy with context preservation | The requested source context can be retained where the policy and filesystem allow it. | The exact tool options and observed label, which may differ from the destination expectation. |
| Replace via a prepared file and rename | The public name now leads to the prepared object's attributes. | Resulting inode and context, then the named site's response. |
For the controlled lab create one fresh target with a chosen public read mode and verify its actual context. Treat any other transfer method as a planned variation. A command that succeeds in the publisher's shell tells you that publisher created or moved the file. The worker's later permissions are a separate observation. If a path has the correct expected type but the result still differs, inspect the exact file, each ancestor, and the access log and policy evidence before making a broad change.
Lab one. Publish one fresh guide and read both request outcomes
Prepare the three initial marked files and the named site on the assigned guest. The guide file should be absent from the published directory at first. Create a small visitor-guide.html sample containing the update marker in your learner workspace. Keep that source outside the served tree. Before adding it, use the following shell function from the same guest to verify the initial homepage and ask for the guide path. The address override limits the connection to the chosen port on this machine and keeps the practice hostname in the request.
museum_request() {
host=museum-guide.example.test
curl --noproxy '*' --resolve "$host:80:127.0.0.1" \
--silent --show-error --max-time 5 --include "http://$host$1"
}
museum_request /
museum_request /css/museum.css
museum_request /visitor-guide.html
Read the response lines and bodies individually. The homepage and stylesheet should return 200 with their expected markers and suitable media types. The unknown guide should return 404 and the museum's custom error body. Write down that request and the intended destination filename. Having a missing-file observation before a controlled write is useful. It demonstrates that the new file is what introduced the new successful path. If the first guide request succeeds instead, inspect the already published file and the selected vhost before continuing.
Now install the source as a fresh file under the approved root. This helper assumes the site belongs to the exercise, has no concurrent publishers, and allows this one public path. It checks the source type and refuses a target that already exists. The command sets the ordinary mode explicitly. It is followed by the ability to compare bytes and observe the guest's actual and expected labels. It does not assume a method of transfer guarantees the label will be correct.
(
set -eu
source="$PWD/visitor-guide.html"
target=/var/www/museum-hours-lab/visitor-guide.html
test -f "$source"
test ! -L "$source"
test -d /var/www/museum-hours-lab
test ! -L /var/www/museum-hours-lab
test ! -e "$target"
test ! -L "$target"
sudo install -m 0644 -- "$source" "$target"
cmp "$source" "$target"
ls -lZ "$target"
matchpathcon "$target"
)
If the actual type differs from the approved expectation at that path, use sudo restorecon -nv /var/www/museum-hours-lab/visitor-guide.html to see the scoped repair. After confirming the mapping, use sudo restorecon -v on this exact file and verify with matchpathcon -V. If the intended mapping is missing, review the scoped rule rather than guessing a label. Fix only the evidence-backed mismatch and leave the host's current enforcement mode unchanged. Record the work whether or not the first copy needed correction.
museum_request /visitor-guide.html
sudo tail -n 12 /var/log/httpd/museum-hours-lab.access.log
sudo tail -n 12 /var/log/httpd/museum-hours-lab.error.log
sudo ausearch -m AVC,USER_AVC -ts recent -i
Expect the same guide URL to return 200 and “Visitor guide revised for this exercise”. There is no need to reload the site configuration after adding a file within its already selected published root. A reader's browser can still show a cached previous response under some caching conditions. The isolated curl request helps compare what the server now returns. Read its status even if the body contains a pleasing error page. Match your before and after requests against the site's access log so a likely-looking result is tied to this vhost.
If the request fails, check name, selected root, filename, policy and the worker's ordinary read permissions in order. A recent AVC with the right process and path can narrow the work to SELinux. If an event identifies a directory traversal operation, do not relabel only the last filename and expect success. If the event is unrelated to the requested path and time, it is not sufficient evidence. Troubleshoot the new file without editing the working homepage. Remove the guide only at the end if it is the single synthetic file you added and the owner wants to restore the original sample.
Lab two. Observe file identity and model where labels can come from
You need Python 3 on a local machine. The first part creates synthetic content inside one temporary directory, moves one file by an actual same-filesystem rename, and copies its bytes to a genuinely fresh file. Python observes the real device and inode numbers. The second part prints illustrative label records that make the context reasoning concrete. Those labels are written into the program as training data. A laptop without SELinux cannot use the same procedure to verify a CentOS policy outcome.
python3 - <<'PY'
from pathlib import Path
from tempfile import TemporaryDirectory
import os
import shutil
with TemporaryDirectory(prefix="museum-release-") as area:
base = Path(area)
inbox = base / "inbox"
web = base / "public"
inbox.mkdir()
web.mkdir()
original = inbox / "draft-guide.html"
original.write_text("Visitor guide revised for this exercise\n")
moved = web / "moved-guide.html"
copied = web / "copied-guide.html"
def identity(path):
st = path.stat()
return st.st_dev, st.st_ino
before = identity(original)
os.rename(original, moved)
assert identity(moved) == before and not original.exists()
shutil.copyfile(moved, copied)
assert identity(copied) != identity(moved)
assert moved.read_bytes() == copied.read_bytes()
print("rename: same inode, new path")
print("copy: different inode, identical bytes")
example_expected = "httpd_sys_content_t"
example_actual = {
moved.name: "user_home_t",
copied.name: "httpd_sys_content_t",
}
for name, actual in example_actual.items():
matches = actual == example_expected
print(f"model: {name} actual={actual}, expected={example_expected}, "
f"{'matches' if matches else 'review before publish'}")
PY
The move and copy results both include the same visitor message because the exercise preserved its bytes. They represent different objects at the end. That is the underlying file observation. The synthetic label rows show one possible outcome under a labelled policy, where the renamed object's retained metadata differs from what the published path expects. The array is a demonstration and does not read the host's actual labels. Use ls -Z and matchpathcon in the first lab to observe the real context on CentOS.
Try extending the local exercise with a separate approved temporary candidate that contains the phrase “Second exhibit hours”. Replace the copied file's bytes in place with those bytes and compare its inode again. Then create another staged candidate and use a guarded rename over the same practice path inside the temporary directory. Compare how the inode behaves in these two variants. These experiments help explain how an upload can produce a new timestamp or content without yielding the label behaviour a beginner expected. Python removes the scratch directory when the script exits.
Keep file access and incoming network access separate
If local requests to the guide work, you have evidence about the Apache configuration and file read for that local path. You still need a separate approved client to test any remote access question. Check the actual address and port, the permitted EC2 routing and security groups, and any active guest firewall. There is no requirement to create a public endpoint for the file-operation lesson. If the remote client is part of the assignment, use the owner-provided access path and the same vhost name to isolate that variable.
sudo ss -ltnp 'sport = :80'
systemctl is-active firewalld
# If firewalld is active on the approved guest:
sudo firewall-cmd --get-active-zones
sudo firewall-cmd --get-default-zone
Firewalld is a guest network control with runtime and saved state. The applicable zone depends on the incoming interface or source assignment, so a rule in the default zone alone does not automatically describe every interface. Inspect the active zone selected by the permitted client path and compare its rules with what the host owner expects. The local guide lesson needs neither a permanent firewall change nor a guest HTTPS opening. A running Apache listener does not by itself require either. If a timed training exception is authorized, document its source, purpose, and cleanup separately.
An HTTP denial in the right site log demonstrates that the server processed enough of that request to return a status. A connection failure with no such request might never have reached the process. The distinction saves time and stops a permission fix from turning into an unrelated network exposure. Record the local and external outcomes with their exact schemes and port numbers. When a browser switches to an HTTPS address or follows a redirect, its response could come through a different endpoint that the plain HTTP guide exercise does not cover.
Follow the request through Apache and two file access checks
At the museum entrance the HTTP request first reaches the socket built by Apache. The destination address and port identify a candidate group, and the name in the request selects one of its virtual hosts. Next the URI maps to the document root and the intended path. Site-level authorization gives the request permission to use the public directory. The service process then needs the operating system to resolve the path and let it read the object. Each of these decisions can prevent the guide from reaching the reader.
Consider the same URL requested after a typo in the candidate root. If Apache uses an earlier folder containing an older guide, the HTTP request may still return 200. The old response marker reveals what was actually served. If the wrong folder has no guide, the custom error body may return 404, and comparing the selected root and manifest makes that result understandable. A label report from the folder you intended to configure cannot explain a request that actually used the older folder. Check the mapping first when the paths disagree.
Now compare a 403 for an existing guide with a 403 for browsing a directory without its index. Apache can make a directory presentation decision before any attempt to read the specific guide. A server-wide file restriction can also reject a path by name even when ordinary Linux mode and SELinux are correct. Look at the exact file request, server log, guest policy report and client path to tell these cases apart. A status is a starting fact. Its cause is the event and configuration in that request context.
On the guest the discretionary access check accounts for the file owner, group, other modes and any applicable access-control lists. SELinux type enforcement accounts for the source domain, object type and requested operation. open on a file and search on a directory are examples of distinct operations. A confined worker may be allowed to read a normal document and denied write access in the same site. A public static release needs read access for the selected document. Read-only presentation is compatible with strong separation between the publisher and server accounts.
Read the current and expected type for the new guide
Write out a worked example based on synthetic output. Suppose the public guide has current context unconfined_u:object_r:user_home_t:s0. The expected rule reports system_u:object_r:httpd_sys_content_t:s0. Separate the fields at the colons. The important practical difference in this example is the type field, user_home_t compared with httpd_sys_content_t. An audit event involving the intended Apache process and the mismatched file can help establish that type enforcement prevented the attempted read.
Use the full verification output when reporting the fix. SELinux's expected mapping may have been changed by local rules. If the expectation already covers the site, the administrator can preview a restore for the guide alone. If the site is intentionally using a nonstandard location and no relevant expected type is defined, record why a scoped mapping needs approval before applying it. A direct temporary type change made separately from its desired mapping can later be undone when restore runs. A reproducible release keeps the intended rule and actual result consistent.
An audit record can describe an ordinary child of the target directory or an ancestor visited during name resolution. A target class of directory describes a different access from a target class of file. Check the affected name and the worker's source type under the same request timestamp. Unrelated policies may log recent activity too. This is why a time-bounded audit search followed by manual matching is preferable to generating a new general allow policy from every event. Fix the published file or directory expectation first when that is what the observed evidence supports.
If the guest's SELinux mode is permissive, events can be logged without blocking the request under that policy. An observed denial message there may describe a situation that would be blocked in enforcing mode. It need not explain a concurrent 403 from another check. Record the current mode before reasoning from labels. In any mode the Apache authorization settings and ordinary file access still matter. The exercise succeeds when the chosen configuration and actual host policy accept the required public requests, with the intended protections left in place.
Compare common symptoms and justify a narrow correction
| Observed symptom | Follow-up | What the follow-up can establish |
|---|---|---|
| The URL shows the initial Apache page. | Run the named request and inspect httpd -S. | Whether the test selected the museum virtual host as intended. |
| The homepage works but the new guide is absent. | Compare the prepared guide to the actual root and path. | Whether the published directory contains the correct name and bytes. |
| The museum log shows a denial and a matching file AVC appears. | Compare actual and expected path context and ordinary access. | Whether a scoped file label repair or mapping review fits the evidence. |
| The guide is readable for an administrator and rejected by Apache. | Review the actual worker context and directive scope, plus path traversal. | Whether the administrator read was in a different permission and policy context. |
| The guide works locally and the permitted remote test cannot connect. | Check destination, binding, allowed route and applicable controls. | Whether the connection can reach the intended service. |
For the first row, remember that testing by address can make a welcome page entirely legitimate. Request the exact assigned hostname and compare its marker. For the second row a guide spelled Visitor-Guide.html is a different path from visitor-guide.html on a typical CentOS filesystem. Check this even if a local case-insensitive preview resolved both spellings. A copied name or directory structure can explain the failure without changing any policy.
For the third row a correct repair is one that changes the evidence you identified. If a file has a stale label and the expected policy is suitable, restore it at the approved exact path and retest. If a parent directory lacks ordinary traverse permission for the web worker, review that permission with the publisher. If the open request never reached the guide because it selected another vhost, correct the host comparison. Keep a previous successful homepage request available as a control so you can see whether other routes unexpectedly changed.
Compare the published guide with the approved visitor copy
Two guides can have the same filename and look similar at a glance while containing different visiting hours. The staging approver should know which version was approved. Before installing the lesson guide, record a distinctive text marker or use sha256sum on the staged file. The checksum represents the exact file bytes. It remains the same when those bytes are copied without modification, even if the destination inode and label are different. After installation compare the checksum and file attributes separately. This checks content identity as well as publishability.
If the server permits access and the response text still describes yesterday's visit schedule, check how the public site got to those bytes. The selected target might already hold another guide, so compare its local bytes and named HTTP response. If both show the old marker, the publication step used the wrong candidate or path. If the correct file exists at the right path and the direct request returns it, look at the reader's delivery path and cache conditions. The active site may be served through an intermediary outside the local exercise, which can have its own copy.
Restore behaviour intentionally if the new guide turns out to contain a mistake. Replacing it with the approved older bytes may preserve or create inode attributes according to the chosen installation method. Check its actual label and modes once more after the replacement. A good rollback record cites the expected content and specific URI, not merely the fact that a particular filename returned 200. If this was a new practice URL that should disappear, restoring its intended state means removing its exact newly created file and checking the former 404.
Review context-sensitive files after restoring an archive
Suppose the museum moves to an identical assigned instance and restores a tar archive of the public site. The archive may preserve file label attributes if they were collected and restored with appropriate tooling and policy. In other setups restoring the bytes creates objects with new attributes. Either way, compare the restored directory and file labels with the actual target machine's expected mappings. The previous guest's success cannot establish the policy of the new one. Read the restore plan and check which metadata will be carried over before exposing the release.
For a simple practice reinstallation you may only need a byte-level copy of the sampled public files into a fresh approved location. The correct labels can then be assigned from that guest's policy and checked after installation. A backup retaining more settings should have a matching change record so administrators know whether a scope-specific mapping must also be recreated. Use a newly created review directory for archives instead of expanding unexamined files into the active document root. This gives the reviewer a chance to inspect the filenames, links and content before any request can reach the files.
Record which virtual host and instance the restored paths belong to, then make the homepage, CSS and guide requests. The first known successful response is a control. The guide should carry the restored release marker and the route for an intentionally missing document should still return the expected 404. Any policy issue should be checked at its actual path. This read-and-repeat approach lets you recover the release without hand-editing labels for private or unrelated directories during the restore.
Preserve the original configuration and record cleanup
Close out the exercise using the before-state record. If you added one site candidate, remove or archive that exact file outside the active include tree. Confirm a clean apachectl configtest and virtual host map. Apply the revised configuration through the approved service operation and verify that the intended prior sites still respond. The process may use another default for the old host, so absence from the active vhost map and a named response check together give clearer cleanup evidence.
If you added only the guide to an otherwise continued exercise, remove just the separately created sample file and repeat its path to restore the original 404 case. If the whole public root is being retired, remove it only after confirming no active vhost or current reviewer needs it. Keep the site's previous release and log data according to the trainer's plan. Do not delete a common parent containing other public roots. A timed remote exception should expire or be removed as specified by the owner, independently of the file or service state.
Remove an SELinux mapping only if you were the person who added it for this exercise and its owner approved cleanup. Record the exact expression /var/www/museum-hours-lab(/.*)? if it was created. Removing a mapping changes expected labels and does not automatically rewrite any existing file context. If the directory remains, re-evaluate what its labels should be in its next approved use. Standard policy rules outside the lab scope should be left in force. For a temporary EC2 instance, follow the resource inventory and check whether any volume or address is separately retained.
Interview questions with explained answers
Why can a same-filesystem move produce the wrong SELinux type?
A rename can leave the underlying object and its attributes unchanged. Its new location may expect a different type. Compare the actual label to the installed path expectation, then use a narrow approved repair.
Does copying always fix the problem?
Copying into a new object can let destination creation rules choose the label. Options and existing destinations can change that result. Verify ordinary permissions, actual context and expected context at the published path after the operation.
Why is an Apache public directory grant insufficient on its own?
It grants authorization in Apache's request handling. The OS still decides whether the running worker can traverse the path and read its file under account permissions and host policy.
When would you change a file context mapping rather than run restorecon?
Review a narrowly scoped mapping when the expected type itself is unsuitable for the approved site path. A restore applies the existing rule. Verify the rule and real labels afterward.
What confirms the new guide update without restarting Apache?
Use the exact host and path before and after the fresh file installation. Verify the expected successful body and status with a matching access record. The current vhost already maps requests into that root.
Check your understanding
A moved file's public path changed and its inode did not. What does that tell you?
Show answer
It can be the same underlying object with its original attributes. Inspect its current and expected file contexts under the new name.
The site file exists but the current and expected labels agree on an unsuitable type. Which review is next?
Show answer
Check whether a site-specific expected mapping is warranted. Reapplying the same existing expectation will not establish a different type.
Why is 403 alone insufficient evidence of a SELinux problem?
Show answer
Directory listing rules, Apache authorization, filesystem access and host policy can all lead to an access failure. Correlate the exact request and matching event.
The correctly named local site works but a remote test times out. Should you relabel its homepage first?
Show answer
Start by verifying the remote path and listener. The local result shows that the existing policy allowed that request to read the homepage.
What does
systemctl is-enabled httpdreport?Show answer
It reports unit activation setup such as enablement for boot. Inspect current active state and the listener separately.
Practise explaining a publication failure
Compare the same guide's path, identity and attributes after the model rename and copy. Explain which observations are real and which are hypothetical labels.
Build a report from an observed before and after guide request. Include host, expected root, requested URI, status, body marker and one scoped log line.
Write the approved cleanup order for a site file, its public root and a temporary firewall exception. Show how each step can be verified without changing another service.
Revision cards
httpd- Expected Apache package and service name for CentOS Stream. Confirm the actual unit and config parameters.
- File identity
- A device and inode pair can distinguish changing a pathname from creating a genuinely new file.
- Source and target contexts
- Policy evidence identifies a process's context and the resource's context for a particular operation.
restorecon- Apply the expected path context. Use preview and verification for the affected exercise file.
- Custom missing response
- A missing known URL should send the useful custom body and keep a true missing-resource status.
- Remote path inspection
- Service socket, guest firewall zone and applicable cloud network controls affect delivery before Apache responds.
Official sources
- CentOS Stream project
- RHEL 9 Apache package, service and configuration
- SELinux context mapping for web roots
- Red Hat examples of preserving and restoring file labels
- SELinux denial troubleshooting
- Linux rename system call
- Restorecon options and context behaviour
- Compare file contexts with the policy
- Apache virtual host resolution
- Apache directory and error settings
- Apache authorization core
- Apache directory index
- Firewalld active zone inspection
- EC2 VPC security groups
- Curl host address override and response options
- Reserved testing names