This plugin controls the access to Docker commands based on authorization policy. The functionality of authorization is provided by Casbin. Since Docker doesn’t perform authentication by now, there’s no user information when executing Docker commands. The access that Casbin plugin can control is actually what HTTP method can be performed on what URL path.
For example, when you run docker images command, the underlying request is really like:
/v1.27/images/json, GET
So Casbin plugin helps you decide whether GET can be performed on /v1.27/images/json base on the policy rules you write. The policy file is basic_policy.csv co-located with the plugin binary by default. And its content is:
p, /v1.27/images/json, GET
The above policy grants anyone to perform GET on /v1.27/images/json, and deny all other requests. The response should be like below:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 48b5124b2768 3 months ago 1.84 kB
$ docker info
Error response from daemon: authorization denied by plugin casbin-authz-plugin: Access denied by casbin plugin
The built-in Casbin model is:
[request_definition]
r = obj, act
[policy_definition]
p = obj, act
[policy_effect]
e = some(where (p.eft == allow))
[matchers]
m = r.obj == p.obj && r.act == p.act
if docker images is denied, simply proceed to Step-8 for the solution
Step-8 Changing the policy
$ vi /usr/lib/docker/examples/basic_policy.csv
p, /v1.29/images/json, GET
$ systemctl restart casbin-authz-plugin
take note that versioning is also included on the authorization. The given policy states /v1.27/. So edit the version in examples/basic_policy.csv that the docker client is throwing which is shown in journalctl like obj: /v1.29/images/json, act: GET res: denied
you can change the $GOPATH to the directory where you put the plugin from go get
Check the logs for more confirmation
Step-9 Test again:
$ docker images
$ docker ps
$ docker info
If docker images is still denied please check STEP-8 more carefully
These should smoothly enable
Stop and uninstall the plugin as a systemd service
NOTE: Before doing below, remove the authorization-plugin configuration added above and restart the docker daemon.
Docker Authorization Plugin Based on Casbin
This plugin controls the access to Docker commands based on authorization policy. The functionality of authorization is provided by Casbin. Since Docker doesn’t perform authentication by now, there’s no user information when executing Docker commands. The access that Casbin plugin can control is actually what HTTP method can be performed on what URL path.
For example, when you run
docker imagescommand, the underlying request is really like:So Casbin plugin helps you decide whether
GETcan be performed on/v1.27/images/jsonbase on the policy rules you write. The policy file isbasic_policy.csvco-located with the plugin binary by default. And its content is:The above policy grants anyone to perform
GETon/v1.27/images/json, and deny all other requests. The response should be like below:The built-in Casbin model is:
The built-in Casbin policy is:
For more information about the Casbin model and policy usage like RBAC, ABAC, please refer to: https://github.com/casbin/casbin
For “non-golang developer” users
Build
Run
Run the plugin directly in a shell
Below should be an example of display when command above is run:
Enable the authorization plugin on docker engine
Step-1: Determine where the systemd service of the plugin is located
Step-2: Add the WorkingDirectory of th plugin’s systemd service
systemctl status casbin-authz-plugin, please use the latterWorkingDirectorymay not be the one given depending on where you put the pluginStep-3: Run the plugin as a systemd service
Step-4: Edit the Execstart of th plugin’s systemd service
systemctl status docker, please use the latter--authorization-plugin=casbin-authz-pluginif there are more options on the pre-definedExecStartplease retain themStep-5: Restart docker engine
Step-6 Activate the plugin logs:
STEP-7 Do a quick test
docker imagesis denied, simply proceed to Step-8 for the solutionStep-8 Changing the policy
examples/basic_policy.csvthat the docker client is throwing which is shown injournalctllikeobj: /v1.29/images/json, act: GET res: denied$GOPATHto the directory where you put the plugin fromgo getStep-9 Test again:
docker imagesis still denied please check STEP-8 more carefullyStop and uninstall the plugin as a systemd service
NOTE: Before doing below, remove the authorization-plugin configuration added above and restart the docker daemon.
Removing the authorization plugin on docker
Stop the plugin service:
Uninstall the plugin service:
Contact
If you have any issues or feature requests, please feel free to contact me at:
License
Apache 2.0