Commit aa33cee3 authored by Kirill Smelkov's avatar Kirill Smelkov

Allow to only unshare (slapns -U) without creating separate chroot

It is handy to reuse slapns uid setup, because e.g. `unshare -U...` does
not allow to use newuidmap & friends, and so with just unshare it is
hard to create a user namespace where e.g. screen will work (openpty
wants to chown(:tty), gid(tty)=5)
parent a150da84
...@@ -139,6 +139,10 @@ def idmap_trysetup_viashadow(kind, pid): ...@@ -139,6 +139,10 @@ def idmap_trysetup_viashadow(kind, pid):
def main(): def main():
slappart = sys.argv[1] slappart = sys.argv[1]
unshareonly = (slappart == "-U")
if unshareonly:
slappart = ""
if not unshareonly:
# create directories inside container # create directories inside container
dirv = ["/proc", "/sys", dirv = ["/proc", "/sys",
"/bin", "/sbin", "/lib", "/lib64", "/usr/bin", "/usr/lib", "/bin", "/sbin", "/lib", "/lib64", "/usr/bin", "/usr/lib",
...@@ -208,6 +212,7 @@ def main(): ...@@ -208,6 +212,7 @@ def main():
mount("none", slappart + "/tmp", "tmpfs") mount("none", slappart + "/tmp", "tmpfs")
mount("none", slappart + "/run", "tmpfs") mount("none", slappart + "/run", "tmpfs")
if not unshareonly:
# read-only bind mount bin, lib, ... from SR # read-only bind mount bin, lib, ... from SR
# FIXME stub: here we bind from base system for now # FIXME stub: here we bind from base system for now
bind("/bin", slappart + "/bin", MS_RDONLY) bind("/bin", slappart + "/bin", MS_RDONLY)
...@@ -235,9 +240,10 @@ def main(): ...@@ -235,9 +240,10 @@ def main():
os.system("/sbin/ifconfig lo 127.0.0.1") # XXX at least loopback works os.system("/sbin/ifconfig lo 127.0.0.1") # XXX at least loopback works
# chroot to container # chroot to container
if not unshareonly:
slappart = abspath(slappart) slappart = abspath(slappart)
os.chdir(slappart) os.chdir(slappart)
os.chroot(slappart) os.chroot(slappart) # XXX -> try pivot_root
# FIXME stub: -> $SHELL # FIXME stub: -> $SHELL
os.execv("/bin/bash", ["bash"]) os.execv("/bin/bash", ["bash"])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment