《中小团队落地配置中心详解》文章中咱们介绍了如何基于Etcd+Confd构建配置中心,最后提到Etcd的安全问题时说了可使用帐号密码认证以达到安全访问的目的,究竟该如何开启认证以及怎么设计权限访问呢?本文将为你详细解读nginx
权限设计应先考虑咱们对权限的需求,从需求出发设计权限安全
1.添加root用户ui
# etcdctl user add root New password: 12345 User root created
2.建立root帐号后,root默认有root角色,对全部KV有读写权限设计
# etcdctl user get root User: root Roles: root # etcdctl role get root Role: root KV Read: /* KV Write: /*
3.开启auth认证code
# etcdctl auth enable Authentication Enabled 开启权限认证后默认会多一个guest的角色 # etcdctl --username root:12345 role list guest root
4.添加非root帐号,一个authz的帐号,一个readx的帐号ssl
# 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的角色ci
# 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有读写权限rem
# 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角色get
# 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.查看用户所拥有的角色it
# 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角色
若是你以为文章对你有帮助,请转发分享给更多的人。若是你以为读的不尽兴,推荐阅读如下文章: