分布式存储系统之Ceph集群CephX认证和授权

  前文我们了解了Ceph集群存储池操作相关话题,回顾请参考//www.cnblogs.com/qiuhom-1874/p/16743611.html;今天我们来聊一聊在ceph上认证和授权的相关话题;

  我们知道ceph作为一个分布式存储系统,用户想要在其上面存储数据,首先得通过认证以后,才能正常使用ceph;那么对于ceph来讲,它是怎么认证用户的呢?除了认证,我们知道不是所有用户都能在ceph上创建存储池,删除存储池等;这也意味着每个用户都有一定的权限,在自己的权限范围内操作,ceph才算得上是一个安全的存储系统;那么ceph的认证和授权到底是怎么做的呢?

  CephX认证机制

  Ceph使用cephx协议对客户端进行身份认证,其过程大致是这样的;每个mon都可以对客户端进行身份验证并分发密钥;这意味着认证靠mon节点完成,不会存在单点和性能瓶颈;mon会返回用于身份验证的数据结构,其中包含获取Ceph服务时用到的session key;所谓session key就是客户端用来向mon请求所需服务的凭证;session key是通过客户端的密钥进行加密传输;当mon收到客户端认证请求后,首先生成session key,然后用客户端的密钥加密session key,然后发送给客户端,客户端用自己的密钥将其解密,拿到session key;客户端有了session key以后,它就可以用这个session key向mon请求服务,mon收到客户端的请求(携带session key),此时mon会向客户端提供一个ticket(入场卷,票据)然后用session key加密后发送给客户端;随后客户端用session key解密,拿着这个凭证到对应osd完成认证;

  以上过程,我们需要注意,客户端的密钥是通过mon节点在创建用户帐号时就会生成,所以mon节点有对应客户端的密钥,所以通过客户端的密钥加密,客户端可以用自己的密钥解密;其次mon节点生成的session key 是有记录的,所以对于不同客户端来说,都有不同的记录;并且该session key是有时间限制的;过期即便是对应客户端,也没法正常使用;所以客户端拿着对应session key向mon请求服务,对应mon都是认可的,所以mon会发放ticket;最后我们要知道,MON和OSD都是共享客户端的密钥和session key,以及mon发放的ticket,所以客户端拿着mon发放的ticket,对应osd是认可的;这也意味着不管是那个mon节点发放的ticket,对应所有mon节点和osd都是知道的;简单讲就是集群组件之间共享同一个secret;

  CephX身份验证MDS和OSD

  提示:简要过程是客户端请求创建用户,mon创建用户并返回与共享密钥给客户端;客户端向mon发起认证,认证成功,mon会返回一个session key;在规定时效范围内,客户端拿着session key向mon请求ticket,mon生成ticket并用对应session加密,客户端收到对应mon返回的数据用session key解密,拿到ticket;随后客户端拿着对应当ticket去mds或者osd进行数据存取操作,对应组件会被认证通过,因为mon和mds、osd之间都是共享secret;

  这里需要注意,CephX身份验正功能仅限制Ceph的各组件之间,它不能扩展到其它非Ceph组件;其次它并不解决数据传输加密的问题;什么意思呢?我们知道ceph的客户端接口有rbd、cephfs和radosgw;对于ceph来讲,它并不关心什么样的客户端通过rbd、cephfs、radosgw接口量访问数据;它只关心rbd、cephfs、radosgw这些客户端接口程序能够正常认证通过;简单讲就是数据最后“一公里”它不负责,至于用rbd、cephfs、radosgw这些接口的客户端是谁,怎么传输数据它管不着;

  认证与授权相关术语

  无论Ceph客户端是何类型,Ceph都会在存储池中将所有数据存储为对象;Ceph用户需要拥有存储池访问权限才能读取和写入数据;Ceph用户必须拥有执行权限才能使用Ceph的管理命令;

  用户:所谓用户是指个人或系统参与者(例如应用);通过创建用户,可以控制谁(或哪个参与者)能够访问Ceph存储集群、以及可访问的存储池及存储池中的数据;Ceph支持多种类型的用户,但可管理的用户都属于Client类型;区分用户类型的原因在于,MON、OSD和MDS等系统组件也使用cephx协议,但它们非人为客户端;通过点号来分隔用户类型和用户名,格式为TYPE.ID,例如client.admin等

  授权和使能:Ceph基于“使能(caps)”来描述用户可针对MON、OSD或MDS使用的权限范围或级别;通用语法格式:daemon-type ‘allow caps’ […];MON使能,包括r、w、x和allow profile cap,例如:mon ‘allow rwx’,以及mon ‘allow profile osd’等;OSD使能包括r、w、x、class-read、class-write和profile osd;此外,OSD 使能还允许进行存储池和名称空间设置;MDS使能只需要allow,或留空;

  使能的意义

  allow:需先于守护进程的访问设置指定,仅对MDS表示rw之意,其它的表示字面意义;

  r:读取权限,访问MON以检索CRUSH时依赖此使能;

  w:对象写入权限;
  x:调用类方法(读取和写入)的能力,以及在MON上执行auth操作的能力;
  class-read:x能力的子集,授予用户调用类读取方法的能力;
  class-write:x的子集,授予用户调用类写入方法的能力;
  *:授予用户对特定守护进程/存储池的读取、写入和执行权限,以及执行管理命令的能力;

  profile osd:授予用户以某个OSD身份连接到其他OSD或监视器的权限,授予OSD权限,使OSD能够处理复制检测信号流量和状态报告;

  profile mds: 授予用户以某个MDS身份连接到其他MDS或监视器的权限;

  profile bootstrap-osd: 授予用户引导OSD的权限,授权给部署工具,使其在引导OSD时有权添加密钥;

  profile bootstrap-mds:授予用户引导元数据服务器的权限,授权给部署工具,使其在引导元数据服务器时有权添加密钥;

  Ceph用户管理

  Ceph集群管理员能够直接在Ceph集群中创建、更新和删除用户;创建用户时,可能需要将密钥分发到客户端,以便将密钥添加到密钥环;所谓密钥环,我们就可以理解为存放密钥的一个文件,该文件可以同时存放一个或多个用户的密钥信息;有点类似我们生活中的钥匙环,我们可以在上面挂一个或多个钥匙;

  列出用户命令:ceph auth list

[root@ceph-admin ~]# ceph auth list
installed auth entries:

mds.ceph-mon02
        key: AQDT1y9jaMUZDRAA79b3XSXqBbXUlNsT0RLeiw==
        caps: [mds] allow
        caps: [mon] allow profile mds
        caps: [osd] allow rwx
osd.0
        key: AQD3+i1j5IJQCxAAOjQdvckg8TskXu7c4MbPAA==
        caps: [mgr] allow profile osd
        caps: [mon] allow profile osd
        caps: [osd] allow *
osd.1
        key: AQAo7C1j+dEDEBAAAA47bD+nZQZuV4kJjnqACA==
        caps: [mgr] allow profile osd
        caps: [mon] allow profile osd
        caps: [osd] allow *
osd.2
        key: AQA77C1j5ot+DhAAJ+Y1KwgI2zsxRHmTUkfing==
        caps: [mgr] allow profile osd
        caps: [mon] allow profile osd
        caps: [osd] allow *
osd.3
        key: AQBM7C1jdIuHEhAAYBA9gzC4J+kZUxkMzhjq4g==
        caps: [mgr] allow profile osd
        caps: [mon] allow profile osd
        caps: [osd] allow *
osd.4
        key: AQBq7C1jZrNZKhAAK+TvnPgK0jAWIwz0PYFT/g==
        caps: [mgr] allow profile osd
        caps: [mon] allow profile osd
        caps: [osd] allow *
osd.5
        key: AQB57C1jVcczERAAxJ3iqvKS/2kfE4HlFQHIWQ==
        caps: [mgr] allow profile osd
        caps: [mon] allow profile osd
        caps: [osd] allow *
