012 - gVisor Lab¶
- This lab demonstrates the use of gVisor, a sandbox runtime for containers that provides an additional layer of security by intercepting and filtering system calls.
Overview¶
gVisoris an applicationkernel, written in Go, that implements a substantial portion of the Linux system call interface.- It provides a strong isolation boundary between the application and the host kernel, making it harder for attackers to compromise the host system even if they gain control of a container.
Prerequisites¶
- Docker installed
- gVisor runtime installed (
runsc) - Basic understanding of Docker and system calls
Installation¶
- To install gVisor:
# Install gVisor
curl -fsSL https://gvisor.dev/archive.key | sudo gpg --dearmor -o /usr/share/keyrings/gvisor-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/gvisor-archive-keyring.gpg] https://storage.googleapis.com/gvisor/releases release main" | sudo tee /etc/apt/sources.list.d/gvisor.list > /dev/null
sudo apt-get update && sudo apt-get install -y runsc
Examples¶
Example 1: Blocking User Creation¶
-
This example demonstrates how to use gVisor with a
seccompprofile to block user creation syscalls.Files:
demo.sh: Script to run the demoblock-user-creation.json: Seccomp profile that blocks user-related syscalls
Run the demo:
-
This will attempt to create a user inside a container running with gVisor and the seccomp profile.
- The operation should fail, demonstrating the security isolation.
Example 2: Blocking Mount Operations¶
- This example shows how to restrict mount operations using gVisor and seccomp.
Files:
demo-mount.sh: Script to run the mount demoblock-mount.json: Seccomp profile that blocks mount-related syscallsDockerfile: Alpine image that attempts to mount tmpfs
Run the demo:
- This will build an Alpine image and attempt to mount a
tmpfsinside the container. - The mount operation should be blocked.
Key Concepts¶
- Seccomp Profiles: JSON files that define which syscalls are allowed or blocked
- gVisor Runtime:
runscprovides the sandboxed execution environment - System Call Filtering: Prevents potentially dangerous operations