Understanding the Deployment Pattern
Keycloak needs public access for login flows, but placing the service directly on the public internet increases risk. A VPC private subnet keeps Keycloak hidden from direct exposure. The way in is through a proxy—Nginx, Envoy, or HAProxy—running in a public subnet while forwarding traffic securely into the private subnet. This proxy terminates TLS, applies routing rules, and passes only approved requests to Keycloak.
Network Architecture
The basic architecture has:
- A public subnet for the proxy.
- A private subnet for Keycloak nodes.
- VPC routing tables configured to allow controlled traffic between them.
Security groups should restrict inbound traffic on the proxy to only necessary ports (443 for HTTPS), and outbound from proxy to private subnet to the Keycloak interface port (usually 8080 or 8443). No other direct inbound routes should reach Keycloak.
Keycloak Configuration
Set proxy-address-forwarding=true in Keycloak to handle X-Forwarded headers correctly. If using HTTPS internally, configure certificates on Keycloak and match them with the proxy settings. Update the Keycloak hostname and frontendUrl to reflect the proxy address to avoid mixed content issues or login callback errors.