osd.6
        key: AQCP7C1jB80KGhAA9iXzAg+9ANWjgPb2ZdWdhw==
        caps: [mgr] allow profile osd
        caps: [mon] allow profile osd
        caps: [osd] allow *
osd.7
        key: AQCe7C1jbx4rNxAANOB3PPLxRXi/st1UYiTWqQ==
        caps: [mgr] allow profile osd
        caps: [mon] allow profile osd
        caps: [osd] allow *
osd.8
        key: AQCz7C1jUGzQIhAAj6aTVM6rNsTO3Lp08rePzg==
        caps: [mgr] allow profile osd
        caps: [mon] allow profile osd
        caps: [osd] allow *
osd.9
        key: AQDA7C1jwXTrEBAATszxwOKepUHzZ5WKwIMu7w==
        caps: [mgr] allow profile osd
        caps: [mon] allow profile osd
        caps: [osd] allow *
client.admin
        key: AQB94C1jTO8jJhAAY4Zhy40wduyIONnRqxtkEA==
        caps: [mds] allow *
        caps: [mgr] allow *
        caps: [mon] allow *
        caps: [osd] allow *
client.bootstrap-mds
        key: AQB94C1jRPwjJhAAZsfgne6whasyCmSCgefocw==
        caps: [mon] allow profile bootstrap-mds
client.bootstrap-mgr
        key: AQB94C1jvQQkJhAA9y2LmEvBTG0Mjew8k0ecdw==
        caps: [mon] allow profile bootstrap-mgr
client.bootstrap-osd
        key: AQB94C1jDg4kJhAAhQPCebi6JfF9HZo4q39WGA==
        caps: [mon] allow profile bootstrap-osd
client.bootstrap-rbd
        key: AQB94C1jkxYkJhAAEUjId8hdDCA67PX+SQXAYw==
        caps: [mon] allow profile bootstrap-rbd
client.bootstrap-rgw
        key: AQB94C1jPx4kJhAAXIwArGEkQ76tQG1NnJ0Wmw==
        caps: [mon] allow profile bootstrap-rgw
client.rgw.ceph-mon01
        key: AQD0zS9jI7e4BRAA7fvC/02D6j2YoGHZwveQCQ==
        caps: [mon] allow rw
        caps: [osd] allow rwx
mgr.ceph-mgr01
        key: AQDi5S1jgpYLHRAAWHJeiwwD86AVg0YzUOPCmQ==
        caps: [mds] allow *
        caps: [mon] allow profile mgr
        caps: [osd] allow *
mgr.ceph-mgr02
        key: AQDk5S1jY6tkBhAAXPIK4N+bia3W6IoqlJRehw==
        caps: [mds] allow *
        caps: [mon] allow profile mgr
        caps: [osd] allow *
mgr.ceph-mon01
        key: AQDD9C1ja0vhOBAAnUkp5RcLBkZl8qfb4qXXLw==
        caps: [mds] allow *
        caps: [mon] allow profile mgr
        caps: [osd] allow *
[root@ceph-admin ~]# 

  提示:该命令是列出集群上所有用户信息,即非人为用户和普通用户;也可以是ceph auth ls命令来列出所有用户信息;

  检索特定用户命令格式:ceph auth get TYPE.ID或者ceph auth export TYPE.ID

[root@ceph-admin ~]# ceph auth get client.admin
exported keyring for client.admin
[client.admin]
        key = AQB94C1jTO8jJhAAY4Zhy40wduyIONnRqxtkEA==
        caps mds = "allow *"
        caps mgr = "allow *"
        caps mon = "allow *"
        caps osd = "allow *"
[root@ceph-admin ~]# ceph auth export client.admin
export auth(auid = 18446744073709551615 key=AQB94C1jTO8jJhAAY4Zhy40wduyIONnRqxtkEA== with 4 caps)
[client.admin]
        key = AQB94C1jTO8jJhAAY4Zhy40wduyIONnRqxtkEA==
        caps mds = "allow *"
        caps mgr = "allow *"
        caps mon = "allow *"
        caps osd = "allow *"
