Commit f8df3b5e authored by Kirill Smelkov's avatar Kirill Smelkov

only unshare: Teach it not to unshare some bits

e.g.

	slapns -U/tmp:/run

will not unshare /tmp and /run from its parent namespace.
parent 1c4ae85d
...@@ -139,8 +139,11 @@ def idmap_trysetup_viashadow(kind, pid): ...@@ -139,8 +139,11 @@ def idmap_trysetup_viashadow(kind, pid):
def main(): def main():
slappart = sys.argv[1] slappart = sys.argv[1]
unshareonly = (slappart == "-U") unshareonly = slappart.startswith("-U")
share = set([]) # of path that not to unshare
if unshareonly: if unshareonly:
_ = slappart[2:] # -U/tmp:/run -> /tmp:/run
share = set(_.split(":"))
slappart = "" slappart = ""
if not unshareonly: if not unshareonly:
# create directories inside container # create directories inside container
...@@ -152,6 +155,12 @@ def main(): ...@@ -152,6 +155,12 @@ def main():
for _ in dirv: for _ in dirv:
mkdir_p(slappart + _) mkdir_p(slappart + _)
# xmount mounts source to slappart/target
def xmount(source, target, fs):
if target in share:
return # user asked us not to unshare this
mount(source, slappart + target, fs)
# find out my uid/gid # find out my uid/gid
uid = os.getuid() uid = os.getuid()
gid = os.getgid() gid = os.getgid()
...@@ -209,11 +218,11 @@ def main(): ...@@ -209,11 +218,11 @@ def main():
# mount new tmpfs'es # mount new tmpfs'es
mount("none", slappart + "/tmp", "tmpfs") xmount("none", "/tmp", "tmpfs")
mount("none", slappart + "/run", "tmpfs") xmount("none", "/run", "tmpfs")
# separate instance for pseudo terminals # separate instance for pseudo terminals
mount("none", slappart + "/dev/pts", "devpts") xmount("none", "/dev/pts", "devpts")
if not unshareonly: if not unshareonly:
# read-only bind mount bin, lib, ... from SR # read-only bind mount bin, lib, ... from SR
...@@ -236,8 +245,8 @@ def main(): ...@@ -236,8 +245,8 @@ def main():
sys.exit(st >> 8) # st = (exit << 8) | signal sys.exit(st >> 8) # st = (exit << 8) | signal
# child # child
mount("none", slappart + "/proc", "proc") xmount("none", "/proc", "proc")
mount("none", slappart + "/sys", "sysfs") xmount("none", "/sys", "sysfs")
# TODO setup networking # TODO setup networking
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
......
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