-
Notifications
You must be signed in to change notification settings - Fork 274
feat(injector): add list of ignored network interfaces #4700
Conversation
This change adds a new configurable list of ignored network interface names. Traffic received from and sent to those interfaces is not forwarded to the sidecar container by iptables. When this list is empty (the default), osm-injector produces the exact same iptables commands as it did before. The list is configured in the chart at `osm.networkInterfaceExclusionList` and in the MeshConfig at `spec.traffic.networkInterfaceExclusionList`. Fixes #4546 Signed-off-by: Jon Huhn <johuhn@microsoft.com>
Codecov Report
@@ Coverage Diff @@
## main #4700 +/- ##
=======================================
Coverage 69.48% 69.48%
=======================================
Files 217 217
Lines 15437 15495 +58
=======================================
+ Hits 10726 10767 +41
- Misses 4661 4678 +17
Partials 50 50
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
Looks good, just 1 blocking comment regarding rule ordering.
@@ -74,6 +74,11 @@ func generateIptablesCommands(outboundIPRangeExclusionList []string, outboundIPR | |||
// 1. Create inbound rules | |||
cmds = append(cmds, iptablesInboundStaticRules...) | |||
|
|||
// Ignore inbound traffic on specified interfaces | |||
for _, iface := range networkInterfaceExclusionList { | |||
cmds = append(cmds, fmt.Sprintf("-I OSM_PROXY_INBOUND -i %s -j RETURN", iface)) |
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.
What's the reason the inbound rule uses -I (insert before) and outbound rule uses -A (append)?
If ordering is important, kindly document this in the code.
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.
These inbound rules only work when they're added before the static rules, either with -I
or by adding them to the slice before with -A
. I would need help figuring out an exact reason why that's the case.
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.
Iptable rules are executed in order. So it makes sense to use -I
here so that the exclusions get applied first before other rules that can match the traffic. Could you add a comment here and also for -I OSM_PROXY_INBOUND -p tcp --match multiport --dports %s -j RETURN
which is missing a comment.
I am looking into the code to see if the ordering of outbound rules is correct.
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 narrowed it down to needing these commands at least before the last static rule:
// Redirect remaining inbound traffic to Envoy
"-A OSM_PROXY_INBOUND -p tcp -j OSM_PROXY_IN_REDIRECT",
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.
So this is how the rules should be ordered.
INBOUND:
exclusions
inclusions
static rules that don't redirect to proxy
redirect to proxy
OUTBOUND
exclusions
inclusions
status rules that don't redirect to proxy
redirect to proxy
The reason -I
is used with inbound is because the redirect to proxy rule: ...-A OSM_PROXY_INBOUND -p tcp -j OSM_PROXY_IN_REDIRECT
is a part of the static rule set. While for outbound, redirect to proxy rule: ... -A OSM_PROXY_OUTBOUND -j OSM_PROXY_OUT_REDIRECT
is added only after the exclusions/inclusions rules because the redirection rule OSM_PROXY_OUTBOUND -> OSM_PROXY_OUT_REDIRECT is different when inclusions are applied.
Your change looks good, could you add the following comment next to the inbound rule added:
// *Note: it is important to use the insert option '-I' instead of the append option '-A' to ensure the
// exclusion of traffic to the network interface happens before the rule that redirects traffic to the proxy
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.
Non blocking comment #4700 (comment)
Signed-off-by: Jon Huhn <johuhn@microsoft.com>
…sh#4700) * feat(injector): add list of ignored network interfaces This change adds a new configurable list of ignored network interface names. Traffic received from and sent to those interfaces is not forwarded to the sidecar container by iptables. When this list is empty (the default), osm-injector produces the exact same iptables commands as it did before. The list is configured in the chart at `osm.networkInterfaceExclusionList` and in the MeshConfig at `spec.traffic.networkInterfaceExclusionList`. Fixes openservicemesh#4546 Signed-off-by: Jon Huhn <johuhn@microsoft.com> * codegen Signed-off-by: Jon Huhn <johuhn@microsoft.com> * add comment Signed-off-by: Jon Huhn <johuhn@microsoft.com> Co-authored-by: Shashank Ram <21697719+shashankram@users.noreply.github.com>
Description:
This change adds a new configurable list of ignored network interface
names. Traffic received from and sent to those interfaces is not
forwarded to the sidecar container by iptables. When this list is empty
(the default), osm-injector produces the exact same iptables commands as
it did before.
The list is configured in the chart at
osm.networkInterfaceExclusionList
and in the MeshConfig at
spec.traffic.networkInterfaceExclusionList
.Fixes #4546
Testing done:
Updated unit tests
Tested manually e2e
Installed Multus CNI on an AKS cluster:
kubectl apply -f https://raw.githubusercontent.com/k8snetworkplumbingwg/multus-cni/master/deployments/multus-daemonset-thick-plugin.yml
Created a new network interface
net1
:Created 2 ubuntu pods from deployments named
client
andserver
each running containers defined by:kubectl exec -it deploy/server -c server -- bash -c 'ip a && python3 -m http.server'
net1
interface, e.g. 192.168.1.200, which changes each time the pod is recreatedkubectl exec -it deploy/client -c client -- curl -I 192.168.1.200:8000
Installed OSM
osm namespace add default
kubectl rollout restart deploy client server
kubectl exec -it deploy/server -c server -- bash -c 'ip a && python3 -m http.server'
kubectl exec -it deploy/client -c client -- curl -I 192.168.1.200:8000
kubectl patch meshconfig -n osm-system osm-mesh-config -p '{"spec": {"traffic": {"networkInterfaceExclusionList": ["net1"]}}}' --type=merge
kubectl rollout restart deploy client server
kubectl exec -it deploy/server -c server -- bash -c 'ip a && python3 -m http.server'
net1
interface, e.g. 192.168.1.200kubectl exec -it deploy/client -c client -- curl -I 192.168.1.200:8000
/stats
Envoy endpoint on either pod didn't show any of that traffic going through Envoy.Affected area:
Please answer the following questions with yes/no.
Does this change contain code from or inspired by another project? No
Is this a breaking change? No
Has documentation corresponding to this change been updated in the osm-docs repo (if applicable)? Yes, add network interface exclusions osm-docs#361