freedomofpress / dangerzone

Take potentially dangerous PDFs, office documents, or images and convert them to safe PDFs
https://dangerzone.rocks/
GNU Affero General Public License v3.0
3.59k stars 170 forks source link

Smallest possible container image for Tails #669

Open apyrgio opened 8 months ago

apyrgio commented 8 months ago

Warning: this is a thought experiment :bulb:

Suppose that Dangerzone was installed in Tails (original discussion). What would the container image look like in this case? Most probably, it would have to be small. Either small enough to be packaged with Tails, or small enough to be downloaded via Tor (see #154).

But how small can we possibly make that image? We have crunched some numbers (https://github.com/freedomofpress/dangerzone/issues/658#issuecomment-1861239821), and while it's still early days, best case scenario looks like ~200MiB. Can we make it smaller? Can we make it 0?

$ cat Dockerfile
FROM scratch
$ podman build . -t dangerzone.rocks/dangerzone:latest
$ podman run --network none -it -v /bin:/bin:ro -v /lib:/lib:ro -v /usr:/usr:ro -v /etc:/etc:ro -v /var:/var:ro -v /lib64:/lib64:ro -v dangerzone.rocks/dangerzone libreoffice --help
LibreOffice [...]

What happened here? Because Tails has LibreOffice installed, we can mount (read-only) Tails' system files within an empty container, and run LibreOffice inside that container, with all of our protections.

This is akin to moving a jailed process from a cell made of concrete into a cell made of hardened glass. Now the process can look outside, but cannot affect it. Can it read sensitive info? We don't mount Tails' persistent storage, symlinks don't work within the container, but still, this is not foolproof. Do we enlarge our attack surface with filesystem bugs? Sadly yes.

Untested territory

Can we make this better? We could copy into the container image the files that LibreOffice needs to run. For instance, we could recursively list all the LibreOffice dependencies:

$ apt-cache depends libreoffice-core --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances | grep "^\w" | sort -u

and then get the files of these dependencies with dpkg -L. This file list is very large though, because we need core system libraries as well.

Alternatively, we could have a Bullseye image with the main LibreOffice dependencies installed, which hopefully won't take much space, and then copying just the LibreOffice dirs into it, e.g.:

/etc/libreoffice
/usr/lib/libreoffice
/usr/share/libreoffice