0

I'm developing a proof-of-concept of some kind of transparent proxy on Linux.

Transparent proxy intercepts TCP traffic and forwards it to backend. I use https://www.kernel.org/doc/Documentation/networking/tproxy.txt and spoofing sockets for outgoing TCP connection.

On my dev PC I was able to emulate network using Docker and all works fine.

But I need to deploy test environment on AWS.

Proposed design:

Three VMs within the same subnet:

  • client, 192.168.0.2
  • proxy, 192.168.0.3
  • backend, 192.168.0.4

On client I add route to 192.168.0.4 thru 192.168.0.3

On proxy I confugure TPROXY to intercept TCP packets and forward it to backend with 192.168.0.2 IP source address. Here our transparent proxy works.

On backend I run simple web server. Also I add route to 192.168.0.2 thru 192.168.0.3 otherwise packets will go back directly to 192.168.0.2

The question:

Will proposed network design work as expected?

AWS uses some kind of software defined network and I don't know will it work in the same way as I would connect 3 Linux boxes to one Ethernet switch.

Alexander Altshuler
  • 2,930
  • 1
  • 17
  • 27
  • Proxying is one of my areas of specialization, but packet mangling is not something I keep in my toolkit when designing solutions -- it's too messy and there is usually a better way. Consider expanding the question to explain more of what you are trying to solve, rather than just how your current solution works. There may be a clean solution that works consistently with the design of VPC. – Michael - sqlbot May 05 '17 at 10:35

1 Answers1

1

Will proposed network design work as expected?

Highly unlikely.

The IP network in VPC that instances can access is, from all appearances, an IP network (Layer 3), not an Ethernet network (Layer 2), even though it's presented to the instances as though it were Ethernet.

The from/to address that is "interesting" to an Ethernet switch is the MAC address. The from/to address of interest to the EC2 network is the IP address. If you tweak your instance's IP stacks by spoofing the addresses and manipulating the route tables, the only two possible outcomes should be one of these: the packets will actually arrive at the correct instance according to the infrastructure's knowledge of where that IP address should exist... or the packets will be dropped by the network. Most likely, the latter.

There is an IP Source/Destination Check Flag on each EC2 instance that disables some of the network's built-in blocking of packets the network would otherwise have considered spoofed, but this should only apply to traffic with IP addresses outside the VPC supernet CIDR block -- the IP address of each instance is known to the infrastructure and not subject to the kind of tweaking you're contemplating.

You could conceivably build tunnels among the instances using the Generic Route Encapsulation (GRE) protocol, or OpenVPN, or some other tunneling solution, and then the instances would have additional network interfaces in different IP subnets where they could directly exchange traffic using a different subnet and rules they make up, since the network wouldn't see the addresses on the packets encapsulated in the tunnels, and wouldn't impose any restrictions on the inner payload.

Possibly related: In a certain cloud provider other than AWS, a provider with a network design that is far less sensible than VPC, I use inter-instance tunnels (built with OpenVPN) to build my own virtual private subnets that make more sense than what that other cloud provider offers, so I would say this is potentially a perfectly viable alternative -- the increased latency of my solution is sub-millisecond.

But this all assumes that you have a valid reason for choosing a solution involving packet mangling. There should be a better, more inside-the-box way of solving the exact problem you are trying to solve.

Michael - sqlbot
  • 169,571
  • 25
  • 353
  • 427
  • Thanks for comment. In real world my proxy will not work within AWS VPC. I need it here only for automation tests purpose. But it looks like AWS VPC is not perfect environment for such things. I was able to simulate what I need using Docker network. – Alexander Altshuler May 05 '17 at 13:42