[root@ceph-admin ~]# 

  提示:如果我们需要将上述信息导出到文件,可以使用-o来指定文件,或者输出重定向到方式;

[root@ceph-admin ~]# ceph auth get client.admin -o client.admin.keyring
exported keyring for client.admin
[root@ceph-admin ~]# ls
ceph-deploy-ceph.log  client.admin.keyring
[root@ceph-admin ~]# cat client.admin.keyring
[client.admin]
        key = AQB94C1jTO8jJhAAY4Zhy40wduyIONnRqxtkEA==
        caps mds = "allow *"
        caps mgr = "allow *"
        caps mon = "allow *"
        caps osd = "allow *"
[root@ceph-admin ~]# ceph auth export client.admin > client.admin.cluster.keyring
export auth(auid = 18446744073709551615 key=AQB94C1jTO8jJhAAY4Zhy40wduyIONnRqxtkEA== with 4 caps)
[root@ceph-admin ~]# ls
ceph-deploy-ceph.log  client.admin.cluster.keyring  client.admin.keyring
[root@ceph-admin ~]# cat client.admin.cluster.keyring
[client.admin]
        key = AQB94C1jTO8jJhAAY4Zhy40wduyIONnRqxtkEA==
        caps mds = "allow *"
        caps mgr = "allow *"
        caps mon = "allow *"
        caps osd = "allow *"
[root@ceph-admin ~]# 

  添加用户命令格式:auth add <entity> {<caps> [<caps>…]}

[root@ceph-admin ~]# ceph auth add client.testuser mon 'allow r' osd 'allow rw'
added key for client.testuser
[root@ceph-admin ~]# ceph auth get client.testuser
exported keyring for client.testuser
[client.testuser]
        key = AQAoaThjCJLsBhAA8gwl/UQkjjSF+DwB6oB/wg==
        caps mon = "allow r"
        caps osd = "allow rw"
[root@ceph-admin ~]# 

  提示:ceph add 是添加用户的规范方法,它能够创建用户、生成密钥并添加指定的caps;这里需要注意我指定的用户是有type.id组成,一般普通用户都是client类型,后面的ID就是用户名称;

  ceph auth get-or-create:简便方法,创建用户并返回密钥文件格式的密钥信息,或者在用户存在时返回用户名及密钥文件格式的密钥信息;

[root@ceph-admin ~]# ceph auth get-or-create client.testuser mon 'allow *' osd 'allow rw pool=rbdpool'
Error EINVAL: key for client.testuser exists but cap mon does not match
[root@ceph-admin ~]# ceph auth get-or-create client.testuser mon 'allow r' osd 'allow rw'       [client.testuser]
        key = AQAoaThjCJLsBhAA8gwl/UQkjjSF+DwB6oB/wg==
[root@ceph-admin ~]# ceph auth get-or-create client.tom mon 'allow *' osd 'allow rw pool=rbdpool'
[client.tom]
        key = AQBcajhj8INfChAAKKFCESxmbHFJqAwiRE4ufg==
[root@ceph-admin ~]#  ceph auth get client.tom
exported keyring for client.tom
[client.tom]
        key = AQBcajhj8INfChAAKKFCESxmbHFJqAwiRE4ufg==
        caps mon = "allow *"
        caps osd = "allow rw pool=rbdpool"
[root@ceph-admin ~]#

  提示:使用ceph auth get-or-create命令添加用户,如果用户存在,但授权不匹配,它会提示我们用户存在,但是权限不匹配;如果用户存在,权限信息也都匹配,则返回对应用户的key;如果用户不存在,则创建对应用并返回用户的key;

  ceph auth get-or-create-key:简便方法,创建用户并返回密钥信息,或者在用户存在时返回密钥信息;

