《中小團隊落地配置中心詳解》文章中咱們介紹瞭如何基於Etcd+Confd構建配置中心,最後提到Etcd的安全問題時說了可使用帳號密碼認證以達到安全訪問的目的,究竟該如何開啓認證以及怎麼設計權限訪問呢?本文將爲你詳細解讀nginx
權限設計應先考慮咱們對權限的需求,從需求出發設計權限安全
1.添加root用戶bash
# etcdctl user add root
New password: 12345
User root created
複製代碼
2.建立root帳號後,root默認有root角色,對全部KV有讀寫權限ui
# etcdctl user get root
User: root
Roles: root
# etcdctl role get root
Role: root
KV Read:
/*
KV Write:
/*
複製代碼
3.開啓auth認證spa
# etcdctl auth enable
Authentication Enabled
開啓權限認證後默認會多一個guest的角色
# etcdctl --username root:12345 role list
guest
root
複製代碼
4.添加非root帳號,一個authz的帳號,一個readx的帳號設計
# etcdctl --username root:12345 user add authz
New password:
User authz created
# etcdctl --username root:12345 user add readx
New password:
User readx created
複製代碼
5.添加角色,一個rootConf的角色,一個readConf的角色code
# etcdctl --username root:12345 role add rootConf
Role rootConf created
# etcdctl --username root:12345 role add readConf
Role readConf created
複製代碼
6.爲角色受權,readConf角色對/conf有隻讀權限,rootConf角色對/conf有讀寫權限cdn
# etcdctl --username root:12345 role grant --read --path /conf/* readConf
Role readConf updated
# etcdctl --username root:12345 role grant --readwrite --path /conf/* rootConf
Role rootConf updated
複製代碼
7.給用戶分配角色,authz帳號分配rootConf角色,readx帳號分配readConf角色ssl
# etcdctl --username root:12345 user grant --roles rootConf authz
User authz updated
# etcdctl --username root:12345 user grant --roles readConf readx
User readx updated
複製代碼
8.查看用戶所擁有的角色ci
# etcdctl --username root:12345 user get authz
User: authz
Roles: rootConf
# etcdctl --username root:12345 user get readx
User: readx
Roles: readConf
複製代碼
這樣readx帳號就對/conf下的全部文件有了只讀權限,authz對/conf下的全部文件有了讀寫權限
有一些命令上邊沒有介紹到,會用獲得的以下:
1.關閉認證
# etcdctl --username root:12345 auth disable
複製代碼
2.刪除用戶
# etcdctl --username root:12345 user remove userx
複製代碼
3.用戶撤銷角色
# etcdctl --username root:12345 user revoke rolex
複製代碼
4.修改用戶密碼
# etcdctl --username root:12345 user passwd
複製代碼
同時還有刪除角色、撤銷角色權限可參看上邊用戶相關操做
在開啓認證後發現系統默認給添加了guest角色,以爲guest角色沒用就給刪除了,因而再鏈接etcd集羣時就報以下錯誤:
報錯:The request requires user authentication (Insufficient credentials)
解決:從新添加guest角色
若是你以爲文章對你有幫助,請轉發分享給更多的人。若是你以爲讀的不盡興,推薦閱讀如下文章: