当前位置: 首页 > news >正文

(一)Kafka 安全之使用 SASL 进行身份验证 —— JAAS 配置、SASL 配置

目录

一. 前言

二. JAAS 配置(JAAS configuration)

2.1. Kafka Broker 的 JAAS 配置

2.2. Kafka 客户端的 JAAS 配置

2.2.1. 使用客户端配置属性的 JAAS 配置

2.2.2. 使用静态配置文件的 JAAS 配置

三. SASL 配置(SASL configuration)

3.1. SASL 机制(SASL mechanisms)

3.2. Kafka Broker 的 SASL 配置

3.3. Kafka 客户端的 SASL 配置


一. 前言

    SASL 是用来认证 C/S 模式也就是服务器与客户端的一种认证机制,全称 Simple Authentication and Security Layer。这就是一种凭据认证方式。通俗的话来讲就是让服务器知道连接进来的客户端的身份是谁。

    比如凭借阅证到图书馆借书,而每个借阅证都有独立的 ID,通过 ID 定位谁是谁,而不是特别关心谁拿到了借阅证,只需要正确的借阅证即可。所以 SASL 就是服务器存储了客户端的身份证书和如何校验密码是否正确,而且仅在于身份认证过程,认证完毕后即可进行相关的服务操作。

二. JAAS 配置(JAAS configuration)

原文引用:Kafka uses the Java Authentication and Authorization Service (JAAS) for SASL configuration.

Kafka 使用 Java 身份验证和授权服务(JAAS)进行 SASL 配置。

2.1. Kafka Broker 的 JAAS 配置

原文引用:KafkaServer is the section name in the JAAS file used by each KafkaServer/Broker. This section provides SASL configuration options for the broker including any SASL client connections made by the broker for inter-broker communication. If multiple listeners are configured to use SASL, the section name may be prefixed with the listener name in lower-case followed by a period, e.g. sasl_ssl.KafkaServer.

    KafkaServer 是每个 KafkaServer/Broker 使用的 JAAS 文件中的段落名。本节提供 Broker 的SASL 配置选项,包括 Broker 为 Broker 间通信建立的任何 SASL 客户端连接。如果将多个监听器配置为使用 SASL,则段落名称可以以小写的监听器名称为前缀,后跟句点,例如 sasl_ssl.KafkaServer

原文引用:Client section is used to authenticate a SASL connection with zookeeper. It also allows the brokers to set SASL ACL on zookeeper nodes which locks these nodes down so that only the brokers can modify it. It is necessary to have the same principal name across all brokers. If you want to use a section name other than Client, set the system property zookeeper.sasl.clientconfig to the appropriate name (e.g., -Dzookeeper.sasl.clientconfig=ZkClient).

    客户端部分用于验证与 ZooKeeper 的 SASL 连接。它还允许 Broker 在 ZooKeeper 节点上设置SASL ACL,从而锁定这些节点,以便只有 Broker 可以修改它。有必要在所有 Broker 中具有相同的主体名称。如果要使用 Client 以外的段落名称,请将系统属性 zookeeper.sasl.clientconfig 设置为适当的名称(例如,-Dzookeeper.sasl.clientconfig=ZkClient)。

原文引用:ZooKeeper uses "zookeeper" as the service name by default. If you want to change this, set the system property zookeeper.sasl.client.username to the appropriate name (e.g., -Dzookeeper.sasl.client.username=zk).

    ZooKeeper 默认使用“zookeeper”作为服务名称。如果要更改此设置,请将系统属性zookeeper.sasl.client.username 设置为适当的名称(例如,-Dzookeeper.sasl.client.username=zk)。

原文引用:Brokers may also configure JAAS using the broker configuration property sasl.jaas.config. The property name must be prefixed with the listener prefix including the SASL mechanism, i.e. listener.name.{listenerName}.{saslMechanism}.sasl.jaas.config. Only one login module may be specified in the config value. If multiple mechanisms are configured on a listener, configs must be provided for each mechanism using the listener and mechanism prefix. For example,

    Broker 还可以使用 Broker 配置属性 sasl.jaas.config 来配置 JAAS。属性名称必须以监听器前缀为前缀,包括 SASL 机制,即 listener.name.{listenerName}.{saslMechanism}.sasl.jaas.config。在配置值中只能指定一个登录模块。如果在监听器上配置了多个机制,则必须使用监听器和机制前缀为每个机制提供配置。例如

listener.name.sasl_ssl.scram-sha-256.sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required \username="admin" \password="admin-secret";
listener.name.sasl_ssl.plain.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required \username="admin" \password="admin-secret" \user_admin="admin-secret" \user_alice="alice-secret";

原文引用:If JAAS configuration is defined at different levels, the order of precedence used is:

  • Broker configuration property listener.name.{listenerName}.{saslMechanism}.sasl.jaas.config
  • {listenerName}.KafkaServer section of static JAAS configuration
  • KafkaServer section of static JAAS configuration

