Http 响应头配置在 Kafka 休息代理和架构注册表中不起作用

问题描述

我们使用的是 confluent 平台 5.3.1 社区版。

最近作为安全扫描的一部分,我们发现 Kafka 休息代理和架构注册服务缺少 http 标头(X-XSS-Protection,X-Content-Type-Options)安全漏洞。

根据 confluent 文档,我们可以在配置中添加 response.http.headers.config 属性添加/设置所需的标头。

https://docs.confluent.io/platform/current/kafka-rest/production-deployment/rest-proxy/config.html https://docs.confluent.io/platform/current/schema-registry/installation/config.html

我们已经在相应的配置文件添加了配置并重新启动了服务。

配置中添加的行

休息代理

response.http.headers.config=添加 X-XSS-Protection: 1; mode=block,添加 X-Content-Type-Options: nosniff

架构注册

response.http.headers.config="add Cache-Control: no-cache,no-store,must-revalidate",添加 X-XSS-Protection: 1; mode=block,添加 Strict-Transport-Security: max-age=31536000; includeSubDomains,添加 X-Content-Type-Options: nosniff

重新启动服务后,我们希望在响应中收到额外的 http 响应标头,但我们仍然没有收到这些标头。

请求: 获取:http://xxxx:8082/

响应头

enter image description here

有什么建议可以在响应中获取那些丢失的标头。?提前致谢

解决方法

查看Confluent rest proxy的源码后。确定此属性 (response.http.headers.config) 已添加到 Confluent 平台 6.0.x 中。所以需要更新平台才能使用这个属性。

参考: https://cwiki.apache.org/confluence/display/KAFKA/KIP+577%3A+Allow+HTTP+Response+Headers+to+be+Configured+for+Kafka+Connect https://docs.confluent.io/platform/current/release-notes/changelog.html https://github.com/confluentinc/rest-utils/blob/6.0.x/core/src/main/java/io/confluent/rest/RestConfig.java