-
Notifications
You must be signed in to change notification settings - Fork 370
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
Support Service loadBalancerSourceRanges in AntreaProxy #6181
base: main
Are you sure you want to change the base?
Support Service loadBalancerSourceRanges in AntreaProxy #6181
Conversation
c1e1141
to
779e504
Compare
This PR is stale because it has been open 90 days with no activity. Remove stale label or comment, or this will be closed in 90 days |
779e504
to
7387fd3
Compare
7387fd3
to
78ec531
Compare
@tnqn @wenyingd @antoninbas Could you help have a look at this PR? Thanks a lot |
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.
I did a quick review, but @tnqn and @wenyingd should definitely take a look if possible.
I wonder if we should have some e2e test coverage for this?
One edge case I can think of would be a NodePort Service with loadBalancerSourceRanges
; according to the kube-proxy code base, loadBalancerSourceRanges
should not apply to NodePort traffic.
docs/design/ovs-pipeline.md
Outdated
3. table=ServiceMark, priority=200,tcp,nw_src=192.168.77.0/24,nw_dst=192.168.77.152,tp_dst=80 actions=set_field:0x20000000/0x20000000->reg4", | ||
4. table=ServiceMark, priority=200,tcp,nw_src=192.168.78.0/24,nw_dst=192.168.77.152,tp_dst=80 actions=set_field:0x20000000/0x20000000->reg4", | ||
5. table=ServiceMark, priority=190,tcp,nw_dst=192.168.77.152,tp_dst=80 actions=set_field:0x4000/0x4000->reg0", |
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.
I am probably missing something obvious, but what is the point of setting LoadBalancerSourceRangesRegMark
in flows 3 and 4? If the source IP doesn't fall in the correct range, we mark the packet for rejection in flow 5, so it doesn't seem that we need to remember that the source IP was in the correct range?
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.
I have updated the commit message. Maybe it can help.
docs/design/ovs-pipeline.md
Outdated
Service `loadBalancerSourceRanges`. It's worth noting that `loadBalancerSourceRanges` only exclusively influences the | ||
traffic from the external network as `LoadBalancerSourceRangesRegMark` is not used in flow 10. |
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.
Does this match the kube-proxy behavior? I took a quick look and it seems that even when traffic comes from local Pods, loadBalancerSourceRanges
is enforced
I may be misunderstanding the comment / implementation
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.
You are right. Since K8s 1.25, the Pod CIDR is not allowed by default. I have updated the implementation.
e8dd1ba
to
edba464
Compare
Added
In the current implementation, loadBalancerSourceRanges only applies to LoadBalancer ingress IPs. |
edba464
to
f54ac3a
Compare
docs/design/ovs-pipeline.md
Outdated
If you dump the flows of this table, you may see the following: | ||
|
||
```text | ||
1. table=LoadBalancerSourceRanges, priority=200,tcp,nw_src=192.168.77.0/24,nw_dst=192.168.77.152,tp_dst=80 actions=goto_table:SessionAffinity", |
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.
When reading the CR example, the thought in my mind is to use OVS conjunction, do you think that works?
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.
In current design, we can leverage most code of pkg/agent/proxier.go and pkg/agent/openflow. For example, like InstallServiceFlows
in pkg/agent/openflow/client.go, installing a single ClusterIP, LoadBalancerIP, externalIP or NodePort of a Service. If we use conjunction, at least we may add a new function or enhance InstallServiceFlows
to install multiple LoadBalancerIPs. Besides, we may also need a conjunction id allocator.
docs/design/ovs-pipeline.md
Outdated
```text | ||
1. table=LoadBalancerSourceRanges, priority=200,tcp,nw_src=192.168.77.0/24,nw_dst=192.168.77.152,tp_dst=80 actions=goto_table:SessionAffinity", | ||
2. table=LoadBalancerSourceRanges, priority=200,tcp,nw_src=192.168.78.0/24,nw_dst=192.168.77.152,tp_dst=80 actions=goto_table:SessionAffinity", | ||
3. table=LoadBalancerSourceRanges, priority=190,tcp,nw_dst=192.168.77.152,tp_dst=80 actions=drop", |
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.
For the packets that don't locate in the source range, is the "Drop" action or "Reject" action expected?
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.
Drop
is expected, as kube-proxy's behavior.
@@ -799,6 +799,9 @@ func (c *client) InstallServiceFlows(config *types.ServiceConfig) error { | |||
if config.IsDSR { | |||
flows = append(flows, c.featureService.dsrServiceMarkFlow(config)) | |||
} | |||
if len(config.LoadBalancerSourceRanges) != 0 { |
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.
ditto, does it need to be scope with condition proxyLoadBalancerIPs==true
?
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.
No, the function will be call in pkg/agent/proxier.go when proxyLoadBalancerIPs==true
.
@@ -3106,6 +3107,34 @@ func (f *featureService) gatewaySNATFlows() []binding.Flow { | |||
return flows | |||
} | |||
|
|||
func (f *featureService) loadBalancerSourceRangesMarkFlows(config *types.ServiceConfig) []binding.Flow { |
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.
We didn't introduce any register mark for LoadBalancer traffic with the check on the source range, and we don't add mark on the packet via the flows built in this function, so maybe remove word "Mark" from the function name? Or rename it as loadBalancerSourceRangesValidateFlows
?
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.
I have changed the designed back because I found the drop action doesn't take effect. For example:
table=1, priority=200,ip actions=resubmit(,2),resubmit(,3),resubmit(,4),resubmit(,5)
table=2, priority=0, actions=goto_tables:3
table=3, priority=190,tcp,nw_dst=169.254.169.1,tp_dst=8080 actions=drop
table=4, priority=0,actions=load:0x1->NXM_NX_REG4[19]
table=5, ......
In above flows, the packet destined for 169.254.169.1
matched by the flow in table 3 will not be dropped when I made some tests.
647e567
to
f4f330a
Compare
Can one of the admins verify this patch? |
4547344
to
c76dd8e
Compare
For antrea-io#5493 This commit introduces support for loadBalancerSourceRanges for LoadBalancer Services. Here is an example of a LoadBalancer Service configuration allowing access from specific CIDRs: ```yaml apiVersion: v1 kind: Service metadata: name: sample-loadbalancer-source-ranges spec: selector: app: web ports: - protocol: TCP port: 80 targetPort: 80 type: LoadBalancer loadBalancerSourceRanges: - "192.168.77.0/24" - "192.168.78.0/24" status: loadBalancer: ingress: - ip: 192.168.77.150 ``` [New] Here are the corresponding flows: ```text 1. table=ServiceMark, priority=200,tcp,nw_src=192.168.77.0/24,nw_dst=192.168.77.150,tp_dst=80 actions=set_field:0x20000000/0x60000000->reg4", 2. table=ServiceMark, priority=200,tcp,nw_src=192.168.78.0/24,nw_dst=192.168.77.150,tp_dst=80 actions=set_field:0x20000000/0x60000000->reg4", 3. table=ServiceMark, priority=190,tcp,nw_dst=192.168.77.150,tp_dst=80 actions=set_field:0x40000000/0x60000000->reg4", 4. table=ServiceLB, priority=200,tcp,reg4=0x0x20010000/0x0x60070000,nw_dst=192.168.77.150,tp_dst=80 actions=set_field:0x200/0x200->reg0,set_field:0x20000/0x70000->reg4,set_field:0xe->reg7,group:14 5. table=ServiceLB, priority=190,reg4=0x40000000/0x60000000 actions=drop ``` - Flow 1 is to match packets from allowed CIDR `192.168.77.0/24`, marking them with `LoadBalancerSourceRangesAllowRegMark`. - Flow 2 is similar to flow 1 but for CIDR `192.168.78.0/24`. - Flow 3 is to match packets not from allowed CIDRs, marking with `LoadBalancerSourceRangesDropRegMark`. - Flow 4 is to match allowed packets with `LoadBalancerSourceRangesAllowRegMark` and perform load balancing. - Flow 5 is to match not allowed packets with `LoadBalancerSourceRangesDropRegMark` and drop. Signed-off-by: Hongliang Liu <hongliang.liu@broadcom.com>
c76dd8e
to
695df4b
Compare
Fix #5493
This commit introduces support for loadBalancerSourceRanges for LoadBalancer
Services.
Here is an example of a LoadBalancer Service configuration allowing access
from specific CIDRs:
[New] Here are the corresponding flows:
192.168.77.0/24
, marking them withLoadBalancerSourceRangesAllowRegMark
.192.168.78.0/24
.LoadBalancerSourceRangesDropRegMark
.LoadBalancerSourceRangesAllowRegMark
andperform load balancing.
LoadBalancerSourceRangesDropRegMark
anddrop.