-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
rootlessport: set source IP to slirp4netns device #9052
rootlessport: set source IP to slirp4netns device #9052
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: giuseppe The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@giuseppe You have to add a new test for this. |
CNI-in-slirp4netns mode would need be updated to use container IP as the RootlessKit child IP |
Also it should be documented that apps will always see 10.0.2.100 (or CNI IP) as the source address. |
6ad04c4
to
6ba2fc1
Compare
test/e2e/run_networking_test.go
Outdated
defer GinkgoRecover() | ||
defer wg.Done() | ||
|
||
// wait 2 seconds to be sure the container is running |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ouch, I'm super uncomfortable with this type of test (the "sleep and hope we don't race" thing). Please stand by, I'm working on an alternative quicker safer test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@giuseppe please try
this test instead:
diff --git a/test/system/500-networking.bats b/test/system/500-networking.bats
index a824ebcd7..b4548c78a 100644
--- a/test/system/500-networking.bats
+++ b/test/system/500-networking.bats
@@ -65,8 +65,13 @@ load helpers
myport=54321
# Container will exit as soon as 'nc' receives input
+ # We use '-n -v' to give us log messages showing an incoming connection
+ # and its IP address; the purpose of that is guaranteeing that the
+ # remote IP is not 127.0.0.1 (podman PR #9052).
+ # We could get more parseable output by using $NCAT_REMOTE_ADDR,
+ # but busybox nc doesn't support that.
run_podman run -d --userns=keep-id -p 127.0.0.1:$myport:$myport \
- $IMAGE nc -l -p $myport
+ $IMAGE nc -l -n -v -p $myport
cid="$output"
# emit random string, and check it
@@ -74,7 +79,20 @@ load helpers
echo "$teststring" | nc 127.0.0.1 $myport
run_podman logs $cid
- is "$output" "$teststring" "test string received on container"
+ # High-level overview of received output. We also check it line by line
+ # but this is a basic test; if it fails, we can see full output, which
+ # is helpful because failure here indicates something is VERY wrong.
+ is "$output" "listening on .*:$myport .*connect to .*$teststring" \
+ "Basic check on received output"
+
+ # Line-by-line output check. If any of these fail, we will not see
+ # the full output of 'nc'. The most important check here is the
+ # second line, in which we check for a 10.X remote IP (not 127.*)
+ is "${lines[0]}" "listening on \[::\]:$myport ..." "First line of output"
+ is "${lines[1]}" \
+ "connect to \[::ffff:10\..*\]:$myport from \[::ffff:10\..*\]:" \
+ "Second output line from nc"
+ is "${lines[2]}" "$teststring" "test string received on container"
# Clean up
run_podman rm $cid
any pointer on how that must be done? |
6ba2fc1
to
d3a9cd7
Compare
This line would need to be changed to pass child IP from CNI result: podman/libpod/networking_linux.go Line 241 in d102d02
|
d3a9cd7
to
4c1a459
Compare
Error looks like a flake:
Will restart. |
@AkihiroSuda PTAL |
ARGH! My test is bad: output from 'nc' is not ordered reliably:
I need to rethink this. Will offer a fix soon. |
Replacement test (with downloadable patch): diff --git a/test/system/500-networking.bats b/test/system/500-networking.bats
index b4548c78a..bcc6737b7 100644
--- a/test/system/500-networking.bats
+++ b/test/system/500-networking.bats
@@ -79,20 +79,17 @@ load helpers
echo "$teststring" | nc 127.0.0.1 $myport
run_podman logs $cid
- # High-level overview of received output. We also check it line by line
- # but this is a basic test; if it fails, we can see full output, which
- # is helpful because failure here indicates something is VERY wrong.
- is "$output" "listening on .*:$myport .*connect to .*$teststring" \
- "Basic check on received output"
-
- # Line-by-line output check. If any of these fail, we will not see
- # the full output of 'nc'. The most important check here is the
- # second line, in which we check for a 10.X remote IP (not 127.*)
- is "${lines[0]}" "listening on \[::\]:$myport ..." "First line of output"
- is "${lines[1]}" \
- "connect to \[::ffff:10\..*\]:$myport from \[::ffff:10\..*\]:" \
- "Second output line from nc"
- is "${lines[2]}" "$teststring" "test string received on container"
+ # Sigh. We can't check line-by-line, because 'nc' output order is
+ # unreliable. We usually get the 'connect to' line before the random
+ # string, but sometimes we get it after. So, just do substring checks.
+ is "$output" ".*listening on \[::\]:$myport .*" "nc -v shows right port"
+
+ # This is the truly important check: make sure the remote IP is
+ # in the 10.X range, not 127.X.
+ is "$output" \
+ ".*connect to \[::ffff:10\..*\]:$myport from \[::ffff:10\..*\]:.*" \
+ "nc -v shows remote IP address in 10.X space (not 127.0.0.1)"
+ is "$output" ".*${teststring}.*" "test string received on container"
# Clean up
run_podman rm $cid |
fa93331
to
f36e15a
Compare
thanks! Just pushed the new version |
Yay, tests are green. LGTM, but I'll let someone more network-knowledgeable do the approving. Thanks @giuseppe, and sorry for my botched first attempt. |
Signed-off-by: Giuseppe Scrivano <[email protected]>
set the source IP to the slirp4netns address instead of 127.0.0.1 when using rootlesskit. Closes: containers#5138 Signed-off-by: Giuseppe Scrivano <[email protected]>
Signed-off-by: Giuseppe Scrivano <[email protected]>
f36e15a
to
ef65494
Compare
/lgtm |
CNI support seems unfixed: #9065 |
set the source IP to the slirp4netns address instead of 127.0.0.1 when
using rootlesskit.
Closes: #5138
Signed-off-by: Giuseppe Scrivano [email protected]