加密Shuffle功能允许使用HTTPS对MapReduce shuffle进行加密,并可选择客户端认证(也称为双向HTTPS,或带客户端证书的HTTPS)。它包括:
一个Hadoop配置设置,用于在HTTP和HTTPS之间切换数据传输方式。
用于指定shuffle服务及获取shuffle数据的reducer任务所使用的密钥库和信任库属性(位置、类型、密码)的Hadoop配置设置。
一种在集群中重新加载信任存储的方式(当节点被添加或移除时)。
要启用加密shuffle功能,请在集群所有节点的core-site.xml文件中设置以下属性:
属性 | 默认值 | 说明 |
---|---|---|
hadoop.ssl.require.client.cert |
false |
Whether client certificates are required |
hadoop.ssl.hostname.verifier |
DEFAULT |
The hostname verifier to provide for HttpsURLConnections. Valid values are: DEFAULT, STRICT, STRICT_IE6, DEFAULT_AND_LOCALHOST and ALLOW_ALL |
hadoop.ssl.keystores.factory.class |
org.apache.hadoop.security.ssl.FileBasedKeyStoresFactory |
The KeyStoresFactory implementation to use |
hadoop.ssl.server.conf |
ssl-server.xml |
Resource file from which ssl server keystore information will be extracted. This file is looked up in the classpath, typically it should be in Hadoop conf/ directory |
hadoop.ssl.client.conf |
ssl-client.xml |
Resource file from which ssl server keystore information will be extracted. This file is looked up in the classpath, typically it should be in Hadoop conf/ directory |
hadoop.ssl.enabled.protocols |
TLSv1.2 |
The supported SSL protocols. The parameter will only be used from DatanodeHttpServer. |
重要提示:当前应将要求客户端证书设置为false。详情请参阅客户端证书部分。
重要提示: 所有这些属性都应在集群配置文件中标记为final。
<property> <name>hadoop.ssl.require.client.cert</name> <value>false</value> <final>true</final> </property> <property> <name>hadoop.ssl.hostname.verifier</name> <value>DEFAULT</value> <final>true</final> </property> <property> <name>hadoop.ssl.keystores.factory.class</name> <value>org.apache.hadoop.security.ssl.FileBasedKeyStoresFactory</value> <final>true</final> </property> <property> <name>hadoop.ssl.server.conf</name> <value>ssl-server.xml</value> <final>true</final> </property> <property> <name>hadoop.ssl.client.conf</name> <value>ssl-client.xml</value> <final>true</final> </property>
mapred-site.xml
属性配置要启用加密shuffle,请在集群所有节点的mapred-site.xml中设置以下属性:
属性 | 默认值 | 说明 |
---|---|---|
mapreduce.shuffle.ssl.enabled |
false |
Whether encrypted shuffle is enabled |
重要提示: 该属性应在集群配置文件中标记为final。
<property> <name>mapreduce.shuffle.ssl.enabled</name> <value>true</value> <final>true</final> </property>
应设置Linux容器执行器,以防止作业任务读取服务器密钥库信息并获取对shuffle服务器证书的访问权限。
有关如何执行此操作的详细信息,请参阅Hadoop Kerberos配置。
目前FileBasedKeyStoresFactory
是唯一的KeyStoresFactory
实现。FileBasedKeyStoresFactory
实现使用ssl-server.xml和ssl-client.xml文件中的以下属性来配置密钥库和信任库。
ssl-server.xml
(Shuffle服务器) 配置:mapred用户应拥有ssl-server.xml文件并对其具有独占读取权限。
属性 | 默认值 | 说明 |
---|---|---|
ssl.server.keystore.type |
jks |
Keystore file type |
ssl.server.keystore.location |
NONE | Keystore file location. The mapred user should own this file and have exclusive read access to it. |
ssl.server.keystore.password |
NONE | Keystore file password |
ssl.server.truststore.type |
jks |
Truststore file type |
ssl.server.truststore.location |
NONE | Truststore file location. The mapred user should own this file and have exclusive read access to it. |
ssl.server.truststore.password |
NONE | Truststore file password |
ssl.server.truststore.reload.interval |
10000 | Truststore reload interval, in milliseconds |
<configuration> <!-- Server Certificate Store --> <property> <name>ssl.server.keystore.type</name> <value>jks</value> </property> <property> <name>ssl.server.keystore.location</name> <value>${user.home}/keystores/server-keystore.jks</value> </property> <property> <name>ssl.server.keystore.password</name> <value>serverfoo</value> </property> <!-- Server Trust Store --> <property> <name>ssl.server.truststore.type</name> <value>jks</value> </property> <property> <name>ssl.server.truststore.location</name> <value>${user.home}/keystores/truststore.jks</value> </property> <property> <name>ssl.server.truststore.password</name> <value>clientserverbar</value> </property> <property> <name>ssl.server.truststore.reload.interval</name> <value>10000</value> </property> </configuration>
ssl-client.xml
(Reducer/Fetcher) 配置:mapred用户应拥有ssl-client.xml文件的所有权,且该文件应保持默认权限。
属性 | 默认值 | 说明 |
---|---|---|
ssl.client.keystore.type |
jks |
Keystore file type |
ssl.client.keystore.location |
NONE | Keystore file location. The mapred user should own this file and it should have default permissions. |
ssl.client.keystore.password |
NONE | Keystore file password |
ssl.client.truststore.type |
jks |
Truststore file type |
ssl.client.truststore.location |
NONE | Truststore file location. The mapred user should own this file and it should have default permissions. |
ssl.client.truststore.password |
NONE | Truststore file password |
ssl.client.truststore.reload.interval |
10000 | Truststore reload interval, in milliseconds |
<configuration> <!-- Client certificate Store --> <property> <name>ssl.client.keystore.type</name> <value>jks</value> </property> <property> <name>ssl.client.keystore.location</name> <value>${user.home}/keystores/client-keystore.jks</value> </property> <property> <name>ssl.client.keystore.password</name> <value>clientfoo</value> </property> <!-- Client Trust Store --> <property> <name>ssl.client.truststore.type</name> <value>jks</value> </property> <property> <name>ssl.client.truststore.location</name> <value>${user.home}/keystores/truststore.jks</value> </property> <property> <name>ssl.client.truststore.password</name> <value>clientserverbar</value> </property> <property> <name>ssl.client.truststore.reload.interval</name> <value>10000</value> </property> </configuration>
完成上述配置更改后,通过重新启动所有NodeManager来激活加密Shuffle功能。
重要提示: 使用加密shuffle会显著影响性能。用户应评估此影响,并可能为加密shuffle预留1个或多个核心。
使用客户端证书并不能完全确保客户端是作业的Reducer任务。目前,客户端证书(及其私钥)的密钥库文件必须对提交作业到集群的所有用户可读。这意味着恶意作业可以读取这些密钥库文件,并使用其中的客户端证书与Shuffle服务器建立安全连接。然而,除非恶意作业拥有正确的JobToken,否则它将无法从Shuffle服务器获取混洗数据。作业只能使用自身的JobToken来获取属于自身的混洗数据。
默认情况下,信任库每10秒会重新加载一次配置。如果用新的信任库文件覆盖旧文件,系统将重新读取该文件,并用其中的证书替换旧证书。这种机制对于在集群中添加或移除节点,或者添加或移除可信客户端非常有用。在这些情况下,客户端或NodeManager证书会被添加到(或从)系统中所有信任库文件中(移除),新配置将自动生效,无需重启NodeManager守护进程。
注意:仅在故障排查时启用调试功能,且仅适用于处理少量数据的作业。调试输出非常详细,会显著降低作业运行速度(可能需要增加mapred.task.timeout参数值,防止因任务运行过慢导致作业失败)。
要在reducer中启用SSL调试,请在mapreduce.reduce.child.java.opts
属性中设置-Djavax.net.debug=all
;例如:
<property> <name>mapred.reduce.child.java.opts</name> <value>-Xmx-200m -Djavax.net.debug=all</value> </property>
您可以在每个作业的基础上执行此操作,或者通过在mapred-site.xml
文件中设置集群范围的参数来实现。
要在NodeManager中设置此属性,请在yarn-env.sh
文件中进行配置:
YARN_NODEMANAGER_OPTS="-Djavax.net.debug=all"
该功能允许对合并和洗牌阶段生成的中间文件进行加密。可以通过将作业属性mapreduce.job.encrypted-intermediate-data
设置为true
来启用此功能。
名称 | 类型 | 描述 |
---|---|---|
mapreduce.job.encrypted-intermediate-data | boolean | 启用或禁用加密中间mapreduce溢出文件。默认为false。 |
mapreduce.job.encrypted-intermediate-data-key-size-bits | int | 用于加密溢出到磁盘数据的密钥生成器所使用的密钥长度。 |
mapreduce.job.encrypted-intermediate-data.buffer.kb | int | 加密后写入磁盘的流缓冲区大小(以KB为单位)。 |
注意: 当前启用加密中间数据溢出会将作业的尝试次数限制为1次。