api7 / apisix-mesh-agent

Apache License 2.0
78 stars 10 forks source link

APISIX should support to get original destination address and port #37

Closed tokers closed 3 years ago

tokers commented 3 years ago

In the case of APISIX as the inbound proxy for an application, the destination of traffic sent to APISIX was the application originally (redirected by iptables rules), after APISIX processed the traffic, ran a several plugins, it should be re-sent to the application, so APISIX has to know the original destination address.

Currently, we cannot get the original address and port from the connection fd, we may patch nginx to provide these two variables, like $connection_original_addr and $connectino_original_port, just call getsockopt with SO_ORIGINAL_DST option.

After APISIX has this capability, we can inject a new server by apisix-mesh-agent, which at lease has the following configurations.

server {
     listen 127.0.0.1:9081 reuseport;
     location / {
          proxy_set_header Connection "";
          proxy_http_version 1.1;
          proxy_pass http://$connection_original_addr:$connection_original_port;
    }
}
tokers commented 3 years ago

@membphis @spacewander Please take a look when you have time.

membphis commented 3 years ago

We need to patch Nginx to support this feature.

There are two ways:

  1. fetch value directly through nginx variables.
  2. add API to fetch the socket fd, and use Lua FFI to fetch the connection_original_addr.
membphis commented 3 years ago

The second method is more common, what do you think? @spacewander @tokers

tokers commented 3 years ago

If we use a second way, so we have to develop another upstream node setting method to combine the value from the lua ffi call.

tokers commented 3 years ago

We may create another upstream discovery type named passing through. In such a case, APISIX will get endpoints with the original destination.

membphis commented 3 years ago

something does not loads correctly.

image

tokers commented 3 years ago

something does not loads correctly.

image

Fixed.

tokers commented 3 years ago

Supported.