(一)Kafka 安全之使用 SSL 的加密和身份验证

目录

一. 前言

二. 使用 SSL 的加密和身份验证

2.1. 为每个 Kafka Broker 生成 SSL 密钥和证书

2.1.1. 主机名验证(Host Name Verification)

2.1.2. 注意(Note)


一. 前言

    SSL(Secure Sockets Layer)是一种网络协议,提供了一种在客户端和服务器之间建立安全连接的方法。启用 SSL 后,Kafka 集群中的所有数据传输,包括生产者、消费者与 Broker 之间的消息交互都会被加密,确保敏感信息在网络传输过程中不被窃听或篡改。

二. 使用 SSL 的加密和身份验证

原文引用:Apache Kafka allows clients to use SSL for encryption of traffic as well as authentication. By default, SSL is disabled but can be turned on if needed. The following paragraphs explain in detail how to set up your own PKI infrastructure, use it to create certificates and configure Kafka to use these.

    Apache Kafka 允许客户端使用 SSL 对流量进行加密和身份验证。默认情况下,SSL 是禁用的,但如果需要,可以打开。以下段落详细解释了如何设置自己的 PKI 基础设施,使用它来创建证书,并配置 Kafka 来使用这些证书。

2.1. 为每个 Kafka Broker 生成 SSL 密钥和证书

原文引用:The first step of deploying one or more brokers with SSL support is to generate a public/private keypair for every server. Since Kafka expects all keys and certificates to be stored in keystores we will use Java's keytool command for this task. The tool supports two different keystore formats, the Java specific jks format which has been deprecated by now, as well as PKCS12. PKCS12 is the default format as of Java version 9, to ensure this format is being used regardless of the Java version in use all following commands explicitly specify the PKCS12 format.

    部署一个或多个支持 SSL 的 Broker 程序的第一步是为每个服务器生成一个 public/priate 密钥对。由于 Kafka 希望所有密钥和证书都存储在密钥库中,因此我们将使用 Java 的 keytool 命令来完成此任务。该工具支持两种不同的密钥存储格式,一种是 Java 特定的 jks 格式(目前已弃用),另一种是 PKCS12。PKCS12 是 Java 9 版本的默认格式,为了确保无论使用的 Java 版本如何都使用此格式,以下所有命令都明确指定 PKCS12 格式。

> keytool -keystore {keystorefile} -alias localhost -validity {validity} -genkey -keyalg RSA -storetype pkcs12

原文引用:You need to specify two parameters in the above command:

  1. keystorefile: the keystore file that stores the keys (and later the certificate) for this broker. The keystore file contains the private and public keys of this broker, therefore it needs to be kept safe. Ideally this step is run on the Kafka broker that the key will be used on, as this key should never be transmitted/leave the server that it is intended for.
  2. validity: the valid time of the key in days. Please note that this differs from the validity period for the certificate, which will be determined in Signing the certificate. You can use the same key to request multiple certificates: if your key has a validity of 10 years, but your CA will only sign certificates that are valid for one year, you can use the same key with 10 certificates over time.

您需要在上面的命令中指定两个参数:

  1. keystorefile:存储此 Broker 的密钥(以及后来的证书)的密钥库文件。密钥库文件包含该 Broker 的私钥和公钥,因此需要保持安全。理想情况下,这一步骤是在密钥将在其上使用的Kafka Broker 上运行的,因为该密钥永远不应该被传输/离开其目的服务器。
  2. validity:密钥的有效时间,以天为单位。请注意,这与证书的有效期不同,该有效期将在签署证书时确定。您可以使用同一密钥申请多个证书:如果您的密钥的有效期为10年,但您的CA 只会签署有效期为一年的证书,那么您可以在一段时间内将同一密钥与10个证书一起使用。

原文引用:To obtain a certificate that can be used with the private key that was just created a certificate signing request needs to be created. This signing request, when signed by a trusted CA results in the actual certificate which can then be installed in the keystore and used for authentication purposes.


