其他分享
首页 > 其他分享> > 分布式存储Ceph(四) Cephx认证机制

分布式存储Ceph(四) Cephx认证机制

作者:互联网

五 cephx认证机制

5.1 cephx协议

5.2 授权流程

  1. 客户端向mon请求认证;
  2. mon生成session key,用key加密后发送给客户端;
  3. 客户端收到后解密key得到session key,向mon申请tikey;
  4. mon收到请求后验证session key,并向客户端发送tikey;
  5. 客户端收到tiket后,用tikey访问OSD;
  6. OSD验证tiket并返回数据。

5.3 访问流程

5.4 ceph用户

点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ cat /etc/ceph/ceph.client.admin.keyring
[client.admin]
        key = AQALKythrxA6IhAAVDlgRrH+xWLn2FYbXAFRaw==
        caps mds = "allow *"
        caps mgr = "allow *"
        caps mon = "allow *"
        caps osd = "allow *"

5.5 ceph授权和使能

5.5.1 授权基础

5.5.2 能力一览表

点击查看代码
r: 向用户授予读取权限。访问监视器(mon)以检索CRUSH运行图时需要由此能力。
w:向用户授予针对对象的写入权限。
x: 授予用户调用类方法(包括读取和写入)的能力,以及在监视器中执行auth操作的能力。
*:授予用户对特定守护进程/存储池的读取、写入和执行权限,以及执行管理命令的能力

class-read: 授予用户调用类读取方法的能力,属于是x能力的子集。
class-write: 授予用户调用类写入方法的能力,属于是x能力的子集。

profile osd: 授予用户以某个OSD身份连接到其它OSD或监视器的权限。授予OSD权限,使OSD能够处理复制检测信号流量和状态报告(获取OSD的状态信息)。
profile mds:授予用户以某个MDS身份连接到其它MDS或监视器权限。
profile bootstrap-osd:授予用户引导OSD的权限(初始化OSD并将OSD加入ceph集群),授权给部署工具,使其在引导OSD时有权添加秘钥。
profile bootstrap-mds:授予用户引导元数据服务器的权限,授权部署工具权限,使其在引导元数据服务器时有权添加秘钥。

5.5.3 MON能力

点击查看代码
#包括r/w/x和allow profile cap(caph的运行图)
例如:
mon 'allow rwx'
mon 'allow profile osd'

5.5.4 OSD能力

#包括r/w/x、clas-read、class-write和profile osd,另外OSD能力还允许进行存储池和名称空间设置。

例如:
osd 'allow capability' [pool=poolname] [namespace=namespace-name]

5.5.5 MDS能力

#只需要allow或空都表示允许

例如:
mds 'allow'

5.6 ceph用户管理

5.6.1 用户管理基础

5.6.2 ceph auth 使用帮助

点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph auth -h
 General usage:
 ==============
usage: ceph [-h] [-c CEPHCONF] [-i INPUT_FILE] [-o OUTPUT_FILE]
            [--setuser SETUSER] [--setgroup SETGROUP] [--id CLIENT_ID]
            [--name CLIENT_NAME] [--cluster CLUSTER]
            [--admin-daemon ADMIN_SOCKET] [-s] [-w] [--watch-debug]
            [--watch-info] [--watch-sec] [--watch-warn] [--watch-error]
            [-W WATCH_CHANNEL] [--version] [--verbose] [--concise]
            [-f {json,json-pretty,xml,xml-pretty,plain,yaml}]
            [--connect-timeout CLUSTER_TIMEOUT] [--block] [--period PERIOD]

Ceph administration tool

optional arguments:
-h, --help request mon help
-c CEPHCONF, --conf CEPHCONF
ceph configuration file
-i INPUT_FILE, --in-file INPUT_FILE
input file, or "-" for stdin
-o OUTPUT_FILE, --out-file OUTPUT_FILE
output file, or "-" for stdout
--setuser SETUSER set user file permission
--setgroup SETGROUP set group file permission
--id CLIENT_ID, --user CLIENT_ID
client id for authentication
--name CLIENT_NAME, -n CLIENT_NAME
client name for authentication
--cluster CLUSTER cluster name
--admin-daemon ADMIN_SOCKET
submit admin-socket commands ("help" for help)
-s, --status show cluster status
-w, --watch watch live cluster changes
--watch-debug watch debug events
--watch-info watch info events
--watch-sec watch security events
--watch-warn watch warn events
--watch-error watch error events
-W WATCH_CHANNEL, --watch-channel WATCH_CHANNEL
watch live cluster changes on a specific channel
(e.g., cluster, audit, cephadm, or '*' for all)
--version, -v display version
--verbose make verbose
--concise make less verbose
-f {json,json-pretty,xml,xml-pretty,plain,yaml}, --format {json,json-pretty,xml,xml-pretty,plain,yaml}
--connect-timeout CLUSTER_TIMEOUT
set a timeout for connecting to the cluster
--block block until completion (scrub and deep-scrub only)
--period PERIOD, -p PERIOD
polling period, default 1.0 second (for polling
commands only)

