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

Scan /proc/net/{tcp,udp} for host network driver port bindings #7746

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Nino-K
Copy link
Member

@Nino-K Nino-K commented Nov 8, 2024

This introduces a scanner that monitors entries in /proc/net/{tcp,udp}. When using the host network driver (--net=host) in Docker or containerd, some port bindings are not exposed through the API. However, these bindings are still visible in /proc/net because the container shares the host network namespace.

The procnet scanner scans the corresponding files every 3 seconds and if a new entry is found or removed it calls the host switch API to expose and unexpose accordingly.

Fixes: #7378

@Nino-K Nino-K changed the title Add scanner to /proc/net/{tcp,udp} Scan /proc/net/{tcp,udp} for host network driver port bindings Nov 8, 2024
src/go/guestagent/main.go Fixed Show fixed Hide fixed
src/go/guestagent/main.go Fixed Show fixed Hide fixed
@jandubois
Copy link
Member

Can you fix the spelling errors (by adding the words to the dictionary)? That should re-trigger the actions...

@Nino-K Nino-K force-pushed the procnet-scanning-guest-agent branch 2 times, most recently from d621770 to b2aa16f Compare November 12, 2024 18:56
This introduces a scanner that monitors entries in /proc/net/{tcp,udp}.
When using the host network driver (--net=host) in Docker or containerd,
some port bindings are not exposed through the API. However, these bindings
are still visible in /proc/net because the container shares the host network
namespace.

The procnet scanner scans the corresponding files every 3 seconds and if
a new entry is found or removed it calls the host switch API to expose
and unexpose accordingly.

Signed-off-by: Nino Kodabande <[email protected]>
@Nino-K Nino-K force-pushed the procnet-scanning-guest-agent branch from b2aa16f to 348ef33 Compare November 12, 2024 19:21
Signed-off-by: Nino Kodabande <[email protected]>
Added scanner_stub to accomodate for non-linux build

Signed-off-by: Nino Kodabande <[email protected]>
When a container uses the host network driver (--network=host), it shares the host's network namespace.
In this case, it's important to consider the IP address the container's process is bound to. For example:

`nerdctl run --network=host -d python:slim python -m http.server 8020 --bind 127.0.0.1`

vs

`nerdctl run --network=host -d python:slim python -m http.server 8020`

If the process is bound to 127.0.0.1 (localhost), we need to create additional iptables rules to allow access
to the container’s bound port from outside the network namespace (e.g., localhost:8020).

This change ensures that the appropriate iptables rules are created and removed when a container's port is
bound to localhost, enabling external access to the bound port.

Signed-off-by: Nino Kodabande <[email protected]>
@Nino-K Nino-K force-pushed the procnet-scanning-guest-agent branch from bc3af5b to a615fb7 Compare November 13, 2024 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docker network setting "--net=host" does not work with 1.15.x using windows and wsl
2 participants