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)。
<property>
<name>hbase.security.authentication.ui/<name>
<value>kerberos/<value>
<description>Controls what kind of authentication should be used for the HBase web UIs./<description>
<property>
<name>hbase.security.authentication/<name>
<value>kerberos/<value>
<description>The Kerberos keytab file to use for SPNEGO authentication by the web server./<description>
Web服務配置SPNEGO認證:
<property>
<name>hbase.security.authentication.spnego.kerberos.principal/<name>
<value>HTTP/[email protected]/<value>
<description>Required for SPNEGO, the Kerberos principal to use for SPNEGO authentication by the/<description>
web server. The _HOST keyword will be automatically substituted with the node's
hostname.
<property>
<name>hbase.security.authentication.spnego.kerberos.keytab/<name>
<value>/etc/security/keytabs/spnego.service.keytab/<value>
<description>Required for SPNEGO, the Kerberos keytab file to use for SPNEGO authentication by the/<description>
web server.
<property>
<name>hbase.security.authentication.spnego.kerberos.name.rules/<name>
<value>
<description>Optional, Hadoop-style `auth_to_local` rules which will be parsed and used in the/<description>
handling of Kerberos principals
<property>
<name>hbase.security.authentication.signature.secret.file/<name>
<value>
<description>Optional, a file whose contents will be used as a secret to sign the HTTP cookies/<description>
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服務。
<property>
<name>hbase.security.authentication/<name>
<value>kerberos/<value><property>
<name>hbase.security.authorization/<name>
<value>true/<value><property><name>hbase.coprocessor.region.classes/<name>/<property>
<value>org.apache.hadoop.hbase.security.token.TokenProvider/<value>
為安全操作HBase配置客戶端
確保滿足先決條件,HDSF也啟用安全配置
每個客戶端的hbase-site.xml配置為:
<property>
<name>hbase.security.authentication/<name>
<value>kerberos/<value>
對於2.2.0之前的版本,客戶端環境必須通過kinit命令從KDC或keytab登錄到Kerberos,然後才能與HBase集群進行通信。
2.2.0及之後的版本,應如下配置hbase-site.xml:
<property>
<name>hbase.client.keytab.file/<name>
<value>/local/path/to/client/keytab/<value>
<property>
<name>hbase.client.keytab.principal/<name>
<value>[email protected]/<value>
配置完成以後,應用程序可以自動完成登錄和證書更新,無需客戶端干預。這是可選的特性,對於升級到2.2.0的客戶端,仍然可以保留舊版本中已有的登錄和憑證更新邏輯,只要未設置hbase.client.keytab.file和hbase.client.keytab.principal便可。
注意,如果客戶端和服務端的hbase.security.authentication屬性配置不匹配,那麼客戶端無法和集群通信。
一旦HBase被配置為安全的RPC,那麼加密通信變成可配置的,即每一個客戶端hbase-site.xml配置為:
<property>
<name>hbase.rpc.protection/<name>
<value>privacy/<value>
也可以在編碼中對每個連接進行設置:
Configuration conf = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(conf);
conf.set("hbase.rpc.protection", "privacy");
try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(TableName.valueOf(tablename))) {
.... do your stuff
}
加密通信會有0-10%的性能損失。
客戶端配置-安全地使用Thrift Gateway
為每個Thrift網關設置hbase-site.xml:
<property>
<name>hbase.thrift.keytab.file/<name>
<value>/etc/hbase/conf/hbase.keytab/<value>
<property>
<name>hbase.thrift.kerberos.principal/<name>
<value>$USER/[email protected]/<value>
<property>
<name>hbase.thrift.dns.interface/<name>
<value>default/<value>
<property>
<name>hbase.thrift.dns.nameserver/<name>
<value>default/<value>
用適當的憑據和秘鑰文件替換$USER和$KEYTAB。
為了使用Thrift API訪問HBase,需要將hbase.thrift.kerberos.principal添加到acl表。例如:為使thrift_server具有管理員權限,使用如下命令
grant 'thrift_server', 'RWCA'
Thrift gateway會使用已指定的憑據認證HBase。Thrift gateway本身不使用憑據。所有使用Thrift gateway的客戶端將會使用這個憑據並共享特權。
配置Thrift gateway以便代表客戶端執行驗證
“客戶端配置-安全地使用Thrift Gateway”,這一步描述了以固定用戶,通過Thrift Gateway訪問HBase。除了這種方式外,還可以配置Thrift Gateway來代表客戶端進行驗證,並通過代理用戶訪問HBase。
Thrift Framed傳輸限制
如果使用framed傳輸方式,就沒法通過配置Thrift Gateway來進行驗證,因為SASL無法和Thrift Framed傳輸機制一起工作。
為了使用這種機制,應這樣做:
1)確保Thrift運行在安全模式下,依照“客戶端配置-安全地使用Thrift Gateway”的做法。
2)確保HBase允許代理用戶,依照“Rest網關模擬配置”的做法。
3)集群中每個運行Thrift gateway的節點,hbase-site.xml配置如下:
hbase.thrift.security.qop可選的三個值為:
privacy:認證檢驗、完整性檢驗、機密性檢驗
integrity:認證檢驗、完整性檢驗
authentication:認證檢驗
4) 重啟Thrift Gateway使配置生效。
在運行Thrift的機器上使用命令:jps,可列出所有運行的Thrift服務。
停止服務:bin/hbase-daemon.sh stop thrift
啟動服務:bin/hbase-daemon.sh start thrift
這種方式是有侷限性的:包含了一系列憑據的客戶端初始化以後,這些憑據將不能在會話期間改變。
配置Thrift Gateway以使用doAs特性
doAs特性提供了一種靈活的方式模擬一個客戶端的多種驗證規則。Thrift1實現了這一特性,但Thrift 2沒有實現這一特性。
在每個Thrift gateway的hbase-site.xml文件中做如下配置:
<property>
<name>hbase.regionserver.thrift.http/<name>
<value>true/<value>
<property>
<name>hbase.thrift.support.proxyuser/<name>
<value>true/value>/<value>
為了允許代理用戶,HBase節點的hbase-site.xml做如下配置:
<property>
<name>hadoop.security.authorization/<name>
<value>true/<value>
<property>
<name>hadoop.proxyuser.$USER.groups/<name>
<value>$GROUPS/<value>
<property>
<name>hadoop.proxyuser.$USER.hosts/<name>
<value>$GROUPS/<value>
安全訪問Rest網關的客戶端配置
每一個REST gateway的hbase-site.xml文件配置如下:
<property>
<name>hbase.rest.keytab.file/<name>
<value>$KEYTAB/<value>
<property>
<name>hbase.rest.kerberos.principal/<name>
<value>$USER/[email protected]/<value>
用適當的憑據和秘鑰文件替換$USER和$KEYTAB。
REST gateway會使用提供的憑據進行驗證。
為了使用REST API訪問HBase,需將hbase.rest.kerberos.principal添加到acl表,例如給REST API,即rest_server賦予管理員訪問權限:
grant 'rest_server', 'RWCA'
為使客戶端可以訪問網關,HBase REST網關支持SPNEGO HTTP認證。為使HBase REST網關給客戶端訪問授權,對每個REST gateway的hbase-site.xml做如下配置:
<property>
<name>hbase.rest.support.proxyuser/<name>
<value>true/<value>
<property>
<name>hbase.rest.authentication.type/<name>
<value>kerberos/<value>
<property>
<name>hbase.rest.authentication.kerberos.principal/<name>
<value>HTTP/[email protected]/<value>
<property>
<name>hbase.rest.authentication.kerberos.keytab/<name>
<value>$KEYTAB/<value>
<property>
<name>hbase.rest.dns.interface/<name>
<value>default/<value>
<property>
<name>hbase.rest.dns.nameserver/<name>
<value>default/<value>
使用適當的秘鑰文件替換$KEYTAB。
HBase REST gateway支持不同的hbase.rest.authentication.type,可配置為simple或kerberos,也可以實現Hadoop的AuthenticationHandler定義自己的authentication類型,然後將hbase.rest.authentication.type的值設置為完整的類名。
Rest網關模擬配置
默認地REST gateway不支持扮演,只要如前面那樣配置,它就可以代替客戶端訪問HBase。對於HBase服務器,所有的請求都來自於REST網關的用戶。不知道真實的用戶是誰。可以使用模擬,有了模擬,REST網關的用戶就成為代理用戶。這樣HBase網關就能知道每個請求的真實用戶,因此他能使用正確的權限。
為開啟REST網關模擬,需要這樣配置:
<property>
<name>hadoop.security.authorization/<name>
<value>true/<value><property>
<name>hadoop.proxyuser.$USER.groups/<name>
<value>$GROUPS/<value><property>
<name>hadoop.proxyuser.$USER.hosts/<name>
<value>$GROUPS/<value>
使用REST 網關代理用戶替換$USER,並且用允許的組列表替換$GROUPS。
為每一個REST網關配置hbase-site.xml:
<property>
<name>hbase.rest.authentication.type/<name>
<value>kerberos/<value><property>
<name>hbase.rest.authentication.kerberos.principal/<name>
<value>HTTP/[email protected]/<value><property>
<name>hbase.rest.authentication.kerberos.keytab/<name>
<value>$KEYTAB/<value>
用秘鑰替換$KEYTAB
4 簡單的用戶訪問權限
0.92及其以上版本支持SASL認證。
4.1簡單用戶訪問與安全訪問
簡單用戶訪問不是一種安全的操作方式,配置為這種訪問方式主要是為了防止操作錯誤。它可以模仿賬戶控制機制。這種方式無法阻止惡意的操作。
服務端配置hbase-site.xml:
對於0.94版本,增加如下配置為每臺服務器,配置完後要重啟集群:
客戶端配置hbase-site.xml:
對於0.94版本,增加如下配置為每臺服務器:
為Thrift gateway設置權限:
grant 'admin',RWCA'
為REST Gateway設置權限,
grant 'rest_server', 'RWCA'
閱讀更多 甜橙很酸 的文章