Local commands

ping <mon.id> Send simple presence/life test to a mon
<mon.id> may be 'mon.*' for all mons
daemon {type.id|path} <cmd>
Same as --admin-daemon, but auto-find admin socket
daemonperf {type.id | path} [stat-pats] [priority] [<interval>] [<count>]
daemonperf {type.id | path} list|ls [stat-pats] [priority]
Get selected perf stats from daemon/admin socket
Optional shell-glob comma-delim match string stat-pats
Optional selection priority (can abbreviate name):
critical, interesting, useful, noninteresting, debug
List shows a table of all available stats
Run <count> times (default forever),
once per <interval> seconds (default 1)

Monitor commands:

auth add <entity> [<caps>...] add auth info for <entity> from input file,
or random key if no input is given, and/or
any caps specified in the command
auth caps <entity> <caps>... update caps for <name> from caps specified
in the command
auth export [<entity>] write keyring for requested entity, or
master keyring if none given
auth get <entity> write keyring file with requested key
auth get-key <entity> display requested key
auth get-or-create <entity> [<caps>...] add auth info for <entity> from input file,
or random key if no input given, and/or any
caps specified in the command
auth get-or-create-key <entity> [<caps>...] get, or add, key for <name> from system/caps
pairs specified in the command. If key
already exists, any given caps must match
the existing caps for that key.
auth import auth import: read keyring file from -i <file>
auth ls list authentication state
auth print-key <entity> display requested key
auth print_key <entity> display requested key
auth rm <entity> remove all caps for <name>

5.6.3 用户管理

5.6.3.1 列出用户

5.6.3.1.1 列出用户
点击查看代码
# 针对用户采用TYPE.ID表示法,例如osd.0指定是osd类并且ID为0的用户(节点),client.admin是针对client类型的用户,其ID为admin。
ceph@ceph-deploy:~/ceph-cluster$ ceph auth ls
osd.0
        key: AQCGsDVhhhXOAxAAD7GOy2/7BctI1wRwHK17OA==
        caps: [mgr] allow profile osd
        caps: [mon] allow profile osd
        caps: [osd] allow *
osd.1
        key: AQAVsTVhp80wCxAA5nJA080MT3BjWtEzgjjwTQ==
        caps: [mgr] allow profile osd
        caps: [mon] allow profile osd
        caps: [osd] allow *
osd.2
        key: AQCA5DVhV53BFRAA/HbGphI7pVsUGIlliF1GYw==
        caps: [mgr] allow profile osd
        caps: [mon] allow profile osd
        caps: [osd] allow *
osd.3
        key: AQDLtDVhbgzOGhAAuxYy1eISS2jAgWNQMKp+Cg==
        caps: [mgr] allow profile osd
        caps: [mon] allow profile osd
        caps: [osd] allow *
osd.4
        key: AQArtTVh67tKIxAA9fR3RaP9tHE2LQ0dHABKqw==
        caps: [mgr] allow profile osd
        caps: [mon] allow profile osd
        caps: [osd] allow *
osd.5
        key: AQCftTVhcVw0ChAAH5oEXBvQ8VEl51tTBJ7gMQ==
        caps: [mgr] allow profile osd
        caps: [mon] allow profile osd
        caps: [osd] allow *
osd.6
        key: AQBZtjVhSeWQGRAAKEt6qSw0JhaS1cXHsH7ZzQ==
        caps: [mgr] allow profile osd
        caps: [mon] allow profile osd
        caps: [osd] allow *
osd.7
        key: AQD4tzVhpmG3JRAAWBQYh+BFXrN82qsQxlrUHw==
        caps: [mgr] allow profile osd
        caps: [mon] allow profile osd
        caps: [osd] allow *        
osd.8
        key: AQA5uDVhkEoKARAAa6Z4eEcme3yxVUN1hzBplQ==
        caps: [mgr] allow profile osd
        caps: [mon] allow profile osd
        caps: [osd] allow *
client.admin
        key: AQALKythrxA6IhAAVDlgRrH+xWLn2FYbXAFRaw==
        caps: [mds] allow *
        caps: [mgr] allow *
        caps: [mon] allow *
        caps: [osd] allow *
client.bootstrap-mds
        key: AQALKythdSI6IhAAP/QG4NkILRTELptXEMYspA==
        caps: [mon] allow profile bootstrap-mds
