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

test: skip if the namespace cannot be set up due to permissions or if python3 is too old #485

Merged
merged 2 commits into from
Aug 26, 2024
Merged
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
29 changes: 18 additions & 11 deletions test/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,24 @@ def setup_test_namespace(data_dir):
# Setup a new mount & user namespace, so we can use mount() unprivileged (see user_namespaces(7))
euid = os.geteuid()
egid = os.getegid()
os.unshare(os.CLONE_NEWNS|os.CLONE_NEWUSER)
# Map root to the original EUID and EGID, so we can actually call mount() inside our namespace
with open("/proc/self/uid_map", "w") as f:
f.write(f"0 {euid} 1")
with open("/proc/self/setgroups", "w") as f:
f.write("deny")
with open("/proc/self/gid_map", "w") as f:
f.write(f"0 {egid} 1")

# Overmount /etc with our own version
subprocess.check_call(["mount", "--bind", os.path.join(data_dir, "etc"), "/etc"])
try:
os.unshare(os.CLONE_NEWNS|os.CLONE_NEWUSER)
# Map root to the original EUID and EGID, so we can actually call mount() inside our namespace
with open("/proc/self/uid_map", "w") as f:
f.write(f"0 {euid} 1")
with open("/proc/self/setgroups", "w") as f:
f.write("deny")
with open("/proc/self/gid_map", "w") as f:
f.write(f"0 {egid} 1")

# Overmount /etc with our own version
subprocess.check_call(["mount", "--bind", os.path.join(data_dir, "etc"), "/etc"])
except PermissionError:
print("Lacking permissions to set up test harness, skipping")
sys.exit(77)
except AttributeError:
print("Python 3.12 is required for os.unshare(), skipping")
sys.exit(77)

if __name__ == "__main__":
parser = argparse.ArgumentParser()
Expand Down