[root@ceph-admin ~]# ceph auth get-or-create-key client.testuser mon 'allow r' osd 'allow *' 
Error EINVAL: key for client.testuser exists but cap osd does not match
[root@ceph-admin ~]# ceph auth get-or-create-key client.testuser mon 'allow r' osd 'allow rw'
AQAoaThjCJLsBhAA8gwl/UQkjjSF+DwB6oB/wg==
[root@ceph-admin ~]# ceph auth get-or-create-key client.jerry mon 'allow r' osd 'allow rw'        
AQDDazhjLbMTIhAADsXyBkPS079vU7dqGs2E+A==
[root@ceph-admin ~]# ceph auth get client.jerry
exported keyring for client.jerry
[client.jerry]
        key = AQDDazhjLbMTIhAADsXyBkPS079vU7dqGs2E+A==
        caps mon = "allow r"
        caps osd = "allow rw"
[root@ceph-admin ~]# 

  提示:该命令和上面的get-or-create类似,都是用户存在,如果权限匹配则返回对应用户的key,如果不匹配则告诉我们用户存在,但权限不匹配;如果不存在则创建,并返回对应用户的key;不同的是返回key的格式不同;get-or-create是返回keyring文件中的格式;而get-or-create-key则返回key的值,没有key = ;

  注意:典型的用户至少对 Ceph monitor 具有读取功能,并对 Ceph OSD 具有读取和写入功能;另外,用户的 OSD 权限通常应该限制为只能访问特定的存储池,否则,他将具有访问集群中所有存储池的权限;

  列出用户的密钥格式 命令:ceph auth print-key TYPE.ID

[root@ceph-admin ~]# ceph auth print-key client.jerry
AQDDazhjLbMTIhAADsXyBkPS079vU7dqGs2E+A==[root@ceph-admin ~]# 

  导入用户命令:ceph auth import

[root@ceph-admin ~]# ll
total 16
-rw-r--r-- 1 root root 1568 Sep 25 11:40 ceph-deploy-ceph.log
-rw-r--r-- 1 root root  151 Oct  2 00:14 client.admin.cluster.keyring
-rw-r--r-- 1 root root  151 Oct  2 00:14 client.admin.keyring
-rw-r--r-- 1 root root  164 Oct  2 00:43 client.test.keyring
[root@ceph-admin ~]# cat client.test.keyring 
[client.test]
        key = AQB94C1jTO8jJhAAY4Zhy40wduyIONnRqxtkEA==
        caps mds = "allow *"
        caps mgr = "allow *"
        caps mon = "allow r"
        caps osd = "allow rw pool=rbdpool"
[root@ceph-admin ~]# ceph auth get client.test
Error ENOENT: failed to find client.test in keyring
[root@ceph-admin ~]# ceph auth import -i client.test.keyring
imported keyring
[root@ceph-admin ~]# ceph auth get client.test              
exported keyring for client.test
[client.test]
        key = AQB94C1jTO8jJhAAY4Zhy40wduyIONnRqxtkEA==
        caps mds = "allow *"
        caps mgr = "allow *"
        caps mon = "allow r"
        caps osd = "allow rw pool=rbdpool"
[root@ceph-admin ~]# 

  提示:从keyring文件导入用户需要用到-i选项来指定对应导入的keyring文件;

  修改用户caps命令:ceph auth caps TYPE.ID daemon ‘allow [r|w|x|*|…] [pool=pool-name] [namespace=namespace-name]’ …

[root@ceph-admin ~]# ceph auth get client.test
exported keyring for client.test
[client.test]
        key = AQB94C1jTO8jJhAAY4Zhy40wduyIONnRqxtkEA==
        caps mds = "allow *"
        caps mgr = "allow *"
        caps mon = "allow r"
        caps osd = "allow rw pool=rbdpool"
[root@ceph-admin ~]# ceph auth caps client.test mds 'allow rw' mgr 'allow r' mon 'allow rw'   
updated caps for client.test
[root@ceph-admin ~]# ceph auth get client.test
exported keyring for client.test
[client.test]
        key = AQB94C1jTO8jJhAAY4Zhy40wduyIONnRqxtkEA==
        caps mds = "allow rw"
        caps mgr = "allow r"
        caps mon = "allow rw"
