Etcd访问控制
1. ETCD资源类型
There are three types of resources in etcd
permission resources
: users and roles in the user storekey-value resources
: key-value pairs in the key-value storesettings resources
: security settings, auth settings, and dynamic etcd cluster settings (election/heartbeat)
2. 权限资源
Users:user用来设置身份认证(user:passwd),一个用户可以拥有多个角色,每个角色被分配一定的权限(只读、只写、可读写),用户分为root用户和非root用户。
Roles:角色用来关联权限,角色主要三类:root角色。默认创建root用户时即创建了root角色,该角色拥有所有权限;guest角色,默认自动创建,主要用于非认证使用。普通角色,由root用户创建角色,并分配指定权限。
注意:如果没有指定任何验证方式,即没显示指定以什么用户进行访问,那么默认会设定为 guest 角色。默认情况下 guest 也是具有全局访问权限的。如果不希望未授权就获取或修改etcd的数据,则可收回guest角色的权限或删除该角色,etcdctl role revoke 。
Permissions:权限分为只读、只写、可读写三种权限,权限即对指定目录或key的读写权限。
3. ETCD访问控制
3.1. 访问控制相关命令
3.2. user相关命令
3.2.1. 添加root用户并设置密码
3.2.2. 添加非root用户并设置密码
3.2.3. 查看当前所有用户
3.2.4. 将用户添加到对应角色
3.2.5. 查看用户拥有哪些角色
3.3. role相关命令
3.3.1. 添加角色
3.3.2. 查看所有角色
3.3.3. 给角色分配权限
3.3.4. 查看角色所拥有的权限
3.4. auth相关操作
3.4.1. 开启认证
4. 访问控制设置步骤
1
添加root用户
etcdctl --endpoints http://: user add root
2
开启认证
etcdctl --endpoints http://: auth enable
3
添加非root用户
etcdctl --endpoints http://: –username root: user add
4
添加角色
etcdctl --endpoints http://: –username root: role add
5
给角色授权(只读、只写、可读写)
etcdctl --endpoints http://: –username root: role grant --readwrite --path
6
给用户分配角色(即分配了角色对应的权限)
etcdctl --endpoints http://: –username root: user grant --roles
5. 访问认证的API调用
更多参考
https://coreos.com/etcd/docs/latest/v2/auth_api.html
https://coreos.com/etcd/docs/latest/v2/authentication.html
最后更新于
这有帮助吗?