Commit Graph

246 Commits

Author SHA1 Message Date
Dan Winship
4381973a44 Revert (most of) "Issue 70020; Flush Conntrack entities for SCTP"
This commit did not actually work; in between when it was first
written and tested, and when it merged, the code in
pkg/proxy/endpoints.go was changed to only add UDP endpoints to the
"stale endpoints"/"stale services" lists, and so checking for "either
UDP or SCTP" rather than just UDP when processing those lists had no
effect.

This reverts most of commit aa8521df66
(but leaves the changes related to
ipvs.IsRsGracefulTerminationNeeded() since that actually did have the
effect it meant to have).
2023-03-14 12:18:58 -04:00
Kubernetes Prow Robot
611273a5bb
Merge pull request #115253 from danwinship/proxy-update-healthchecknodeport
Split out HealthCheckNodePort stuff from service/endpoint map Update()
2023-03-13 15:22:48 -07:00
Dan Winship
0c2711bf24 Make NodePortAddresses abstraction around GetNodeAddresses/ContainsIPv4Loopback 2023-02-22 08:32:19 -05:00
Kubernetes Prow Robot
c94f708ce4
Merge pull request #114470 from danwinship/kep-3178-fixups
KEP-3178-related iptables rule fixups
2023-02-21 14:24:08 -08:00
Artem Minyaylov
f573e14942 Update k8s.io/utils to latest version
Update all usages of FakeExec to pointer to avoid copying the mutex
2023-02-04 11:05:22 -08:00
Dan Winship
d901992eae Split out HealthCheckNodePort stuff from service/endpoint map Update()
In addition to actually updating their data from the provided list of
changes, EndpointsMap.Update() and ServicePortMap.Update() return a
struct with some information about things that changed because of that
update (eg services with stale conntrack entries).

For some reason, they were also returning information about
HealthCheckNodePorts, but they were returning *static* information
based on the current (post-Update) state of the map, not information
about what had *changed* in the update. Since this doesn't match how
the other data in the struct is used (and since there's no reason to
have the data only be returned when you call Update() anyway) , split
it out.
2023-01-22 10:33:33 -05:00
Dan Winship
b9bc0e5ac8 Ensure needFullSync is set at iptables proxy startup
The unit tests were broken with MinimizeIPTablesRestore enabled
because syncProxyRules() assumed that needFullSync would be set on the
first (post-setInitialized()) run, but the unit tests didn't ensure
that.