To generate certificate signing requests run the following command for all server keystores created so far.

    要获得可与刚创建的私钥一起使用的证书,需要创建证书签名请求。当由受信任的 CA 签名时,此签名请求会生成实际证书,然后可以将该证书安装在密钥库中并用于身份验证。

    要生成证书签名请求,请对迄今为止创建的所有服务器密钥库运行以下命令。

> keytool -keystore server.keystore.jks -alias localhost -validity {validity} -genkey -keyalg RSA -destkeystoretype pkcs12 -ext SAN=DNS:{FQDN},IP:{IPADDRESS1}

原文引用:This command assumes that you want to add hostname information to the certificate, if this is not the case, you can omit the extension parameter -ext SAN=DNS:{FQDN},IP:{IPADDRESS1}. Please see below for more information on this.

    此命令假定您要将主机名信息添加到证书中,如果不是这样,则可以省略扩展参数 -ext SAN=DNS:{FQDN},IP:{IPADDRESS1}。有关此方面的更多信息,请参见下文。

2.1.1. 主机名验证(Host Name Verification)

原文引用:Host name verification, when enabled, is the process of checking attributes from the certificate that is presented by the server you are connecting to against the actual hostname or ip address of that server to ensure that you are indeed connecting to the correct server.

    主机名验证(如果启用)是根据服务器的实际主机名或 ip 地址检查连接到的服务器提供的证书中的属性的过程,以确保您确实连接到了正确的服务器。

原文引用:The main reason for this check is to prevent man-in-the-middle attacks. For Kafka, this check has been disabled by default for a long time, but as of Kafka 2.0.0 host name verification of servers is enabled by default for client connections as well as inter-broker connections.

    进行此检查的主要原因是为了防止中间人攻击。对于 Kafka,此检查已被默认禁用很长一段时间,但从 Kafka 2.0.0 起,客户端连接和 Broker 间连接默认启用服务器的主机名验证。

原文引用:Server host name verification may be disabled by setting ssl.endpoint.identification.algorithm to an empty string.


For dynamically configured broker listeners, hostname verification may be disabled using kafka-configs.sh: 

可以通过将 ssl.endpoint.identification.agorithm 设置为空字符串来禁用服务器主机名验证。

对于动态配置的 Broker 监听器,可以使用 kafka-configs.sh 禁用主机名验证:

> bin/kafka-configs.sh --bootstrap-server localhost:9093 --entity-type brokers --entity-name 0 --alter --add-config "listener.name.internal.ssl.endpoint.identification.algorithm="

2.1.2. 注意(Note)

原文引用:Normally there is no good reason to disable hostname verification apart from being the quickest way to "just get it to work" followed by the promise to "fix it later when there is more time"!

    通常情况下,禁用主机名验证没有什么好的理由,除了这是“让它正常工作”的最快方法,然后承诺“稍后有更多时间时修复它”!

原文引用:Getting hostname verification right is not that hard when done at the right time, but gets much harder once the cluster is up and running - do yourself a favor and do it now!

    在正确的时间进行主机名验证并不是那么困难,但一旦集群启动并运行,就会变得非常困难——帮自己一个忙,现在就做!

原文引用:If host name verification is enabled, clients will verify the server's fully qualified domain name (FQDN) or ip address against one of the following two fields:

  1. Common Name (CN)
  2. Subject Alternative Name (SAN)

    如果启用了主机名验证,客户端将根据以下两个字段之一验证服务器的完全限定域名(FQDN)或 ip 地址:

  1. 通用名称(CN)。
  2. 使用者备选名称(SAN)。

原文引用:While Kafka checks both fields, usage of the common name field for hostname verification has been deprecated since 2000 and should be avoided if possible. In addition the SAN field is much more flexible, allowing for multiple DNS and IP entries to be declared in a certificate.

    虽然 Kafka 同时检查这两个字段,但自2000年以来,使用通用名称字段进行主机名验证的做法一直受到反对,如果可能的话,应该避免使用。此外,SAN 字段更加灵活,允许在证书中声明多个 DNS 和 IP 条目。

