
# HBase访问多ZooKeeper场景安全认证
#### 场景说明
在同一个客户端进程内同时访问FusionInsight ZooKeeper和第三方的ZooKeeper时，为了避免访问连接ZooKeeper认证冲突，提供了样例代码使HBase客户端访问FusionInsight ZooKeeper和客户应用访问第三方ZooKeeper。
以下为"src/main/resources"目录下提供的与认证相关的配置文件。
- zoo.cfg
  ```
  # The configuration in jaas.conf used to connect fi 
  zookeeper.zookeeper.sasl.clientconfig=Client_new[1]
  # Principal of fi zookeeper server side.
  zookeeper.server.principal=zookeeper/hadoop.hadoop.com[2]
  # Set true if the fi cluster is security mode.
  # The other two parameters doesn't work if the value is false.
  zookeeper.sasl.client=true[3]
  ```
  \[1\] zookeeper.sasl.clientconfig：指定使用jaas.conf文件中的对应配置访问FusionInsight ZooKeeper；
  \[2\] zookeeper.server.principal：指定ZooKeeper服务端使用principal；
  \[3\] zookeeper.sasl.client：如果MRS集群是安全模式，该值设置为"true"，否则设置为"false"，设置为"false"的情况下，"zookeeper.sasl.clientconfig"和"zookeeper.server.principal"参数不生效。
  
- jaas.conf
  ```
  Client_new {  [4]
    com.sun.security.auth.module.Krb5LoginModule required 
    useKeyTab=true
    keyTab="D:\\work\\sample_project\\src\\hbase-examples\\hbase-zk-example\\target\\classes\\conf\\user.keytab" [5]
    principal="hbaseuser1"
    useTicketCache=false
    storeKey=true
    debug=true;
  };
  Client {  [6]
    org.apache.zookeeper.server.auth.DigestLoginModule required
    username="bob"
    password="xxxxxx"; [7]
  };
  ```
  \[4\] Client_new：zoo.cfg中指定的读取配置，当该名称修改时，需要同步修改zoo.cfg中对应配置。
  \[5\] keyTab ：指明工程使用的"user.keytab"在运行样例的主机上的保存路径，使用绝对路径便于更好定位文件位置。在Windows环境和Linux环境下配置时需注意区分不同操作系统路径书写方式，即"\\\\"与"\\"差异。
  \[6\] Client：第三方ZooKeeper使用该配置进行访问连接，具体连接认证配置由第三方ZooKeeper版本决定。
  \[7\] password：密码明文存储存在安全风险，建议在配置文件或者环境变量中密文存放，使用时解密，确保安全。
  
 
