Skip to content

Instantly share code, notes, and snippets.

@jamesdube
Forked from int128/README.md
Created March 18, 2022 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesdube/18c520c79384e7104651a1b1b9d46ce9 to your computer and use it in GitHub Desktop.
Save jamesdube/18c520c79384e7104651a1b1b9d46ce9 to your computer and use it in GitHub Desktop.
Example of Envoy TCP Proxy

Envoy TCP Proxy

This is an example of Envoy TCP Proxy from localhost:10000 to www.google.com:80. See also https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/listeners/tcp_proxy.

To run a proxy:

% docker run --rm getenvoy/envoy:stable --version

/usr/bin/envoy  version: 1a0363c885c2dbb1e48b03847dbd706d1ba43eba/1.14.2/clean-getenvoy-fbeeb15-envoy/RELEASE/BoringSSL

% docker run --rm -p 10000:10000 -v $PWD/envoy.yaml:/envoy.yaml:ro getenvoy/envoy:stable -c /envoy.yaml
...
[2021-04-04 11:04:12.267][1][info][main] [external/envoy/source/server/server.cc:554] starting main dispatch loop
[2021-04-04 11:04:12.268][1][info][upstream] [external/envoy/source/common/upstream/cluster_manager_impl.cc:171] cm init: all clusters initialized
[2021-04-04 11:04:12.268][1][info][main] [external/envoy/source/server/server.cc:533] all clusters initialized. initializing init manager
[2021-04-04 11:04:12.270][1][info][config] [external/envoy/source/server/listener_manager_impl.cc:725] all dependencies initialized. starting workers

To connect to the remote host via the proxy:

% curl -v localhost:10000
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 10000 (#0)
> GET / HTTP/1.1
> Host: localhost:10000
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Content-Type: text/html
< Date: Sun, 04 Apr 2021 11:04:30 GMT
< Server: ECS (sjc/4E8D)
< Content-Length: 345
<
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<title>404 - Not Found</title>
	</head>
	<body>
		<h1>404 - Not Found</h1>
	</body>
</html>
* Connection #0 to host localhost left intact
* Closing connection 0

Note that this is an example of TCP proxy (not HTTP proxy).

static_resources:
listeners:
- name: listener_0
address:
socket_address:
address: 0.0.0.0
port_value: 10000
filter_chains:
- filters:
- name: envoy.filters.network.tcp_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy
stat_prefix: destination
cluster: cluster_0
clusters:
- name: cluster_0
connect_timeout: 30s
type: LOGICAL_DNS
dns_lookup_family: V4_ONLY
load_assignment:
cluster_name: cluster_0
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: www.example.com
port_value: 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment