kubernetes-sigs / ip-masq-agent

Manage IP masquerade on nodes
Apache License 2.0
217 stars 70 forks source link

[FEATURE] Implement masquerade CIDRs #9

Closed vdavidoff closed 5 years ago

vdavidoff commented 7 years ago

Let me preface this PR by indicating I realize there may be reasons this feature has already been considered and rejected, or never considered, but I can't find trace of that and don't want to assume anything.

Context:

I can think of a number of reasons this feature could be useful, but I'll describe my most straightforward use case.

I want to allow pods to masquerade to an explicit list of CIDRs. If that range of CIDRs is small and/or can be collapsed easily, using the existing nonMasqueradeCIDR list causes me to think a little bit backwards about what I'm trying to accomplish, but it's doable relatively easily.

However, if the CIDRs to which I want to allow masquerade are large in number and/or cannot be collapsed into a very small set of CIDRs, I run into two problems:

For more context on the use case, I would use the feature by creating an explicit list of masqueradeCIDRs, and a single entry of 0.0.0.0/0 for nonMasqueradeCIDRs, effectively disabling the end of chain MASQUERADE catch-all.

A pull request implementing this feature has already been opened.

Thanks for your consideration.

pydevops commented 6 years ago

My use case is sending the logstash and fluentd data over the VPC peered ELK cluster, which sits in its own GCP project (management project). With the changes from @vdavidoff made, I am able to add the CIDR range in masqueradeCIDRs. Verified working in this case. example configmap.yaml

apiVersion: v1
data:
  config: |-
    nonMasqueradeCIDRs:
      - 10.0.0.0/8
      - 172.16.0.0/12
      - 192.168.0.0/16
    masqueradeCIDRs:
      - 10.10.0.0/20
    resyncInterval: 60s
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: ip-masq-agent
  namespace: kube-system

iptables changes on the GKE node

Chain POSTROUTING (policy ACCEPT 24 packets, 1440 bytes)
 pkts bytes target     prot opt in     out     source               destination
 2953  188K KUBE-POSTROUTING  all  --  *      *       0.0.0.0/0            0.0.0.0/0            /* kubernetes postrouting rules */
 1600 99790 MASQUERADE  all  --  *      *       0.0.0.0/0           !10.0.0.0/8           /* kubenet: SNAT for outbound traffic from cluster */ ADDRTYPE match dst-type !LOCAL
  666 43411 IP-MASQ-AGENT  all  --  *      *       0.0.0.0/0            0.0.0.0/0            /* ip-masq-agent: ensure nat POSTROUTING directs all non-LOCAL destination traffic to our custom IP-MASQ-AGENT chain */ ADDRTYPE match dst-type !LOCAL

Chain DOCKER (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain IP-MASQ-AGENT (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 MASQUERADE  all  --  *      *       0.0.0.0/0            10.10.0.0/20          /* ip-masq-agent: outbound traffic is subject to MASQUERADE */
    0     0 RETURN     all  --  *      *       0.0.0.0/0            169.254.0.0/16       /* ip-masq-agent: local traffic is not subject to MASQUERADE */
   20  1200 RETURN     all  --  *      *       0.0.0.0/0            10.0.0.0/8           /* ip-masq-agent: local traffic is not subject to MASQUERADE */
    0     0 RETURN     all  --  *      *       0.0.0.0/0            172.16.0.0/12        /* ip-masq-agent: local traffic is not subject to MASQUERADE */
    0     0 RETURN     all  --  *      *       0.0.0.0/0            192.168.0.0/16       /* ip-masq-agent: local traffic is not subject to MASQUERADE */
    0     0 MASQUERADE  all  --  *      *       0.0.0.0/0            0.0.0.0/0            /* ip-masq-agent: outbound traffic is subject to MASQUERADE (must be last in chain) */
fejta-bot commented 5 years ago

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale

fejta-bot commented 5 years ago

Stale issues rot after 30d of inactivity. Mark the issue as fresh with /remove-lifecycle rotten. Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle rotten

fejta-bot commented 5 years ago

Rotten issues close after 30d of inactivity. Reopen the issue with /reopen. Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /close

k8s-ci-robot commented 5 years ago

@fejta-bot: Closing this issue.

In response to [this](https://github.com/kubernetes-incubator/ip-masq-agent/issues/9#issuecomment-504446751): >Rotten issues close after 30d of inactivity. >Reopen the issue with `/reopen`. >Mark the issue as fresh with `/remove-lifecycle rotten`. > >Send feedback to sig-testing, kubernetes/test-infra and/or [fejta](https://github.com/fejta). >/close Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.