Search code examples
keycloakhttpd.confguacamole

keycloak and guacamole configuration behind httpd reverse proxy configuration


I have Apache httpd configured as a reverse proxy with SSL. I'm trying to configure keycloak and guacamole using http behind the proxy. I'm using the keycloak, mysql, guacd and guacamole containers. I have the entire flow working until keycloak attempts to redirect back to the guacamole page. FYI...my configuration is very similar to the following question, but with a different access error shown below: How to configure Keycloak to work with Guacamole's OpenID plugin?

So, user hits webserver via: https://example.com/guacamole/. Httpd redirects to http://guacamole:8080/guacamole. Guacamole redirects to keycloak for authentication. Login as valid user and the redirect to guacamole fails.

My guacamole is configured as:

openid-jwks-endpoint: https://example.com/auth/realms/Guacamole-test/protocol/openid-connect/certs
openid-issuer: https://example.com/auth/realms/Guacamole-test
openid-client-id: Guacamole
openid-redirect-uri: https://example.com/guacamole/

My httpd configuration:

   ServerName example.com

   SSLEngine On
   SSLCertificateFile      /opt/test.crt
   SSLCertificateKeyFile   /opt/test.key

  ProxyPass /guacamole/ http://guacamole:8080/guacamole/ flushpackets=on
  ProxyPassReverse /guacamole/ http://guacamole:8080/guacamole/

  ProxyPass /guacamole/websocket-tunnel ws://guacamole:8080/guacamole/websocket-tunnel
  ProxyPassReverse /guacamole/websocket-tunnel ws://guacamole:8080/guacamole/websocket-tunnel

  ProxyPass /auth/ http://keycloak:8080/auth/
  ProxyPassReverse /auth/ http://keycloak:8080/auth/

</VirtualHost>

I'm getting following error in guacamole:

INFO  o.a.g.a.o.t.TokenValidationService - Rejected invalid OpenID token: Unable to process JOSE object (cause: org.jose4j.lang.UnresolvableKeyException: Unable to find a suitable verification key for JWS w/ header {"alg":"RS256","typ" : "JWT","kid" : "bSv9K9W2us7SaUamJP3bWD1HWJuo6hbne2t3Gsc6V44"} due to an unexpected exception (javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target) while obtaining or using keys from JWKS endpoint at https://example.com/auth/realms/ocprealm/protocol/openid-connect/certs): JsonWebS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ryIcStNATcuf1dCvF_v1oqoacYsRNFljyg7Xf0ZQIuA53xY3czKkiVVqZt55LArjAv1cPmrekkf77NlGpFzPbyw29_yItAy1rPqxfYphYDCm55qM97agjIE7WsKKC5lHwZ6gCWoMIcrMw

I don't understand why it is attempting to use SSL validation on the final redirect. I believe after keycloak validates the login and attempts to redirect back to https://example.com/guacamole/ the httpd configuration should proxy this to http://guacamole:8080/guacamole. I've also tried configuring keycloak with the tls.key and tls.crt according to the keycloak documentation to see if it made any difference but it does not. Any help would be greatly appreciated as I am obviously missing or not understanding something in the configuration.


Solution

  • You are using OIDC, so when Guacamole receives the JWT key it is trying to validate the signature of the token. To do that, it has to contact Keycloak (via https) to retrieve the public key used to sign the token. This is failing with a SSL handshake error. Probably the JVM for Guacamole does not trust the SSL cert so you need to import it to the JVM keystore.

    I do not think it is related to your problem, but when running Keycloak like this behind a proxy there are some attributes you need to set. I run Keycloak in Docker and you do it with environment variables. These two are fairly critical to set:

    KEYCLOAK_FRONTEND_URL="https://hostname/auth/"
    PROXY_ADDRESS_FORWARDING="true"
    

    If you are not using the Docker version you can pretty easily translate how these values are communicated to Keycloak when it starts here: https://github.com/keycloak/keycloak-containers/blob/11.0.3/server/tools/docker-entrypoint.sh