ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Nginx登录后的密钥泄漏失败,帖子中缺少端口号等

2019-10-25 16:09:48  阅读:200  来源: 互联网

标签:keycloak nginx proxy


进入页面时,Keycloak无法保留通过的端口号:30666

但是,提交按钮不包含ip端口号,仅在此处使用ip-address.由于发布失败.

重定向失败…

如何使Keycloak在代理后面工作?

enter image description here
enter image description here
enter image description here
enter image description here

密钥斗篷在具有以下conf的NGinx代理后面的kubernetes集群中运行:

worker_processes  1;
error_log /dev/stderr warn;

events {
    worker_connections 1024;
}

# make sure to set plaintext JWT_SECRET environment variable
env JWT_SECRET;

http {

    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log /dev/stdout main;

    lua_package_path "/usr/local/openresty/lualib/?.lua;;";

    server {
        listen 8080;
        root /;

        # load index page from nginx implementing the KC javascript:
        location / {
            index index.htm index.html;
        }

        location /auth {
            proxy_pass http://idp:8080/auth;
            proxy_http_version 1.1; # this is essential for chunked responses to work
            proxy_buffering    off;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Scheme $scheme;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
        }

        # Secured endpoints
        location /secure/ {
            access_by_lua_file /bearer.lua;

            default_type text/plain;
            echo "<p>i am protected by jwt<p>";
        }
    }
}

我的idp部署如下所示:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert -f docker-compose.yml
    kompose.version: 1.2.0 ()
  creationTimestamp: null
  labels:
    io.kompose.service: idp
  name: idp
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: idp
    spec:
      containers:
      - env:
        - name: KEYCLOAK_PASSWORD
          value: pass
        - name: KEYCLOAK_USER
          value: admin
        - name: PROXY_ADDRESS_FORWARDING
          value: 'true'
        image: jboss/keycloak
        name: idp
        ports:
        - containerPort: 9990
        - containerPort: 8080
        resources: {}
      restartPolicy: Always
status: {}

解决方法:

问题是proxy_set_header $host,应该是$host:$server_port

此外,不需要在代理URL后面加上/ auth URI.如果未指定,则Nginx将传输URI而不进行更改.

配置应为:

location /auth {
        proxy_pass http://idp:8080;
        ...
        proxy_set_header Host $host:$server_port;

参考http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass

注意:Keycloak客户端可能需要HTTPS URL.如果您在Nginx中启用HTTPS,则请记住也将方案与x-forwarded-proto标头一起传递给Keycloak.

        proxy_set_header x-forwarded-proto $scheme;

标签:keycloak,nginx,proxy
来源: https://codeday.me/bug/20191025/1929859.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有