etcd常规操作

详细步骤
1.添加root用户

# etcdctl user add root
New password: 12345
User root created
复制代码
2.创建root账号后,root默认有root角色,对所有KV有读写权限

# etcdctl user get root
User: root
Roles: root


# 备份
etcdctl --endpoints=127.0.0.1:2379 snapshot save snapshot.db

# 还原
etcdctl --endpoints=127.0.0.1:2379 snapshot restore snapshot.db \
--initial-cluster-token=crp-repo \
--data-dir=/deepin/userdata/etcd_service/etcd_data


# etcdctl role get root
Role: root
KV Read:
/*
KV Write:
/*
复制代码

3.开启auth认证

# etcdctl auth enable
Authentication Enabled

开启权限认证后默认会多一个guest的角色
# etcdctl --username root:12345 role list
guest
root

复制代码
4.添加非root账号,一个authz的账号,一个readx的账号

# etcdctl --username root:12345 user add authz
New password:
User authz created

# etcdctl --username root:12345 user add readx
New password:
User readx created
复制代码
5.添加角色,一个rootConf的角色,一个readConf的角色

# etcdctl --username root:12345 role add rootConf
Role rootConf created

# etcdctl --username root:12345 role add readConf
Role readConf created
复制代码
6.为角色授权,readConf角色对/conf有只读权限,rootConf角色对/conf有读写权限

# etcdctl --username root:12345 role grant --read --path /conf/* readConf
Role readConf updated

# etcdctl --username root:12345 role grant --readwrite --path /conf/* rootConf
Role rootConf updated
复制代码
7.给用户分配角色,authz账号分配rootConf角色,readx账号分配readConf角色

# etcdctl --username root:12345 user grant --roles rootConf authz
User authz updated

# etcdctl --username root:12345 user grant --roles readConf readx
User readx updated
复制代码
8.查看用户所拥有的角色

# etcdctl --username root:12345 user get authz
User: authz
Roles: rootConf

# etcdctl --username root:12345 user get readx
User: readx
Roles: readConf
复制代码
这样readx账号就对/conf下的所有文件有了只读权限,authz对/conf下的所有文件有了读写权限

常用命令
有一些命令上边没有介绍到,会用得到的如下:

1.关闭认证

# etcdctl --username root:12345 auth disable
复制代码
2.删除用户

# etcdctl --username root:12345 user remove userx
复制代码
3.用户撤销角色

# etcdctl --username root:12345 user revoke rolex
复制代码
4.修改用户密码

# etcdctl --username root:12345 user passwd
复制代码
同时还有删除角色、撤销角色权限可参看上边用户相关操作

 

posted @ 2023-01-10 10:08  Cookie-Fei  阅读(193)  评论(0编辑  收藏  举报