当前位置:网站首页>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='密码' ……
边栏推荐
- 消息订阅与发布
- 泰凌冲刺科创板:拟募资13亿 国家大基金与小米长江是股东
- Exercise 10-6 recursively find Fabonacci sequence
- How to promote the progress of project collaboration | community essay solicitation
- Use vscode to view hex or UTF-8 codes
- Too many files with unapproved license
- JS get DPI, PX to cm, cm to PX
- Metal organic framework material zif-8 containing curcumin( [email protected] Nanoparticles) | nano metal organic framework carry
- QT learning 24 layout manager (III)
- jvm-类加载
猜你喜欢

全局事件总线

Exercise 7-6 count capital consonants

Understanding of closures

Exercise 10-2 recursive factorial sum

How to use lxml to judge whether the website announcement is updated

好看、好用、强大的手写笔记软件综合评测:Notability、GoodNotes、MarginNote、随手写、Notes Writers、CollaNote、CollaNote、Prodrafts、Noteshelf、FlowUs、OneNote、苹果备忘录

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

Exercise 10-3 recursive implementation of exponential functions

消息订阅与发布

The small project (servlet+jsp+mysql+el+jstl) completes a servlet with login function, with the operation of adding, deleting, modifying and querying. Realize login authentication, prevent illegal log
随机推荐
28:第三章:开发通行证服务:11:在配置文件中定义属性,然后在代码中去获取;
Exercise 8-8 moving letters
Uniapp skills - scrolling components -1
Common mixins
常见问题之PHP——ldap_add(): Add: Undefined attribute type in
[ACNOI2022]猜数
中感微冲刺科创板:年营收2.4亿净亏1782万 拟募资6亿
js 2023. String pair equal to the target string after connection
金属有机骨架MOFs装载非甾体类抗炎药物|ZIF-8包裹普鲁士蓝负载槲皮素(制备方法)
JVM runtime data area
Folic acid modified metal organic framework (zif-8) baicalin loaded metal organic framework composite magnetic material (AU- [email
Leetcode (4) - - trouver la médiane de deux tableaux ordonnés positifs
QT learning 24 layout manager (III)
Exercise 8-7 string sorting
中国锂电池电解液行业市场专项调研报告(2022版)
八大排序
Exercise 9-3 plane vector addition
How to promote the progress of project collaboration | community essay solicitation
Exercise 8-2 calculate the sum and difference of two numbers
6-9 statistics of single digits (15 points)