一、概述
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