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

network isolation: set hostname to localhost #530

Draft
wants to merge 1 commit into
base: main
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
10 changes: 9 additions & 1 deletion src/fromager/run_network_isolation.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/usr/bin/env -S unshare -rn /bin/bash
#!/usr/bin/env -S unshare --uts --net --map-root-user /bin/bash
#
# Run command with network isolation (CLONE_NEWNET) and set up loopback
# interface in the new network namespace. This is somewhat similar to
# Bubblewrap `bwrap --unshare-net --dev-bind / /`, but works in an
# unprivilged container. The user is root inside the new namespace and mapped
# to the euid/egid if the parent namespace.
#
# Unshare UTS namespace, so we can set the hostname to "localhost", so
# lookup of "localhost" does not fail.
#
# Ubuntu 24.04: needs `sysctl kernel.apparmor_restrict_unprivileged_userns=0`
# to address `unshare: write failed /proc/self/uid_map: Operation not permitted`.
#
Expand All @@ -21,5 +24,10 @@ fi
# bring loopback up
ip link set lo up

# set hostname to "localhost"
if command -v hostname 2>&1 >/dev/null; then
hostname localhost
fi

# replace with command
exec "$@"
Loading