Interview Prep/Linux/Security, hardening and incident response

A web app runs as `www-data` and you want it unable to read anything outside `/var/www`, even if exploited. What options do you have?

AdvancedScenarioSecurity, hardening and incident response
Answer

Situation read → Mandatory access control or systemd sandboxing.

What I'd do →

  1. systemd: ProtectSystem=strict, ProtectHome=yes, ReadWritePaths=/var/www/uploads, TemporaryFileSystem=/etc:ro with BindReadOnlyPaths= for needed files, or InaccessiblePaths=/etc/ssh /root.
  2. SELinux: keep the default httpd_t domain and label only allowed content httpd_sys_content_t.
  3. AppArmor (Ubuntu): profile in /etc/apparmor.d/ with /var/www/** r, and aa-enforce.

Why → Even with code execution, the process is fenced by the kernel.

Interview tip → Mention starting AppArmor profiles in complain mode (aa-complain) and tuning from logs.

All Linux questions Roadmap: Linux

More on Security, hardening and incident response