Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --user option to create user namespace #1

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,29 @@ def do_netns_play():

vprint("-"*80)

def check_unpriv_userns():
if os.geteuid() == 0:
return

name = "kernel.unprivileged_userns_clone"
path = SYSCTL_PATH / name.replace(".", "/")
if not path.exists():
return

val = int(path.read_text())
if val == 0:
print(f"Sysctl {name} is disallowing unprivileged userns creation.", file=sys.stderr)
print(f"Either run this as root, or run:")
print(f"sudo sysctl -w {name}=1")
raise SystemExit(1)


def parse_args():
global g_verbose
import argparse
ap = argparse.ArgumentParser()
ap.add_argument('-U', '--user', action='store_true',
help="Create new user namespace")
ap.add_argument('-v', '--verbose', action='store_true',
help="Verbose output")
args = ap.parse_args()
Expand All @@ -192,6 +210,10 @@ def main():
s1 = snapshot()

flags = clone.CLONE_NEWNET
if args.user:
check_unpriv_userns()
flags |= clone.CLONE_NEWUSER

clone.clone_call(do_netns_play, flags)

s2 = snapshot()
Expand Down