原文引用:Another advantage is that if the SAN field is used for hostname verification the common name can be set to a more meaningful value for authorization purposes. Since we need the SAN field to be contained in the signed certificate, it will be specified when generating the signing request. It can also be specified when generating the keypair, but this will not automatically be copied into the signing request.

To add a SAN field append the following argument -ext SAN=DNS:{FQDN},IP:{IPADDRESS} to the keytool command:

    另一个优点是,如果 SAN 字段用于主机名验证,则出于授权目的,可以将通用名称设置为更有意义的值。由于我们需要在签名证书中包含 SAN 字段,因此在生成签名请求时会指定该字段。它也可以在生成密钥对时指定,但不会自动复制到签名请求中。

    要添加 SAN 字段,请将以下参数 -ext SAN=DNS:{FQDN},IP:{IPADDRESS} 附加到 keytool 命令:

> keytool -keystore server.keystore.jks -alias localhost -validity {validity} -genkey -keyalg RSA -destkeystoretype pkcs12 -ext SAN=DNS:{FQDN},IP:{IPADDRESS1}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/29267.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Oracle数据库面试题-14

81. 解释RAC(Real Application Clusters)的工作原理。 RAC(Real Application Clusters)是Oracle Corporation开发的高可用性解决方案,它允许用户将多个数据库实例集群在一起,以提高数据库系统的可用性和性…

【Java】已解决java.lang.IllegalAccessException异常

文章目录 一、问题分析背景二、可能出错的原因三、错误代码示例四、正确代码示例五、注意事项 已解决java.lang.IllegalAccessException异常 一、问题分析背景 在Java开发中,java.lang.IllegalAccessException是一个常见的运行时异常,它通常发生在尝试…

【人工智能】人工智能就业岗位发展方向有哪些?

人工智能领域的岗位多样,涵盖了从技术研发到应用实施、从产品设计到市场运营等各个方面,以下是人工智能就业岗位的主要发展方向 研发与应用岗位: 机器学习工程师:负责开发和实施机器学习算法,解决各种问题&#xff0c…

CDA二级(Level II)数据分析师——考试内容梳理二

