NOSSLETTER.techLIVE
back to archive

Isolate the filesystem of the server at startup

Language: C+++4172 -11feature
concepts demonstrated
Mount namespacespivot_root system callBind mountsseccomp filters
The Issue & Context

Before this change, the ClickHouse server process had full access to the host filesystem, allowing an attacker who gained code execution to run arbitrary binaries or access sensitive host files outside the server's directories.

Root Cause Analysis

The server ran without any filesystem namespace isolation, so it inherited the host's global mount namespace and root filesystem, exposing all files and binaries on the host to the server process and any compromised code it might execute.

Solution Strategy & Architectural Pattern

The PR introduces a new mount namespace at startup with an empty read-only tmpfs as root, selectively bind-mounting only required paths (config, data, binaries, /proc, /dev nodes, etc.) into this isolated view. It uses pivot_root to switch to this new root and removes the old root, then applies seccomp filters to prevent undoing the isolation. The isolation is set up before any threads start to avoid namespace sharing issues, and capabilities are dropped to prevent privilege escalation.

Key Takeaway for Contributors

For multi-threaded servers, filesystem isolation via mount namespaces must be done early in the startup lifecycle before threads spawn, and capability dropping combined with seccomp filters is essential to enforce robust sandboxing.