2015-11-04 08:49:53 -05:00
<!-- [metadata]>
+++
title = "Access authorization plugin"
description = "How to create authorization plugins to manage access control to your Docker daemon."
keywords = ["security, authorization, authentication, docker, documentation, plugin, extend"]
2016-03-08 16:34:35 -05:00
aliases = ["/engine/extend/authorization/"]
2015-11-04 08:49:53 -05:00
[menu.main]
2016-01-23 23:36:40 -05:00
parent = "engine_extend"
2016-08-16 14:53:36 -04:00
weight = 4
2015-11-04 08:49:53 -05:00
+++
<![end-metadata]-->
2015-12-08 07:54:33 -05:00
# Create an authorization plugin
2015-11-04 08:49:53 -05:00
2016-08-29 19:37:01 -04:00
This document describes the Docker Engine plugins generally available in Docker
Engine. To view information on plugins managed by Docker Engine currently in
experimental status, refer to [Docker Engine plugin system ](index.md ).
2016-08-16 14:53:36 -04:00
2016-01-12 19:38:18 -05:00
Docker's out-of-the-box authorization model is all or nothing. Any user with
2015-12-10 05:53:27 -05:00
permission to access the Docker daemon can run any Docker client command. The
2015-12-08 07:54:33 -05:00
same is true for callers using Docker's remote API to contact the daemon. If you
require greater access control, you can create authorization plugins and add
them to your Docker daemon configuration. Using an authorization plugin, a
Docker administrator can configure granular access policies for managing access
to Docker daemon.
Anyone with the appropriate skills can develop an authorization plugin. These
skills, at their most basic, are knowledge of Docker, understanding of REST, and
sound programming knowledge. This document describes the architecture, state,
and methods information available to an authorization plugin developer.
2015-11-04 08:49:53 -05:00
## Basic principles
2015-12-10 05:53:27 -05:00
Docker's [plugin infrastructure ](plugin_api.md ) enables
extending Docker by loading, removing and communicating with
2015-12-08 07:54:33 -05:00
third-party components using a generic API. The access authorization subsystem
was built using this mechanism.
Using this subsystem, you don't need to rebuild the Docker daemon to add an
2015-12-10 05:53:27 -05:00
authorization plugin. You can add a plugin to an installed Docker daemon. You do
2015-12-08 07:54:33 -05:00
need to restart the Docker daemon to add a new plugin.
2015-11-04 08:49:53 -05:00
2015-12-08 07:54:33 -05:00
An authorization plugin approves or denies requests to the Docker daemon based
on both the current authentication context and the command context. The
authentication context contains all user details and the authentication method.
The command context contains all the relevant request data.
2015-11-04 08:49:53 -05:00
2016-01-23 23:36:40 -05:00
Authorization plugins must follow the rules described in [Docker Plugin API ](plugin_api.md ).
Each plugin must reside within directories described under the
2015-12-10 05:53:27 -05:00
[Plugin discovery ](plugin_api.md#plugin-discovery ) section.
2015-11-04 08:49:53 -05:00
2016-01-12 19:38:18 -05:00
**Note**: the abbreviations `AuthZ` and `AuthN` mean authorization and authentication
respectively.
2016-03-30 14:14:33 -04:00
## Default user authorization mechanism
2016-06-22 08:50:51 -04:00
If TLS is enabled in the [Docker daemon ](../security/https.md ), the default user authorization flow extracts the user details from the certificate subject name.
2016-03-30 14:14:33 -04:00
That is, the `User` field is set to the client certificate subject common name, and the `AuthenticationMethod` field is set to `TLS` .
2015-11-04 08:49:53 -05:00
## Basic architecture
2015-12-08 07:54:33 -05:00
You are responsible for registering your plugin as part of the Docker daemon
startup. You can install multiple plugins and chain them together. This chain
can be ordered. Each request to the daemon passes in order through the chain.
Only when all the plugins grant access to the resource, is the access granted.
When an HTTP request is made to the Docker daemon through the CLI or via the
remote API, the authentication subsystem passes the request to the installed
authentication plugin(s). The request contains the user (caller) and command
context. The plugin is responsible for deciding whether to allow or deny the
request.
2015-12-10 05:53:27 -05:00
The sequence diagrams below depict an allow and deny authorization flow:
2015-12-08 07:54:33 -05:00
2015-12-10 05:53:27 -05:00
![Authorization Allow flow ](images/authz_allow.png )
2015-12-08 07:54:33 -05:00
2015-12-10 05:53:27 -05:00
![Authorization Deny flow ](images/authz_deny.png )
2015-11-04 08:49:53 -05:00
2015-12-08 07:54:33 -05:00
Each request sent to the plugin includes the authenticated user, the HTTP
headers, and the request/response body. Only the user name and the
authentication method used are passed to the plugin. Most importantly, no user
credentials or tokens are passed. Finally, not all request/response bodies
are sent to the authorization plugin. Only those request/response bodies where
the `Content-Type` is either `text/*` or `application/json` are sent.
2015-11-04 08:49:53 -05:00
2015-12-10 05:53:27 -05:00
For commands that can potentially hijack the HTTP connection (`HTTP
Upgrade`), such as `exec` , the authorization plugin is only called for the
2015-12-08 07:54:33 -05:00
initial HTTP requests. Once the plugin approves the command, authorization is
not applied to the rest of the flow. Specifically, the streaming data is not
passed to the authorization plugins. For commands that return chunked HTTP
2015-12-10 05:53:27 -05:00
response, such as `logs` and `events` , only the HTTP request is sent to the
authorization plugins.
2015-11-04 08:49:53 -05:00
2015-12-10 05:53:27 -05:00
During request/response processing, some authorization flows might
2015-12-08 07:54:33 -05:00
need to do additional queries to the Docker daemon. To complete such flows,
plugins can call the daemon API similar to a regular user. To enable these
additional queries, the plugin must provide the means for an administrator to
configure proper authentication and security policies.
2015-11-04 08:49:53 -05:00
2015-12-08 07:54:33 -05:00
## Docker client flows
2015-11-04 08:49:53 -05:00
2016-01-23 23:36:40 -05:00
To enable and configure the authorization plugin, the plugin developer must
2015-12-10 05:53:27 -05:00
support the Docker client interactions detailed in this section.
2015-11-04 08:49:53 -05:00
2015-12-08 07:54:33 -05:00
### Setting up Docker daemon
Enable the authorization plugin with a dedicated command line flag in the
2016-01-12 19:38:18 -05:00
`--authorization-plugin=PLUGIN_ID` format. The flag supplies a `PLUGIN_ID`
value. This value can be the plugin’ s socket or a path to a specification file.
2016-05-16 14:12:48 -04:00
Authorization plugins can be loaded without restarting the daemon. Refer
to the [`dockerd` documentation ](../reference/commandline/dockerd.md#configuration-reloading ) for more information.
2015-12-08 07:54:33 -05:00
2015-12-10 05:53:27 -05:00
```bash
2016-08-24 23:47:33 -04:00
$ dockerd --authorization-plugin=plugin1 --authorization-plugin=plugin2,...
2015-12-08 07:54:33 -05:00
```
2015-11-04 08:49:53 -05:00
2016-01-12 19:38:18 -05:00
Docker's authorization subsystem supports multiple `--authorization-plugin` parameters.
2015-11-04 08:49:53 -05:00
2015-12-08 07:54:33 -05:00
### Calling authorized command (allow)
2015-12-10 05:53:27 -05:00
```bash
2015-12-08 07:54:33 -05:00
$ docker pull centos
...
f1b10cd84249: Pull complete
...
```
### Calling unauthorized command (deny)
2015-11-04 08:49:53 -05:00
2015-12-10 05:53:27 -05:00
```bash
2015-12-08 07:54:33 -05:00
$ docker pull centos
2015-12-18 06:34:19 -05:00
...
docker: Error response from daemon: authorization denied by plugin PLUGIN_NAME: volumes are not allowed.
2015-12-08 07:54:33 -05:00
```
2015-12-18 06:34:19 -05:00
### Error from plugins
2015-12-08 07:54:33 -05:00
2015-12-18 06:34:19 -05:00
```bash
$ docker pull centos
...
docker: Error response from daemon: plugin PLUGIN_NAME failed with error: AuthZPlugin.AuthZReq: Cannot connect to the Docker daemon. Is the docker daemon running on this host?.
```
2015-12-08 07:54:33 -05:00
## API schema and implementation
2016-01-23 23:36:40 -05:00
In addition to Docker's standard plugin registration method, each plugin
2015-12-10 05:53:27 -05:00
should implement the following two methods:
2015-12-08 07:54:33 -05:00
2016-07-24 23:57:48 -04:00
* `/AuthZPlugin.AuthZReq` This authorize request method is called before the Docker daemon processes the client request.
2015-12-08 07:54:33 -05:00
2016-07-24 23:57:48 -04:00
* `/AuthZPlugin.AuthZRes` This authorize response method is called before the response is returned from Docker daemon to the client.
2015-12-08 07:54:33 -05:00
2016-07-24 23:57:48 -04:00
#### /AuthZPlugin.AuthZReq
2015-12-08 07:54:33 -05:00
**Request**:
2015-12-10 05:53:27 -05:00
```json
2015-12-15 03:49:18 -05:00
{
"User": "The user identification",
"UserAuthNMethod": "The authentication method used",
"RequestMethod": "The HTTP method",
2016-04-09 06:15:55 -04:00
"RequestURI": "The HTTP request URI",
2015-12-15 03:49:18 -05:00
"RequestBody": "Byte array containing the raw HTTP request body",
2016-05-12 01:26:39 -04:00
"RequestHeader": "Byte array containing the raw HTTP request header as a map[string][]string "
2015-12-08 07:54:33 -05:00
}
```
**Response**:
2015-12-10 05:53:27 -05:00
```json
2015-12-15 03:49:18 -05:00
{
"Allow": "Determined whether the user is allowed or not",
"Msg": "The authorization message",
"Err": "The error message if things go wrong"
2015-12-08 07:54:33 -05:00
}
```
2016-07-24 23:57:48 -04:00
#### /AuthZPlugin.AuthZRes
2015-12-08 07:54:33 -05:00
**Request**:
2015-12-10 05:53:27 -05:00
```json
2015-12-08 07:54:33 -05:00
{
2015-12-15 03:49:18 -05:00
"User": "The user identification",
"UserAuthNMethod": "The authentication method used",
"RequestMethod": "The HTTP method",
2016-04-09 06:15:55 -04:00
"RequestURI": "The HTTP request URI",
2015-12-15 03:49:18 -05:00
"RequestBody": "Byte array containing the raw HTTP request body",
"RequestHeader": "Byte array containing the raw HTTP request header as a map[string][]string",
"ResponseBody": "Byte array containing the raw HTTP response body",
"ResponseHeader": "Byte array containing the raw HTTP response header as a map[string][]string",
2015-12-08 07:54:33 -05:00
"ResponseStatusCode":"Response status code"
}
```
**Response**:
2015-12-10 05:53:27 -05:00
```json
2015-12-08 07:54:33 -05:00
{
2015-12-15 03:49:18 -05:00
"Allow": "Determined whether the user is allowed or not",
"Msg": "The authorization message",
2016-05-02 15:19:23 -04:00
"Err": "The error message if things go wrong"
2015-12-08 07:54:33 -05:00
}
```
### Request authorization
Each plugin must support two request authorization messages formats, one from the daemon to the plugin and then from the plugin to the daemon. The tables below detail the content expected in each message.
2015-11-04 08:49:53 -05:00
#### Daemon -> Plugin
Name | Type | Description
-----------------------|-------------------|-------------------------------------------------------
User | string | The user identification
Authentication method | string | The authentication method used
Request method | enum | The HTTP method (GET/DELETE/POST)
Request URI | string | The HTTP request URI including API version (e.g., v.1.17/containers/json)
Request headers | map[string]string | Request headers as key value pairs (without the authorization header)
Request body | []byte | Raw request body
#### Plugin -> Daemon
Name | Type | Description
--------|--------|----------------------------------------------------------------------------------
Allow | bool | Boolean value indicating whether the request is allowed or denied
2015-12-15 03:49:18 -05:00
Msg | string | Authorization message (will be returned to the client in case the access is denied)
2015-12-18 05:28:28 -05:00
Err | string | Error message (will be returned to the client in case the plugin encounter an error. The string value supplied may appear in logs, so should not include confidential information)
2015-11-04 08:49:53 -05:00
2015-12-08 07:54:33 -05:00
### Response authorization
The plugin must support two authorization messages formats, one from the daemon to the plugin and then from the plugin to the daemon. The tables below detail the content expected in each message.
2015-11-04 08:49:53 -05:00
#### Daemon -> Plugin
Name | Type | Description
----------------------- |------------------ |----------------------------------------------------
User | string | The user identification
Authentication method | string | The authentication method used
Request method | string | The HTTP method (GET/DELETE/POST)
2015-12-08 07:54:33 -05:00
Request URI | string | The HTTP request URI including API version (e.g., v.1.17/containers/json)
2015-11-04 08:49:53 -05:00
Request headers | map[string]string | Request headers as key value pairs (without the authorization header)
Request body | []byte | Raw request body
Response status code | int | Status code from the docker daemon
Response headers | map[string]string | Response headers as key value pairs
Response body | []byte | Raw docker daemon response body
#### Plugin -> Daemon
Name | Type | Description
--------|--------|----------------------------------------------------------------------------------
Allow | bool | Boolean value indicating whether the response is allowed or denied
2015-12-15 03:49:18 -05:00
Msg | string | Authorization message (will be returned to the client in case the access is denied)
2015-12-18 05:28:28 -05:00
Err | string | Error message (will be returned to the client in case the plugin encounter an error. The string value supplied may appear in logs, so should not include confidential information)