[root@ceph-admin ~]# ceph auth caps client.test mds 'allow rw' mgr 'allow r' mon 'allow rw' osd 'allow rw pool=rbdpool'
updated caps for client.test
[root@ceph-admin ~]# ceph auth get client.test
exported keyring for client.test
[client.test]
        key = AQB94C1jTO8jJhAAY4Zhy40wduyIONnRqxtkEA==
        caps mds = "allow rw"
        caps mgr = "allow r"
        caps mon = "allow rw"
        caps osd = "allow rw pool=rbdpool"
[root@ceph-admin ~]# 

  提示:该命令会覆盖用户现有权限因此建立事先使用ceph auth get TYPE.ID命令查看用户的caps;若是为添加caps,则需要先指定现有的caps;若为删除某些权限,则对应权限不指定即可;

  删除用户命令:ceph auth del TYPE.ID

[root@ceph-admin ~]# ceph auth del client.test
updated
[root@ceph-admin ~]# ceph auth del client.tom
updated
[root@ceph-admin ~]# ceph auth del client.jerry
updated
[root@ceph-admin ~]# ceph auth del client.testuser
updated
[root@ceph-admin ~]# ceph auth get client.testuser
Error ENOENT: failed to find client.testuser in keyring
[root@ceph-admin ~]# 

  Keyring

  客户端访问Ceph集群时,客户端会于本地查找密钥环, 默认情况下,Ceph会使用以下四个密钥环名称预设密钥环;

  • /etc/ceph/cluster-name.user-name.keyring:保存单个用户的keyring
  • /etc/ceph/cluster.keyring:保存多个用户的keyring
  • /etc/ceph/keyring
  • /etc/ceph/keyring.bin

  cluster-name是为集群名称,user-name是为用户标识(TYPE.ID), client.admin用户的在名为ceph的集群上的密钥环文件名为ceph.client.admin.keyring;

  管理keyring

  创建keyring命令:ceph-authtool –create-keyring /path/to/kerying

[root@ceph-admin ~]# ceph-authtool --create-keyring ./client.abc.keyring
creating ./client.abc.keyring
[root@ceph-admin ~]# cat ./client.abc.keyring
[root@ceph-admin ~]# 

  提示:创建keyring文件,里面没有任何内容,我们需要用ceph auth add 添加用户,然后通过ceph auth get或export命令将对应用户信息导入到对应keyring文件即可;这里说一下keyring文件的命名规则,keyring文件一般应该保存于/etc/ceph目录中,以便客户端能自动查找;创建包含多个用户的keyring文件时,应该使用cluster-name.keyring作为文件名;创建仅包含单个用户的kerying文件时,应该使用cluster-name.user-name.keyring作为文件名;这个是规范的keyring命名方式;

  将用户的keyring合并至一个统一的keyring文件中命令:ceph-authtool /etc/ceph/cluster-name.keyring –import-key /etc/ceph/cluster-name.user-name.keyring

[root@ceph-admin ~]# ll
total 16
-rw-r--r-- 1 root root 1568 Sep 25 11:40 ceph-deploy-ceph.log
-rw------- 1 root root    0 Oct  2 00:57 client.abc.keyring
-rw-r--r-- 1 root root  151 Oct  2 00:14 client.admin.cluster.keyring
-rw-r--r-- 1 root root  151 Oct  2 00:14 client.admin.keyring
-rw-r--r-- 1 root root  164 Oct  2 00:43 client.test.keyring
[root@ceph-admin ~]# cat client.test.keyring                                    
[client.test]
        key = AQB94C1jTO8jJhAAY4Zhy40wduyIONnRqxtkEA==
        caps mds = "allow *"
        caps mgr = "allow *"
        caps mon = "allow r"
        caps osd = "allow rw pool=rbdpool"
[root@ceph-admin ~]# ceph-authtool ./client.test.keyring --import-keyring ./client.admin.keyring  
importing contents of ./client.admin.keyring into ./client.test.keyring
[root@ceph-admin ~]# cat client.test.keyring   
[client.admin]
        key = AQB94C1jTO8jJhAAY4Zhy40wduyIONnRqxtkEA==
        caps mds = "allow *"
        caps mgr = "allow *"
        caps mon = "allow *"
        caps osd = "allow *"
