Hey Roman,
I touched on this at a high level in my talk at HashiDays and it's a situation we've considered. The relevant section is here
https://youtu.be/KZIu33sbwQQ?t=1149 and has a graphic if that helps but there are more details given below.
It's actually not quite possible with the current release to make this work with the built-in proxy but only for lack of a few simple config options that were not in scope for the primary localhost only use case. In practice we hope to release Envoy support soon which will be able to do this anyway and is probably a preferable solution in every respect. I'll attempt to cover roughly how below, but it's a use-case we will need better tooling and specific docs for going forward.
The proposal from the talk is roughly this:
1. Provision one or more (for redundancy/throughput) nodes that are dedicated "proxies for external service X"
2. On each one run a consul client agent (necessary since the proxy itself needs a local agent to get efficient auth calls and config from)
3. Register an external service (optionally using consul-esm to run health checks) representing the external resource
4. Register an
unmanaged proxy on the proxy host agent with target service as the external service name
5. Configure the proxy (assuming it's Envoy in future when supported) to proxy not to localhost but to the external service endpoint. You likely need to configure TLS and authentication tokens here somehow too.
At this point you can grant access to that external resource with an intention like `ALLOW web => hosted-db` and then web services will be allowed to connect to that proxy and through to the external service.
You obviously need to ensure nothing else can connect to the external service directly to make that meaningful and how you do that will depend on the service and platform - you might only provide credentials for the external service to those dedicated proxy nodes, or something more robust with a separate VPC or subnet and controlled routing/ip whitelisting etc.
This is how it works for a singe external service. If you have many external services you either replicate this with dedicated proxies for each (most secure as it limits blast radius of access of one proxy host is compromised) or you can colocate proxies for different services to reduce cost of dedicated instance per external service.
Medium term we want to make this more first class but will probably wait til Envoy integration is done rather than build more stuff on the built-in proxy. I can imagine at least that means documenting how to set it up thoroughly but might involve tooling or options that make it simpler too.
Hope this helps.
Paul