使用FreeIPA为CDH6.3集群部署安全

技术

01

文档编写目的

C loudera从CM6.3版本开始,引入了Red Hat IdM来做整个集群的认证,Red Hat IdM对应的软件为FreeIPA,在本文中描述如何使用FreeIPA来做CDH集群的认证。 关于FreeIPA服务器搭建参考<使用FreeIPA对Linux用户权限统一管理>。

文档内容

文档主要包括以下内容

  1. FreeIPA客户端配置
  2. CDH集群使用FreeIPA启用Kerberos
  3. Kerberos使用

假设前提

这篇文档将重点介绍如何在CDH集群使用FreeIPA启用及配置Kerberos,并基于以下假设:

  1. CDH集群运行正常
  2. 集群未启用Kerberos
  3. MySQL 5.1.73

测试环境

以下是本次测试环境,但不是本操作手册的必需环境:

  1. 操作系统:CentOS7.5
  2. CDH和CM版本为6.3.1
  3. 采用root用户进行操作

02

部署FreeIPA客户端

集群所有节点部署FreeIPA客户端

1)在集群的所有节点上安装FreeIPA客户端介质:


        
            

          yum -y install ipa-client
        
      

picture.image

picture.image

2)配置IPA客户端


          
[root@wangxf ~]# ipa-client-install
          
WARNING: ntpd time&date synchronization service will not be configured as
          
conflicting service (chronyd) is enabled
          
Use --force-ntpd option to disable it and force configuration of ntpd
          

          

          
DNS discovery failed to determine your DNS domain
          
Provide the domain name of your IPA server (ex: example.com): vpc.cloudera.com
          
Provide your IPA server name (ex: ipa.example.com): xuefeng.vpc.cloudera.com
          
The failure to use DNS to find your IPA server indicates that your resolv.conf file is not properly configured.
          
Autodiscovery of servers for failover cannot work with this configuration.
          
If you proceed with the installation, services will be configured to always access the discovered server for all operations and will not fail over to other servers in case of failure.
          
Proceed with fixed values and no DNS discovery? [no]: yes
          
Client hostname: wangxf.vpc.cloudera.com
          
Realm: VPC.CLOUDERA.COM
          
DNS Domain: vpc.cloudera.com
          
IPA Server: xuefeng.vpc.cloudera.com
          
BaseDN: dc=vpc,dc=cloudera,dc=com
          

          

          
Continue to configure the system with these values? [no]: yes
      

picture.image

picture.image

  1. 修改集群节点的/etc/krb5.conf配置文件。
  1. 注释掉default_ccache_name
  2. 添加 renew_lifetime = 7d

        
            

          [root@wangxf ~]# vi /etc/krb5.conf                                                                                       
        
      

picture.image

  1. 验证Kerberos配置成功

          
[root@wangxf ~]# kinit admin                                                                                              
          
Password for admin@VPC.CLOUDERA.COM:
          
You have new mail in /var/spool/mail/root
          
[root@wangxf ~]# klist
          
Ticket cache: FILE:/tmp/krb5cc_0
          
Default principal: admin@VPC.CLOUDERA.COM
          

          

          
Valid starting       Expires              Service principal
          
11/28/2019 03:54:32  11/29/2019 03:54:29  krbtgt/VPC.CLOUDERA.COM@VPC.CLOUDERA.COM
          
[root@wangxf ~]#
      

picture.image

03

CDH集群启动安全

  1. 登陆CM,进入Administration->Security,准备启动安全

picture.image

  1. 进入Security,点击Status,在集群中点击Enable Kerberos

picture.image

  1. 开始启动Enable Kerberos for Cluster,依次检查每项,确保都已经执行完成。对于执行完成的点击复选框

picture.image

所有操作都执行完成后,才能进行下一步操作。

picture.image

  1. 设置KDC

picture.image

在设置KDC页面中,KDC Type选择Redhat IPA,然后依次填写配置相关的KDC信息,包括类型、KDC服务器、KDC Realm、加密类型以及待创建的Service Principal(hdfs,yarn,,hbase,hive等)的更新生命期等,填写完成后点击下一步

picture.image

  1. 不建议让Cloudera Manager来管理krb5.conf, 点击“继续”

picture.image

  1. 输入Cloudera Manager的Kerbers管理员账号,一定得和之前创建的账号一致,点击“继续”

picture.image

  1. 导入KDC账户。如果重复执行会报错,这时需要到FreeIPA中把新加入的用户删除,然后重新执行。

picture.image

picture.image

  1. 配置Kerberos,包括部署其他节点客户端命令,配置端口等。我们前面已经配置了其他机器的kerberos客户端,这里不需要配置。端口保存默认。

picture.image

  1. 点击“继续”启用Kerberos

picture.image

  1. 集群重启完成,点击“继续”

picture.image

  1. 点击“继续”,完成集群安全设置工作。

picture.image

picture.image

04

Kerberos验证

Hdfs验证

  1. 在FreeIPA系统中已经存在admin用户,使用admin用户认证后,访问hdfs正常。Kdestroy掉已有的凭据,hdfs访问报权限问题,无法访问。

          
[root@wangxf ~]# klist
          
Ticket cache: FILE:/tmp/krb5cc_0
          
Default principal: admin@VPC.CLOUDERA.COM
          

          

          
Valid starting       Expires              Service principal
          
