You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

代理环境下GraphDB与Keycloak的OpenID配置问题求助

问题描述

部署基于Keycloak认证、GraphDB存储的应用,前端通过Nginx反向代理访问。配置GraphDB的OpenID认证时出现冲突:

  • 若将GraphDB的graphdb.auth.openid.issuer设为Docker内部地址http://auth-server:8080/realms/termit,GraphDB能连接Keycloak,但验证令牌时报错:
    The Issuer "http://localhost/auth/realms/termit" provided in the configuration did not match the requested issuer "http://auth-server:8080/realms/termit"
    
  • 若将issuer设为公共代理地址http://localhost/auth/realms/termit,GraphDB无法通过内部网络访问Keycloak获取OpenID元数据。

核心Docker Compose配置:

version: "3.9"
services:
  nginx:
    build: ./nginx
    ports:
      - 80:80
      - 443:443
  auth-server:
    image: quay.io/keycloak/keycloak:22.0
    environment:
      KC_HOSTNAME_URL: ${URL}/auth
      KC_PROXY: edge
      # 数据库、管理员配置略
  db-server:
    image: ontotext/graphdb:10.3.2
    environment:
      GDB_JAVA_OPTS: -Dgraphdb.external-url=${URL}/db-server -Dgraphdb.auth.methods=openid -Dgraphdb.auth.openid.issuer=http://auth-server:8080/realms/termit -Dgraphdb.auth.openid.token_issuer=${URL}/auth/realms/termit -Dgraphdb.auth.openid.client_id=${GDB_CLIENTID} # 其他参数略

Nginx核心代理配置:

location /auth/ {
    proxy_pass http://auth-server:8080/;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    # 其他头配置略
}

location /db-server/ {
    proxy_pass http://db-server:7200;
    proxy_redirect http://db-server:7200/ /db-server/;
    proxy_set_header X-Forwarded-Host $host;
}

用户有Spring应用代理部署经验,通常将JWT Issuer设为公共URL,JWK Set URI设为内部服务URL,询问GraphDB是否支持类似拆分配置。

解决方案

1. 拆分GraphDB的OpenID配置参数

GraphDB支持单独指定JWKS密钥集地址,以此分开令牌验证的Issuer(公共URL)和元数据/密钥获取的内部地址:

  • 将graphdb.auth.openid.issuer设为公共代理地址(和令牌中的Issuer一致):${URL}/auth/realms/termit
  • 添加graphdb.auth.openid.jwks_uri参数,指向Keycloak的内部JWKS地址:http://auth-server:8080/realms/termit/protocol/openid-connect/certs
  • 确保graphdb.auth.openid.token_issuer和公共Issuer地址一致,移除原有的内部Issuer配置

修改后的db-server环境变量示例:

environment:
  GDB_JAVA_OPTS: >-
    -Dgraphdb.external-url=${URL}/db-server
    -Dgraphdb.auth.methods=openid
    -Dgraphdb.auth.openid.issuer=${URL}/auth/realms/termit
    -Dgraphdb.auth.openid.token_issuer=${URL}/auth/realms/termit
    -Dgraphdb.auth.openid.jwks_uri=http://auth-server:8080/realms/termit/protocol/openid-connect/certs
    -Dgraphdb.auth.openid.client_id=${GDB_CLIENTID}
    -Dgraphdb.auth.openid.username_claim=preferred_username
    -Dgraphdb.auth.openid.auth_flow=code
    -Dgraphdb.auth.openid.token_type=access
    -Dgraphdb.auth.openid.proxy=true
    # 其他JVM参数略

2. 确认Keycloak的代理配置正确性

确保Keycloak的KC_HOSTNAME_URL和KC_PROXY=edge配置生效,让Keycloak生成的令牌中Issuer字段为公共代理地址(${URL}/auth/realms/termit),而非内部服务地址。同时检查Nginx的Keycloak代理头,确保X-Forwarded-Proto、Host等头正确传递,避免Keycloak生成错误的Issuer地址。

3. 验证GraphDB的回调地址

确保graphdb.external-url配置为代理后的公共地址${URL}/db-server,这样GraphDB在生成OpenID认证回调URL时会使用正确的代理地址,避免回调失败。

内容的提问来源于stack exchange,提问作者kidney

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 16:58:10