Skip to content

Security model

This page gives the threat model of boxfork: what the daemon trusts, what it does not trust and what it does not protect. It is for an operator who decides where to run the daemon, and for a person who changes the code.

To report a security problem, read ../SECURITY.md. Do not open a public issue.

  • The daemon does not trust the code that runs in a sandbox. This includes the helper process there.
  • The project trusts the host, the engine, the daemon and each holder of the API key.
  • gVisor is the boundary between a sandbox and the host kernel. Without gVisor, a sandbox is a plain container.
  • The daemon makes sure that the engine did what it asked. It does not rely on the answer of the engine to the request.
  • The section “What is not protected” lists the gaps. Read it before you run code from an unknown source.
Party Trusted Reason
The host and its root user Yes The daemon and the engine run there.
Other users of the host Yes A user who can use the engine socket controls each container. The daemon does not defend against local users.
The engine Yes It makes the containers. The daemon checks its results for errors of configuration, not for an attack.
The daemon Yes It has the engine socket and the API key.
A holder of the API key Yes The key permits each operation on each sandbox.
A model that calls the tools As the client that gives it the tools The tools run with the API key of that client.
An image No Its content runs only in a sandbox.
Each process in a sandbox No It runs the code of the agent.
The helper in a sandbox No Code in the sandbox can stop it, replace its file or write to its output.

The helper is the file /.boxfork/guest in the sandbox. The daemon copies it there, but after the start the file belongs to the sandbox. Thus the daemon reads each byte from a helper as data from the sandbox.

Detect in internal/sandbox/manager.go selects the isolation at the start of the daemon.

--isolation Behavior
auto (default) The daemon uses gVisor if it works. If not, it uses plain containers and writes a warning.
gvisor The daemon starts only if gVisor works.
container The daemon uses plain containers.

With gVisor, the engine runs each sandbox with the runtime runsc. The system calls of the sandbox go to the kernel of gVisor in user space, not directly to the host kernel.

An engine can list a runsc runtime that does not work. An engine can also accept the name and then use a different runtime. The API of Podman does this. Thus the daemon does not rely on the list.

  • At the start, tryRuntime starts a trial container with runsc. The trial container has no network.
  • The daemon then inspects the trial container and reads the runtime that the engine used.
  • If the runtime is different, or the container stops immediately, gVisor does not work.
  • At each create, boot inspects the new container again. If the runtime is not the expected one, the daemon removes the container and the create fails.

Each path that starts a container uses boot: a create, a fork, the start of a waiting sandbox and a wake. boxfork info and the HTTP route /v1/info report the isolation that is in use.

Create in internal/engine/docker.go sends these settings for each sandbox, with gVisor and without it:

Setting Effect
no-new-privileges A process cannot get more privileges than it started with.
Capabilities NET_RAW, MKNOD and AUDIT_WRITE dropped No raw sockets, no device nodes, no audit records.
CPU limit The default is 2 CPUs.
Memory limit, with no swap above it The default is 1024 MiB, or 8192 MiB for a sandbox with a GPU.
Process limit 4096 processes.
Mounts of the type volume only The daemon does not send a bind mount. A sandbox cannot get a path of the host.

The daemon does not ask for a privileged container and does not publish a port. It accepts an image reference only if the reference matches a fixed pattern and does not contain ...

Each route but /v1/health needs the API key. auth in internal/api/server.go does the check.

  • The client sends the key as Authorization: Bearer <key> or as X-API-Key.
  • The daemon calculates the SHA-256 of the two keys and compares the results with subtle.ConstantTimeCompare. Thus the time of the comparison does not show the key or its length.
  • If the daemon has an empty key, it refuses each request.

loadKey in cmd/boxfork/main.go makes and reads the key:

  • The key is abx_ and 24 random bytes from the system, as 48 hex characters.
  • The file is api-key in the data directory. The directory has mode 0700 and the file has mode 0600.
  • The daemon makes the file with O_EXCL. Two daemons that start at the same time cannot each make a different key.
  • The daemon does not start if other users can read the file.
  • The daemon does not start if the key has less than 16 characters.
  • The daemon prints a new key one time, and only if its output is a terminal. In a log it writes only the path of the file.
  • The default address is 127.0.0.1:7070. Only programs on the host can connect.
  • --tls-cert and --tls-key switch on HTTPS, with TLS 1.2 as the minimum.
  • If the address is not a loopback address and TLS is off, the daemon starts and writes a warning. On that connection, a person on the network can read the key and all data.
  • The Go client and the Python SDK do not follow an HTTP redirect. Thus the API key does not go to a different server.
  • BOXFORK_PIN_CERT makes a client accept only one certificate. PinEnv in internal/client/client.go has the details.
  • The daemon reads a maximum of 8 MiB for a JSON body and refuses a field that it does not know.
  • A file upload has a maximum of 4 GiB.
  • --max-sandboxes, --max-snapshots, --max-volumes, --max-pooled and --max-timeout limit what the holders of the key can use on one host. The default of the first three and of --max-timeout is 0, which means no limit.
  • If a client closes the connection before a create finishes, the daemon kills the sandbox that nobody got.

