Skip to content
Merged
Show file tree
Hide file tree
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
27 changes: 27 additions & 0 deletions hack/integration-net.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,30 @@ if [ "${net}" = "lxc-user-nic" ]; then
sudo /usr/lib/$(uname -m)-linux-gnu/lxc/lxc-net start || sudo /etc/init.d/lxc-net start || true
fi
$ROOTLESSKIT --net=${net} --copy-up=/etc --copy-up=/run --disable-host-loopback ${flags} -- nslookup example.com

# Test that a server process listening on the host loopback is not accessible from the isolated namespace
tmp=$(mktemp -d)
echo "hello host loopback" >${tmp}/index.html

busybox httpd -f -p 127.0.0.1:8080 -h ${tmp} &
pid=$!

sleep 1

statedir=$(mktemp -d)
CURL="timeout 3 curl -fsSL http://127.0.0.1:8080"
if echo "${flags}" | grep -q -- --detach-netns; then
# With --detach-netns, the child command runs in the host's network namespace,
# so it has to enter the detached network namespace explicitly.
CURL="nsenter -n${statedir}/netns ${CURL}"
fi

if $ROOTLESSKIT --state-dir=${statedir} --net=${net} --copy-up=/etc --copy-up=/run --disable-host-loopback ${flags} -- ${CURL}; then
ERROR "the host loopback should not be accessible from the isolated namespace"
exit 1
fi

INFO "the host loopback is not accessible from the isolated namespace, as expected"

kill -9 $pid || true
rm -rf ${tmp} ${statedir}
2 changes: 1 addition & 1 deletion pkg/network/pasta/pasta.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (d *parentDriver) ConfigureNetwork(childPID int, stateDir, detachedNetNSPat
"--dns-forward=" + dns.String(),
}
if d.disableHostLoopback {
opts = append(opts, "--no-map-gw")
opts = append(opts, "--no-map-gw", "--tcp-ns=none", "--udp-ns=none")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it break port forwarding with implicit port driver?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review!

No, it doesn't.

-T/-U (--tcp-ns/--udp-ns) and -t/-u (--tcp-ports/--udp-ports) handle opposite directions, and this PR only touches the former.

Even when specifying --disable-host-loopback, --port-driver=implicit uses --tcp-ports=auto --udp-ports=auto, which forwards connections from the host to the isolated namespace. (ref)

On the other hand, --tcp-ns/--udp-ns configure port forwarding from the isolated namespace to the host, so passing --tcp-ns=none --udp-ns=none blocks only that path, and the inbound implicit port forwarding keeps working.

Note that after applying this fix, I've confirmed that we can access the server in the isolated namespace from the host via port forwarding as follows:

(host) > rootlesskit --copy-up=/etc --disable-host-loopback \
--net=pasta --port-driver=implicit \
python3 -m http.server 8080
WARN[0000] [rootlesskit:parent] "pasta" network driver is experimental. Needs very recent version of pasta (see docs/network.md).
Serving HTTP on 0.0.0.0 port 8080 (http://0.0.0.0:8080/) ...

(host) > curl -4 localhost:8080  2>/dev/null | head -3
<!DOCTYPE HTML>
<html lang="en">
<head>

Please let me know if I've misunderstood your question 🙏

}
if !d.enableIPv6 {
opts = append(opts, "--ipv4-only")
Expand Down