go通过thrift连接hbase_海量数据存储技术之HBase:安全策略(第一部分)

a0d7ae6b3e4508dade5a11b934ba1f7e.png

1 Web UI使用HTTPS

看下Web UI为何物:

a7cb0a3061ac88e4d3b11fc337ea22ab.png

上面篮框中有三个连接,看下他们都代表了什么

1586054829ced70a13a3d0964de82e04.png

由上图可知那三个连接对应了三个Master实例。

随便选择一个点击,看看Web UI的样式

c70032a556ce4a83c52716678d74e5af.png

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Python中使用Thrift连接HBase,您需要按照以下步骤进行设置: 1. 安装所需的依赖项: 您需要安装`thrift`和`happybase`这两个Python库。可以使用以下命令进行安装: ```bash pip install thrift happybase ``` 2. 生成HBaseThrift代码: 使用Thrift工具生成HBaseThrift代码。您可以使用以下命令: ```bash thrift -r --gen py hbase.thrift ``` 这将生成Python的Thrift代码文件。 3. 创建HBase连接: 在Python脚本中,您需要首先创建一个HBase连接。示例代码如下: ```python import happybase connection = happybase.Connection(host='localhost', port=9090) ``` 4. 执行HBase操作: 在创建了HBase连接之后,您可以使用`connection`对象执行各种HBase操作,例如创建表、插入数据、获取数据等。以下是一些示例代码: - 创建表: ```python connection.create_table( 'mytable', { 'cf': dict(max_versions=10), } ) ``` - 插入数据: ```python table = connection.table('mytable') table.put( b'row1', { b'cf:col1': b'value1', b'cf:col2': b'value2', } ) ``` - 获取数据: ```python table = connection.table('mytable') row = table.row(b'row1') print(row) ``` - 删除数据: ```python table = connection.table('mytable') table.delete(b'row1') ``` 这只是一些示例代码,您可以根据需要使用其他HappyBase方法来执行更多操作。 5. 关闭连接: 当您完成HBase操作后,记得关闭连接以释放资源: ```python connection.close() ``` 请注意,为了成功执行这些操作,您需要确保HBase正在运行并且在指定的主机和端口上进行监听。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值