The landlock-restrict tool executes a process under Landlock filesystem restrictions. It allows you to define specific paths that the target command can access with varying permissions (Read-Only or Read-Write) and for different object types (Directories or Files).
Usage Pattern
landlock-restrict [GLOBAL_FLAGS] [RULE_FLAGS] -- COMMAND [ARGS...]
Note that the command being executed must use an absolute binary path.
Rule Flags
Rules are defined by specifying a mode followed by a list of paths. You can modify path behavior using special tokens within the path list:
-ro PATH...: Restrict to Read-Only directories.-rw PATH...: Restrict to Read-Write directories.-rofiles PATH...: Restrict to Read-Only files.-rwfiles PATH...: Restrict to Read-Write files.
Path Modifiers (must be included in the path list):
+refer: Grants the refer access right to the path.+ioctl_dev: Grants ioctl device access.+resolve_unix: Enables Unix domain socket resolution.
Global Flags
-v: Enables verbose logging.-l: Enables audit logging for subprocesses.-strict: Disables "best effort" mode, enforcing strict Landlock constraints.-1 through -10: Selects the Landlock version (e.g., -10 for V10).
Example
To run /usr/bin/ls with read-only access to /tmp and read-write access to /home/user/data (including the refer right):
landlock-restrict -ro /tmp -rw +refer /home/user/data -- /usr/bin/ls /home/user/data
landlock-restrict -ro /tmp -rw +refer /home/user/data -- /usr/bin/ls /home/user/data