github.com/kim0/docker@v0.6.2-0.20161130212042-4addda3f07e7/docs/extend/plugins_authorization.md (about)

     1  ---
     2  title: "Access authorization plugin"
     3  description: "How to create authorization plugins to manage access control to your Docker daemon."
     4  keywords: ["security, authorization, authentication, docker, documentation, plugin, extend"]
     5  aliases: ["/engine/extend/authorization/"]
     6  ---
     7  
     8  <!-- This file is maintained within the docker/docker Github
     9       repository at https://github.com/docker/docker/. Make all
    10       pull requests against that repo. If you see this file in
    11       another repository, consider it read-only there, as it will
    12       periodically be overwritten by the definitive file. Pull
    13       requests which include edits to this file in other repositories
    14       will be rejected.
    15  -->
    16  
    17  # Create an authorization plugin
    18  
    19  This document describes the Docker Engine plugins generally available in Docker
    20  Engine. To view information on plugins managed by Docker Engine currently in
    21  experimental status, refer to [Docker Engine plugin system](index.md).
    22  
    23  Docker's out-of-the-box authorization model is all or nothing. Any user with
    24  permission to access the Docker daemon can run any Docker client command. The
    25  same is true for callers using Docker's remote API to contact the daemon. If you
    26  require greater access control, you can create authorization plugins and add
    27  them to your Docker daemon configuration. Using an authorization plugin, a
    28  Docker administrator can configure granular access policies for managing access
    29  to Docker daemon.
    30  
    31  Anyone with the appropriate skills can develop an authorization plugin. These
    32  skills, at their most basic, are knowledge of Docker, understanding of REST, and
    33  sound programming knowledge. This document describes the architecture, state,
    34  and methods information available to an authorization plugin developer.
    35  
    36  ## Basic principles
    37  
    38  Docker's [plugin infrastructure](plugin_api.md) enables
    39  extending Docker by loading, removing and communicating with
    40  third-party components using a generic API. The access authorization subsystem
    41  was built using this mechanism.
    42  
    43  Using this subsystem, you don't need to rebuild the Docker daemon to add an
    44  authorization plugin.  You can add a plugin to an installed Docker daemon. You do
    45  need to restart the Docker daemon to add a new plugin.
    46  
    47  An authorization plugin approves or denies requests to the Docker daemon based
    48  on both the current authentication context and the command context. The
    49  authentication context contains all user details and the authentication method.
    50  The command context contains all the relevant request data.
    51  
    52  Authorization plugins must follow the rules described in [Docker Plugin API](plugin_api.md).
    53  Each plugin must reside within directories described under the
    54  [Plugin discovery](plugin_api.md#plugin-discovery) section.
    55  
    56  **Note**: the abbreviations `AuthZ` and `AuthN` mean authorization and authentication
    57  respectively.
    58  
    59  ## Default user authorization mechanism
    60  
    61  If TLS is enabled in the [Docker daemon](https://docs.docker.com/engine/security/https/), the default user authorization flow extracts the user details from the certificate subject name.
    62  That is, the `User` field is set to the client certificate subject common name, and the `AuthenticationMethod` field is set to `TLS`.
    63  
    64  ## Basic architecture
    65  
    66  You are responsible for registering your plugin as part of the Docker daemon
    67  startup. You can install multiple plugins and chain them together. This chain
    68  can be ordered. Each request to the daemon passes in order through the chain.
    69  Only when all the plugins grant access to the resource, is the access granted.
    70  
    71  When an HTTP request is made to the Docker daemon through the CLI or via the
    72  remote API, the authentication subsystem passes the request to the installed
    73  authentication plugin(s). The request contains the user (caller) and command
    74  context. The plugin is responsible for deciding whether to allow or deny the
    75  request.
    76  
    77  The sequence diagrams below depict an allow and deny authorization flow:
    78  
    79  ![Authorization Allow flow](images/authz_allow.png)
    80  
    81  ![Authorization Deny flow](images/authz_deny.png)
    82  
    83  Each request sent to the plugin includes the authenticated user, the HTTP
    84  headers, and the request/response body. Only the user name and the
    85  authentication method used are passed to the plugin. Most importantly, no user
    86  credentials or tokens are passed. Finally, not all request/response bodies
    87  are sent to the authorization plugin. Only those request/response bodies where
    88  the `Content-Type` is either `text/*` or `application/json` are sent.
    89  
    90  For commands that can potentially hijack the HTTP connection (`HTTP
    91  Upgrade`), such as `exec`, the authorization plugin is only called for the
    92  initial HTTP requests. Once the plugin approves the command, authorization is
    93  not applied to the rest of the flow. Specifically, the streaming data is not
    94  passed to the authorization plugins. For commands that return chunked HTTP
    95  response, such as `logs` and `events`, only the HTTP request is sent to the
    96  authorization plugins.
    97  
    98  During request/response processing, some authorization flows might
    99  need to do additional queries to the Docker daemon. To complete such flows,
   100  plugins can call the daemon API similar to a regular user. To enable these
   101  additional queries, the plugin must provide the means for an administrator to
   102  configure proper authentication and security policies.
   103  
   104  ## Docker client flows
   105  
   106  To enable and configure the authorization plugin, the plugin developer must
   107  support the Docker client interactions detailed in this section.
   108  
   109  ### Setting up Docker daemon
   110  
   111  Enable the authorization plugin with a dedicated command line flag in the
   112  `--authorization-plugin=PLUGIN_ID` format. The flag supplies a `PLUGIN_ID`
   113  value. This value can be the plugin’s socket or a path to a specification file.
   114  Authorization plugins can be loaded without restarting the daemon. Refer
   115  to the [`dockerd` documentation](../reference/commandline/dockerd.md#configuration-reloading) for more information.
   116  
   117  ```bash
   118  $ dockerd --authorization-plugin=plugin1 --authorization-plugin=plugin2,...
   119  ```
   120  
   121  Docker's authorization subsystem supports multiple `--authorization-plugin` parameters.
   122  
   123  ### Calling authorized command (allow)
   124  
   125  ```bash
   126  $ docker pull centos
   127  ...
   128  f1b10cd84249: Pull complete
   129  ...
   130  ```
   131  
   132  ### Calling unauthorized command (deny)
   133  
   134  ```bash
   135  $ docker pull centos
   136  ...
   137  docker: Error response from daemon: authorization denied by plugin PLUGIN_NAME: volumes are not allowed.
   138  ```
   139  
   140  ### Error from plugins
   141  
   142  ```bash
   143  $ docker pull centos
   144  ...
   145  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?.
   146  ```
   147  
   148  ## API schema and implementation
   149  
   150  In addition to Docker's standard plugin registration method, each plugin
   151  should implement the following two methods:
   152  
   153  * `/AuthZPlugin.AuthZReq` This authorize request method is called before the Docker daemon processes the client request.
   154  
   155  * `/AuthZPlugin.AuthZRes` This authorize response method is called before the response is returned from Docker daemon to the client.
   156  
   157  #### /AuthZPlugin.AuthZReq
   158  
   159  **Request**:
   160  
   161  ```json
   162  {
   163      "User":              "The user identification",
   164      "UserAuthNMethod":   "The authentication method used",
   165      "RequestMethod":     "The HTTP method",
   166      "RequestURI":        "The HTTP request URI",
   167      "RequestBody":       "Byte array containing the raw HTTP request body",
   168      "RequestHeader":     "Byte array containing the raw HTTP request header as a map[string][]string "
   169  }
   170  ```
   171  
   172  **Response**:
   173  
   174  ```json
   175  {
   176      "Allow": "Determined whether the user is allowed or not",
   177      "Msg":   "The authorization message",
   178      "Err":   "The error message if things go wrong"
   179  }
   180  ```
   181  #### /AuthZPlugin.AuthZRes
   182  
   183  **Request**:
   184  
   185  ```json
   186  {
   187      "User":              "The user identification",
   188      "UserAuthNMethod":   "The authentication method used",
   189      "RequestMethod":     "The HTTP method",
   190      "RequestURI":        "The HTTP request URI",
   191      "RequestBody":       "Byte array containing the raw HTTP request body",
   192      "RequestHeader":     "Byte array containing the raw HTTP request header as a map[string][]string",
   193      "ResponseBody":      "Byte array containing the raw HTTP response body",
   194      "ResponseHeader":    "Byte array containing the raw HTTP response header as a map[string][]string",
   195      "ResponseStatusCode":"Response status code"
   196  }
   197  ```
   198  
   199  **Response**:
   200  
   201  ```json
   202  {
   203     "Allow":              "Determined whether the user is allowed or not",
   204     "Msg":                "The authorization message",
   205     "Err":                "The error message if things go wrong"
   206  }
   207  ```
   208  
   209  ### Request authorization
   210  
   211  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.
   212  
   213  #### Daemon -> Plugin
   214  
   215  Name                   | Type              | Description
   216  -----------------------|-------------------|-------------------------------------------------------
   217  User                   | string            | The user identification
   218  Authentication method  | string            | The authentication method used
   219  Request method         | enum              | The HTTP method (GET/DELETE/POST)
   220  Request URI            | string            | The HTTP request URI including API version (e.g., v.1.17/containers/json)
   221  Request headers        | map[string]string | Request headers as key value pairs (without the authorization header)
   222  Request body           | []byte            | Raw request body
   223  
   224  
   225  #### Plugin -> Daemon
   226  
   227  Name    | Type   | Description
   228  --------|--------|----------------------------------------------------------------------------------
   229  Allow   | bool   | Boolean value indicating whether the request is allowed or denied
   230  Msg     | string | Authorization message (will be returned to the client in case the access is denied)
   231  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)
   232  
   233  ### Response authorization
   234  
   235  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.
   236  
   237  #### Daemon -> Plugin
   238  
   239  
   240  Name                    | Type              | Description
   241  ----------------------- |------------------ |----------------------------------------------------
   242  User                    | string            | The user identification
   243  Authentication method   | string            | The authentication method used
   244  Request method          | string            | The HTTP method (GET/DELETE/POST)
   245  Request URI             | string            | The HTTP request URI including API version (e.g., v.1.17/containers/json)
   246  Request headers         | map[string]string | Request headers as key value pairs (without the authorization header)
   247  Request body            | []byte            | Raw request body
   248  Response status code    | int               | Status code from the docker daemon
   249  Response headers        | map[string]string | Response headers as key value pairs
   250  Response body           | []byte            | Raw docker daemon response body
   251  
   252  
   253  #### Plugin -> Daemon
   254  
   255  Name    | Type   | Description
   256  --------|--------|----------------------------------------------------------------------------------
   257  Allow   | bool   | Boolean value indicating whether the response is allowed or denied
   258  Msg     | string | Authorization message (will be returned to the client in case the access is denied)
   259  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)