|
| 1 | +--- |
| 2 | +features: [Proxy, Security, Network, Configuration, Environment variables] |
| 3 | +languages: [YAML] |
| 4 | +--- |
| 5 | +# Using Aidbox with Outbound Proxy |
| 6 | + |
| 7 | +This guide demonstrates how to configure Aidbox to route outbound HTTPS traffic through a proxy server (Squid). This is useful in enterprise environments where all external traffic must go through a corporate proxy for security, compliance, or monitoring purposes. |
| 8 | + |
| 9 | +## Overview |
| 10 | + |
| 11 | +In many enterprise environments, direct internet access is restricted and all outbound traffic must be routed through a proxy server. This example shows how to: |
| 12 | + |
| 13 | +- **Network Isolation**: Run Aidbox in an internal network without direct internet access |
| 14 | +- **Proxy Configuration**: Route outbound HTTPS traffic through a Squid proxy |
| 15 | +- **Reverse Proxy Access**: Expose Aidbox through the proxy for external access |
| 16 | + |
| 17 | +Common use cases include: |
| 18 | + |
| 19 | +- Corporate environments requiring traffic inspection |
| 20 | +- Compliance requirements for logging all external communications |
| 21 | +- Security policies that restrict direct internet access |
| 22 | +- Environments where terminology servers or other external services must be accessed via proxy |
| 23 | + |
| 24 | +## Architecture |
| 25 | + |
| 26 | +This setup uses Docker networks to isolate Aidbox from external access while allowing it to reach the internet through a Squid proxy. |
| 27 | + |
| 28 | +```mermaid |
| 29 | +graph LR |
| 30 | + subgraph external[External Network] |
| 31 | + internet((Internet)) |
| 32 | + user((User)) |
| 33 | + end |
| 34 | + subgraph internal[Internal Network] |
| 35 | + aidbox[Aidbox] |
| 36 | + postgres[(PostgreSQL)] |
| 37 | + end |
| 38 | + squid[Squid Proxy] |
| 39 | +
|
| 40 | + user -->|:8080| squid |
| 41 | + squid <-->|Reverse Proxy| aidbox |
| 42 | + aidbox -->|HTTPS via :3128| squid |
| 43 | + squid <-->|HTTPS| internet |
| 44 | + aidbox <--> postgres |
| 45 | +``` |
| 46 | + |
| 47 | +### Network Configuration |
| 48 | + |
| 49 | +- **Internal Network**: Aidbox and PostgreSQL run on an isolated internal network with no direct internet access |
| 50 | +- **External Network**: Squid proxy has access to both internal and external networks |
| 51 | +- **Proxy Ports**: |
| 52 | + - Port `3128`: Forward proxy for outbound HTTPS traffic from Aidbox |
| 53 | + - Port `8080`: Reverse proxy for accessing Aidbox UI/API |
| 54 | + |
| 55 | +## Prerequisites |
| 56 | + |
| 57 | +- [Docker](https://www.docker.com/) |
| 58 | +- Clone the repository and navigate to the working directory: |
| 59 | + ```sh |
| 60 | + git clone https://github.com/Aidbox/examples.git |
| 61 | + cd aidbox-features/aidbox-outbound-proxy |
| 62 | + ``` |
| 63 | + |
| 64 | +## Up and Running |
| 65 | + |
| 66 | +Below is a Docker Compose configuration ([docker-compose.yaml](./docker-compose.yaml)) that sets up: |
| 67 | + |
| 68 | +1. A PostgreSQL database on the internal network |
| 69 | +2. Aidbox configured to use the proxy for outbound HTTPS traffic |
| 70 | +3. A Squid proxy server bridging internal and external networks |
| 71 | + |
| 72 | +```shell |
| 73 | +docker-compose up |
| 74 | +``` |
| 75 | + |
| 76 | +### Configuration |
| 77 | + |
| 78 | +Pay special attention to the `JAVA_OPTS` environment variable that configures the HTTPS proxy for Aidbox: |
| 79 | + |
| 80 | +```yaml |
| 81 | +JAVA_OPTS: "-Dhttps.proxyHost=squid -Dhttps.proxyPort=3128" |
| 82 | +``` |
| 83 | +
|
| 84 | +This Java system property tells Aidbox to route all outbound HTTPS connections through the Squid proxy. |
| 85 | +
|
| 86 | +#### Squid Proxy Configuration |
| 87 | +
|
| 88 | +The [squid.conf](./squid.conf) file configures Squid to: |
| 89 | +
|
| 90 | +1. **Forward Proxy** (port 3128): Handle outbound HTTPS traffic from Aidbox |
| 91 | +2. **Reverse Proxy** (port 8080): Provide access to Aidbox from external clients |
| 92 | +
|
| 93 | +Key configuration sections: |
| 94 | +
|
| 95 | +```squid |
| 96 | +# Forward proxy port |
| 97 | +http_port 3128 |
| 98 | + |
| 99 | +# Reverse proxy to Aidbox |
| 100 | +http_port 8080 accel vhost |
| 101 | +cache_peer aidbox parent 8080 0 no-query originserver name=aidbox |
| 102 | +``` |
| 103 | + |
| 104 | +## Usage Examples |
| 105 | + |
| 106 | +### Initializing Aidbox |
| 107 | + |
| 108 | +1. Navigate to [Aidbox UI](http://localhost:8080) and [initialize](https://docs.aidbox.app/getting-started/run-aidbox-locally#id-4.-activate-your-aidbox-instance) the Aidbox instance. |
| 109 | + |
| 110 | + The initialization process requires a connection to access to the package registry to download the FHIR core package - that will go through the proxy. If you restart Aidbox it will connect to the license server to validate your license - that will go through the proxy. |
| 111 | + |
| 112 | +### Verifying Proxy Usage |
| 113 | + |
| 114 | +To confirm that Aidbox is using the proxy, monitor Squid's access logs: |
| 115 | + |
| 116 | +```shell |
| 117 | +docker-compose exec squid tail -f /var/log/squid/access.log |
| 118 | +``` |
| 119 | + |
| 120 | +## Additional Resources |
| 121 | + |
| 122 | +- [Squid Proxy Documentation](http://www.squid-cache.org/Doc/) |
| 123 | +- [Java Networking and Proxies](https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html) |
0 commit comments