(In fact, there was a race condition in the real Proxier case as well;
theoretically syncProxyRules() could be run by the
BoundedFrequencyRunner after OnServiceSynced() called setInitialized()
but before it called forceSyncProxyRules(), thus causing the first
real sync to try to do a partial sync and fail. This is now fixed as
well.)
2023-01-18 10:50:12 -05:00
Dan Winship
0ea0295965 Duplicate the "anti-martian-packet" rule in kube-proxy
This rule was mistakenly added to kubelet even though it only applies
to kube-proxy's traffic. We do not want to remove it from kubelet yet
because other components may be depending on it for security, but we
should make kube-proxy output its own rule rather than depending on
kubelet.
2022-12-29 16:24:58 -05:00
Dan Winship
37a8a2bdaf fix indentation of iptables dumps in some test cases
(Especially, use tabs rather than spaces.)
2022-12-29 16:24:58 -05:00
Dan Winship
1870c4cdd7 Add a comment-only rule to the end of KUBE-FW-* chains
With the removal of the "-j KUBE-MARK-DROP" rules, the firewall chains
end rather ambiguously. Add a comment-only rule explaining what will
happen.
2022-12-29 16:24:58 -05:00
Dan Winship
c6cc056675 Replace iptables-proxy-specific SCTP e2e test with a unit test
We had a test that creating a Service with an SCTP port would create
an iptables rule with "-p sctp" in it, which let us test that
kube-proxy was doing vaguely the right thing with SCTP even if the e2e
environment didn't have SCTP support. But this would really make much
more sense as a unit test.
2022-12-13 16:21:12 -05:00
Tim Hockin
dd0a50336e
ServiceInternalTrafficPolicyType: s/Type//
Rename ServiceInternalTrafficPolicyType => ServiceInternalTrafficPolicy
2022-12-11 13:48:31 -08:00
Tim Hockin
d0e2b06850
ServiceExternalTrafficPolicyType: s/Type//
Rename ServiceExternalTrafficPolicyType => ServiceExternalTrafficPolicy
2022-12-11 13:48:27 -08:00
Kubernetes Prow Robot
d86c013b0d
Merge pull request #108250 from cyclinder/add_flag_in_proxy
kube-proxy:  add a flag  to  disable nodePortOnLocalhost
2022-11-03 17:10:13 -07:00
Andy Voltz
29f4862ed8 Promote ServiceInternalTrafficPolicy to GA 2022-11-03 13:17:03 -04:00
Manav Agarwal
3320e50e24 If applied, this commit will refactor variable names in kube-proxy 2022-11-03 03:45:57 +05:30
cyclinder
bef2070031
kube-proxy: add a flag to disables the allowing NodePort services to be accessed via localhost 2022-11-02 16:17:52 +08:00
Dan Winship
818de5a545 proxy/iptables: Add metric for partial sync failures, add test 2022-09-26 16:31:42 -04:00
Dan Winship
ab326d2f4e proxy/iptables: Don't rewrite chains that haven't changed
iptables-restore requires that if you change any rule in a chain, you
have to rewrite the entire chain. But if you avoid mentioning a chain
at all, it will leave it untouched. Take advantage of this by not
rewriting the SVC, SVL, EXT, FW, and SEP chains for services that have
not changed since the last sync, which should drastically cut down on
the size of each iptables-restore in large clusters.
2022-09-26 16:30:42 -04:00
Dan Winship
c437b15441 proxy/iptables: make part of the unit test sanity-checking optional 2022-08-24 09:02:48 -04:00
ialidzhikov
f2bc2ed2da pkg/proxy: Replace deprecated func usage from the k8s.io/utils/pointer pkg 2022-08-14 18:27:33 +03:00
Dan Winship
f65fbc877b proxy/iptables: remove last references to KUBE-MARK-DROP 2022-07-28 09:03:49 -04:00
Dan Winship
9313188909 proxy/iptables: Don't use KUBE-MARK-DROP for LoadBalancerSourceRanges 2022-07-28 09:03:46 -04:00
Dan Winship
95705350d5 proxy/iptables: Don't use KUBE-MARK-DROP for "no local endpoints"
Rather than marking packets to be dropped in the "nat" table and then
dropping them from the "filter" table later, just use rules in
"filter" to drop the packets we don't like directly.
2022-06-29 16:37:24 -04:00
Dan Winship
283218bd4c proxy/iptables: update TestTracePackets
Re-sync the rules from TestOverallIPTablesRulesWithMultipleServices to
make sure we're testing all the right kinds of rules. Remove a
duplicate copy of the KUBE-MARK-MASQ and KUBE-POSTROUTING rules.