client.bootstrap-mgr
        key: AQALKythMS86IhAAYztFGK8yvtXvrhU1GJM2Uw==
        caps: [mon] allow profile bootstrap-mgr
client.bootstrap-osd
        key: AQALKythwDk6IhAA9kqvq3TMGiIkjsS1JWTtLg==
        caps: [mon] allow profile bootstrap-osd
client.bootstrap-rbd
        key: AQALKythB0U6IhAAS4daHonswhJtdbtuWvGk1w==
        caps: [mon] allow profile bootstrap-rbd
client.bootstrap-rbd-mirror
        key: AQALKythSlA6IhAAHuhETKA8j5l+U6kUJHpfZQ==
        caps: [mon] allow profile bootstrap-rbd-mirror
client.bootstrap-rgw
        key: AQALKythNFs6IhAA3fq6Q6KJQpxEZG0OEL2fUA==
        caps: [mon] allow profile bootstrap-rgw
mgr.ceph-mgr-01
        key: AQCCPithsDrjERAArrm5PowGLYrEUnjHlmaA/Q==
        caps: [mds] allow *
        caps: [mon] allow profile mgr
        caps: [osd] allow *
mgr.ceph-mgr-02
        key: AQBbITdh+dHoCxAAAYdKmuFK09dJ9axa0w72cA==
        caps: [mds] allow *
        caps: [mon] allow profile mgr
        caps: [osd] allow *
installed auth entries:
5.6.3.1.2  导出用户信息
ceph@ceph-deploy:~/ceph-cluster$ ceph auth ls -o auth_all.key
installed auth entries:

5.6.3.2  获取指定用户信息

点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph auth get client.admin
[client.admin]
        key = AQALKythrxA6IhAAVDlgRrH+xWLn2FYbXAFRaw==
        caps mds = "allow *"
        caps mgr = "allow *"
        caps mon = "allow *"
        caps osd = "allow *"
exported keyring for client.admin

5.6.3.3 ceph auth add

5.6.3.3.1 添加用户
ceph@ceph-deploy:~/ceph-cluster$ ceph auth add client.wgs mon 'allow r' osd 'allow rwx pool=wgspool'
added key for client.wgs
5.6.3.3.2 验证用户
点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph auth get client.wgs                                 for <entity> from input file, or random key if no input is[client.wgs]                                                                               any caps specified in the command
        key = AQCzwkZhgvOIEhAAJxUykVvuDsqPBfCWDoBG9w==                                    r <name> from caps specified in the command
        caps mon = "allow r"                                                              for requested entity, or master keyring if none given
        caps osd = "allow rwx pool=wgspool"                                               file with requested key
exported keyring for client.wgs   

5.6.3.4 ceph auth get-or-create

5.6.3.4.1 创建用户
点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph auth get-or-create client.wgs01 mon 'allow r' osd 'allow rwx pool=wgspool'
[client.wgs01]
        key = AQCixkZhajt0FBAAB9Tvd938Ntv3zAM7rNjLdw==
5.6.3.4.2 验证用户
点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph auth get client.wgs01[client.wgs01]
        key = AQCixkZhajt0FBAAB9Tvd938Ntv3zAM7rNjLdw==                                            
        caps mon = "allow r"                                                              
        caps osd = "allow rwx pool=wgspool"                                              
exported keyring for client.wgs01
5.6.3.4.3 创建已存在的用户
点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph auth get-or-create client.wgs01 mon 'allow r' osd 'allow rwx pool=wgspool'
[client.wgs01]
        key = AQCixkZhajt0FBAAB9Tvd938Ntv3zAM7rNjLdw==
5.6.3.4.4 导出用户信息
点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph auth get-or-create client.wgs01 mon 'allow r' osd 'allow rwx pool=wgspool' -o wgs.key
ceph@ceph-deploy:~/ceph-cluster$ cat wgs.key
[client.wgs01]
        key = AQCixkZhajt0FBAAB9Tvd938Ntv3zAM7rNjLdw==

5.6.3.5  ceph auth get-or-cereate-key

点击查看代码
#用户有key就显示没有就创建
ceph@ceph-deploy:~/ceph-cluster$ ceph auth get-or-create-key client.wgs01 mon 'allow r' osd 'allow rwx pool=wgspool'
AQCixkZhajt0FBAAB9Tvd938Ntv3zAM7rNjLdw==

5.6.3.6 ceph auth print-key

点击查看代码
#只获取单个指定用户key信息
ceph@ceph-deploy:~/ceph-cluster$ ceph auth print-key client.wgs01
AQCixkZhajt0FBAAB9Tvd938Ntv3zAM7rNjLdw==

5.6.3.7 ceph auth caps

