【Knox】Knox 转发访问 Trino Web UI 返回 406 错误的原因与处理

一、问题现象:Knox 转发访问 Trino Web UI 返回 406

在 Knox 已完成接入、并通过 Knox 访问 Trino Web UI 时,点击页面链接后直接返回 406 错误:

我们的代码已经开源>>>>>TTbigdata

对应的访问地址示例如下:

text 复制代码
https://dev1:28443/ui/login.html?doAs=admin

浏览器返回的完整错误信息为:

bash 复制代码
HTTP ERROR 406 Server configuration does not allow processing of the X-Forwarded-For header
URI:	https://dev1:28443/ui/login.html?doAs=admin
STATUS:	406
MESSAGE:	Server configuration does not allow processing of the X-Forwarded-For header
Caused by:
org.eclipse.jetty.http.BadMessageException: 406: Server configuration does not allow processing of the X-Forwarded-For header
	at io.airlift.http.server.RejectForwardedRequestCustomizer.customize(RejectForwardedRequestCustomizer.java:20)
	at org.eclipse.jetty.server.internal.HttpChannelState$HandlerInvoker.run(HttpChannelState.java:655)
	at org.eclipse.jetty.server.internal.HttpConnection.onFillable(HttpConnection.java:416)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:322)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:99)
	at org.eclipse.jetty.io.ssl.SslConnection$SslEndPoint.onFillable(SslConnection.java:575)
	at org.eclipse.jetty.io.ssl.SslConnection.onFillable(SslConnection.java:390)
	at org.eclipse.jetty.io.ssl.SslConnection$2.succeeded(SslConnection.java:150)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:99)
	at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.runTask(AdaptiveExecutionStrategy.java:480)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:443)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:293)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.run(AdaptiveExecutionStrategy.java:201)
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:311)
	at org.eclipse.jetty.util.thread.MonitoredQueuedThreadPool$1.run(MonitoredQueuedThreadPool.java:73)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:979)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.doRunJob(QueuedThreadPool.java:1209)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1164)
	at java.base/java.lang.Thread.run(Thread.java:1575)

后端 Jetty 日志中可看到如下异常堆栈(节选):

text 复制代码
org.eclipse.jetty.http.BadMessageException: 406:
Server configuration does not allow processing of the X-Forwarded-For header
	at io.airlift.http.server.RejectForwardedRequestCustomizer.customize

::: danger 现象特征

  • Knox 本身工作正常
  • Trino 进程未崩溃
  • 请求在 Trino Jetty 层被直接拒绝
  • 错误与 X-Forwarded-For 请求头强相关
    :::

二、问题根因:Trino 默认拒绝 Forwarded 请求头

Knox 在转发 Web UI 请求时,会自动附加标准代理请求头,包括:

  • X-Forwarded-For
  • X-Forwarded-Proto
  • X-Forwarded-Host

这是反向代理场景的标准行为

Trino 的 Web UI 是基于 Jetty(Airlift HTTP Server)实现的,

其默认安全策略是:

如果未显式开启 forwarded header 处理,则拒绝包含 X-Forwarded- 的请求*

因此在默认配置下,Trino 会在 Jetty 层直接抛出:

text 复制代码
RejectForwardedRequestCustomizer

并返回 HTTP 406。

::: tip 结论

这不是 Knox 的问题,也不是认证问题,

而是 Trino 未开启 forwarded header 支持

:::

三、Ttbigdata 发行版的处理方式(推荐)

Ttbigdata 发行版 中,该参数已经被纳入 Trino 的可配置项,只需开启即可。

3.1 配置项说明

需要启用的配置为:

text 复制代码
http-server.process-forwarded

其含义是:

允许 Trino 处理来自反向代理(如 Knox)的 X-Forwarded-* 请求头

3.2 在 Ambari / 管理界面中开启

在 Trino 的配置栏目中,找到对应配置项并设置为 true

配置完成后:

  1. 保存配置
  2. 重启 Trino 服务

3.3 验证结果

重启完成后,再次通过 Knox 访问 Trino Web UI:

页面可以正常加载,406 错误消失。

四、非 Ttbigdata 发行版的处理方式

如果使用的不是 Ttbigdata 发行版,需要从 模板与配置文件层面补齐该参数。

4.1 修改 config.properties.j2 模板

在 Trino 的 config.properties.j2 模板中追加如下内容:

新增配置:

jinja2 复制代码
http-server.process-forwarded={{ config_properties['http-server.process-forwarded'] }}

4.2 在 config.properties.xml 中声明配置项

同时,需要在 config.properties.xml 中补齐该配置定义:

用于让 Ambari / 配置系统能够感知并下发该参数。

4.3 文件下发与生效

上述两个文件:

  • config.properties.j2
  • config.properties.xml

需要放置到对应的 Trino 配置模板目录中,

具体路径与发布方式在其它章节已有详细说明,此处不再展开。

完成配置后,重启 Trino 服务即可生效。

相关推荐
子兮曰2 天前
jev-ultrafast 深度解析:7 秒订机票的浏览器 Agent 是如何炼成的
前端·后端·agent
小羊没烦恼!2 天前
微服务化的基石——持续集成
java·大数据·word·powerpoint·.net
子兮曰2 天前
Jev 爆发一周:7 秒 Agent 背后的 System One 生态与三场争议
前端·后端·ai编程
一隅论数智2 天前
给AI一张“业务概念地图“:本体如何从哲学走向企业智能
大数据·人工智能·经验分享·笔记·学习·学习方法·政务
卷毛迷你猪2 天前
快速实验篇(A11)数据集成与多维分析:从单实验产出到跨实验宽表
hive·hadoop
前端小万2 天前
写公众号赚了 3000 块后,我做了一款叫 "一键成稿" 的软件
前端·微信小程序
爱勇宝2 天前
ZCode 开源 24 小时:一份没有历史的账本,回答不了"有没有偷代码"
前端·后端·chatglm (智谱)
虎头金猫2 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
三十而立洋2 天前
Cookie 详解:从产生到安全,一次讲透
前端·javascript
大蓝头2 天前
安装包UI美化之路-nsNiuniuSkin全新UI调试与预览方法
ui·electron·安装包·截图控件·截屏控件