Work in progress: The policy specification is currently unstable.
The goal of Landlock Policy is to define a simple and flexible specification for Landlock security policies, and to provide a reference implementation and command-line tools that can parse both JSON and TOML formats. These formats are designed to be easy to write, read, and parse, leveraging libraries available in a wide variety of programming languages.
For instance, JSON can serve as an intermediate representation leveraged by higher-level policy languages. In contrast, TOML is more user-friendly, making it ideal for end users who need to document their policies and minimize errors due to its less strict format. Both formats translate to the same semantics, ensuring that the security policies defined are consistent regardless of the format used.
The associated library is designed to be embeddable in various programs, facilitating sandboxing and providing well-defined security and compatibility guarantees.
The JSON format is used to define a Landlock security policy as specified by the related JSON schema.
As the Landlock kernel maintainers, we can guarantee that the specification and the library will be kept in sync with kernel changes.
Because the Linux kernel and user space might be updated independently according to the their own upstream and downstream release cycles, a launcher (e.g., service managers, container runtimes) might be newer or older than the running kernel.
In the case of an older kernel and a newer user space, an up-to-date Landlock policy should be still compatible as much as possible with older kernels. The default behavior should then be to following a best-effort approach to protect users as much as possible. See the "compatibility" modes in the specification.
TODO: In the case of an older user space and a newer kernel, it should be possible for users to still leverage a subset of the newer kernel features. This means that the Landlock policy should be flexible enough to extend over the current (soon old) specification. Access rights are defined with meaningful keywords (text), but to be able to protect users as much as possible, the policy format should also handle numbers mapping to the kernel's UAPI bits. This should not be seen as a replacement for the keyword representation of access rights, but as a way to leverage some new features without being coupled too much with the launcher's code. The limit for supporting unknown features would be the introduction of entirely new categories, such as new rule types or ruleset properties. With the current fields, only unknown access rights would be supported. However, if raw access rights are used, the library will not be able to provide the same level of compatibility guarantees. See opencontainers/runtime-spec#1241 (review)
The policy format should ease conciseness (e.g., by handling arrays of paths).
The policy format should handle groups of access rights per Landlock ABI version.
The parser should limit error cases as much as possible. One way to achieve that is to automatically complete the known properties (e.g., handled access rights are automatically completed according to all used access rights).
This repository enables developers to build an ELF shared object library, which can then be used by any program and most programming languages via a foreign function interface (FFI) and a C API.
To install this library, first install
cargo-c using your package manager or with
cargo install cargo-c, and then run these commands:
cargo cinstall --package=landlock-policy-ffi --release --prefix=/usr/local --destdir=out
sudo cp -dr out/usr/local/* /usr/local/The library is then usable via pkg-config as landlock-policy. See the C
example and its Makefile.
The parser should be resilient against any input.
Rust is used as the referenced implementation, which help build and maintain a robust library while still being able to convert it to a shared object. This Rust crate can be used as a standalone library.
This repository contains the policy specification and a test suite that can be used to test the library implementation against a set of valid and invalid samples. This could also be used to test Landlock libraries to make sure the execution traces are similar.
The test suite uses an in-process JSON schema validator by default. To also
validate every inline JSON snippet with check-jsonschema, install it and run:
LANDLOCK_POLICY_TEST_JSON_SCHEMA=1 cargo test --locked --allWhen set, LANDLOCK_POLICY_TEST_JSON_SCHEMA accepts 0 or 1. Enabling it
requires the check-jsonschema executable to be available in PATH.
landlock-policy is the policy development, inspection, and transformation
tool. It currently prints the canonical JSON schema and is intended to grow
operations for debugging, linting, formatting, updating, merging, and
translating policy inputs:
git clone https://github.com/landlock-lsm/landlock-policy
cd landlock-policy
cargo install --path landlock-policy-cli
landlock-policy schemalandlock-exec is the policy enforcement and execution wrapper. It applies
one effective policy composed from JSON or TOML policy inputs and replaces
itself with the confined command. It is an intentionally minimal reference
wrapper; end users looking for a full-featured sandboxing tool should use
Island instead.
git clone https://github.com/landlock-lsm/landlock-policy
cd landlock-policy
cargo install --path landlock-exec
landlock-exec --json examples/mini-write-tmp.json shPolicy inputs can be composed by specifying --json or --toml (and related
file or directory paths) several times.
Here is an example of a TOML policy that uses variables, access right groups, and list of directory hierarchies for conciseness.
abi = 6
[[variable]]
name = "tmp"
literal = ["/tmp", "/var/tmp"]
[[variable]]
name = "home"
literal = ["/root", "/home"]
[[variable]]
name = "config"
literal = ["/etc"]
# Main system file hierarchies can be read and executed.
[[path_beneath]]
allowed_access = ["abi.read_execute"]
parent = ["/bin", "/lib", "/usr", "/dev", "/proc", "${config}"]
# Only allow writing to temporary and home directories.
[[path_beneath]]
allowed_access = ["abi.read_write"]
parent = ["${tmp}", "${home}"]We can get a view of the created Landlock rules:
landlock-exec --toml examples/micro-var.toml --debug datelandlockconfig was the previous name of this project and its public
interfaces. Because these interfaces have not been released from this
repository, they are replaced without compatibility aliases:
- The repository and Rust crate move from
landlockconfigtolandlock-policy; the FFI crate moves fromlandlockconfig_ffitolandlock-policy-ffi. - The schema moves from
schema/landlockconfig.jsontoschema/landlock-policy.json. - The C library, pkg-config module, header, object type, and function prefix
move from
liblandlockconfig,landlockconfig,landlockconfig.h,struct landlockconfig, andlandlockconfig_*toliblandlock-policy,landlock-policy,landlock-policy.h,struct landlock_policy, andlandlock_policy_*. - The former
llconfig schemacommand is nowlandlock-policy schema;llconfig runis nowlandlock-execwith the same options and command arguments, but without therunsubcommand. - The Debian
liblandlockconfig0,liblandlockconfig-dev, andllconfigpackages are replaced byliblandlock-policy0,liblandlock-policy-dev,landlock-policy, andlandlock-exec.