ceph (luminous 版) 用户管理

时间:2023-01-13 12:36:11

说明

对 ceph luminous 版 ceph-12.2.0-0 版本进行用户管理

权限

当前环境中, 只使用到 RBD 服务, 因此只需要管理 mon, osd 两者的权限属性则可
mon 需要由 mgr 进程提供, 提供了 ceph 集群状态监控功能
osd 对 pools 中的文提供增删改的功能

用户创建

用户名格式: client.username

ceph auth add

当用户不存在, 则创建用户并授权
当用户存在, 当权限不变, 则不进行任何输出
当用户存在, 不支持修改权限

[root@hh-ceph-128040 ceph]# ceph auth add client.terry mon 'allow r' osd 'allow rw pool=volumes'
added key for client.terry

ceph auth get-or-create

当用户不训在, 则创建用户并授权并输出当前 key
当用户存在, 权限不变, 则输出当前 key
当用户存在, 权限修改, 则返回报错

[root@hh-ceph-128040 ceph]# ceph auth get-or-create client.terry mon 'allow r' osd 'allow rw pool=volumes'
[client.terry]
key = AQChnBNaLX4ODxAAU6pISxf94adRvUe2zGJ6Jw==

ceph auth caps

当用户不存在, 则返回错误信息

[root@hh-ceph-128040 ceph]# ceph auth caps client.terry mon 'allow r' osd 'allow rw pool=volumes'
Error ENOENT: couldn't find entry client.terry

当用户存在, 则覆盖当前用户的所有属性

[root@hh-ceph-128040 ceph]# ceph auth add client.terry mon 'allow r' osd 'allow rwx pool=volumes'
added key for client.terry
[root@hh-ceph-128040 ceph]# ceph auth caps client.terry mon 'allow r' osd 'allow rwx pool=rbd'
updated caps for client.terry

假如需要新增用户属性, 则需要保留原有属性基础上新增新的属性
参考下面新增对池 rbd 操作的属性

[root@hh-ceph-128040 ceph]# ceph auth caps client.terry mon 'allow r' osd 'allow rwx pool=volumes, allow rwx pool=rbd'
updated caps for client.terry

用户删除

参考下面命令操作

[root@hh-ceph-128040 ceph]# ceph auth del client.terry
updated

查看密钥

[root@hh-ceph-128040 ceph]# ceph auth print-key client.terry
AQDQnhNanVGGHBAAwv9xmu7WApiOG5S1fcUd3Q==

导出用户 keyring

[root@hh-ceph-128040 ceph]# ceph auth get client.terry
exported keyring for client.terry
[client.terry]
key = AQDQnhNanVGGHBAAwv9xmu7WApiOG5S1fcUd3Q==
caps mon = "allow r"
caps osd = "allow rw pool=volumes, allow rw pool=rbd"

导出用户 keyrings 到文件

[root@hh-ceph-128040 ceph]# ceph auth get client.terry -o /etc/ceph/ceph.client.terry.keyring
exported keyring for client.terry

[root@hh-ceph-128040 ceph]# cat /etc/ceph/ceph.client.terry.keyring
[client.terry]
key = AQDQnhNanVGGHBAAwv9xmu7WApiOG5S1fcUd3Q==
caps mon = "allow r"
caps osd = "allow rw pool=volumes, allow rw pool=rbd"

查询所有授权

ceph auth list

keyrings 文件说明

在 ceph 中, mon, osd, user, mgr 等用户与进程在使用时候, 都会需要使用到 keyrings 用户权限校验

mon keyring

在 ceph 配置中, 常见的 mon keyrings 会存放到 /etc/ceph/ceph.mon.keyring 中

[root@hh-ceph-128040 ceph]# ls /etc/ceph/ceph.mon.keyring
/etc/ceph/ceph.mon.keyring
[root@hh-ceph-128040 ceph]# cat /etc/ceph/ceph.mon.keyring
[mon.]
key = AQD3ug5a3jQiGRAAUfiSG6LKPmubrW5a7E79dg==
caps mon = "allow *"
[client.admin]
key = AQA3uw5ap6cxOxAAFzfyucOfOjmp7nwu6c+/UA==
auid = 0
caps mds = "allow"
caps mon = "allow *"
caps osd = "allow *"

admin keyring

作为 ceph 中管理员

[root@hh-ceph-128040 ceph]# cat /etc/ceph/ceph.client.admin.keyring
[client.admin]
key = AQA3uw5ap6cxOxAAFzfyucOfOjmp7nwu6c+/UA==
auid = 0
caps mds = "allow"
caps mon = "allow *"
caps osd = "allow *"

