Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load Denied by X-Frame-Options In Keycloak Docker Instace When Behind A Nginx Proxy

I have a fairly similar docker-compose file to what is officially provided namely

version: '3'

volumes:
mysql_data:
    driver: local

services:
mysql:
    image: mysql:5.7
    volumes:
        - mysql_data:/var/lib/mysql
    environment:
        MYSQL_ROOT_PASSWORD: root
        MYSQL_DATABASE: keycloak
        MYSQL_USER: keycloak
        MYSQL_PASSWORD: mypassword
keycloak:
    image: jboss/keycloak
    environment:
        DB_VENDOR: MYSQL
        DB_ADDR: mysql
        DB_DATABASE: keycloak
        DB_USER: keycloak
        DB_PASSWORD: mypass
        KEYCLOAK_USER: admin
        KEYCLOAK_PASSWORD: mypass
        # It didn't look like this actually got set. 
        PROXY_ADDRESS_FORWARDING: "true"
    ports:
        - 10000:8080
    depends_on:
        - mysql

I also have the nginx config file to be used as a reverse proxy to keycloak

## Redirects all HTTP traffic to the HTTPS host
server {
    listen 80;
    listen [::]:80;
    server_name keycloak keycloak.fqdn.com keycloak.fq.fqdn.com; 
    server_tokens off;
    return 301 https://keycloak.fqdn.com$request_uri;
}

## HTTPS host
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name keycloak.fqdn.com; 
    server_tokens off; 
    autoindex off;    

    include conf.d/site-common-config/ssl.conf;

    access_log  /var/log/nginx/keycloak-access.log combined;
    error_log   /var/log/nginx/keycloak-error.log warn;

    location / {
        gzip                    on;
        proxy_http_version 1.1;

        proxy_set_header    Host                $host;
        proxy_set_header    X-Real-IP           $remote_addr;
        proxy_set_header    X-Forwarded-For      $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Proto   $scheme;

        proxy_pass http://127.0.0.1:10000;
    }
}

I have furthermore confirmed that (as far as I understand it) the /auth/realms/master/.well-known/openid-configuration is returning the correct values. I have been following the guide here and have updated the appropiate xml files as well and ran a reload command to ensure that the proxy-address-forwarding was set to true. However I get the javascript error

Load denied by X-Frame-Options: https://keycloak.fqdn.com/auth/realms/master/protocol/openid-connect/login-status-iframe.html?version=4.3.0.final does not permit framing.

I haven't been able to find anything in the docs so far to resolve this issue so any help would be appreciated.

like image 343
piperRyan Avatar asked Oct 25 '25 05:10

piperRyan


2 Answers

If I add the following header in the nginx/openresty config it works:

location / {
     …
     add_header X-Frame-Options "SAMEORIGIN";
     …
}

If you want to change the value in the realm with kcadm.sh (as the gui is not working) you can export, edit and import the realm with

sudo -u keycloak /opt/keycloak/bin/kcadm.sh config credentials --realm master --user admin --server http://localhost:8080/auth
sudo -u keycloak /opt/keycloak/bin/kcadm.sh get realms/master > realm.json
# edit realm.json
sudo -u keycloak /opt/keycloak/bin/kcadm.sh update realms/master -f realm.json
like image 159
Fabian Avatar answered Oct 26 '25 18:10

Fabian


Configure X-Frame-Options in the realm configuration and permit your domain there. Maybe you will need to tweak also Content-Security-Policy.

Doc: https://www.keycloak.org/docs/latest/server_admin/index.html#clickjacking

like image 31
Jan Garaj Avatar answered Oct 26 '25 17:10

Jan Garaj