5.6.3.7.1 查看用户当前权限
点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph auth get client.wgs01
[client.wgs01]
        key = AQCixkZhajt0FBAAB9Tvd938Ntv3zAM7rNjLdw==
        caps mon = "allow r"
        caps osd = "allow rwx pool=wgspool"
exported keyring for client.wgs01
5.6.3.7.2 修改用户权限
点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph auth caps client.wgs01 mon 'allow r' osd 'allow rw pool=wgspool'
updated caps for client.wgs01
5.6.3.7.3 验证权限
点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph auth get client.wgs01
[client.wgs01]
        key = AQCixkZhajt0FBAAB9Tvd938Ntv3zAM7rNjLdw==
        caps mon = "allow r"
        caps osd = "allow rw pool=wgspool"
exported keyring for client.wgs01

5.6.3.8 ceph auth del

点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph auth del client.wgs01
updated

5.7 密钥管理

5.7.1 密钥管理基础

5.7.2 创建用户密钥环文件

5.7.2.1 ceph-authtool使用帮助

点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ 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
  -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'

5.7.2.2 创建key文件

点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph-authtool --create-keyring wgs.key
creating wgs.key

5.7.2.3 验证文件

点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph-authtool -l wgs.key
-rw-rw-r-- 1 ceph ceph 0 Sep 19 15:42 wgs.key

5.7.3 导出用户认证信息至keyring文件

5.7.3.1 导出用户认证信息

点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph auth get client.wgs -o ceph.client.wgs.keyring
exported keyring for client.wgs

5.7.3.2 验证认证信息

点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph-authtool -l ceph.client.wgs.keyring
[client.wgs]        
	key = AQCzwkZhgvOIEhAAJxUykVvuDsqPBfCWDoBG9w==        
        caps mon = "allow r"
        caps osd = "allow rwx pool=wgspool"

5.7.4 从keyring文件恢复用户认证信息

5.7.4.1 验证用户认证文件

点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph-authtool -l ceph.client.wgs.keyring
[client.wgs]
        key = AQCzwkZhgvOIEhAAJxUykVvuDsqPBfCWDoBG9w==
        caps mon = "allow r"
        caps osd = "allow rwx pool=wgspool"

5.7.4.2 删除用户

点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph auth del client.wgs
updated

5.7.4.3 验证删除用户

点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph auth get client.wgs
Error ENOENT: failed to find client.wgs in keyring

5.7.4.4 导入用户

点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph auth import -i ceph.client.wgs.keyring
imported keyring

5.7.4.5 验证用户

点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph auth get client.wgs
[client.wgs]
        key = AQCzwkZhgvOIEhAAJxUykVvuDsqPBfCWDoBG9w==
        caps mon = "allow r"
        caps osd = "allow rwx pool=wgspool"
exported keyring for client.wgs

5.7.5 密钥环文件包含多用户

5.7.5.1 创建keyring文件

点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph-authtool --create-keyring ceph.client.user.keyring
creating ceph.client.user.keyring

5.7.5.2 验证创建keyring文件

点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph-authtool -l ceph.client.user.keyring

5.7.5.3 创建测试用户信息

点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph auth add client.wgs mon 'allow r' osd 'allow rwx pool=wgspool'
added key for client.wgs
ceph@ceph-deploy:~/ceph-cluster$ ceph auth add client.wgs01 mon 'allow r' osd 'allow rwx pool=wgspool'
added key for client.wgs01
ceph@ceph-deploy:~/ceph-cluster$ ceph auth add client.wgs02 mon 'allow r' osd 'allow rwx pool=wgspool'
added key for client.wgs02

5.7.5.4 导出用户信息

点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph-authtool ceph.client.user.keyring --import-keyring ceph.client.admin.keyring
importing contents of ceph.client.admin.keyring into ceph.client.user.keyring
ceph@ceph-deploy:~/ceph-cluster$ ceph-authtool ceph.client.user.keyring --import-keyring ceph.client.wgs.keyring
importing contents of ceph.client.wgs.keyring into ceph.client.user.keyring

5.7.5.5 再次验证keyring文件

点击查看代码
ceph@ceph-deploy:~/ceph-cluster$ ceph-authtool -l ceph.client.user.keyring
[client.admin]
        key = AQALKythrxA6IhAAVDlgRrH+xWLn2FYbXAFRaw==
        caps mds = "allow *"
        caps mgr = "allow *"
        caps mon = "allow *"
        caps osd = "allow *"
[client.wgs]
        key = AQCzwkZhgvOIEhAAJxUykVvuDsqPBfCWDoBG9w==
        caps mon = "allow r"
        caps osd = "allow rwx pool=wgspool"

标签:Cephx,ceph,key,caps,Ceph,client,allow,osd,分布式
来源: https://www.cnblogs.com/wangguishe/p/15311317.html