如果在不同级别定义了 JAAS 配置,则使用的优先顺序为:

  • Broker 配置属性 listener.name.{listenerName}.{saslMechanism}.sasl.jaas.config
  • JAAS 静态配置部分 {listenerName}.KafkaServer
  • JAAS 静态配置部分 KafkaServer

原文引用:Note that ZooKeeper JAAS config may only be configured using static JAAS configuration.

See GSSAPI (Kerberos), PLAIN, SCRAM or OAUTHBEARER for example broker configurations.

请注意,ZooKeeper JAAS 配置只能使用静态 JAAS 配置进行配置。

有关 Broker 配置的示例,请参阅 GSSAPI(Kerberos)、PLAIN、SCRAM 或 OAUTHBEARER。

2.2. Kafka 客户端的 JAAS 配置

原文引用:Clients may configure JAAS using the client configuration property sasl.jaas.config or using the static JAAS config file similar to brokers.

    客户端可以使用客户端配置属性 sasl.jas.config 或类似于 Broker 的静态 JAAS 配置文件来配置JAAS。

2.2.1. 使用客户端配置属性的 JAAS 配置

原文引用:Clients may specify JAAS configuration as a producer or consumer property without creating a physical configuration file. This mode also enables different producers and consumers within the same JVM to use different credentials by specifying different properties for each client. If both static JAAS configuration system property java.security.auth.login.config and client property sasl.jaas.config are specified, the client property will be used.

See GSSAPI (Kerberos), PLAIN, SCRAM or OAUTHBEARER for example configurations.

    客户端可以将 JAAS 配置指定为生产者或消费者属性,而无需创建物理配置文件。这种模式还允许同一 JVM 中的不同生产者和消费者通过为每个客户端指定不同的属性来使用不同的凭据。如果同时指定了静态 JAAS 配置系统属性 java.security.auth.login.config 和客户端属性sasl.jas.config,则将使用客户端属性。

有关配置示例,请参阅 GSSAPI(Kerberos)、PLAIN、SCRAM 或 OAUTHBEARER。

2.2.2. 使用静态配置文件的 JAAS 配置

原文引用:To configure SASL authentication on the clients using static JAAS config file:

  1. Add a JAAS config file with a client login section named KafkaClient. Configure a login module in KafkaClient for the selected mechanism as described in the examples for setting up GSSAPI (Kerberos), PLAIN, SCRAM or OAUTHBEARER. For example, GSSAPI credentials may be configured as:

要使用静态 JAAS 配置文件在客户端上配置 SASL 身份验证,请执行以下操作:

  1. 添加一个 JAAS 配置文件,其中包含一个名为 KafkaClient 的客户端登录部分。在KafkaClient 中为所选机制配置登录模块,如设置 GSSAPI(Kerberos)、PLAIN、SCRAM或 OAUTHBEARER 的示例中所述。例如,GSSAPI 凭据可以配置为:
    KafkaClient {com.sun.security.auth.module.Krb5LoginModule requireduseKeyTab=truestoreKey=truekeyTab="/etc/security/keytabs/kafka_client.keytab"principal="kafka-client-1@EXAMPLE.COM";
    };

 原文引用:

  1. Pass the JAAS config file location as JVM parameter to each client JVM. For example:
  1. 将 JAAS 配置文件位置作为 JVM 参数传递给每个客户端 JVM。例如
    -Djava.security.auth.login.config=/etc/kafka/kafka_client_jaas.conf

三. SASL 配置(SASL configuration)

原文引用:SASL may be used with PLAINTEXT or SSL as the transport layer using the security protocol SASL_PLAINTEXT or SASL_SSL respectively. If SASL_SSL is used, then SSL must also be configured.

    SASL 可以与 PLAINTEXT 或 SSL 一起使用,作为分别使用安全协议 SASL_PLAINTEXT 或 SASL_SSL 的传输层。如果使用 SASL_SSL,则还必须配置 SSL。

3.1. SASL 机制(SASL mechanisms)

原文引用:Kafka supports the following SASL mechanisms:

  • GSSAPI (Kerberos)
  • PLAIN
  • SCRAM-SHA-256
  • SCRAM-SHA-512
  • OAUTHBEARER

Kafka 支持以下 SASL 机制:

  • GSSAPI(Kerberos)
  • PLAIN
  • SCRAM-SHA-256
  • SCRAM-SHA-512
  • OAUTHBEARER

3.2. Kafka Broker 的 SASL 配置

原文引用:1. Configure a SASL port in server.properties, by adding at least one of SASL_PLAINTEXT or SASL_SSL to the listeners parameter, which contains one or more comma-separated values:

1. 在 server.properties 中配置 SASL 端口,方法是将 SASL_PLAINTEXT 或 SASL_SSL 中的至少一个添加到 listener 参数中,该参数包含一个或多个逗号分隔的值:

listeners=SASL_PLAINTEXT://host.name:port

原文引用:If you are only configuring a SASL port (or if you want the Kafka brokers to authenticate each other using SASL) then make sure you set the same SASL protocol for inter-broker communication:

    如果您只配置 SASL 端口(或者如果您希望 Kafka Broker 使用 SASL 相互验证),请确保为 Broker 间通信设置相同的 SASL 协议:

security.inter.broker.protocol=SASL_PLAINTEXT (or SASL_SSL)

原文引用:2. Select one or more supported mechanisms to enable in the broker and follow the steps to configure SASL for the mechanism. To enable multiple mechanisms in the broker, follow the steps here.

2. 选择一个或多个要在 Broker 中启用的支持机制,然后按照步骤为该机制配置 SASL。要在 Broker 中启用多个机制,请按照此处的步骤操作。

3.3. Kafka 客户端的 SASL 配置

原文引用:SASL authentication is only supported for the new Java Kafka producer and consumer, the older API is not supported.

To configure SASL authentication on the clients, select a SASL mechanism that is enabled in the broker for client authentication and follow the steps to configure SASL for the selected mechanism.

    SASL 身份验证仅支持新的 Java Kafka 生产者和消费者,不支持旧的 API。

    要在客户端上配置 SASL 身份验证,请选择在 Broker 中启用的用于客户端身份验证的 SASL 机制,然后按照步骤为所选机制配置 SASL。

原文引用:Note: When establishing connections to brokers via SASL, clients may perform a reverse DNS lookup of the broker address. Due to how the JRE implements reverse DNS lookups, clients may observe slow SASL handshakes if fully qualified domain names are not used, for both the client's bootstrap.servers and a broker's advertised.listeners.

注意:当通过 SASL 与 Broker 建立连接时,客户端可能会对 Broker 地址执行反向 DNS 查找。由于 JRE 是实现反向 DNS 查找的,如果客户端的 bootstrap.servers 和 Broker 的advertised.listeners 都没有使用完全限定的域名,则客户端可能会观察到 SASL 握手缓慢。

相关文章:

  • 在线随机密码生成工具
  • 制作微信小程序“飞翔的小鸟”
  • 【Redis】如何保证缓存和数据库的一致性
  • Vue发送http请求
  • 计算机网络之TCP的三次握手和四次挥手
  • webpack 中 require.context() 的用法
  • 力扣刷题笔记
  • Redis连接池配置:深入探索JedisPoolConfig
  • create-react-app创建的项目中设置webpack配置
  • 【科技前沿】电子设计新贵SmartEDA:为何它引领行业风潮?
  • 物联网 IoT 收录
  • 等保测评练习10
  • 程序员系统入门大模型的路径和资源,看这篇就够了
  • 道路救援小程序源码
  • 把sql拿到数据库中执行,和程序返回的值不一样??????
  • [译]如何构建服务器端web组件,为何要构建?
  • 【个人向】《HTTP图解》阅后小结
  • 【刷算法】求1+2+3+...+n
  • css布局,左右固定中间自适应实现
  • JavaScript设计模式系列一:工厂模式
  • Java比较器对数组,集合排序
  • laravel5.5 视图共享数据
  • MySQL用户中的%到底包不包括localhost?
  • SwizzleMethod 黑魔法
  • Three.js 再探 - 写一个跳一跳极简版游戏
  • use Google search engine
  • 前端代码风格自动化系列(二)之Commitlint
  • 前嗅ForeSpider中数据浏览界面介绍
  • 设计模式(12)迭代器模式(讲解+应用)
  • 线性表及其算法(java实现)
  • 在electron中实现跨域请求,无需更改服务器端设置
  • LIGO、Virgo第三轮探测告捷,同时探测到一对黑洞合并产生的引力波事件 ...
  • 仓管云——企业云erp功能有哪些?
  • 第二十章:异步和文件I/O.(二十三)
  • ​Spring Boot 分片上传文件
  • # include “ “ 和 # include < >两者的区别
  • #includecmath
  • (13)Hive调优——动态分区导致的小文件问题
  • (2024,Vision-LSTM,ViL,xLSTM,ViT,ViM,双向扫描)xLSTM 作为通用视觉骨干
  • (3)(3.5) 遥测无线电区域条例
  • (Bean工厂的后处理器入门)学习Spring的第七天
  • (不用互三)AI绘画:科技赋能艺术的崭新时代
  • (六)vue-router+UI组件库
  • (生成器)yield与(迭代器)generator
  • (一)模式识别——基于SVM的道路分割实验(附资源)
  • (转)IOS中获取各种文件的目录路径的方法
  • (转)自己动手搭建Nginx+memcache+xdebug+php运行环境绿色版 For windows版
  • ***微信公众号支付+微信H5支付+微信扫码支付+小程序支付+APP微信支付解决方案总结...
  • .NET CF命令行调试器MDbg入门(一)
  • .NET/ASP.NETMVC 深入剖析 Model元数据、HtmlHelper、自定义模板、模板的装饰者模式(二)...
  • .Net--CLS,CTS,CLI,BCL,FCL
  • .NET是什么
  • .NET学习教程二——.net基础定义+VS常用设置
  • .NET应用架构设计:原则、模式与实践 目录预览
  • /var/spool/postfix/maildrop 下有大量文件