当前位置:网站首页>etcd集群权限管理和账号密码使用
etcd集群权限管理和账号密码使用
2022-07-03 13:46:00 【开发运维玄德公】
文章目录
1. 操作实例
1.1 环境说明
节点 | IP |
---|---|
etcd1 | 10.10.239.31:1379 |
etcd2 | 10.10.239.31:2379 |
etcd3 | 10.10.239.31:3379 |
1.2 创建root用户
root用户自带所有权限,因此只需创建该用户,开启认证即有所有权限。
I have no name!@555187fb758c:/opt/bitnami/etcd$ etcdctl --endpoints http://10.10.239.31:1379,http://10.10.239.31:2379,http://10.10.239.31:3379 user add root
- 输出如下
Password of root:
Type password of root again for confirmation:
User root created
交互需要输入用户密码
1.3 开启身份验证
- 开启身份验证
I have no name!@555187fb758c:/opt/bitnami/etcd$ etcdctl --user='root' --password='[email protected]' --endpoints http://10.10.239.31:1379,http://10.10.239.31:2379,http://10.10.239.31:3379 auth enable
- 测试:使用用户操作
I have no name!@555187fb758c:/opt/bitnami/etcd$ etcdctl --user='root' --password='[email protected]' put name "guanyu"
OK
I have no name!@555187fb758c:/opt/bitnami/etcd$ etcdctl --user='root' --password='[email protected]' get name
name
guanyu
- 测试:不使用用户密码操作报错
I have no name!@555187fb758c:/opt/bitnami/etcd$ etcdctl get name
{
"level":"warn","ts":"2022-07-02T08:11:34.599Z","logger":"etcd-client","caller":"v3/retry_interceptor.go:62","msg":"retrying of unary invoker failed","target":"etcd-endpoints://0xc00014c000/127.0.0.1:2379","attempt":0,"error":"rpc error: code = InvalidArgument desc = etcdserver: user name is empty"}
Error: etcdserver: user name is empty
- 如果你决定对外公布root用户,那么到这里就可以了
- 如果要隐藏高权限的root用户,而公布普通用户,那继续往下操作
1.4 普通用户管理
1.4.1 创建普通用户
- 创建读用户
因为之前已经启用了密码访问,所以这里要加上用户和密码。没有启用的前当然不用加。
I have no name!@555187fb758c:/opt/bitnami/etcd$ etcdctl --user='root' --password='[email protected]' --endpoints http://10.10.239.31:1379,http://10.10.239.31:2379,http://10.10.239.31:3379 user add myRead
- 创建写用户
I have no name!@555187fb758c:/opt/bitnami/etcd$ etcdctl --user='root' --password='[email protected]' --endpoints http://10.10.239.31:1379,http://10.10.239.31:2379,http://10.10.239.31:3379 user add myWrite
- 创建读写用户
I have no name!@555187fb758c:/opt/bitnami/etcd$ etcdctl --user='root' --password='[email protected]' --endpoints http://10.10.239.31:1379,http://10.10.239.31:2379,http://10.10.239.31:3379 user list
- 查看用户
I have no name!@555187fb758c:/opt/bitnami/etcd$ etcdctl --user='root' --password='[email protected]' --endpoints http://10.10.239.31:1379,http://10.10.239.31:2379,http://10.10.239.31:3379 user add myReadWrite
输出:
myRead
myReadWrite
myWrite
root
1.4.2 创建角色
- 创建读角色
I have no name!@555187fb758c:/opt/bitnami/etcd$ etcdctl --user='root' --password='[email protected]' --endpoints http://10.10.239.31:1379,http://10.10.239.31:2379,http://10.10.239.31:3379 role add roleRead
- 创建写角色
I have no name!@555187fb758c:/opt/bitnami/etcd$ etcdctl --user='root' --password='[email protected]' --endpoints http://10.10.239.31:1379,http://10.10.239.31:2379,http://10.10.239.31:3379 role add roleWrite
- 创建读写角色
I have no name!@555187fb758c:/opt/bitnami/etcd$ etcdctl --user='root' --password='[email protected]' --endpoints http://10.10.239.31:1379,http://10.10.239.31:2379,http://10.10.239.31:3379 role add roleReadWrite
- 查看角色
I have no name!@75cdaac66149:/opt/bitnami/etcd$ etcdctl --user='root' --password='[email protected]' --endpoints http://10.10.239.31:1379,http://10.10.239.31:2379,http://10.10.239.31:3379 role list
结果
roleRead
roleReadWrite
roleWrite
root
1.4.3 给角色赋权
- 读角色赋读权限
I have no name!@555187fb758c:/opt/bitnami/etcd$ etcdctl --user='root' --password='[email protected]' --endpoints http://10.10.239.31:1379,http://10.10.239.31:2379,http://10.10.239.31:3379 role grant-permission roleRead read /xishu/*
- 写角色赋写权限
I have no name!@555187fb758c:/opt/bitnami/etcd$ etcdctl --user='root' --password='[email protected]' --endpoints http://10.10.239.31:1379,http://10.10.239.31:2379,http://10.10.239.31:3379 role grant-permission roleWrite write /xishu/*
- 读写角色赋读写权限
I have no name!@555187fb758c:/opt/bitnami/etcd$ etcdctl --user='root' --password='[email protected]' --endpoints http://10.10.239.31:1379,http://10.10.239.31:2379,http://10.10.239.31:3379 role grant-permission roleReadWrite readwrite /xishu/*
- 查看角色权限
I have no name!@75cdaac66149:/opt/bitnami/etcd$ etcdctl --user='root' --password='[email protected]' --endpoints http://10.10.239.31:1379,http://10.10.239.31:2379,http://10.10.239.31:3379 role get roleReadWrite
结果显示
Role roleReadWrite
KV Read:
/xishu/*
KV Write:
/xishu/*
1.4.4 给用户绑定角色
- 读用户绑定读角色
I have no name!@555187fb758c:/opt/bitnami/etcd$ etcdctl --user='root' --password='[email protected]' --endpoints http://10.10.239.31:1379,http://10.10.239.31:2379,http://10.10.239.31:3379 user grant-role myRead roleRead
- 写用户绑定写角色
I have no name!@555187fb758c:/opt/bitnami/etcd$ etcdctl --user='root' --password='[email protected]' --endpoints http://10.10.239.31:1379,http://10.10.239.31:2379,http://10.10.239.31:3379 user grant-role myWrite roleWrite
- 读角用户绑定读写角色
I have no name!@555187fb758c:/opt/bitnami/etcd$ etcdctl --user='root' --password='[email protected]' --endpoints http://10.10.239.31:1379,http://10.10.239.31:2379,http://10.10.239.31:3379 user grant-role myReadWrite roleReadWrite
- 查看结果
I have no name!@75cdaac66149:/opt/bitnami/etcd$ etcdctl --user='root' --password='[email protected]' --endpoints http://10.10.239.31:1379,http://10.10.239.31:2379,http://10.10.239.31:3379 user get myReadWrite
输出
User: myReadWrite
Roles: roleReadWrite
1.1.5 测试
- 用写账号写两条数据
I have no name!@75cdaac66149:/opt/bitnami/etcd$ etcdctl --user='myWrite' --password='[email protected]' --endpoints http://10.10.239.31:1379,http://10.10.239.31:2379,http://10.10.239.31:3379 put /xishu/name "liubei"
OK
I have no name!@75cdaac66149:/opt/bitnami/etcd$ etcdctl --user='myWrite' --password='[email protected]' --endpoints http://10.10.239.31:1379,http://10.10.239.31:2379,http://10.10.239.31:3379 put /xishu/age "28"
OK
- 用读账号读出来
I have no name!@75cdaac66149:/opt/bitnami/etcd$ etcdctl --user='myRead' --password='[email protected]' --endpoints http://10.10.239.31:1379,http://10.10.239.31:2379,http://10.10.239.31:3379 get /xishu/age
/xishu/age
28
2. 权限常用命令
2.1 用户管理
创建用户
etcdctl user add 用户名
删除用户
etcdctl user del 用户名
修改密码
etcdctl user passwd 用户名
查看所有用户
etcdctl user list
查看指定用户及绑定角色
etcdctl user get 用户名
2.2 角色
增加角色
etcdctl role add 角色名
给角色赋权
etcdctl grant-permission 角色名 [read|write|readwrite] 范围
范围如:
/xishu/*
,/liubei
回收角色赋权
etcdctl role revoke-permission 角色名 被回收范围
删除角色
etcdctl role del 角色名
查询角色列表
etcdctl role list
查询指定角色的权限
etcdctl role get 角色名
2.3 用户&角色
用户绑定角色
etcdctl user grant-role 用户名 角色名
回收用户绑定权限
etcdctl user revoke-role 用户名 角色名
2.4 权限使用
etcdctl --user='用户名' --password='密码' ……
边栏推荐
- JS general form submission 1-onsubmit
- [combinatorics] permutation and combination (examples of combinatorial number of multiple sets | three counting models | selection problem | combinatorial problem of multiple sets | nonnegative intege
- Doxorubicin loaded on metal organic framework MIL-88 DOX | folic acid modified uio-66-nh2 doxorubicin loaded [email
- Solution to failure or slow downloading of electron when electron uses electron builder to package
- Nucleic acid modified metal organic framework drug carrier | pcn-223 metal organic framework encapsulated ad adamantane | zif-8 encapsulated adriamycin (DOX)
- FPGA test method takes mentor tool as an example
- Why don't I have a rookie medal
- [ACNOI2022]猜数
- 交联环糊精金属有机骨架负载甲氨蝶呤缓释微粒|金属-有机多孔材料UiO-66负载黄酮苷类药物|齐岳
- “又土又穷”的草根高校,凭什么被称为“东北小清华”?
猜你喜欢
Implementation of Muduo asynchronous logging
JVM object lifecycle
7-11 calculation of residential water charges by sections
QT learning 19 standard dialog box in QT (top)
Nucleic acid modified metal organic framework drug carrier | pcn-223 metal organic framework encapsulated ad adamantane | zif-8 encapsulated adriamycin (DOX)
Mysql:insert date:sql error [1292] [22001]: data truncation: incorrect date value:
金属有机骨架MOFs装载非甾体类抗炎药物|ZIF-8包裹普鲁士蓝负载槲皮素(制备方法)
JVM runtime data area
Global event bus
QT learning 21 standard dialog box in QT (Part 2)
随机推荐
Nucleic acid modified metal organic framework drug carrier | pcn-223 metal organic framework encapsulated ad adamantane | zif-8 encapsulated adriamycin (DOX)
MIL-100( Fe) 包裹小分子阿司匹林形成[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)
消息订阅与发布
Exercise 10-8 recursive implementation of sequential output of integers
QT learning 25 layout manager (4)
Configure stylelint
Leetcode(4)——寻找两个正序数组的中位数
Mysql:insert date:sql error [1292] [22001]: data truncation: incorrect date value:
Learn to punch in today
Simulated access
Example analysis of QT learning 18 login dialog box
JS first summary
[combinatorics] permutation and combination (examples of combinatorial number of multiple sets | three counting models | selection problem | combinatorial problem of multiple sets | nonnegative intege
6-9 statistics of single digits (15 points)
Implementation of Muduo asynchronous logging
selenium 浏览器(1)
[clean up the extraordinary image of Disk C]
protobuf与grpc
愉悦资本新双币基金近40亿元完成首次关账
js 2023. String pair equal to the target string after connection