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

[Windows] Fix Pod cannot access endpoints with external IP through ClusterIP Service #1824

Merged
merged 3 commits into from
Feb 9, 2021

Conversation

ruicao93
Copy link
Contributor

@ruicao93 ruicao93 commented Feb 5, 2021

When a Pod accesses a ClusterIP Service and the IP of the selected
endpoint is not in "cluster-cidr". The request packets need to be
SNAT'd after have been DNAT'd. For example, the endpoint Pod may
run in hostNetwork and the IP of the endpoint is the current
Node IP. Currently, on Windows Node antrea applies both DNAT
and SNAT in the same ct_zone. That's not supported by OVS.

In this patch, we introduce a new ct_zone to track this kind of
SNATed connection in a different ct_zone.

Fixes: #1759

Signed-off-by: Rui Cao [email protected]

@ruicao93 ruicao93 changed the title [WIP][Windows] Fix Pod cannot access k8s API server service issue [WIP][Windows] Fix Pod cannot access k8s API server service Feb 5, 2021
@ruicao93
Copy link
Contributor Author

ruicao93 commented Feb 5, 2021

/test-all

@codecov-io
Copy link

codecov-io commented Feb 5, 2021

Codecov Report

❗ No coverage uploaded for pull request base (main@abb6c33). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1824   +/-   ##
=======================================
  Coverage        ?   42.26%           
=======================================
  Files           ?      196           
  Lines           ?    16715           
  Branches        ?        0           
=======================================
  Hits            ?     7065           
  Misses          ?     8654           
  Partials        ?      996           
Flag Coverage Δ
kind-e2e-tests 42.26% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

@ruicao93 ruicao93 force-pushed the service_api branch 2 times, most recently from c8e2eef to 267accb Compare February 8, 2021 01:20
@ruicao93 ruicao93 added this to the Antrea v0.13.0 release milestone Feb 8, 2021
@ruicao93 ruicao93 changed the title [WIP][Windows] Fix Pod cannot access k8s API server service [Windows] Fix Pod cannot access k8s API server service Feb 8, 2021
@ruicao93
Copy link
Contributor Author

ruicao93 commented Feb 8, 2021

/test-all

@ruicao93 ruicao93 requested a review from tnqn February 8, 2021 01:46
@ruicao93 ruicao93 force-pushed the service_api branch 2 times, most recently from 89c7786 to efc9f5c Compare February 8, 2021 03:19
Copy link
Contributor

@jianjuns jianjuns left a comment

Choose a reason for hiding this comment

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

I think this change also fixes traffic to Services with external endpoints, besides Services backed by Node IPs. Could you change the commit message for this?

pkg/ovs/openflow/ofctrl_builder.go Outdated Show resolved Hide resolved
pkg/ovs/openflow/ofctrl_builder.go Outdated Show resolved Hide resolved
pkg/agent/openflow/pipeline.go Outdated Show resolved Hide resolved
pkg/agent/openflow/pipeline.go Outdated Show resolved Hide resolved
pkg/agent/openflow/pipeline.go Outdated Show resolved Hide resolved
pkg/agent/openflow/pipeline.go Outdated Show resolved Hide resolved
pkg/agent/openflow/pipeline.go Outdated Show resolved Hide resolved
pkg/agent/openflow/pipeline.go Outdated Show resolved Hide resolved
pkg/agent/openflow/pipeline.go Outdated Show resolved Hide resolved
pkg/agent/openflow/pipeline.go Outdated Show resolved Hide resolved
@ruicao93
Copy link
Contributor Author

ruicao93 commented Feb 8, 2021

I think this change also fixes traffic to Services with external endpoints, besides Services backed by Node IPs. Could you change the commit message for this?

Yes, exactly. Thanks Jianjun for your review. Will change message soon in next update.

@ruicao93
Copy link
Contributor Author

ruicao93 commented Feb 8, 2021

/test-all

@ruicao93 ruicao93 force-pushed the service_api branch 3 times, most recently from 245fada to 2915296 Compare February 8, 2021 05:36
@jianjuns
Copy link
Contributor

jianjuns commented Feb 8, 2021

Would you change the title of the commit too?

@ruicao93 ruicao93 changed the title [Windows] Fix Pod cannot access k8s API server service [Windows] Fix Pod cannot access endpoints with external IP through cluster service Feb 8, 2021
@ruicao93
Copy link
Contributor Author

ruicao93 commented Feb 8, 2021

Would you change the title of the commit too?

Sure, thanks for your reminder.

@ruicao93
Copy link
Contributor Author

ruicao93 commented Feb 8, 2021

/test-all

@ruicao93 ruicao93 changed the title [Windows] Fix Pod cannot access endpoints with external IP through cluster service [Windows] Fix Pod cannot access endpoints with external IP through ClusterIP Service Feb 8, 2021
pkg/agent/openflow/pipeline.go Outdated Show resolved Hide resolved
// - ct_mark is set to 0x21(ServiceCTMark)
// This flow resubmits the packets to the following table to avoid being forwarded
// to the bridge port by default.
flows = append(flows, c.pipeline[conntrackStateTable].BuildFlow(priorityHigh).
Copy link
Member

Choose a reason for hiding this comment

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

How is it different from the first flow created in L711? seems duplicate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we add a new match field markTrafficFromUplink . Or the traffic recieved from uplink will hit L1563 and be forwarded to br-int directly.

		// Output the non-SNAT packet to the bridge interface directly if it is received from the uplink interface.
		c.pipeline[conntrackStateTable].BuildFlow(priorityNormal).
			MatchProtocol(binding.ProtocolIP).
			MatchRegRange(int(marksReg), markTrafficFromUplink, binding.Range{0, 15}).
			Action().Output(int(bridgeOFPort)).
			Cookie(c.cookieAllocator.Request(category).Raw()).
			Done(),

Copy link
Member

Choose a reason for hiding this comment

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

For simplicity, could we make L1563 low priority, L1552 flow can be normal priority too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's reasonable by analyzing the flows. Will have a try.

pkg/agent/openflow/pipeline.go Outdated Show resolved Hide resolved
pkg/agent/openflow/pipeline.go Show resolved Hide resolved
pkg/agent/openflow/pipeline.go Outdated Show resolved Hide resolved
Cookie(c.cookieAllocator.Request(category).Raw()).
Done())
// If SNAT is needed after DNAT:
// - For new connection: commit to CtZoneSNAT
Copy link
Member

Choose a reason for hiding this comment

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

Do we consider doing all SNAT in this zone later? It seems currently SNAT is performed in CtZone when it's not DNATed and in CtZoneSNAT otherwise, which seems a little difficult complex. Or you plan to unify them when moving to two bridges?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think unify them when moving to two bridges. This PR only handle the DNAT + SNAT case to aovid introducing big change.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would agree we should handle all SNAT in a single way. Need to understand the two bridge proposal better.

Copy link
Contributor

Choose a reason for hiding this comment

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

Once you have something, could you share? I hope to understand how we are going to organize flows with two bridges, as I am designing flows for SNAT policy, which might be impacted by the two-bridge change.

Copy link
Contributor Author

@ruicao93 ruicao93 Feb 9, 2021

Choose a reason for hiding this comment

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

Sure @jianjuns. Actually the two bridges is just a draft idea for NodePort Service support on Windows and need to be investigated.

Agree with you and Quan, handle all SNAT in a single way would be better.

But consider the v0.13.0 is near to release, do you think if we could merge current change first and make further step(all SNAT in single ct_zone or use other ways) after v0.13.0?

Copy link
Contributor

Choose a reason for hiding this comment

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

We can unify SNAT flows in the next release.

When a Pod access cluster service and the selected endpoint uses
node IP(hostnetwork mode). The request packets need to be SNATed
after have been DNATed. On Windows node, antrea both applied both
DNAT and SNAT in the same ct_zone. That's not supported by OVS.

In this patch, we introduce a new ct_zone to track this kind of
SNATed connection in a different ct_zone.

Fixes: antrea-io#1759

Signed-off-by: Rui Cao <[email protected]>
When a Pod accesses a ClusterIP Service and the IP of the selected
endpoint is not in "cluster-cidr". The request packets need to be
SNAT'd after have been DNAT'd. For example, the endpoint Pod may
run in hostNetwork and the IP of the endpoint is the current
Node IP. Currently, on Windows Node antrea applies both DNAT
and SNAT in the same ct_zone. That's not supported by OVS.

In this patch, we introduce a new ct_zone to track this kind of
SNATed connection in a different ct_zone.

Fixes: antrea-io#1759

Signed-off-by: Rui Cao <[email protected]>
Signed-off-by: Rui Cao <[email protected]>
@ruicao93
Copy link
Contributor Author

ruicao93 commented Feb 8, 2021

/test-all

@ruicao93
Copy link
Contributor Author

ruicao93 commented Feb 9, 2021

/test-containerd-networkpolicy

@ruicao93
Copy link
Contributor Author

ruicao93 commented Feb 9, 2021

/test-containerd-conformance

@ruicao93 ruicao93 merged commit 8027293 into antrea-io:main Feb 9, 2021
antoninbas pushed a commit to antoninbas/antrea that referenced this pull request Feb 10, 2021
…usterIP Service (antrea-io#1824)

When a Pod accesses a ClusterIP Service and the IP of the selected
endpoint is not in "cluster-cidr". The request packets need to be
SNAT'd after have been DNAT'd. For example, the endpoint Pod may
run in hostNetwork and the IP of the endpoint is the current
Node IP. Currently, on Windows Node antrea applies both DNAT
and SNAT in the same ct_zone. That's not supported by OVS.

In this patch, we introduce a new ct_zone to track this kind of
SNATed connection in a different ct_zone.

Fixes: antrea-io#1759

Signed-off-by: Rui Cao <[email protected]>
antoninbas pushed a commit to antoninbas/antrea that referenced this pull request Feb 10, 2021
…usterIP Service (antrea-io#1824)

When a Pod accesses a ClusterIP Service and the IP of the selected
endpoint is not in "cluster-cidr". The request packets need to be
SNAT'd after have been DNAT'd. For example, the endpoint Pod may
run in hostNetwork and the IP of the endpoint is the current
Node IP. Currently, on Windows Node antrea applies both DNAT
and SNAT in the same ct_zone. That's not supported by OVS.

In this patch, we introduce a new ct_zone to track this kind of
SNATed connection in a different ct_zone.

Fixes: antrea-io#1759

Signed-off-by: Rui Cao <[email protected]>
antoninbas pushed a commit that referenced this pull request Feb 11, 2021
…usterIP Service (#1824)

When a Pod accesses a ClusterIP Service and the IP of the selected
endpoint is not in "cluster-cidr". The request packets need to be
SNAT'd after have been DNAT'd. For example, the endpoint Pod may
run in hostNetwork and the IP of the endpoint is the current
Node IP. Currently, on Windows Node antrea applies both DNAT
and SNAT in the same ct_zone. That's not supported by OVS.

In this patch, we introduce a new ct_zone to track this kind of
SNATed connection in a different ct_zone.

Fixes: #1759

Signed-off-by: Rui Cao <[email protected]>
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.

Pods running on windows nodes cannot access the API server using the internal Kubernetes Service
5 participants