github.com/brahmaroutu/docker@v1.2.1-0.20160809185609-eb28dde01f16/docs/extend/plugins_authorization.md (about)

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