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

Apply the iptables rule to all networks #48

Merged
merged 1 commit into from
Jun 16, 2023

Conversation

Nino-K
Copy link
Member

@Nino-K Nino-K commented Jun 8, 2023

When using containerd publishing ports using 127.0.0.1 does not currently work. This issue seems to have existed since 1.7 or prior (I have only tested back to 1.7). The core of the issue is when a published port is bound to localhost the following CNI iptables rule is created for DNAT target for the running container:

DNAT       tcp  --  anywhere             localhost            tcp dpt:555 to:10.4.0.2:80

While this rule works fine if a user was about to establish a connection from the localhost network (VM network), however, if a connection is established from the host network the destination NAT rule above is no longer able to handle the incoming connection from other networks.

Since in the initial rule, the destination address is set to "localhost," the rule is designed to redirect incoming TCP packets from any source IP address to the destination loopback interface of the local machine (127.0.0.1:555). We modify this behavior by adding an additional rule below the existing rule to allow access to the service from external networks (host network) by setting the destination address to "anywhere." This means that the rule applies to packets with any destination IP address.

To summarize:

DNAT       tcp  --  anywhere             localhost            tcp dpt:555 to:10.4.0.2:80 // original rule
DNAT       tcp  --  anywhere             anywhere             tcp dpt:555 to:10.4.0.2:80 // additional rule

The original CNI rule redirects the traffic from any source to (from) destination localhost:servicePort to a final destination of 10.4.0.2:80.

Whereas the additional rule redirects the traffic from any source to (from) any destination anywhere:servicePort to a final destination of 10.4.0.2:80.

It is important to note that the additional rule does not directly modify or impact the existing behavior but rather enables wider network accessibility.

Related to: #46

@Nino-K Nino-K requested a review from mook-as June 8, 2023 19:18
When using containerd publishing ports using 127.0.0.1 does not currently work.
This issue seems to have existed since 1.7 or prior (I have only tested back to 1.7).
The core of the issue is when a published port is bound to localhost the following CNI
iptables rule is created for DNAT target for the running container:

DNAT       tcp  --  anywhere             localhost            tcp dpt:555 to:10.4.0.2:80

While this rule works fine if a user was about to establish a connection from the
localhost network (VM network), however, if a connection is established from the host
network the destination NAT rule above is no longer able to handle the incoming
connection from other networks.

Since in the initial rule, the destination address is set to "localhost," the rule is
designed to redirect incoming TCP packets from any source IP address to the destination
loopback interface of the local machine (127.0.0.1:555). We modify this behavior by adding
an additional rule below the existing rule to allow access to the service from external
networks (host network) by setting the destination address to "anywhere." This means that
the rule applies to packets with any destination IP address.

To summarize:

DNAT       tcp  --  anywhere             localhost            tcp dpt:555 to:10.4.0.2:80 // original rule
DNAT       tcp  --  anywhere             anywhere             tcp dpt:555 to:10.4.0.2:80 // additional rule

The original CNI rule redirects the traffic from any source to (from) destination
localhost:servicePort to a final destination of 10.4.0.2:80.

Whereas the additional rule redirects the traffic from any source to (from) any destination
anywhere:servicePort to a final destination of 10.4.0.2:80.

It is important to note that the additional rule does not directly modify or impact the
existing behavior but rather enables wider network accessibility.

Signed-off-by: Nino Kodabande <nkodabande@suse.com>
@Nino-K Nino-K force-pushed the apply-iptable-rules-default-network branch from 4ea2c20 to 036c067 Compare June 16, 2023 20:31
@Nino-K Nino-K merged commit c430550 into main Jun 16, 2023
3 checks passed
@Nino-K Nino-K deleted the apply-iptable-rules-default-network branch June 16, 2023 20:45
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.

None yet

2 participants