etcd 开启auth认证

我与影子孤独终老i 提交于 2019-12-11 21:02:41

一、概述

1、etcd的v2和v3的认证有些不同,需要分别设置
2、Etcd通过用户(user)-角色(role)-权限的方式来控制访问,用户关联角色,角色拥有权限,从而用户也就拥有了相应的权限
3、Etcd开启Basic Auth之后,默认会启用两个角色root和guest,root角色拥有所有权限,guest拥有只读权限,这两个角色都不要删除

二、授权

v2:
1、添加root,创建root后,root默认有root最高权限
etcdctl --endpoints=http://127.0.0.1:2379 user add root

2、开启认证
etcdctl --endpoints=http://127.0.0.1:2379 auth enable

3、添加一个读写账号和一个只读账号
etcdctl --endpoints=http://127.0.0.1:2379 --username root:123456 user add reado
etcdctl --endpoints=http://127.0.0.1:2379 --username root:123456 user add readw

4、添加只读角色和读写角色
etcdctl --endpoints=http://127.0.0.1:2379 --username root:123456 role add readConf
etcdctl --endpoints=http://127.0.0.1:2379 --username root:123456 role add rootConf

5、为角色授权
etcdctl --endpoints=http://127.0.0.1:2379 --username root:123456 grant --read --path /* readConf
etcdctl --endpoints=http://127.0.0.1:2379 --username root:123456 grant --readwrite --path /* rootConf

6、为用户分配角色
etcdctl --endpoints=http://127.0.0.1:2379 --username root:123456 user grant --roles readConf reado
etcdctl --endpoints=http://127.0.0.1:2379 --username root:123456 user grant --roles rootConf readw

7、常用命令
1)关闭auth
etcdctl --endpoints=http://127.0.0.1:2379 --username root:123456 auth disable

2)删除用户
etcdctl --endpoints=http://127.0.0.1:2379 --username root:123456 user remove reado

3)用户撤销角色
etcdctl --endpoints=http://127.0.0.1:2379 --username root:123456 user revoke --roles readConf reado

4)修改用户密码
etcdctl --endpoints=http://127.0.0.1:2379 --username root:123456 user passwd reado


v3:
1、添加root,创建root后,root默认有root最高权限
etcdctl --endpoints=http://127.0.0.1:2379 user add root

2、创建普通用户
etcdctl --endpoints=http://127.0.0.1:2379 --user=root:123456 user add putong

3、添加角色
etcdctl --endpoints=http://127.0.0.1:2379 --user=root:123456 role add normal

4、角色授权
etcdctl --endpoints=http://127.0.0.1:2379 --user=root:123456 role grant-permission --prefix=true normal readwrite /path_name

5、用户绑定角色
etcdctl --endpoints=http://127.0.0.1:2379 --user=root:123456 user grant-role putong normal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!