1 Web UI使用HTTPS
看下Web UI为何物:
上面篮框中有三个连接,看下他们都代表了什么
由上图可知那三个连接对应了三个Master实例。
随便选择一个点击,看看Web UI的样式
Web UIs默认使用不安全的HTTP连接master和region servers。
若要使用HTTPS,配置hbase-site.xml:
hbase.ssl.enabled=true
这样只是开启HTTPS,但此时HTTPS和HTTP使用相同的默认端口
更改Web UIs默认的端口,那么配置:
hbase.master.info.port
hbase.regionserver.info.port
注意:如果开启HTTPS,客户端应避免使用不安全的HTTP连接,因为在这种情形下,如果使用http://URL 发请求,响应状态为200,但是无法获得数据。如果https和http使用相同端口会抛异常:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
这是因为HBase使用Jetty作为Web UI服务器。
2 Web UIs为Kerberos 认证使用SPNEGO
简单说下SPNEGO。
SPNEGO是Simple and Protected GSSAPI Negotiation Mechanism的缩写,这里有一个概念GSSAPI 先介绍下。
GSSAPI是Generic Security Services Application Program Interface的缩写,它是GSSAPI是IETF标准,为用户提供了应用程序接口,具体实现由软件供应商提供。
SPNEGO的作用就是协调客户端和服务器完成安全认证。客户端和服务器都不知道对方支持哪种认证协议,这时为了完成认证,使用SPNEGO选择客户端和服务器都支持的GSSAPI。
HBase Web UIs使用Kerberos-authentication,通过配置SPNEGO使其生效,即配置hbase-site.xml中的hbase.security.authentication.ui属性。为使其生效,同时需要配置为RPC使用Kerberos认证(例如hbase.security.authentication = kerberos)。
hbase.security.authentication.ui
kerberos
Controls what kind of authentication should be used for the HBase web UIs.
hbase.security.authentication
kerberos
The Kerberos keytab file to use for SPNEGO authentication by the web server.
Web服务配置SPNEGO认证:
hbase.security.authentication.spnego.kerberos.principal
HTTP/_HOST@EXAMPLE.COM
Required for SPNEGO, the Kerberos principal to use for SPNEGO authentication by the
web server. The _HOST keyword will be automatically substituted with the node's
hostname.
hbase.security.authentication.spnego.kerberos.keytab
/etc/security/keytabs/spnego.service.keytab
Required for SPNEGO, the Kerberos keytab file to use for SPNEGO authentication by the
web server.
hbase.security.authentication.spnego.kerberos.name.rules
Optional, Hadoop-style `auth_to_local` rules which will be parsed and used in the
handling of Kerberos principals
hbase.security.authentication.signature.secret.file
Optional, a file whose contents will be used as a secret to sign the HTTP cookies
as a part of the SPNEGO authentication handshake. If this is not provided, Java's `Random` library
will be used for the secret.
3使用安全的客户端访问HBase
0.92及其以上版本可以选择SASL(Simple Authentication And Security Layer,简单认证和安全层)认证。
先决条件
为了HBase RPC执行强制验证机制,必须设置:
hbase-site.xml中
hbase.security.authentication=kerberos
core-site.xml中
hadoop.security.authentication = kerberos
如果不设置,那么会对HBase执行强制验证而不会对HDFS执行强制验证。
同时,必须要有Kerberos KDC(秘钥分发中心)。
为安全操作HBase配置服务端
确保满足先决条件。
每台服务器的hbase-site.xml中,配置完要重启HBase服务。
hbase.security.authentication
kerberos
hbase.security.authorization
truehbase.coprocessor.region.classes
org.apache.hadoop.hbase.security.token.TokenProvider
为安全操作HBase配置客户端
确保满足先决条件,HDSF也启用安全配置
每个客户端的hbase-site.xml配置为:
hbase.security.authentication
kerberos
对于2.2.0之前的版本,客户端环境必须通过kinit命令从KDC或keytab登录到Kerberos,然后才能与HBase集群进行通信。
2.2.0及之后的版本,应如下配置hbase-site.xml:
hbase.client.keytab.file
/local/path/to/client/keytab
hbase.client.keytab.principal
foo@EXAMPLE.COM
配置完成以后,应用程序可以自动完成登录和证书更新,无需客户端干预。这是可选的特性,对于升级到2.2.0的客户端,仍然可以保留旧版本中已有的登录和凭证更新逻辑,只要未设置hbase.client.keytab.file和hbase.client.keytab.principal便可。
注意,如果客户端和服务端的hbase.security.authentication属性配置不匹配,那么客户端无法和集群通信。
一旦HBase被配置为安全的RPC,那么加密通信变成可配置的,即每一个客户端hbase-site.xml配置为:
hbase.rpc.protection
privacy
也可以在编码中对每个连接进行设置:
Configuration conf = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(conf);
conf.set("hbase.rpc.protection