用户 keyring

ceph 在校验用户 keyring 时候, 会读取下面几个文件, 是否存在着用户合法授权 keyring

    /etc/ceph/$cluster.$name.keyring
/etc/ceph/$cluster.client.$name.keyring
/etc/ceph/$cluster.keyring
/etc/ceph/keyring
/etc/ceph/keyring.bin

用户操作

参考命令, 如何指定用户与对应 keyring 方法

[root@hh-ceph-128040 ceph]# ceph --user terry -s
cluster:
id: c45b752d-5d4d-4d3a-a3b2-04e73eff4ccd
health: HEALTH_OK

services:
mon: 3 daemons, quorum hh-ceph-128040,hh-ceph-128214,hh-ceph-128215
mgr: openstack(active)
osd: 36 osds: 36 up, 36 in

data:
pools: 1 pools, 2048 pgs
objects: 383 objects, 1496 MB
usage: 8476 MB used, 196 TB / 196 TB avail
pgs: 2048 active+clean

权限说明

mon 权限

允许使用 ceph -s 进行监控

mon 'allow r' 

osd 权限

允许使用
rbd –user usernamme -p volumes ls
rbd –user username -p volumes export xxx xxxx
切记需要添加 x 权限, 否则显示权限拒绝
luminous 版本可以直接使用 class-read 包含下面属性

osd 'allow rx pool=volumes'

允许使用
rbd –user username -p volumes import xxx xxxx
切记需要添加 x 权限, 否则显示权限拒绝
luminous 版本可以直接使用 class-write 包含下面属性

osd 'allow wx pool=volumes'

因此允许用户能够对池授权上传, 下载, 则需要授权

osd 'allow rwx pool=volumes'

mgr 权限

luminous 版本新特性
只有 mgr 正常工作, 那么监控信息才能够完整, 才可以对 pg, osd 等执行操作

举例说明
当前 admin 用户(理论上是整个 ceph 集群中的管理员) 没有授权 mgr 权限

[root@hh-ceph-128040 ~]# ceph auth get client.admin
exported keyring for client.admin
[client.admin]
key = AQA3uw5ap6cxOxAAFzfyucOfOjmp7nwu6c+/UA==
auid = 0
caps mds = "allow"
caps mon = "allow *"
caps osd = "allow *"

下面命令会出错, 原因, 没有授权

[root@hh-ceph-128040 ~]# ceph --user admin health
HEALTH_OK
[root@hh-ceph-128040 ~]# ceph --user admin pg dump
Error EACCES: access denied' does your client key have mgr caps?

根据提示可以看见, admin 也需要有 mgr caps 授权
解决方法

[root@hh-ceph-128040 ~]# ceph auth caps client.admin osd 'allow *' mds 'allow ' mon 'allow *' mgr 'allow *'
updated caps for client.admin
[root@hh-ceph-128040 ~]# ceph auth get client.admin
exported keyring for client.admin
[client.admin]
key = AQA3uw5ap6cxOxAAFzfyucOfOjmp7nwu6c+/UA==
auid = 0
caps mds = "allow "
caps mgr = "allow *"
caps mon = "allow *"
caps osd = "allow *"

验证, 已经解决了授权问题

[root@hh-ceph-128040 ~]# ceph --user admin pg dump | head -n 6
dumped all
version 82945
stamp 2017-11-23 11:03:27.268874
last_osdmap_epoch 0
last_pg_scan 0
full_ratio 0
nearfull_ratio 0

profile {name} 用法

对于 monitor 的权限, 可以包含 rwx  ex:  mon 'rwx'
在 luminous 版本中, 新增了 profile {name} 的权限 ex: mon 'profile osd'

常见 profle 可以包含下面几种属性

    profile osd (Monitor only)
profile mds (Monitor only)
profile bootstrap-osd (Monitor only)
profile bootstrap-mds (Monitor only)
profile rbd (Monitor and OSD)
profile rbd-read-only (OSD only)

例子

[root@hh-ceph-128040 ~]# ceph auth caps client.terry profile rbd
updated caps for client.terry
[root@hh-ceph-128040 ~]# ceph auth get client.terry
exported keyring for client.terry
[client.terry]
key = AQDQnhNanVGGHBAAwv9xmu7WApiOG5S1fcUd3Q==
caps profile = "rbd"