当前位置:网站首页>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 . Find the first palindrome string in the array
- Webpage connection database ~ simple implementation of addition, deletion, modification and query complete code
- Article content typesetting and code highlighting
- 愉悦资本新双币基金近40亿元完成首次关账
- selenium 浏览器(1)
- Common plug-ins for vite project development
- 28: Chapter 3: develop Passport Service: 11: define attributes in the configuration file, and then obtain them in the code;
- 全局事件总线
- Redis:字符串類型數據的操作命令
- jvm-类加载
猜你喜欢

7-10 calculate salary
[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)"/>MIL-100( Fe) 包裹小分子阿司匹林形成[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)

Exercise 8-8 moving letters

Leetcode(4)——寻找两个正序数组的中位数

7-7 12-24 hour system

Vite project commissioning

QT learning 25 layout manager (4)

“又土又穷”的草根高校,凭什么被称为“东北小清华”?

7-9 find a small ball with a balance

Uniapp tips - scrolling components
随机推荐
Canvas utility library fabric JS user manual
关于回溯问题中的排列问题的思考(LeetCode46题与47题)
战略、战术(和 OKR)
C library function - qsort()
allegro,orcad, net alias,port,off-page connector之间的异同点和如何选取
虽然不一定最优秀,但一定是最努力的!
JVM垃圾回收机
jvm-类加载
Selenium browser (1)
好看、好用、强大的手写笔记软件综合评测:Notability、GoodNotes、MarginNote、随手写、Notes Writers、CollaNote、CollaNote、Prodrafts、Noteshelf、FlowUs、OneNote、苹果备忘录
UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料
Exercise 10-1 judge the three digits that meet the conditions
Uniapp tips - scrolling components
Folic acid modified metal organic framework (zif-8) baicalin loaded metal organic framework composite magnetic material (AU- [email
page owner特性浅析
核酸修饰的金属有机框架药物载体|PCN-223金属有机骨架包载Ad金刚烷|ZIF-8包裹阿霉素(DOX)
Mysql:insert date:sql error [1292] [22001]: data truncation: incorrect date value:
Onmenusharetimeline custom shared content is invalid, and the title and icon are not displayed
6-9 statistics of single digits (15 points)
JVM family - overview, program counter day1-1