Running Sandlock in a Docker container
Is it possible to run sandlock in a docker container without changing the default seccomp profile or adding capabilities? That seems to be one of the primary advertised usages of sandlock.
Upon testing it seems that sandlock run fails when calling pidfd_getfd unless SYS_PTRACE is enabled or the seccomp profile is modified to explicitly allow pidfd_getfd. This seems related to this issue https://github.com/moby/moby/issues/45622.
Is there a suggested way of running sandlock from within docker?
Hi @adkinsjd
You are right, the default docker profile disallows pidfd_getfd() etc. syscalls which are fundamental building blocks used by sandlock. You would need --cap-add SYS_PTRACE to grant the permission for sandlock.
If it looks insecure, you could add it back on the sandlock side, something like this:
docker run --rm --cap-add SYS_PTRACE \
-v /usr/local/bin/sandlock:/usr/local/bin/sandlock:ro \
-v /tmp/your_program.py:/tmp/your_program.py:ro \
python:3.12-slim sandlock run \
--extra-deny-syscall ptrace \
--extra-deny-syscall pidfd_getfd \
--extra-deny-syscall process_vm_readv \
--extra-deny-syscall process_vm_writev \
-r / -w /tmp -- python3 /tmp/your_program.py
I created an FAQ page here: https://sandlock.io/faq.html