逻辑回归:Ln(P/(1-P)-30.06X0.05X2-0.02X3X1 岭回归的扰动性越大,模型越不容易受到共线性的影响; LOSSO只是缓解了由于共线性导致的估计误差的问题,而不是解决共线性 ; AUC值接近0.5时,我们认为这个模型…

ARM32开发--FreeRTOS-事件组

系列文章目录 知不足而奋进 望远山而前行 目录 系列文章目录 文章目录 前言 目标 内容 概念 事件标志位 开发流程 功能介绍 创建事件组 触发事件 等待事件触发 同步 清理事件 案例 总结 前言 在嵌入式系统开发中,任务之间的同步和通信是至关重要的…

智慧矿山项目建设整体解决方案(938页 )

智慧矿山,究竟是什么? 在深入探讨之前,让我们先来提出一个深刻的问题:我们能否借助科技的力量,让矿山作业不仅安全、高效,还能做到环保可持续?答案是肯定的。智慧矿山,正是这一理念…

支撑每秒 600 万订单无压力,SpringBoot + Disruptor 太猛了!

一、背景 工作中遇到项目使用Disruptor做消息队列,对你没看错,不是Kafka,也不是rabbitmq;Disruptor有个最大的优点就是快,还有一点它是开源的哦,下面做个简单的记录. 二、Disruptor介绍 Disruptor 是英国外汇交易公司LMAX开发的一个高性能队列,研发的初衷是解决内存…

【postgresql初级使用】条件表达式触发器,兼顾DML执行性能,又能执行复杂逻辑,只在结帐时计算总帐

条件触发器 ​专栏内容: postgresql使用入门基础手写数据库toadb并发编程 个人主页:我的主页 管理社区:开源数据库 座右铭:天行健,君子以自强不息;地势坤,君子以厚德载物. 文章目录 条件触发器概…

【docker入门】

在软件开发过程中,环境配置是一个至关重要的步骤,它不仅影响开发效率,也直接关联到软件的最终质量。正确的环境配置可以极大地减少开发中的潜在问题,提升软件发布的流畅度和稳定性。以下是几个关键方面,以及如何优化环…

【机器学习】第6章 支持向量机(SVM)

一、概念 1.支持向量机(support vector machine,SVM): (1)基于统计学理论的监督学习方法,但不属于生成式模型,而是判别式模型。 (2)支持向量机在各个领域内的…

如何在不丢失数据的情况下解锁安卓手机密码

手机是我们生活中必不可少的工具,可以帮助我们与朋友和家人保持联系,了解最新消息,甚至经营我们的业务。然而,当我们在 Android 手机或 iPhone 上设置密码时,我们经常会忘记密码,或者根本没有设置密码。当这…

IntelliJ IDEA 使用 Maven 时不加载本地私服的最新版本快照(snapshot)JAR 包

IntelliJ IDEA 使用 Maven 时不加载本地私服的最新版本快照(snapshot)JAR 包 目录 IntelliJ IDEA 使用 Maven 时不加载本地私服的最新版本快照(snapshot)JAR 包1. 检查 settings.xml2. IDEA Maven 配置3. 强制更新 Snapshot4. 使用…

学习笔记——路由网络基础——路由度量值

3、路由度量值 (1)基本概念 路由度量值表示到达这条路由所指目的地址的代价。度量值数值越小越优先,度量值最小路由将会被添加到路由表中。度量值很多时候被称为开销(Cost)。 路由度量(路由开销 cost)对于同一个路由协议,当到达某目标网段有多条路由供…

SQL Server入门-安装和测试(2008R2版)

环境:win10,SQL Server 2008 R2 因为工作需要用到SQL Server(而且要用2008R2版),完全不熟,所以来学习学习。 SQL Server是微软开发的关系型数据库,支持SQL。同时还有微软还开发了自己的T-SQL&am…

Fontconfig head is null, check your fonts or fonts configuration问题解决

报错信息: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [R equest processing failed: com.alibaba.excel.exception.ExcelGenerateException: java.lang.InternalError: java.lang.reflect.InvocationTargetExcep…

11 类型泛化

11 类型泛化 1、函数模版1.1 前言1.2 函数模版1.3 隐式推断类型实参1.4 函数模板重载1.5 函数模板类型形参的默认类型(C11标准) 2、类模版2.1 类模板的成员函数延迟实例化2.2 类模板的静态成员2.3 类模板的递归实例化2.4 类模板类型形参缺省值 3、类模板…

小鹏汽车2025冲刺类L4智驾,挑战与机遇并存

随着科技的飞速发展,智能驾驶已成为汽车行业的前沿领域。近日,小鹏汽车在AI DAY上宣布国内首个量产上车的端到端大模型,这一创新举措无疑为智能驾驶的发展注入了新的活力。然而,在迈向2025年实现类L4级智能驾驶的道路上&#xff0…

大前端 业务架构 插件库 设计模式 属性 线程

大前端 业务架构 插件库 适配模式之(多态)协议1对多 抽象工厂模式 观察者模式 外观模式 装饰模式之参考catagory 策略模式 属性

橡胶油封的用途是什么?

橡胶油封的用途是什么? 在机械工程和设备维护领域,橡胶油封发挥着至关重要的作用,确保各部件的耐用性和效率。那么,橡胶油封的具体用途是什么呢?本文将从多角度探讨橡胶油封的应用和优势,突出其在各个工业和汽车领域中的重要性…

QT 中文乱码 以及 tr 的使用

一、关于显示中文 1、网上常规的做法 - 第一步:代码文件选择用utf8编码带bom。QT Creator 文本编辑 行为配置里可以配置 - 第二步:在有中文汉字的代码文件顶部加一行(一般是cpp文件) #pragma execution_character_set("utf-…