基于角色的访问控制(TBD)
Overview
Authentication was added in etcd 2.1. The etcd v3 API slightly modified the authentication feature's API and user interface to better fit the new data model. This guide is intended to help users set up basic authentication and role-based access control in etcd v3.
Special users and roles
There is one special user, root
, and one special role, root
.
User root
root
The root
user, which has full access to etcd, must be created before activating authentication. The idea behind the root
user is for administrative purposes: managing roles and ordinary users. The root
user must have the root
role and is allowed to change anything inside etcd.
Role root
root
The role root
may be granted to any user, in addition to the root user. A user with the root
role has both global read-write access and permission to update the cluster's authentication configuration. Furthermore, the root
role grants privileges for general cluster maintenance, including modifying cluster membership, defragmenting the store, and taking snapshots.
Working with users
The user
subcommand for etcdctl
handles all things having to do with user accounts.
A listing of users can be found with:
Creating a user is as easy as
Creating a new user will prompt for a new password. The password can be supplied from standard input when an option --interactive=false
is given.
Roles can be granted and revoked for a user with:
The user's settings can be inspected with:
And the password for a user can be changed with
Changing the password will prompt again for a new password. The password can be supplied from standard input when an option --interactive=false
is given.
Delete an account with:
Working with roles
The role
subcommand for etcdctl
handles all things having to do with access controls for particular roles, as were granted to individual users.
List roles with:
Create a new role with:
A role has no password; it merely defines a new set of access rights.
Roles are granted access to a single key or a range of keys.
The range can be specified as an interval [start-key, end-key) where start-key should be lexically less than end-key in an alphabetical manner.
Access can be granted as either read, write, or both, as in the following examples:
To see what's granted, we can look at the role at any time:
Revocation of permissions is done the same logical way:
As is removing a role entirely:
Enabling authentication
The minimal steps to enabling auth are as follows. The administrator can set up users and roles before or after enabling authentication, as a matter of preference.
Make sure the root user is created:
Enable authentication:
After this, etcd is running with authentication enabled. To disable it for any reason, use the reciprocal command:
Using etcdctl
to authenticate
etcdctl
to authenticateetcdctl
supports a similar flag as curl
for authentication.
The password can be taken from a prompt:
Otherwise, all etcdctl
commands remain the same. Users and roles can still be created and modified, but require authentication by a user with the root role.
Using TLS Common Name
If an etcd server is launched with the option --client-cert-auth=true
, the field of Common Name (CN) in the client's TLS cert will be used as an etcd user. In this case, the common name authenticates the user and the client does not need a password.
Last updated