Update the "REJECT" test to use the new svc6 from
TestOverallIPTablesRulesWithMultipleServices. (Previously it had used
a modified version of TOIPTRWMS's svc3.)
2022-06-29 16:33:13 -04:00
Dan Winship
59b7f969e8 proxy/iptables: fix up TestOverallIPTablesRulesWithMultipleServices
svc2b was using the same ClusterIP as svc3; change it and rename the
service to svc5 to make everything clearer.

Move the test of LoadBalancerSourceRanges from svc2 to svc5, so that
svc2 tests the rules for dropping packets due to
externalTrafficPolicy, and svc5 tests the rules for dropping packets
due to LoadBalancerSourceRanges, rather than having them both mixed
together in svc2.

Add svc6 with no endpoints.
2022-06-29 16:33:13 -04:00
Dan Winship
7d3ba837f5 proxy/iptables: only clean up chains periodically in large clusters
"iptables-save" takes several seconds to run on machines with lots of
iptables rules, and we only use its result to figure out which chains
are no longer referenced by any rules. While it makes things less
confusing if we delete unused chains immediately, it's not actually
_necessary_ since they never get called during packet processing. So
in large clusters, make it so we only clean up chains periodically
rather than on every sync.
2022-06-29 11:14:38 -04:00
Dan Winship
1cd461bd24 proxy/iptables: abstract the "endpointChainsNumberThreshold" a bit
Turn this into a generic "large cluster mode" that determines whether
we optimize for performance or debuggability.
2022-06-29 11:14:38 -04:00
Dan Winship
c12da17838 proxy/iptables: Add a unit test with multiple resyncs 2022-06-29 11:14:38 -04:00
Kubernetes Prow Robot
dc4e91a875
Merge pull request #109844 from danwinship/iptables-tests-new
improve parsing in iptables unit tests
2022-06-10 14:27:44 -07:00
Dan Winship
24e1e3d9ee proxy/iptables: port packet-flow tests to use new parsing stuff 2022-05-09 11:29:08 -04:00
Dan Winship
10a72a9e03 pkg/util/iptables/testing: Add IPTables dump-parsing helpers 2022-05-09 11:29:06 -04:00
Dan Winship
f0f47ae590 proxy/iptables: tweak sortIPTablesRules some more
Sort the ":CHAINNAME" lines in the same order as the "-A CHAINNAME"
lines (meaning, KUBE-NODEPORTS and KUBE-SERVICES come first).

(This will simplify IPTablesDump because it won't need to keep track
of the declaration order and the rule order separately.)
2022-05-09 11:19:28 -04:00
Dan Winship
b0d9c063a8 unexport mistakenly-exported constants 2022-05-06 07:33:29 -04:00
Kubernetes Prow Robot
2b3508e0f1
Merge pull request #109826 from danwinship/multi-load-balancer
fix kube-proxy bug with multiple LB IPs and source ranges
2022-05-06 03:09:15 -07:00
Dan Winship
813aca47af proxy/iptables: fix firewall rules with multiple LB IPs
The various loops in the LoadBalancer rule section were mis-nested
such that if a service had multiple LoadBalancer IPs, we would write
out the firewall rules multiple times (and the allowFromNode rule for
the second and later IPs would end up being written after the "else
DROP" rule from the first IP).
2022-05-05 10:58:09 -04:00
Dan Winship
df589b46a1 proxy/iptables: test multiple LoadBalancer IPs on one service 2022-05-05 10:58:09 -04:00
Dan Winship
709b4f696d proxy/iptables: test LoadBalancerSourceRanges vs node IP
The LoadBalancer rules change if the node IP is in one of the
LoadBalancerSourceRange subnets, so make sure to set nodeIP on the
fake proxier so we can test this, and add a second source range to
TestLoadBalancer containing the node IP. (This changes the result of
one flow test that previously expected that node-to-LB would be
dropped.)
2022-05-05 10:58:07 -04:00
Kubernetes Prow Robot
50e1f70027
Merge pull request #109782 from danwinship/no-local-endpoints-metric
Don't increment "no local endpoints" metric when there are no remote endpoints
2022-05-05 05:02:20 -07:00
Kubernetes Prow Robot
794d3ab686
Merge pull request #109740 from AllenZMC/fix_test_iptables
Optimize test cases for iptables
2022-05-05 01:42:51 -07:00
Dan Winship
84ad54f0e5 Don't increment "no local endpoints" metric when there are no remote endpoints
A service having no _local_ endpoints when it does have remote
endpoints is different from a service having no endpoints at all.
2022-05-04 12:38:17 -04:00
AllenZMC
a5fb9bbd35 Optimize test cases for iptables 2022-05-01 19:33:06 +08:00
Dan Winship
0ecf11a23b proxy/iptables: add a general test of internal vs external traffic
Add TestInternalExternalMasquerade, which tests whether various
packets are considered internal or external for purposes of traffic
policy, and whether they get masqueraded, with and without
--masquerade-all, with and without a working LocalTrafficDetector.
(This extends and replaces the old TestMasqueradeAll.)
2022-04-11 13:23:08 -04:00
Dan Winship
f4261283ac proxy/iptables: add packet-flow-based tests of iptables rules
Add a new framework for testing out how particular packets would be
handled by a given set of iptables rules. (eg, "assert that a packet
from 10.180.0.2 to 172.30.0.41:80 gets NATted to 10.180.0.1:80 without
being masqueraded"). Add tests using this to all of the existing unit
tests.

This makes it easier to tell whether a given code change has any
effect on behavior, without having to carefully examine the diffs to
the generated iptables rules.
2022-04-11 13:23:08 -04:00
Dan Winship
cd55f35306 proxy/iptables: tweak sortIPTablesRules a bit
It's confusing to have the "this must be the last rule" get sorted to
be the first rule in KUBE-SERVICES...
2022-04-07 08:38:14 -04:00
Dan Winship
d9ca665551 proxy/iptables: fix up some test case comments 2022-04-07 08:38:14 -04:00
Dan Winship
261f4f9e2d proxy/iptables: remove redundant test
We originally had one HealthCheckNodePort test that used
assertIPTablesRulesEqual() and one that didn't, but later I went
through and made all the tests use assertIPTablesRulesEqual() and
didn't notice that this resulted in there now being two
nearly-identical HealthCheckNodePort tests.
2022-04-07 08:36:34 -04:00
Max Renaud
198367a486 Added test where both policies are set 2022-03-31 18:54:28 +00:00
Max Renaud
f0dfac5d07 Add sync_proxy_rules_no_local_endpoints_total metric 2022-03-31 18:54:23 +00:00
Tim Hockin
40e21e310f Elide the -FW- chain when possible
This makes it epsilon harder to reason about but saves one chain
declaration and one rule per service-port usually.
2022-03-30 09:55:34 -07:00