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

Allow additional CIDRs to be excluded from SNAT #520

Conversation

totahuanocotl
Copy link
Contributor

@totahuanocotl totahuanocotl commented Jul 3, 2019

Connects to #469

Introduces a mechanism to provide an exclusion list of CIDRs that should
not be SNATed.

Adds an environment variable AWS_VPC_K8S_CNI_EXCLUDE_SNAT_CIDRS to
provide a comma separated list of ipv4 CIDRs to exclude from SNAT.
The value of this environment variable will only be use when
AWS_VPC_K8S_CNI_EXTERNALSNAT is false.

The SNAT exclusion CIDRs will be used to:

  • Generate iptable rules to prevent SNATing for packets directed to
    the excluded CIDRs
  • Generate ip rule entries to route packets directed to the excluded
    CIDRs through the pod's eni. This configuration is done both at the
    cni plugin level via the rpc_handler, and the runtime network api.

Given that the list of excluded CIDRs may vary by configuration it was
necessary to include a mechanism to clean up stale SNAT rules. If a
CIDR is removed from the exclusion list, the corresponding iptable
rule will be removed as well, and the chain will be adjusted.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Co-authored-by: @rewiko
Co-authored-by: @yorg1st

@totahuanocotl totahuanocotl force-pushed the add-exclusion-snat-cidrs-to-allow-direct-communication-to-others-network branch from 21a8a6a to 65aa823 Compare July 4, 2019 09:51
Introduces a mechanism to provide an exclusion list of CIDRs that should
not be SNATed.

Adds an environment variable `AWS_VPC_K8S_CNI_EXCLUDE_SNAT_CIDRS` to
provide a comma separated list of ipv4 CIDRs to exclude from SNAT.
The value of this environment variable will only be use when
`AWS_VPC_K8S_CNI_EXTERNALSNAT` is false.

The SNAT exclusion CIDRs will be used to:
- Generate `iptable` rules to prevent SNATing for packets directed to
the excluded CIDRs
- Generate `ip rule` entries to route packets directed to the excluded
CIDRs through the pod's `eni`. These configuration is done both at the
`cni` plugin level via the `rpc_handler`, and the runtime `network` api.

Given that the list of excluded CIDRs may vary by configuration it was
necessary to include a mechanism to clean up stale SNAT rules. If a
CIDR is removed from the exclusion list, the corresponding `iptable`
rule will be removed as well, and the chain will be adjusted.

Connects aws#469

Co-authored-by: @rewiko
Co-authored-by: @yorg1st
@totahuanocotl totahuanocotl force-pushed the add-exclusion-snat-cidrs-to-allow-direct-communication-to-others-network branch from 65aa823 to b30f2ba Compare July 4, 2019 09:52
@totahuanocotl
Copy link
Contributor Author

totahuanocotl commented Jul 8, 2019

Hi @mogren , do you think this PR could be looked at?
We are quite interested in this feature.

Copy link
Contributor

@mogren mogren left a comment

Choose a reason for hiding this comment

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

Nice work, thanks a lot for adding this.

Just a few small nitpicks to fix and I'd be happy to merge it.

pkg/networkutils/network.go Outdated Show resolved Hide resolved
pkg/networkutils/network.go Show resolved Hide resolved
pkg/networkutils/network.go Outdated Show resolved Hide resolved
pkg/networkutils/network_test.go Show resolved Hide resolved
pkg/networkutils/network_test.go Show resolved Hide resolved
README.md Show resolved Hide resolved
pkg/networkutils/network.go Show resolved Hide resolved
pkg/networkutils/network.go Outdated Show resolved Hide resolved
@mogren mogren added this to the v1.6 milestone Jul 10, 2019
`format` applies formatting to the project's go files.
`check-format` checks that no files require formatting; if they do it
will fail the command.

It adds the `check-format` target to the travis build so that CI fails
if files are not properly formatted.
Copy link
Contributor

@mogren mogren left a comment

Choose a reason for hiding this comment

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

Looks great, thanks again!

@mogren mogren merged commit a4b14eb into aws:master Jul 11, 2019
@totahuanocotl
Copy link
Contributor Author

Thanks @mogren !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants