Building a Minimal seccomp Profile for Running gnome-terminal in Docker
Running gnome-terminal inside a Docker container with a minimal seccomp profile is a challenging task due to the complexity of graphical applications. gnome-terminal is a full-featured terminal emulator that interacts with the X server, spawns child processes, manages pseudo-terminals, and interfaces with various desktop services. This means it requires a broad set of Linux syscalls.
Below is a step-by-step approach to building and refining a seccomp profile for this use case, including how to identify and justify each syscall you add.
1. Start with the Default Docker seccomp Profile
Docker’s default seccomp profile is a whitelist that blocks around 44 out of 300+ syscalls, providing moderate protection while maintaining compatibility for most applications[1][2][4]. For graphical applications like gnome-terminal, this default profile is often too restrictive, and you will likely encounter errors due to blocked syscalls.
2. Identify Required Syscalls
To create a minimal profile, you need to determine exactly which syscalls gnome-terminal uses. The recommended method is to:
- Run
gnome-terminal under strace inside a container with seccomp disabled (--security-opt seccomp=unconfined).
- Capture all syscalls made during a typical session.
- Use a tool like seccomp-gen[5] to convert the
strace output into a seccomp profile[5].
Example:
docker run --rm -it --security-opt seccomp=unconfined ubuntu:latest \
strace -ff -o /tmp/strace.log gnome-terminal
Then process the logs with seccomp-gen to generate a draft profile.
3. Iterative Refinement
- Apply the generated profile to your container.
- Run
gnome-terminal and observe any failures.
- If a syscall is denied and causes a failure, add it to the profile.
- Repeat until
gnome-terminal runs without seccomp-related errors[5].
4. Example Minimal seccomp Profile Structure
A Docker seccomp profile is a JSON file with the following structure[4]:
{
"defaultAction": "SCMP_ACT_ERRNO",
"architectures": [
"SCMP_ARCH_X86_64",
"SCMP_ARCH_X86",
"SCMP_ARCH_X32"
],
"syscalls": [
{
"names": ["read", "write", "open", "close", ...],
"action": "SCMP_ACT_ALLOW",
"args": []
}
// Add more syscalls as needed
]
}
5. Common Syscalls Required by gnome-terminal
While the exact list will depend on your environment and session, you will almost certainly need to allow at least the following syscalls (with justification):
| Syscall | Reason/Justification |
|---|
read, write | Basic I/O operations |
open, close | File and device access |
mmap, munmap | Memory mapping for libraries and graphical buffers |
clone, fork, execve | Process creation and management |
ioctl | Terminal and device control |
socket, connect, accept, bind, listen | Inter-process and network communication |
stat, fstat, lstat | File metadata access |
getpid, getppid, getuid, geteuid, getgid, getegid | User and process info |
sigaction, sigprocmask | Signal handling |
prctl | Process control (used by many desktop apps) |
recvmsg, sendmsg, recvfrom, sendto | IPC and X11 communication |
shmget, shmat, shmdt, shmctl | Shared memory for X11/DBus |
futex | Thread synchronization |
set_tid_address, set_robust_list | Thread management |
eventfd2, epoll_create1, epoll_ctl, epoll_wait | Event notification |
getrandom | Random number generation (for security) |
uname | System information |
brk | Heap memory management |
rt_sigreturn, rt_sigaction, rt_sigprocmask |
You may also need to allow syscalls related to DBus, X11, and pseudo-terminal management, such as grantpt, unlockpt, and ptsname.
6. How to Revise and Justify Each Syscall
For every syscall you add, document its necessity. For example:
clone: Required for spawning child processes (e.g., when opening new tabs or running shell commands).
ioctl: Needed for terminal window resizing and device control.
socket: Used for communication with X11, DBus, and other desktop services.
futex: Required for thread synchronization in modern glibc and graphical applications.
If you encounter a denied syscall, research its purpose in the context of gnome-terminal and only add it if it is essential for correct operation.
7. Testing and Finalization
- After each revision, test
gnome-terminal thoroughly: open new tabs, run commands, resize the window, and interact with the UI.
- If a feature fails, check Docker/container logs for seccomp violations and add the missing syscall as needed.
- Once all features work and no unnecessary syscalls are allowed, your profile is complete.
Summary Table: Example syscalls and their purpose
| Syscall | Purpose in gnome-terminal/X11 context |
|---|
clone | Process/thread creation |
ioctl | Terminal and device control |
socket | X11, DBus, and IPC communication |
futex | Thread synchronization |
mmap/munmap | Memory management for graphics and libraries |
execve | Launching shells and commands |
shm* | Shared memory for X11/DBus |
eventfd2 | Event notification |
getrandom | Secure random number generation |
Final Notes
- Automate: Use tools like
seccomp-gen to automate syscall discovery[5].
- Iterate: The process is iterative—test, observe, and refine.
- Document: For each syscall, record why it is needed.
- Security: Only allow syscalls that are strictly necessary for
gnome-terminal to function.
This approach ensures your Docker container running gnome-terminal is as secure as possible, with only the minimum syscalls permitted for correct operation[1][2][4][5].