-
Notifications
You must be signed in to change notification settings - Fork 742
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
Randomise outgoing port for connections in the SNAT iptables rule. #246
Conversation
Realized that since kernel 3.14 there has been an option in the extensions called |
As the PR adds the
I'm not aware of the reasoning behind the original naming scheme, but this should make clear what each option actually means and may also make the code a bit cleaner/less convoluted. |
The first revision I wrote was tested on an old kernel that didn't support I modified the code to therefore support |
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.
Thanks for contributing!
Could you please squash these changes to a single commit?
I like this idea and believe that it is necessary. But I guess that updated SNAT rule is not available until the host was rebooted? I mean that if you change
Even if the answer is yes, it might be better to leave it as a known limitation rather than fixing it, though. |
dddf2c7
to
54c6547
Compare
54c6547
to
77f8938
Compare
Sorry for the mess of commits, probably shouldn't be coding late at night. That's what Squash on Merge is for right?
Right now, any changes to the network environment (including modification of this setting) will require an instance reboot to action. It might be possible to make it work with just a CNI plugin restart by looping through and inspecting all of the rules. I've written some code to this end, but I want to do some robust testing of it before I create a PR. This also means writing unit tests for the code, right now we don't have many for SNAT. For example: if a customer adds or removes VPC CIDR to their VPC, the number of |
Issue #, if available: N/A
Description of changes: This change introduces the
--random
flag to outgoing SNAT connections, and enables it by default.When making a large number of outgoing connections to the same endpoint there is a known race condition with SNAT rules that means that two connections can be assigned the same outgoing port from the ephemeral range. This results in connection traffic (for both the client and server) being unable to track both connections because they will have the same Source IP Address, Source Port, Destination IP Address, and Destination Port, resulting in one process being "orphaned".
To prevent this edge case from occurring you can enable the
--random
flag within the SNAT rule which will select a random (unused) port from the ephemeral range rather than assigning them sequentially.The impact for enabling this should be minimal for most customers, so this option is enabled by default in this pull request.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.