Skip to content

⚠️ OLD EXPERIMENT I used to learn Rust and linux namespaces ⚠️ A port of the excellent process isolation library NsJail to rust with experimental features to decrease the startup latency further

License

Notifications You must be signed in to change notification settings

arthurweinmann/experiment-process-containers

Repository files navigation

DISCLAIMER: THIS IS AN OLD EXPERIMENT MADE PUBLIC

This repository contains an old experiment of mine, so it should not be used as is and probably won't work. Nevertheless, it may give you some useful information.

I used it as a way to learn Rust too so it is not very pretty and contains a lot of notes about Rust behaviours and syntax. Also the version of Rust used is quite old now.

With all that said, enjoy!

It is mainly a port in Rust of the excellent project: https://github.com/google/nsjail

Usage

Interactively build rootfs image

  • Compile toastainer
  • then run the binary with command line argument --create_image={absolute path to rootfs directory}, like:
./rust/toastainer/target/debug/toastainer --create_image=/home/arthurbuntu/alpine
  • If you want to use a shell script, do:
./rust/toastainer/target/debug/toastainer --create_image=/home/arthurbuntu/alpine --use_script={absolute path to sh script}

# like

./rust/toastainer/target/debug/toastainer --create_image=/home/arthurbuntu/alpine --use_script=/home/arthurbuntu/rust/toastainer/rootfs/src/test.sh

Installation

  • steps for ubuntu 18.04. Todo: see how to make it work on other distrib, like debian for example.

libnl

If command pkg-config --exists libnl-route-3.0 && echo yes does not echo "yes", you probably miss libnl3(-dev)/libnl-route-3(-dev) libraries

On ubuntu 18.04, install with:

sudo apt-get install libnl-3-dev
sudo apt-get install libnl-route-3-dev

It should put the lib (at least its headers) in /usr/include/libnl3.

To check which version is currently installed, you can use cat /usr/include/libnl3/netlink/version.h.

libcap

Used in caps package

sudo apt-get install libcap-dev

newuidmap and newgidmap

if which newuidmap and/or which newgidmap prints nothing, then you need to install them with sudo apt install uidmap. They should go in /usr/bin/newuidmap and /usr/bin/newgidmap

Network Setup

ip link add dev tveth0 type veth peer name tveth1
ip link set dev tveth0 up
ip link set dev tveth1 up
ip addr add 10.166.0.1/16 broadcast 10.166.255.255 dev tveth0 # 10.0.0.0/8 is by convention a block of private IP addresses, See http://www.faqs.org/rfcs/rfc1918.html

# On your local PC only
iptables -t nat -A POSTROUTING -s 10.166.0.0/16 -j MASQUERADE

# on TVS only,  do not do this on your PC, it is to prevent Toaster from calling private toaster servers in aws VPC
# iptables -t nat -A POSTROUTING -s 10.166.0.0/16 ! -d 172.16.0.0/12 -j MASQUERADE

echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf
sysctl -p /etc/sysctl.conf

# it is tveth1 that will be moved into the child NET namespace

# without one of these line, toaster/container/child in new net namespace, won't be able to resolve hostnames to ip addresses
# echo "nameserver 8.8.8.8" > /chroot/binary/etc/resolv.conf # with a rootfs
# echo "nameserver 8.8.8.8" > /etc/resolv.conf # with native root (no pivot root done)

See jail/src/net.md for more information

Inspiration

NSJail (C++)

Firecracker (rust)

Moby by Docker (golang)

Notes

Things still to learn and apply to this package:

For a TCP server with linux epoll and rust async/.await

GPU support

Read List

Tricks

Bash

Print process namespaces

ls -l /proc/$$/ns | awk '{print $1, $9, $10, $11}'

About

⚠️ OLD EXPERIMENT I used to learn Rust and linux namespaces ⚠️ A port of the excellent process isolation library NsJail to rust with experimental features to decrease the startup latency further

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages