# Reverse proxy

> Serve the workspace address and the account service from your own reverse proxy on the Docker host instead of the bundled Caddy.

Source: https://docs.corfedo.ai/operate/single-host/reverse-proxy/

By default Caddy serves the workspace address and `auth.<workspace address>`. To use a proxy you already run on the Docker host, such as nginx, publish the platform and Keycloak to the host and point your proxy at them.

## Before you begin

- A proxy on the Docker host with a certificate for both addresses.
- The trusted proxy address: the address Corfedo sees your proxy connect from. For a proxy on the host it is the gateway of the installation's network:

```sh
docker network inspect corfedo-corfedo --format '{{range .IPAM.Config}}{{.Gateway}}{{end}}'
```

The network is named `corfedo-` followed by the installation name, `corfedo` by default.

## Switch to your proxy

### Turn off Caddy

In `.env`, set `COMPOSE_PROFILES=keycloak`, or leave it empty with your own identity provider. Set `CORFEDO_PROXY_ADDRESS` to the gateway address.

### Publish the platform and Keycloak

In `compose.override.yaml`, publish the platform's port 8081 and Keycloak's port 8080 on the host's loopback address. Give `platform`, `keycloak` and `platform-setup` an `extra_hosts` entry that maps `auth.` followed by your host name to `host-gateway`. The [operator guide](https://github.com/corfedo/corfedo-install/blob/main/docs/operator.md#your-own-reverse-proxy) has the complete file.

Corfedo serves HTTPS with its internal certificate, under the name `platform`. Keycloak serves plain HTTP. Corfedo reaches `auth.<workspace address>` through your proxy at the default Docker bridge address, usually `172.17.0.1`, which is not the gateway above. So the proxy listens on that address too, not only on the loopback address. `docker network inspect bridge --format '{{range .IPAM.Config}}{{.Gateway}}{{end}}'` prints it. With your own identity provider there is no Keycloak, so leave out its port and the `extra_hosts` entries.

### Trust a private certificate

If your proxy's certificate comes from a private CA, add that CA to `generated/tls/ca.crt`.

### Apply it

Run `sh ~/corfedo/install.sh update --version "$(cat ~/corfedo/VERSION)"`. It applies the installed release again, removes Caddy and starts the rest.

## What the proxy must do

| For | The proxy |
| --- | --- |
| The workspace address | Connects to the platform's port 8081 over HTTPS, verifies the certificate against `generated/workload/ca.crt` under the name `platform`, and does not buffer responses, because answers stream |
| `auth.` address | Connects to Keycloak's port 8080 over HTTP and sets `X-Forwarded-Port` |
| Both | Forwards `Host` with the port, appends the client to `X-Forwarded-For` and sets `X-Forwarded-Proto: https` |

The [operator guide](https://github.com/corfedo/corfedo-install/blob/main/docs/operator.md#your-own-reverse-proxy) has a complete nginx configuration for both addresses.

**Check:** the workspace opens in the browser and sign-in works. **Your address** on **Settings** › **Network access** shows your browser's address, not the proxy's.

## Set the trusted proxy

`CORFEDO_PROXY_ADDRESS` is the trusted proxy the **Network access** page asks for. Corfedo takes a client's address from `X-Forwarded-For` only when the request comes from `CORFEDO_PROXY_ADDRESS`, and then uses the last address in the header. When that setting is wrong, or a load balancer or NAT in front of the proxy hides the client, every request appears to come from the proxy. Network lists then admit everyone or no one, and audit records show the proxy's address. Check **Network access** before a workspace administrator limits networks.

`status` does not check your proxy. Open both addresses in a browser to check it.

## Related

- [Certificates and trust](https://docs.corfedo.ai/operate/single-host/certificates-and-trust/) and [Security](https://docs.corfedo.ai/operate/security/).
