-
Notifications
You must be signed in to change notification settings - Fork 18.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docker authorization plug-in infrastructure #15365
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
630f695
Adding authorization subsystem documentation
75c353f
Docker authorization plug-in infrastructure enables extending the fun…
8cc0892
Fixing documentation according to comments by @moxiegirl and @thaJeztah
f28230d
Rebase from master
b7af5bc
Fixing documentation comments by @thaJeztah
de4ffdf
Change authz plugin argument name
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,252 @@ | ||
<!--[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"] | ||
[menu.main] | ||
parent = "mn_extend" | ||
weight = -1 | ||
+++ | ||
<![end-metadata]--> | ||
|
||
|
||
# Create an authorization plugin | ||
|
||
Docker’s out-of-the-box authorization model is all or nothing. Any user with | ||
permission to access the Docker daemon can run any Docker client command. The | ||
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. | ||
|
||
## Basic principles | ||
|
||
Docker's [plugin infrastructure](plugin_api.md) enables | ||
extending Docker by loading, removing and communicating with | ||
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 | ||
authorization plugin. You can add a plugin to an installed Docker daemon. You do | ||
need to restart the Docker daemon to add a new plugin. | ||
|
||
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. | ||
|
||
Authorization plugins must follow the rules described in [Docker Plugin API](plugin_api.md). | ||
Each plugin must reside within directories described under the | ||
[Plugin discovery](plugin_api.md#plugin-discovery) section. | ||
|
||
## Basic architecture | ||
|
||
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. | ||
|
||
The sequence diagrams below depict an allow and deny authorization flow: | ||
|
||
![Authorization Allow flow](images/authz_allow.png) | ||
|
||
![Authorization Deny flow](images/authz_deny.png) | ||
|
||
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. | ||
|
||
For commands that can potentially hijack the HTTP connection (`HTTP | ||
Upgrade`), such as `exec`, the authorization plugin is only called for the | ||
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 | ||
response, such as `logs` and `events`, only the HTTP request is sent to the | ||
authorization plugins. | ||
|
||
During request/response processing, some authorization flows might | ||
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. | ||
|
||
## Docker client flows | ||
|
||
To enable and configure the authorization plugin, the plugin developer must | ||
support the Docker client interactions detailed in this section. | ||
|
||
### Setting up Docker daemon | ||
|
||
Enable the authorization plugin with a dedicated command line flag in the | ||
`--authz-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. | ||
|
||
```bash | ||
$ docker daemon --authz-plugin=plugin1 --authz-plugin=plugin2,... | ||
``` | ||
|
||
Docker's authorization subsystem supports multiple `--authz-plugin` parameters. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be |
||
|
||
### Calling authorized command (allow) | ||
|
||
Your plugin must support calling the `allow` command to authorize a command. | ||
This call does not impact Docker's command line. | ||
|
||
```bash | ||
$ docker pull centos | ||
... | ||
f1b10cd84249: Pull complete | ||
... | ||
``` | ||
|
||
### Calling unauthorized command (deny) | ||
|
||
Your plugin must support calling the `deny` command to report on the outcome of | ||
a plugin interaction. This call returns messages to Docker's command line informing | ||
the user of the outcome of each call. | ||
|
||
```bash | ||
$ docker pull centos | ||
… | ||
Authorization failed. Pull command for user 'john_doe' is | ||
denied by authorization plugin 'ACME' with message | ||
‘[ACME] User 'john_doe' is not allowed to perform the pull | ||
command’ | ||
``` | ||
|
||
Where multiple authorization plugins are installed, multiple messages are expected. | ||
|
||
|
||
## API schema and implementation | ||
|
||
In addition to Docker's standard plugin registration method, each plugin | ||
should implement the following two methods: | ||
|
||
* `/AuthzPlugin.AuthZReq` This authorize request method is called before the Docker daemon processes the client request. | ||
|
||
* `/AuthzPlugin.AuthZRes` This authorize response method is called before the response is returned from Docker daemon to the client. | ||
|
||
#### /AuthzPlugin.AuthZReq | ||
|
||
**Request**: | ||
|
||
```json | ||
{ | ||
"User": "The user identification" | ||
"UserAuthNMethod": "The authentication method used" | ||
"RequestMethod": "The HTTP method" | ||
"RequestUri": "The HTTP request URI" | ||
"RequestBody": "Byte array containing the raw HTTP request body" | ||
"RequestHeader": "Byte array containing the raw HTTP request header as a map[string][]string " | ||
"RequestStatusCode": "Request status code" | ||
} | ||
``` | ||
|
||
**Response**: | ||
|
||
```json | ||
{ | ||
"Allow" : "Determined whether the user is allowed or not" | ||
"Msg": "The authorization message" | ||
} | ||
``` | ||
|
||
#### /AuthzPlugin.AuthZRes | ||
|
||
**Request**: | ||
|
||
```json | ||
{ | ||
"User": "The user identification" | ||
"UserAuthNMethod": "The authentication method used" | ||
"RequestMethod": "The HTTP method" | ||
"RequestUri": "The HTTP request URI" | ||
"RequestBody": "Byte array containing the raw HTTP request body" | ||
"RequestHeader": "Byte array containing the raw HTTP request header as a map[string][]string" | ||
"RequestStatusCode": "Request status code" | ||
"ResponseBody": "Byte array containing the raw HTTP response body" | ||
"ResponseHeader": "Byte array containing the raw HTTP response header as a map[string][]string" | ||
"ResponseStatusCode":"Response status code" | ||
} | ||
``` | ||
|
||
**Response**: | ||
|
||
```json | ||
{ | ||
"Allow" : "Determined whether the user is allowed or not" | ||
"Msg": "The authorization message" | ||
"ModifiedBody": "Byte array containing a modified body of the raw HTTP body (or nil if no changes required)" | ||
"ModifiedHeader": "Byte array containing a modified header of the HTTP response (or nil if no changes required)" | ||
"ModifiedStatusCode": "int containing the modified version of the status code (or 0 if not change is required)" | ||
} | ||
``` | ||
|
||
The modified response enables the authorization plugin to manipulate the content | ||
of the HTTP response. In case of more than one plugin, each subsequent plugin | ||
receives a response (optionally) modified by a previous plugin. | ||
|
||
### 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. | ||
|
||
#### 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 | ||
Message | string | Authorization message (will be returned to the client in case the access is denied) | ||
|
||
### 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. | ||
|
||
#### 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) | ||
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 | ||
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 | ||
Message | string | Authorization message (will be returned to the client in case the access is denied) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liron-l thank you for the contribution. As @thaJeztah points out, there are several redundancies in this information. Also, structurally, I think there are opportunities to help the reader out by tightening the language used. A couple of questions come to mind:
Below I've included the complete text the incorporates all my comments. You can reach at the gist indicated.
---> https://gist.github.com/moxiegirl/852dbab3b392c28e29b2
Create an authorization plugin
Docker’s out-of-the-box authorization model is all or nothing. Any user with
permission to access to the Docker daemon can run any Docker client command. The
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.
Basic principles
Docker's plugin
infrastructure enables
extending Docker by dynamically loading, removing and communicating with
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
authorization plugin. You can add a plugin to a installed Docker daemon. You do
need to restart the Docker daemon to add a new plugin.
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.
Authorization plugins must follow the rules described in Docker Plugin
API. Each plugin must reside
within directories described under the plugin
discovery
section.
Basic architecture
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.
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 eithertext/*
orapplication/json
are sent.For commands that can potentially the hijack the HTTP connection (
HTTP Upgrade
), such asexec
, the authorization plugin are only called for theinitial 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
response, such as
logs
andevents
, only the HTTP request are sent to theauthorization plugins as well.
During request/response processing, some authorization plugins flows might
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.
Docker client flows
To enable and configure the authorization plugin, the plugin developer must support the Docker client interactions detailed in this section.
Setting up Docker daemon
Enable the authorization plugin with a dedicated command line flag in the
--authz-plugins=PLUGIN_ID
format. The flag supplies aPLUGIN_ID
value.This value can be the plugin’s socket or a path to a specification file.
Docker's authorization subsystem supports multiple
--authz-plugin
parameters.Calling authorized command (allow)
Your plugin must support calling the
allow
command to authorize a command. This call does not impact Docker's command line.Calling unauthorized command (deny)
Your plugin must support calling the
deny
command to report on the outcome of a plugin interaction. This call returns messages to Docker's command line informing the user of the outcome of each call.Where multiple authorization plugins are installed, multiple messages are expected.
API schema and implementation
Sample code for a typical plugin can be found here [ADD LINK]. In addition to Docker's standard plugin registration method, each plugin should implement the following two methods:
/AuthzPlugin.AuthZReq
This authorize request method is called before the Docker daemon processes the client request./AuthzPlugin.AuthZRes
This authorize response method is called before the response is returned from Docker daemon to the client./AuthzPlugin.AuthZReq
Request:
Response:
/AuthzPlugin.AuthZRes
Request:
Response:
The modified response enables the authorization plugin to manipulate the content
of the HTTP response. In case of more than one plugin, each subsequent plugin
receives a response (optionally) modified by a previous plugin.
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.
Daemon -> Plugin
Plugin -> Daemon
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.
Daemon -> Plugin
Plugin -> Daemon