Skip to main content

Crate cant_launch

Crate cant_launch 

Source
Expand description

Sandbox setup and exec for Cantainer.

plan completes a policy with what the executable needs to start (its ELF interpreter, shared libraries and a small runtime base), filters the environment and builds argv. exec then makes the kernel enforce the plan and replaces the current process with the program:

  1. create writable command-line files that do not exist yet (so they have an inode),
  2. Landlock: deny by default, allow each grant (also sets no_new_privs),
  3. seccomp: baseline deny list plus the socket families the policy does not allow,
  4. execve.

There is no supervisor process: exit status, signals and the terminal belong to the program, exactly as if it had been run directly. Restrictions are inherited by everything it starts and cannot be lifted.

Linux only. On other systems every entry point returns LaunchError::Unsupported, so the workspace still builds on macOS for editing.

Structs§

CanStart
How to start a can’s program: through the can’s own ELF loader, with the can’s own libraries, and nothing resolved from the host.
KernelSupport
Facts about the running kernel, for cant check.
Plan
Everything needed to start a cant.
Resolved
What an executable needs from the filesystem to start.

Enums§

ElfError
Errors reading an executable.
LaunchError
Errors from planning or launching.

Constants§

DYNAMIC_LOADERS
The system’s dynamic loaders. A cant that may execute files in a directory (cargo’s build scripts in $CWD) gets these, because the kernel needs execute access to a program’s loader to start it, and cant can’t know in advance which files will run. Programs whose libraries cant resolves get their own loader anyway.
MIN_ABI
Below ABI 3, truncate(2) is not controlled, so a read-only grant would not stop a cant from emptying a file. We refuse to run rather than pretend.
NETWORK_READ
What name resolution reads, granted (read-only) to every cant with network = true: without them a program may reach the network but can’t look up a host name. They hold no secrets. A symlinked /etc/resolv.conf (systemd-resolved) resolves to its target.
POLICY_ENV
Name of the environment variable carrying the effective policy into a cant, so that a nested cant can explain and pre-check attenuation. It is informational: the kernel enforces the real restrictions, and a forged value cannot widen them.
RUNTIME_READ
Files every program may need to read: the loader cache, locale, time zone, terminfo, the CA trust store and a few devices.
RUNTIME_READ_WRITE
Devices every program may read and write.

Functions§

exec
Enforces plan and replaces the current process with the program. Returns only on failure. warn receives non-fatal notices (printed by the CLI).
in_merged_usr
The path under a merged-/usr root of an absolute path as a program names it: /lib/ld-linux-aarch64.so.1 is <root>/usr/lib/ld-linux-aarch64.so.1.
plan
Completes built into a launch plan.
probe_kernel
Probes kernel support. On Linux this applies a no-op Landlock ruleset to the calling process (the only way to learn the ABI through the landlock crate), so call it only from a process that is about to exit, such as cant check.
resolve_libraries
Resolves the interpreter and all shared libraries of binary.
resolve_libraries_in
Like resolve, but only inside root, a sysroot laid out like Debian’s merged /usr (cant build unpacks pinned packages there): nothing is looked up on this machine. The interpreter is found at <root>/usr/lib/… for a /lib/… PT_INTERP, and interpreter_literal stays as written in the program. Files that resolve outside root (a symlink pointing out) count as missing.