11/28/2019 03:54:32  11/29/2019 03:54:29  krbtgt/VPC.CLOUDERA.COM@VPC.CLOUDERA.COM
          
[root@wangxf ~]# hdfs dfs -ls /
          
Found 2 items
          
drwxrwxrwt   - hdfs supergroup          0 2019-11-28 01:07 /tmp
          
drwxr-xr-x   - hdfs supergroup          0 2019-11-28 01:07 /user
          
[root@wangxf ~]# kdestroy
          
[root@wangxf ~]# hdfs dfs -ls /
          
19/11/28 03:56:28 WARN ipc.Client: Exception encountered while connecting to the server : org.apache.hadoop.security.AccessControlException: Client cannot authenticate via:[TOKEN, KERBEROS]
          
ls: Failed on local exception: java.io.IOException: org.apache.hadoop.security.AccessControlException: Client cannot authenticate via:[TOKEN, KERBEROS]; Host Details : local host is: "wangxf.vpc.cloudera.com/10.65.48.117"; destination host is: "wangxf.vpc.cloudera.com":8020;
          
[root@wangxf ~]#
      

picture.image

  1. 使用admin用户执行MapReduce任务,因为MapReduce任务需要写到用户的临时目录下,而在hdfs中没有为该用户创建临时目录,因此任务由于访问权限问题报错。

picture.image

picture.image

这是因为在hadoop中没有/user/admin的目录,导致mapreduce的临时文件没有地方写,导致作业错误。

  1. 使用hdfs用户来创建/user/admin目录并赋权

进入/var/run/cloudera-scm-agent/process/,找到hdfs最新的目录


          
cd /var/run/cloudera-scm-agent/process/
          
cd 89-hdfs-NAMENODE
      

执行hdfs用户的凭据认证


        
            

          kinit -kt hdfs.keytab hdfs/wangxf.vpc.cloudera.com@VPC.CLOUDERA.COM
        
      

如果执行遇到下面的错误:


        
            

          kinit: Pre-authentication failed: Unsupported key table format version number while getting initial credentials
        
      

则是凭据过期,找到的文件目录不是最新的。


          
[root@wangxf 89-hdfs-NAMENODE]# hdfs dfs -mkdir /user/admin                                                                              
          
[root@wangxf 89-hdfs-NAMENODE]# hdfs dfs -chown -R admin:hadoop /user/admin                                                              
          
[root@wangxf 89-hdfs-NAMENODE]# hdfs dfs -ls /user/
          
Found 6 items
          
drwxr-xr-x   - admin  hadoop              0 2019-11-28 04:06 /user/admin
          
drwxrwxrwx   - mapred hadoop              0 2019-11-28 01:07 /user/history
          
drwxrwxr-t   - hive   hive                0 2019-11-28 01:07 /user/hive
          
drwxrwxr-x   - hue    hue                 0 2019-11-28 01:12 /user/hue
          
drwxrwxr-x   - oozie  oozie               0 2019-11-28 01:06 /user/oozie
          
drwxr-xr-x   - hdfs   supergroup          0 2019-11-28 01:06 /user/yarn
      

picture.image

  1. 切换到admin用户,再次执行刚才的MapReduce任务

picture.image

picture.image

picture.image

Hive验证

  1. 使用beeline连接hive进行测试

使用admin用户进行hive连接、以及建表和插入数据和查询等操作都可以正常完成。


          
beeline
          
!connect jdbc:hive2://localhost:10000/;principal=hive/wangxf.vpc.cloudera.com@VPC.CLOUDERA.COM
          
show databases;
          
use default
          
create table t1 (s1 string,s2 string)
          
insert into t1 values('1','2')
          
select * from t1
      

picture.image

picture.image

picture.image

picture.image

picture.image

Hue验证

使用admin用户在hue中执行hive和访问hdfs

picture.image

使用admin用户往/user目录上传文件失败,用户没有权限。

使用admin用户往/user/admin目录上传文件成功。

picture.image

05

常见问题

hue 的Kerberos Ticket Renewer角色报错,查看角色详细日志:

picture.image

执行klist -f -c /var/run/hue/hue_krb5_ccache

picture.image

解决方案:

在/etc/krb5.conf中增加:


          
  ticket_lifetime = 24h
          
  renew_lifetime = 7d
          
  forwardable = true
      

然后重启hue服务即可。

picture.image

06

参考资料

  1. https://docs.cloudera.com/documentation/enterprise/6/latest/topics/cm\_sg\_intro\_kerb.html#xd\_583c10bfdbd326ba--6eed2fb8-14349d04bee--76dd

  2. HUE+kerberos启动报错Couldn't renew kerberos ticket解决方案:https://blog.csdn.net/vah101/article/details/79111585

0
0
0
0
关于作者
关于作者

文章

0

获赞

0

收藏

0

相关资源
火山引擎音视频体验白皮书
火山引擎联合AMD发布了音视频体验白皮书,以抖音亿级日活用户实践和大规模场景落地经验,详细解读音视频体验评估指标和模型,分享火山引擎音视频实验室的评测方案和抖音在音视频体验优化上的典型策略、案例,助力企业优化用户体验,促进业务增长。
相关产品
评论
未登录
看完啦,登录分享一下感受吧~
暂无评论