ACLs on Debian: allow public files and protect the private tree
Give www-data traversal to public files, verify denial for private paths, and examine default ACL inheritance and the mask after chmod.
A web process needs to read a static file in public, but that does not require access to code, cache, .env.local, or .git. In our Debian training model, we separated permissions with ACLs and tested actual file opens as www-data.
We first tested the model on a separate Debian 13 virtual machine, then applied it on E-01. Nginx was not installed in this exercise: www-data represents a future web process, and the checks cover filesystem access.
Install only the required tools
We installed acl version 2.3.2-2+b1 on E-01. A fresh simulation showed one new package without upgrades or removals. Comparing the complete package lists afterwards confirmed that all other versions stayed unchanged; the dpkg audit was empty. Teaching commands:
sudo apt-get --simulate --no-install-recommends --no-remove --no-upgrade install acl=2.3.2-2+b1
sudo apt-get --no-install-recommends --no-remove --no-upgrade install acl=2.3.2-2+b1
A short excerpt from the actual installation stdout; other operational lines are omitted:
Setting up acl (2.3.2-2+b1) ...
Run the second command only after reviewing a current simulation. This version belongs to our exercise; check the available version against the repositories on another server.
Directory traversal and listing are different permissions
Opening a known file by its full path requires x on every parent directory. Directory r allows reading its list of names. We gave www-data only --x on the three new parents and application root, and r-x on public.
This fragment requires the prepared frontend tree. It does not create parents or users: their ownership, modes, and traversal ACLs must already be configured. The admin tree uses the same separation:
APP=/srv/solution200/products/lab/frontend
sudo setfacl -m u:www-data:--x,m::r-x "$APP"
sudo setfacl -m u:www-data:r-x,m::r-x "$APP/public"
sudo setfacl -m \
d:u::rwx,d:u:www-data:r-x,d:g::r-x,d:m::r-x,d:o::--- \
"$APP/public"
sudo getfacl -p "$APP" "$APP/public"
The named permission does not require adding www-data to a runtime group. We set a default ACL only on public. Options are documented in the Debian setfacl manual.
What the filesystem allowed
| Operation as www-data | E-01 result |
|---|---|
| Read public/sample.txt | Allowed |
| Read new public/nested/new.txt | Allowed |
| Open public/sample.txt for writing | Denied |
| List the application root | Denied |
| Read src/code.txt, dummy .env.local and .git/config | Denied |
| List var/cache | Denied |
This summarizes actual operations under the www-data UID for both applications. Processes opened files and attempted directory listings; we did not rely only on getfacl. The env and Git files are teaching markers without secrets.
Default ACLs do not override creation modes
The new nested directory and file inherited the named ACL. The creation mode still limits effective permissions. A default ACL does not guarantee that a file created privately with mode 0600 will be readable. The relationship between ACLs, modes, and inheritance is documented in acl(5).
Why chmod can remove access while retaining the named entry
We applied chmod 0600 to our own test file, public/nested/new.txt. The named entry remained, but its mask became empty. An actual read was then denied.
FILE="$APP/public/nested/new.txt"
sudo chmod 0600 "$FILE"
sudo getfacl -c -p "$FILE"
sudo setfacl -m m::r-- "$FILE"
sudo getfacl -c -p "$FILE"
This shortened representation shows the verified state after chmod, with a user name replacing the numeric UID; it is not raw stdout:
user:www-data:r-x #effective:---
mask::---
Explicitly setting setfacl -m m::r-- restored reading while writing remained denied. Shortened representation:
user:www-data:r-x #effective:r--
mask::r--
The frame shows a summary from a fresh SSH connection and state readback. It is not raw command stdout; the 44 filesystem checks ran during this batch's apply phase.
The mask limits named entries and the owning group's rights, so changing it affects that entire class of ACL entries. This example concerns one new test file, not a bulk permission repair. With an extended ACL, group mode bits in ls -l represent the mask; use getfacl for the full picture.
Filesystem access and HTTP need separate checks
The filesystem boundary is tested: www-data reads the required public files and cannot open the tested private paths. That does not establish an Nginx HTTP response. After installation we will check the document root, routes, symlinks, and denial for private URLs. Recursively setting the whole application to 0755 is unnecessary.
The gallery brings together three frames from this exercise: the directory layout, service identities, and ACLs.