How to enable SSL Load Balancer or Reverse Proxy in front of RH-SSO/Keycloak
Red Hat Single Sign-On (RH-SSO) is not set up by default to handle SSL/HTTPS. It is highly recommended that you either enable SSL on the Red Hat Single Sign-On server itself or on a reverse proxy in front of the Red Hat Single Sign-On server.
For enabling SSL on the RH-SSO server itself, follow the documentation on Setting up HTTPS/SSL as under the Network Setup chapter.
For Setting Up with a Load Balancer or Reverse Proxy, the usual setup is to have a frontend proxy sitting on a public network that load balances and forwards requests to backend RH-SSO server instance(s) located in a private network.
Several things need to be considered, such as identifying the clients IP addresses that are forwarded to and processed by the RH-SSO server instance(s).
This is a general set of steps:
- Configure your reverse proxy or loadbalancer to:
- Properly set
X-Forwarded-For
andX-Forwarded-Proto
HTTP headers. - Preserve the original
Host
HTTP header (on Apache HTTPD this is done with directiveProxyPreserveHost On
).
- Properly set
-
Configure RH-SSO:
-
Configure the authentication server to read the client’s IP address from
X-Forwarded-For
header- For http proxy forwarding, set
proxy-address-forwarding="true"
in thehttp-listener
orhttps-listener
element as under the undertow subsystem configuration.
To set using jboss-cli.sh, the command for
https
is:/subsystem=undertow/server=default-server/https-listener=https:write-attribute(name=proxy-address-forwarding, value=true)
For
http
is:/subsystem=undertow/server=default-server/http-listener=default:write-attribute(name=proxy-address-forwarding, value=true)
- If you're using the AJP protocol for Apache HTTPD + mod-cluster, then you have to add a specific filter for it in the undertow config (See documentation below).
- For http proxy forwarding, set
- If the listening port of the reverse proxy doesn't match the port of the RH-SSO server (8443 for https, or 8080 for http by default):
- Configure a
redirect-socket
for specifying to what port the HTTP/HTTPS traffic is going to be redirected. It must have a unique name, for example:proxy-https
. - Add a new
socket-binding
element to thesocket-binding-group
element using the unique name it last step,proxy-https
.
- Configure a
-
-
Verify Configuration
- Go to
http[s]://{reverse-proxy}/auth/realms/master/.well-known/openid-configuration
. For example if the reverse proxy address ishttps://acme.com/
then open the URLhttps://acme.com/auth/realms/master/.well-known/openid-configuration
.- This returns a JSON document listing the end points for RH-SSO. Make sure the endpoints starts with the address (scheme, domain and port) of your reverse proxy or load balancer.
- If the these values are incorrect, forwarding the original
Host
header andX-Forwarded-Proto
headers may be incorrect.
-
Verify RH-SSO sees the correct source IP address. Go to the admin console, then attempt to login with an invalid username, and you'll see a warning in server.log like:
[org.keycloak.events] type=LOGIN_ERROR, realmId=master, clientId=security-admin-console, userId=8f20d7ba-4974-4811-a695-242c8fbd1bf8, ipAddress=X.X.X.X,...
- The
ipAddress=X.X.X.X
part should be the address of the machine attempting the login. - If the address is incorrect, the
X-Forwarder-For
orproxy-address-forwarding="true"
setting in undertow is not correct..
- The
- Go to
Note To help with verification, you can configure RH-SSO to dump the paired http requests and responses. See Configure Request logging / RequestDumping handler in JBoss EAP 7
For a detailed explanation of each step, see Setting Up a Load Balancer or Proxy.
Comments