etcd Resources

There are three types of resources in etcd

  1. permission resources: users and roles in the user store
  2. key-value resources: key-value pairs in the key-value store
  3. settings resources: security settings, auth settings, and dynamic etcd cluster settings (election/heartbeat)

Permission Resources

Users

A user is an identity to be authenticated. Each user can have multiple roles. The user has a capability (such as reading or writing) on the resource if one of the roles has that capability.

A user named root is required before authentication can be enabled, and it always has the ROOT role. The ROOT role can be granted to multiple users, but root is required for recovery purposes.

Roles

Each role has exact one associated Permission List. An permission list exists for each permission on key-value resources.

The special static ROOT (named root) role has a full permissions on all key-value resources, the permission to manage user resources and settings resources. Only the ROOT role has the permission to manage user resources and modify settings resources. The ROOT role is built-in and does not need to be created.

There is also a special GUEST role, named ‘guest’. These are the permissions given to unauthenticated requests to etcd. This role will be created automatically, and by default allows access to the full keyspace due to backward compatibility. (etcd did not previously authenticate any actions.). This role can be modified by a ROOT role holder at any time, to reduce the capabilities of unauthenticated users.

Permissions

There are two types of permissions, read and write. All management and settings require the ROOT role.

A Permission List is a list of allowed patterns for that particular permission (read or write). Only ALLOW prefixes are supported. DENY becomes more complicated and is TBD.

Key-Value Resources

A key-value resource is a key-value pairs in the store. Given a list of matching patterns, permission for any given key in a request is granted if any of the patterns in the list match.