Boundary 3: what the daemon reads from a sandbox

Section titled “Boundary 3: what the daemon reads from a sandbox”

All traffic between the daemon and a sandbox goes through the engine, as the input and the output of a helper process. The daemon opens no network connection into a sandbox, and no port of a sandbox is necessary.

Each read from a sandbox has a limit of size, a limit of time, or both:

What the daemon reads Limit Source
The one-line answer of a helper command such as version, gpus or procs 16 KiB, and a time limit of 30 seconds by default askAs in manager.go
The answer line of a file operation 32 MiB maxAnswer in files.go
One frame of the command protocol 4 MiB MaxFrame in proto.go
The output of a command, not streamed 4 MiB for each of the two streams, then the answer says truncated MaxOutput in server.go
The error output of a helper process 16 KiB maxStderr in docker.go
The first answer on a kept connection 15 seconds keptHello in kept.go
A kept connection that does not take data. Time in which the engine freezes the sandbox does not count. 10 seconds keptStall in kept.go
The content of a file The size that the helper gave in the header, and no more ReadFile in files.go

Other rules for this boundary:

  • The daemon ignores a frame of a type that it does not know. It does not stop.
  • A helper that is stopped or that lies can break only the commands of its own sandbox. The client then gets an error, and the daemon opens a new connection for the next command.
  • The daemon starts a file operation as one helper process with arguments. It does not build a shell command from a path.
  • The state file does not contain the environment variables of a sandbox.

CheckNetwork in internal/sandbox/manager.go makes the network boxfork at the start.

  • Between sandboxes. The daemon makes the bridge with the option com.docker.network.bridge.enable_icc=false. It then reads the network back. If the option is not there, it writes a warning, and boxfork info reports it. Docker supports the option. Podman drops it.
  • No raw sockets. Without NET_RAW, a sandbox cannot make packets with a false address on the bridge.
  • No network. A sandbox that a client creates with network: false gets the network mode none.
  • Into a sandbox. The daemon publishes no port.
  • The metadata service of a cloud. internal/hostfw sets firewall rules that block these addresses from the sandbox network: 169.254.0.0/16, 168.63.129.16, 100.100.100.200, 192.0.0.192, and the IPv6 addresses fd00:ec2::254, fd20:ce::254 and fd00:42::42. Port 53 stays open, because some clouds give their name server on such an address.
  • Name servers. The daemon refuses a --dns address that is a loopback address or the unspecified address.

The rules for the metadata service need Linux, root, iptables and the DOCKER-USER chain of Docker. The daemon sets them again each 30 seconds and before a sandbox goes on a new network range.

--block-metadata Behavior if the daemon cannot set the rules
auto (default) The daemon starts. On Linux it writes a warning. On a different system it writes an Info line.
require The daemon does not start. Later, it refuses a sandbox with a network if the rules fail.
off The daemon does not set the rules.

The GPU allocator in internal/gpu/gpu.go gives full GPUs only. One GPU has one owner.

  • A request gets all its GPUs or none.
  • The daemon sets NVIDIA_VISIBLE_DEVICES itself. A sandbox without a GPU gets the value void. A client cannot set this variable. On a host where the NVIDIA runtime is the default, the value all gives each GPU.
  • After the start of a sandbox with GPUs, the daemon asks the helper which GPUs the container sees. If the list is not the list that the daemon gave, the daemon removes the container. --gpu-check controls this check.
  • The daemon releases a GPU only when the engine confirms that the container is gone. If the removal fails, the GPU stays with the container, and the daemon tries again later.
  • The daemon does not hand out a GPU on which a program outside boxfork uses more memory than --gpu-busy-mb.
  • After a restart, the daemon reads the label boxfork.gpus of the containers that it cannot remove, and keeps their GPUs out of use.

The check that asks the helper is a check of the configuration of the engine. It finds an engine that gives the incorrect devices. It is not a defense against a sandbox, because the helper is in the sandbox.

internal/sandbox/volume.go has the rules.

  • A volume name must match ^[a-z0-9][a-z0-9_.-]{0,62}$. The name on the engine is boxfork-vol-<name>.
  • The daemon uses and deletes only volumes that have its labels and the correct name. It does not touch other volumes of the engine.
  • A mount path must be absolute and clean. It cannot be /, and it cannot be at or below /.boxfork, /proc, /sys or /dev.
  • A sandbox mounts a maximum of 16 volumes.
  • The helper gives an empty volume to the user of the sandbox with Lstat and Lchown. It does not follow a symbolic link.

The model cache is a volume that the operator gives with the flag --volume, for example --volume models:/models:ro. Each new sandbox then gets the volume at that path. With :ro the mount is read-only, and the engine applies this. Thus code in one sandbox cannot change the model files that the next sandbox reads.

The read-only rule applies to the default mount, not to the volume. A holder of the API key can mount the same volume in a sandbox without :ro and write to it.

A file operation names a path in the sandbox. runFS in internal/guest/fs.go does the operation.

  • The helper process runs in the container, as the user of the image. Thus a path can name only a file that the sandbox can see. A path with .. or a symbolic link stays in the sandbox, because the process has no view of the host.
  • The daemon sends the path as data in one argument. No shell reads it.
  • remove refuses the path /.
  • read opens only regular files, and it does not block on a named pipe. For a file that reports no size, the limit is 16 MiB.
  • write writes a temporary file and then renames it. A reader does not see half of a file.

The CLI command cp writes on the computer of the client. There the path is the one that the user gave. A sandbox does not select it.

  • It removes each container that has the label boxfork.managed=true, a name that starts with boxfork- and no record in the state file. It does not remove a container that has only the label or only the name.
  • It filters the list of containers itself. It does not rely on the label filter of the engine.
  • It does not start with a state file that it cannot read. It does not replace the file with an empty one.

This list is as important as the lists above.

  • One API key for all clients. The key has no scopes, no users and no expiry. Each holder can read, change and kill each sandbox, snapshot, volume and pool. To change the key, stop the daemon, delete the file and start the daemon. decisions.md gives the reason for one key.
  • The fallback to plain containers. With --isolation auto, a host where gVisor does not work runs sandboxes on the host kernel. A defect in the kernel is then a way out of the sandbox. The daemon writes a warning but starts. Use --isolation gvisor to make the daemon refuse.
  • The GPU driver. A sandbox with a GPU sends calls to the NVIDIA driver in the host kernel. With gVisor, the installer switches on the nvproxy function of runsc for this. A defect in the driver is then a way out of the sandbox. Nobody tested this surface for this project.
  • The memory of a GPU. The daemon does not clear the memory of a GPU between two sandboxes. No code in this repository does it.
  • No limit on the size of a volume. The daemon sends no size to the engine. A sandbox can fill the disk of the host through a volume.
  • No limit on the disk of a sandbox. The daemon sends no disk limit for the files that a sandbox writes in its container.
  • Traffic between sandboxes on Podman. Podman drops the network option. Sandboxes on one host can then connect to each other.
  • Services on the engine host. A sandbox with a network can connect to a service that listens on the host of the engine. The firewall rules of the daemon apply only to traffic that the host forwards.
  • The internet. A sandbox with a network can connect to each address on the internet. The daemon has no list of permitted addresses.
  • The metadata service where the rules are not set. This applies on Podman, on an engine on a different machine, without root and without iptables. With --block-metadata auto the daemon starts in these cases.
  • Plain HTTP. Without TLS on an address that is not loopback, a person on the network can read the key. The daemon only warns.
  • Local users. A user of the host who can use the engine socket can do all that the daemon can do. The environment variables of a sandbox are in the configuration of its container, and such a user can read them.
  • Snapshots. A snapshot is an image on the engine. It contains all files of the sandbox, also secrets that a command wrote to a file.
  • Two daemons on one engine. The second daemon removes the sandboxes of the first one. No code refuses the second daemon.
  • Images. The daemon does not verify a signature of an image. It pulls the reference that the client gives.
  • The helper as a witness. The answers of the helper about GPUs and processes come from the sandbox. Code there can change them. The effect stays in that sandbox: for example, a sandbox can stop its own suspend.
  • Records of use. The daemon keeps no audit record of which client did which request. The log has one line for a create and one for a removal.
  • Nobody did a security review from outside the project.
  • Nobody ran the GPU checks on a machine with an NVIDIA GPU. They ran only against stand-ins.
  • Nobody ran the daemon on x86_64 or on a real AWS or Google Cloud account. Thus the block of the metadata service did not run against a real metadata service.
  • The runs on a real engine were on Docker with gVisor on arm64, in a nested virtual machine, and on Podman.
  • The block of the metadata service is not proven on Docker with nftables.
  • The tests of the rules in this page use the test engine. testing.md says what the test engine cannot show.