Debian service users: a separate identity for each application

Create two nonlogin identities and test actual file access: each can write its own cache while code and the other application's private files stay protected.

Two modules with distinct access tokens illustrate separate application service identities.

When frontend and admin run as the same Unix user, filesystem permissions cannot distinguish their processes. To separate access in our Debian training model, we created s200-lab-frontend and s200-lab-admin.

We first rehearsed account creation and the checks on a separate Debian 13 virtual machine. We then checked that the names were available and created both identities on E-01. The results below come from actual file operations on that training VPS.

A service user is not an administrator

It needs an identity for processes and file permissions. This exercise requires no home directory, password login, SSH keys, or sudo. We created a separate system group with the same name:

sudo adduser --system --group --home /nonexistent --no-create-home \
  --shell /usr/sbin/nologin s200-lab-frontend
sudo adduser --system --group --home /nonexistent --no-create-home \
  --shell /usr/sbin/nologin s200-lab-admin

The Debian adduser manual explains the options: --system creates a system user, --group creates its group, and --no-create-home prevents home-directory creation. We set the shell explicitly. We checked that both user and group were absent before creation, rather than changing existing entries.

Read back each account

getent passwd s200-lab-frontend
id s200-lab-frontend
sudo passwd -S s200-lab-frontend

The system assigns UID and GID values; the exact numbers are not part of the model. We verified home /nonexistent, absence of that directory, shell /usr/sbin/nologin, a locked password, and membership in only the user's primary group. There are no supplementary groups.

nologin prevents a normal interactive shell login. It does not stop an administrator from launching a process with that UID: this is how a service or our test performs work as the user. A locked password likewise does not replace checking other authentication paths.

Separate code reading from data writing

Root owns the teaching code, with the application's group. Code and the dummy .env.local use mode 0640: the service user reads through its group but cannot modify them. Its var/cache and var/log directories belong to it with mode 0700.

This teaching check requires the prepared layout. It touches only dummy code and its own new cache file. Opening the file with xb prevents overwriting an existing file:

sudo runuser -u s200-lab-frontend -- python3 -I - <<'PY'
from pathlib import Path

root = Path('/srv/solution200/products/lab/frontend')
assert root.joinpath('src/code.txt').read_text() == 'fixture-code-only\n'

try:
    with root.joinpath('src/code.txt').open('ab'):
        pass
except PermissionError:
    print('code write: denied')
else:
    raise RuntimeError('unexpected code write permission')

probe = root / 'var/cache/article-probe.txt'
with probe.open('xb') as stream:
    stream.write(b'owned-probe')
assert probe.read_bytes() == b'owned-probe'
probe.unlink()
print('own cache: create/read/delete succeeded')
PY

This is a teaching version of the check, not a raw operator transcript. The completed exercise performed the corresponding file opens and a full create, read, and delete cycle for a separate cache marker under both UIDs.

Test access to the other application

Operation as a runtime userE-01 result
Read own code and dummy envAllowed
Open own code for writingDenied
Create, read, and delete own cache markerSucceeded
Read the other application's dummy envDenied
List the other application's cacheDenied
Read root-only .git/config markerDenied
Fresh verification of two nonlogin identities. The 44 filesystem checks ran during this batch's apply phase.

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 table summarizes actual file operations rather than predictions from ls -l. Both frontend and admin were tested. The dummy env contains only a test string without credentials.

Where this boundary ends

A separate UID and suitable permissions restrict access to the tested files. They are not a container or complete OS isolation. Network access, extra capabilities, and open file descriptors require separate checks.

We have not configured PHP-FPM pools, a systemd sandbox, or provider-metadata access. A real application will require checking its actual worker-process user and repeating the relevant file operations. Sharing a runtime user is appropriate only when applications deliberately share a trust boundary.

The gallery brings together three frames from this exercise: the directory layout, service identities, and ACLs.

  1. Databases Four database access roles for one product
  2. Operations & Security A separate administrator: from key login to the right privileges
  3. Operations & Security ACLs on Debian: allow public files and protect the private tree
  4. Architecture An application layout in /srv: code, public files, and writable data
  5. Operations & Security Two PHP-FPM pools: separate UIDs, Unix sockets and file rights