[client.test]
        key = AQB94C1jTO8jJhAAY4Zhy40wduyIONnRqxtkEA==
        caps mds = "allow *"
        caps mgr = "allow *"
        caps mon = "allow r"
        caps osd = "allow rw pool=rbdpool"
[root@ceph-admin ~]# 

  使用ceph-authtool命令管理用户

  ceph-authtool命令可直接创建用户、授予caps并创建keyring

  命令使用帮助

[root@ceph-admin ~]# ceph-authtool -h
usage: ceph-authtool keyringfile [OPTIONS]...
where the options are:
  -l, --list                    will list all keys and capabilities present in
                                the keyring
  -p, --print-key               will print an encoded key for the specified
                                entityname. This is suitable for the
                                'mount -o secret=..' argument
  -C, --create-keyring          will create a new keyring, overwriting any
                                existing keyringfile
  -g, --gen-key                 will generate a new secret key for the
                                specified entityname
  --gen-print-key               will generate a new secret key without set it
                                to the keyringfile, prints the secret to stdout
  --import-keyring FILE         will import the content of a given keyring
                                into the keyringfile
  -n NAME, --name NAME          specify entityname to operate on
  -u AUID, --set-uid AUID       sets the auid (authenticated user id) for the
                                specified entityname
  -a BASE64, --add-key BASE64   will add an encoded key to the keyring
  --cap SUBSYSTEM CAPABILITY    will set the capability for given subsystem
  --caps CAPSFILE               will set all of capabilities associated with a
                                given key, for all subsystems
  --mode MODE                   will set the desired file mode to the keyring
                                e.g: '0644', defaults to '0600'
[root@ceph-admin ~]# 

  提示:-l或–list表示列出所有用户信息;-p表示打印对应用户的key信息,-C表示keyring文件,-g表示给指定用户生成key;-n用于指定用户名称;–cap 用于指定权限信息;–mode用于指定keyring文件的权限信息,默认是0600,即只有root或对应宿主拥有读写权限;

[root@ceph-admin ~]# ceph-authtool -C client.usera.keyring  -n client.usera --gen-key --cap mon 'allow r' --cap osd 'allow rw pool=rbdpool'
creating client.usera.keyring
[root@ceph-admin ~]# ll
total 20
-rw-r--r-- 1 root root 1568 Sep 25 11:40 ceph-deploy-ceph.log
-rw------- 1 root root    0 Oct  2 00:57 client.abc.keyring
-rw-r--r-- 1 root root  151 Oct  2 00:14 client.admin.cluster.keyring
-rw-r--r-- 1 root root  151 Oct  2 00:14 client.admin.keyring
-rw-r--r-- 1 root root  315 Oct  2 01:03 client.test.keyring
-rw------- 1 root root  121 Oct  2 01:25 client.usera.keyring
[root@ceph-admin ~]# ceph auth get client.usera
Error ENOENT: failed to find client.usera in keyring
[root@ceph-admin ~]# cat client.usera.keyring 
[client.usera]
        key = AQAIeDhjTnmLGhAAWgL3GqtJsPwmOD6CPbJO8Q==
        caps mon = "allow r"
        caps osd = "allow rw pool=rbdpool"
[root@ceph-admin ~]# 

  提示:使用这种方式添加用户,对应信息之存在于keyring文件中,并没有存在ceph集群,我们还需要将对应keyring文件中的用户信息导入到集群上;

[root@ceph-admin ~]# ceph auth add client.usera -i client.usera.keyring 
added key for client.usera
[root@ceph-admin ~]# ceph auth get client.usera
exported keyring for client.usera
[client.usera]
        key = AQAIeDhjTnmLGhAAWgL3GqtJsPwmOD6CPbJO8Q==
        caps mon = "allow r"
        caps osd = "allow rw pool=rbdpool"
[root@ceph-admin ~]# 

  提示:上述命令等同ceph auth import;