Create process in linux namespaces
Works with Linux namespaces through glibc with pure python
I want to change this: I want to create native python bindings to glibc with interface of python multiprocessing.Process.
PS: you can look at python-nsenter too, it’s looks awesome.
PPS: new project from author of asylum - butter
First simple example:
import os from pyspaces import Container def execute(argv): os.execvp(argv, argv) cmd = "mount -t proc proc /proc; ps ax" c = Container(target=execute, args=(('bash', '-c', cmd),), uid_map='0 1000 1', newpid=True, newuser=True, newns=True ) c.start() print("PID of child created by clone() is %ld\n" % c.pid) c.join() print("Child returned: pid %s, status %s" % (c.pid, c.exitcode))
PID of child created by clone() is 15978 PID TTY STAT TIME COMMAND 1 pts/19 S+ 0:00 bash -c mount -t proc proc /proc; ps ax 3 pts/19 R+ 0:00 ps ax Child returned: pid 15978, status 0
space execute -v --pid --mnt --user --uid 1000 --gid 1000 bash -c 'mount -t proc /proc; ps ax'
space chroot --pid --uid '0 1000 1' ~/.local/share/lxc/ubuntu/rootfs/ /bin/ls /home/
space inject --net --mnt 19840 bash
Note: If the program you’re trying to exec is dynamically linked, and the dynamic linker is not present in /lib in the chroot environment - you will get the following error: “OSError: [Errno 2] No such file or directory”. You need all the other files the dynamic-linked program depends on, including shared libraries and any essential configuration/tables/etc in the new root directories. src
Read this article please