Only prefixes or exact keys are supported. A prefix permission string ends in *. A permission on /foo is for that exact key or directory, not its children or recursively. /foo* is a prefix that matches /foo recursively, and all keys thereunder, and keys with that prefix (eg. /foobar. Contrast to the prefix /foo/*). * alone is permission on the full keyspace.

Settings Resources

Specific settings for the cluster as a whole. This can include adding and removing cluster members, enabling or disabling authentication, replacing certificates, and any other dynamic configuration by the administrator (holder of the ROOT role).

v2 Auth

Basic Auth

We only support Basic Auth for the first version. Client needs to attach the basic auth to the HTTP Authorization Header.

Authorization field for operations

Added to requests to /v2/keys, /v2/auth Add code 401 Unauthorized to the set of responses from the v2 API Authorization: Basic {encoded string}

Future Work

Other types of auth can be considered for the future (eg, signed certs, public keys) but the Authorization: header allows for other such types

Things out of Scope for etcd Permissions

  • Pluggable AUTH backends like LDAP (other Authorization tokens generated by LDAP et al may be a possibility)
  • Very fine-grained access controls (eg: users modifying keys outside work hours)

API endpoints

An Error JSON corresponds to: { “name”: “ErrErrorName”, “description” : “The longer helpful description of the error.” }

Enable and Disable Authentication

Get auth status

GET /v2/auth/enable

  1. Sent Headers:
  2. Possible Status Codes:
  3. 200 OK
  4. 200 Body:
  5. {
  6. "enabled": true
  7. }

Enable auth

PUT /v2/auth/enable

  1. Sent Headers:
  2. Put Body: (empty)
  3. Possible Status Codes:
  4. 200 OK
  5. 400 Bad Request (if root user has not been created)
  6. 409 Conflict (already enabled)
  7. 200 Body: (empty)

Disable auth

DELETE /v2/auth/enable

  1. Sent Headers:
  2. Authorization: Basic <RootAuthString>
  3. Possible Status Codes:
  4. 200 OK
  5. 401 Unauthorized (if not a root user)
  6. 409 Conflict (already disabled)
  7. 200 Body: (empty)

Users

The User JSON object is formed as follows:

  1. {
  2. "user": "userName",
  3. "password": "password",
  4. "roles": [
  5. "role1",
  6. "role2"
  7. ],
  8. "grant": [],
  9. "revoke": []
  10. }

Password is only passed when necessary.

Get a List of Users

GET/HEAD /v2/auth/users

  1. Sent Headers:
  2. Authorization: Basic <BasicAuthString>
  3. Possible Status Codes:
  4. 200 OK
  5. 401 Unauthorized
  6. 200 Headers:
  7. Content-type: application/json
  8. 200 Body:
  9. {
  10. "users": [
  11. {
  12. "user": "alice",
  13. "roles": [
  14. {
  15. "role": "root",
  16. "permissions": {
  17. "kv": {
  18. "read": ["/*"],
  19. "write": ["/*"]
  20. }
  21. }
  22. }
  23. ]
  24. },
  25. {
  26. "user": "bob",
  27. "roles": [
  28. {
  29. "role": "guest",
  30. "permissions": {
  31. "kv": {
  32. "read": ["/*"],
  33. "write": ["/*"]
  34. }
  35. }
  36. }
  37. ]
  38. }
  39. ]
  40. }

Get User Details

GET/HEAD /v2/auth/users/alice

  1. Sent Headers:
  2. Authorization: Basic <BasicAuthString>
  3. Possible Status Codes:
  4. 200 OK
  5. 401 Unauthorized
  6. 404 Not Found
  7. 200 Headers:
  8. Content-type: application/json
  9. 200 Body:
  10. {
  11. "user" : "alice",
  12. "roles" : [
  13. {
  14. "role": "fleet",
  15. "permissions" : {
  16. "kv" : {
  17. "read": [ "/fleet/" ],
  18. "write": [ "/fleet/" ]
  19. }
  20. }
  21. },
  22. {
  23. "role": "etcd",
  24. "permissions" : {
  25. "kv" : {
  26. "read": [ "/*" ],
  27. "write": [ "/*" ]
  28. }
  29. }
  30. }
  31. ]
  32. }

Create Or Update A User

A user can be created with initial roles, if filled in. However, no roles are required; only the username and password fields

PUT /v2/auth/users/charlie

  1. Sent Headers:
  2. Authorization: Basic <BasicAuthString>
  3. Put Body:
  4. JSON struct, above, matching the appropriate name
  5. * Starting password and roles when creating.
  6. * Grant/Revoke/Password filled in when updating (to grant roles, revoke roles, or change the password).
  7. Possible Status Codes:
  8. 200 OK
  9. 201 Created
  10. 400 Bad Request
  11. 401 Unauthorized
  12. 404 Not Found (update non-existent users)
  13. 409 Conflict (when granting duplicated roles or revoking non-existent roles)
  14. 200 Headers:
  15. Content-type: application/json
  16. 200 Body:
  17. JSON state of the user

Remove A User

DELETE /v2/auth/users/charlie

  1. Sent Headers:
  2. Authorization: Basic <BasicAuthString>
  3. Possible Status Codes:
  4. 200 OK
  5. 401 Unauthorized
  6. 403 Forbidden (remove root user when auth is enabled)
  7. 404 Not Found
  8. 200 Headers:
  9. 200 Body: (empty)

Roles

A full role structure may look like this. A Permission List structure is used for the “permissions”, “grant”, and “revoke” keys.

  1. {
  2. "role" : "fleet",
  3. "permissions" : {
  4. "kv" : {
  5. "read" : [ "/fleet/" ],
  6. "write": [ "/fleet/" ]
  7. }
  8. },
  9. "grant" : {"kv": {...}},
  10. "revoke": {"kv": {...}}
  11. }

Get Role Details

GET/HEAD /v2/auth/roles/fleet

  1. Sent Headers:
  2. Authorization: Basic <BasicAuthString>
  3. Possible Status Codes:
  4. 200 OK
  5. 401 Unauthorized
  6. 404 Not Found
  7. 200 Headers:
  8. Content-type: application/json
  9. 200 Body:
  10. {
  11. "role" : "fleet",
  12. "permissions" : {
  13. "kv" : {
  14. "read": [ "/fleet/" ],
  15. "write": [ "/fleet/" ]
  16. }
  17. }
  18. }

Get a list of Roles

GET/HEAD /v2/auth/roles

  1. Sent Headers:
  2. Authorization: Basic <BasicAuthString>
  3. Possible Status Codes:
  4. 200 OK
  5. 401 Unauthorized
  6. 200 Headers:
  7. Content-type: application/json
  8. 200 Body:
  9. {
  10. "roles": [
  11. {
  12. "role": "fleet",
  13. "permissions": {
  14. "kv": {
  15. "read": ["/fleet/"],
  16. "write": ["/fleet/"]
  17. }
  18. }
  19. },
  20. {
  21. "role": "etcd",
  22. "permissions": {
  23. "kv": {
  24. "read": ["/*"],
  25. "write": ["/*"]
  26. }
  27. }
  28. },
  29. {
  30. "role": "quay",
  31. "permissions": {
  32. "kv": {
  33. "read": ["/*"],
  34. "write": ["/*"]
  35. }
  36. }
  37. }
  38. ]
  39. }

Create Or Update A Role

PUT /v2/auth/roles/rkt

  1. Sent Headers:
  2. Authorization: Basic <BasicAuthString>
  3. Put Body:
  4. Initial desired JSON state, including the role name for verification and:
  5. * Starting permission set if creating
  6. * Granted/Revoked permission set if updating
  7. Possible Status Codes:
  8. 200 OK
  9. 201 Created
  10. 400 Bad Request
  11. 401 Unauthorized
  12. 404 Not Found (update non-existent roles)
  13. 409 Conflict (when granting duplicated permission or revoking non-existent permission)
  14. 200 Body:
  15. JSON state of the role

Remove A Role

DELETE /v2/auth/roles/rkt

  1. Sent Headers:
  2. Authorization: Basic <BasicAuthString>
  3. Possible Status Codes:
  4. 200 OK
  5. 401 Unauthorized
  6. 403 Forbidden (remove root)
  7. 404 Not Found
  8. 200 Headers:
  9. 200 Body: (empty)

Example Workflow

Let’s walk through an example to show two tenants (applications, in our case) using etcd permissions.

Create root role

  1. PUT /v2/auth/users/root
  2. Put Body:
  3. {"user" : "root", "password": "betterRootPW!"}

Enable auth

  1. PUT /v2/auth/enable

Modify guest role (revoke write permission)

  1. PUT /v2/auth/roles/guest
  2. Headers:
  3. Authorization: Basic <root:betterRootPW!>
  4. Put Body:
  5. {
  6. "role" : "guest",
  7. "revoke" : {
  8. "kv" : {
  9. "write": [
  10. "/*"
  11. ]
  12. }
  13. }
  14. }

Create Roles for the Applications

Create the rkt role fully specified:

  1. PUT /v2/auth/roles/rkt
  2. Headers:
  3. Authorization: Basic <root:betterRootPW!>
  4. Body:
  5. {
  6. "role" : "rkt",
  7. "permissions" : {
  8. "kv": {
  9. "read": [
  10. "/rkt/*"
  11. ],
  12. "write": [
  13. "/rkt/*"
  14. ]
  15. }
  16. }
  17. }

But let’s make fleet just a basic role for now:

  1. PUT /v2/auth/roles/fleet
  2. Headers:
  3. Authorization: Basic <root:betterRootPW!>
  4. Body:
  5. {
  6. "role" : "fleet"
  7. }

Optional: Grant some permissions to the roles

Well, we finally figured out where we want fleet to live. Let’s fix it. (Note that we avoided this in the rkt case. So this step is optional.)

  1. PUT /v2/auth/roles/fleet
  2. Headers:
  3. Authorization: Basic <root:betterRootPW!>
  4. Put Body:
  5. {
  6. "role" : "fleet",
  7. "grant" : {
  8. "kv" : {
  9. "read": [
  10. "/rkt/fleet",
  11. "/fleet/*"
  12. ]
  13. }
  14. }
  15. }

Create Users

Same as before, let’s use rocket all at once and fleet separately

  1. PUT /v2/auth/users/rktuser
  2. Headers:
  3. Authorization: Basic <root:betterRootPW!>
  4. Body:
  5. {"user" : "rktuser", "password" : "rktpw", "roles" : ["rkt"]}
  1. PUT /v2/auth/users/fleetuser
  2. Headers:
  3. Authorization: Basic <root:betterRootPW!>
  4. Body:
  5. {"user" : "fleetuser", "password" : "fleetpw"}

Optional: Grant Roles to Users

Likewise, let’s explicitly grant fleetuser access.

  1. PUT /v2/auth/users/fleetuser
  2. Headers:
  3. Authorization: Basic <root:betterRootPW!>
  4. Body:
  5. {"user": "fleetuser", "grant": ["fleet"]}

Start to use fleetuser and rktuser

For example:

  1. PUT /v2/keys/rkt/RktData
  2. Headers:
  3. Authorization: Basic <rktuser:rktpw>
  4. Body:
  5. value=launch

Reads and writes outside the prefixes granted will fail with a 401 Unauthorized.