• Stars
    star
    213
  • Rank 185,410 (Top 4 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Docker RBAC and ABAC Authorization Plugin Based on Casbin: https://github.com/casbin/casbin

docker-casbin-plugin

Go Report Card Build Status GoDoc

TAKE NOTE: the instructions below is valid only for LINUX Host OS

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

The built-in Casbin policy is:

p, /_ping, GET
p, /v1.27/images/json, GET

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

$ apt install golang-go  # install go language
$ mkdir /usr/local/go
$ export GOPATH=/usr/local/go
  • The installation command above is for Ubuntu, other distros may have different commands for installing go
  • The export can be changed according to your satisfaction

Build

$ go get github.com/casbin/casbin-authz-plugin
$ cd $GOPATH/src/github.com/casbin/casbin-authz-plugin
$ make
$ sudo make install

Run

Run the plugin directly in a shell

$ cd /usr/lib/docker
$ mkdir examples
$ cp basic_model.conf examples/.
$ cp basic_policy.csv examples/.
$ ./casbin-authz-plugin

Below should be an example of display when command above is run:

2017/10/21 03:47:39 Current directory: /usr/lib/docker
2017/10/21 03:47:39 Casbin model: examples/basic_model.conf
2017/10/21 03:47:39 Casbin policy: examples/basic_policy.csv
2017/10/21 03:47:39 [Model:]
2017/10/21 03:47:39 p.p: obj, act
2017/10/21 03:47:39 e.e: some(where (p_eft == allow))
2017/10/21 03:47:39 m.m: r_obj == p_obj && r_act == p_act
2017/10/21 03:47:39 r.r: obj, act
2017/10/21 03:47:39 [Policy:]
2017/10/21 03:47:39 [p :  obj, act :  [[/_ping GET] [/v1.27/images/json GET]]]

Enable the authorization plugin on docker engine

Step-1: Determine where the systemd service of the plugin is located

$ systemctl status casbin-authz-plugin

● casbin-authz-plugin.service - Docker RBAC & ABAC Authorization Plugin based on Casbin
   Loaded: loaded (/lib/systemd/system/casbin-authz-plugin.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
  • You can see the directory on the Loaded label

Step-2: Add the WorkingDirectory of th plugin's systemd service

$ vi /lib/systemd/system/casbin-authz-plugin.service

[Service]
WorkingDirectory=/usr/lib/docker
  • If the service directory above is different than the one that returned from the systemctl status casbin-authz-plugin, please use the latter
  • The WorkingDirectory may not be the one given depending on where you put the plugin

Step-3: Run the plugin as a systemd service

$ systemctl daemon-reload
$ systemctl enable casbin-authz-plugin
$ systemctl start casbin-authz-plugin

Step-4: Edit the Execstart of th plugin's systemd service

$ systemctl edit docker

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --authorization-plugin=casbin-authz-plugin
  • If the service directory above is different than the one that returned from the systemctl status docker, please use the latter
  • Just add --authorization-plugin=casbin-authz-plugin if there are more options on the pre-defined ExecStart please retain them

Step-5: Restart docker engine

$ systemctl daemon-reload
$ systemctl restart docker

Step-6 Activate the plugin logs:

$ journalctl -xe -u casbin-authz-plugin -f

STEP-7 Do a quick test

$ docker images
  • 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.

Removing the authorization plugin on docker

$ systemctl edit docker

#[Service]
#ExecStart=
#ExecStart=/usr/bin/dockerd --authorization-plugin=casbin-authz-plugin

$ systemctl restart docker

Stop the plugin service:

$ systemctl stop casbin-authz-plugin
$ systemctl disable casbin-authz-plugin

Uninstall the plugin service:

$ cd $GOPATH/src/github.com/casbin/casbin-authz-plugin
$ make uninstall

Contact

If you have any issues or feature requests, please feel free to contact me at:

License

Apache 2.0

More Repositories

1

casbin

An authorization library that supports access control models like ACL, RBAC, ABAC in Golang: https://discord.gg/S5UjpzGZjN
Go
17,436
star
2

casdoor

An open-source UI-first Identity and Access Management (IAM) / Single-Sign-On (SSO) platform with web UI supporting OAuth 2.0, OIDC, SAML, CAS, LDAP, SCIM, WebAuthn, TOTP, MFA and RADIUS
Go
7,562
star
3

node-casbin

An authorization library that supports access control models like ACL, RBAC, ABAC in Node.js and Browser
TypeScript
2,569
star
4

jcasbin

An authorization library that supports access control models like ACL, RBAC, ABAC in Java
Java
2,379
star
5

pycasbin

An authorization library that supports access control models like ACL, RBAC, ABAC in Python
Python
1,355
star
6

Casbin.NET

An authorization library that supports access control models like ACL, RBAC, ABAC in .NET (C#)
C#
1,149
star
7

casibase

Open-Source Domain Knowledge Database & IM & Forum Software powered by ChatGPT. See demo: https://ai.casbin.com
JavaScript
1,030
star
8

awesome-auth

📊 Software and Libraries for Authentication & Authorization & SSO & IAM
949
star
9

casbin-rs

An authorization library that supports access control models like ACL, RBAC, ABAC in Rust.
Rust
826
star
10

gorm-adapter

GORM adapter for Casbin, see extended version of GORM Adapter Ex at: https://github.com/casbin/gorm-adapter-ex
Go
675
star
11

xorm-adapter

Xorm adapter for Casbin
Go
383
star
12

caswaf

HTTP & OAuth Gateway and Web Application Firewall (WAF) based on ModSecurity, online demo: https://door.caswaf.com
Go
309
star
13

casbin-server

Casbin as a Service (CaaS)
Go
304
star
14

mongodb-adapter

MongoDB adapter for Casbin
Go
256
star
15

caddy-authz

Caddy-authz is a middleware for Caddy that blocks or allows requests based on access control policies.
Go
240
star
16

casbin-cpp

An authorization library that supports access control models like ACL, RBAC, ABAC in C/C++
C++
221
star
17

redis-adapter

Redis adapter for Casbin
Go
193
star
18

protobuf-adapter

Google Protocol Buffers adapter for Casbin
Go
191
star
19

etcd-watcher

Etcd watcher for Casbin
Go
171
star
20

casbin.js

An authorization library that supports access control models like ACL, RBAC, ABAC in Frontend Javascript
TypeScript
161
star
21

negroni-authz

negroni-authz is an authorization middleware for Negroni
Go
157
star
22

casdoor-old

An open-source Identity and Access Management (IAM) / Single-Sign-On (SSO) platform with web UI supporting OAuth 2.0, OIDC, SAML, CAS, LDAP, WebAuthn, TOTP and MFA
Go
104
star
23

casbin-hub

The hub for Casbin
JavaScript
87
star
24

casbin-editor

Web-based model & policy editor for Casbin
TypeScript
85
star
25

casnode

Open-Source Forum and Social Platform, Alternative to StackOverflow & Flarum
Go
75
star
26

casbin-ex

An authorization library that supports access control models like ACL, RBAC, ABAC in Elixir
Elixir
70
star
27

Talent2023

Casbin明日之星预选生计划-Talents for Casbin 2023 【学生报名请加QQ群:540163681】
67
star
28

lua-casbin

An authorization library that supports access control models like ACL, RBAC, ABAC in Lua (Kong, APISIX, OpenResty)
Lua
55
star
29

ent-adapter

Ent adapter for Casbin
Go
51
star
30

casbin-oa

The OA system used by Casbin community
Go
41
star
31

casbin-website

Deprecated! Please use v2 docs site: https://github.com/casbin/casbin-website-v2 | The v1 docs website for Casbin
JavaScript
39
star
32

casbin-pg-adapter

A go-pg adapter for casbin
Go
38
star
33

dart-casbin

An authorization library that supports access control models like ACL, RBAC, ABAC in Dart/Flutter
Dart
36
star
34

redis-watcher

Redis WatcherEx for Casbin
Go
34
star
35

k8s-gatekeeper

Kubernetes (k8s) admission controller webhook based on Casbin
Go
34
star
36

openstack-policy-editor

A Casbin Policy Editor for OpenStack
JavaScript
32
star
37

k8s-authz

Kubernetes (k8s) RBAC & ABAC authorization middleware based on Casbin
Go
28
star
38

casbin-go-client

Go client for Casbin-Server
Go
25
star
39

casbin-mesh

A scalable authorization layer built on Casbin (The experimental project is currently unstable)
Go
25
star
40

SummerOfCode2022

GSoC 2022 Idea List for Casbin
24
star
41

casbin-vscode-plugin

VSCode plugin for working with Casbin Models
JavaScript
23
star
42

beego-orm-adapter

Beego ORM adapter for Casbin
Go
21
star
43

envoy-authz

Istio/Envoy RBAC & ABAC authorization middleware based on Casbin
Go
20
star
44

casbin-website-v2

The new docs website for Casbin based on Docusaurus v2
JavaScript
19
star
45

hraft-dispatcher

A dispatcher based on Hashicorp's Raft for Casbin.
Go
18
star
46

json-adapter

JSON adapter for Casbin
Go
18
star
47

casbin-server-deprecated

Casbin as a Service via RESTful
Go
16
star
48

auth0-role-manager

Auth0 role manager for Casbin
Go
15
star
49

casbin-raft

Etcd Raft Dispatcher for Casbin
Go
14
star
50

govaluate

Arbitrary expression evaluation for golang, maintained by Casbin
Go
13
star
51

session-role-manager

Session based role manager for Casbin
Go
13
star
52

mysql-adapter

MySQL DB adapter for Casbin
Go
12
star
53

SwiftCasbin

An authorization library that supports access control models like ACL, RBAC, ABAC in iOS Swift / Objective-C
Swift
11
star
54

gorm-adapter-ex

Extended version of GORM Adapter, see original version of GORM Adapter at: https://github.com/casbin/gorm-adapter
Go
11
star
55

SummerOfCode2021

GSoC 2021 Idea List for Casbin
10
star
56

iam-to-casbin-translator

Translate AWS IAM policy to Casbin policy
Go
9
star
57

confita

An open-source version of Kaggle written in Go and React
Go
9
star
58

deno-casbin

An authorization library that supports access control models like ACL, RBAC, ABAC in Deno.
JavaScript
7
star
59

Summer2021

开源软件供应链点亮计划-暑期2021 for Casbin 【学生报名请加QQ群:540163681】
7
star
60

mux-authz

gorilla/mux's RBAC & ABAC Authorization middleware based on Casbin
Go
6
star
61

graphql-authz

graphql-authz is an authorization middleware for graphql-go
Go
6
star
62

Talent2024

Casbin明日之星预选生计划-Talents for Casbin 2024 【学生报名请加QQ群:540163681】
6
star
63

casbin-core

An authorization library that supports access control models like ACL, RBAC, ABAC in modern JavaScript platforms
TypeScript
6
star
64

kubesphere-authz

ACL, RBAC, ABAC authorization middleware for KubeSphere
Go
5
star
65

okta-role-manager

Okta role manager for Casbin
Go
5
star
66

cassandra-adapter

Cassandra DB adapter for Casbin
Go
5
star
67

zap-logger

Zap logger for Casbin
Go
5
star
68

google-groups-crawler

This tool is for legitimate use. We internally use it for synchronizing posts between Casnode forum and our own Casbin Google Group
Go
5
star
69

static

Casbin static resources like js, css, img
CSS
5
star
70

revel-authz

revel-authz is an authorization middleware for Revel
Go
4
star
71

xacml-to-casbin-translator

Translate XACML policy to Casbin policy
HTML
4
star
72

laravel-rbac

An authorization library that supports access control models like ACL, RBAC, ABAC in Laravel
PHP
4
star
73

casnode-web-new

JavaScript
3
star
74

casbin-pythonclient

Python client for Casbin Server
Python
3
star
75

scala-casbin

3
star
76

Summer2022

开源软件供应链点亮计划-暑期2022 for Casbin 【学生报名请加QQ群:540163681】
3
star
77

VisualPCD

VisualPCD aims to parse the XACML format policy file and detect the authorization conflicts between XACML policies.
C++
3
star
78

caswire

An open-source host-based anti-virus, firewall and IDS (Intrusion Detection System) platform: https://discord.gg/S5UjpzGZjN
JavaScript
2
star
79

casbin.github.io

The GitHub pages (static site) for: https://github.com/casbin/casbin-website
HTML
2
star
80

Summer2023

开源软件供应链点亮计划-暑期2023 for Casbin 【学生报名请加QQ群:540163681】
2
star
81

tyk-authz

Casbin authorization plugin for tyk API gateway
Go
2
star
82

caswaf-website

The docs website for CasWAF: https://github.com/casbin/caswaf
JavaScript
2
star
83

chi-authz

Chi Authorization Middleware based on Casbin
Go
2
star
84

SeasonOfDocs2022

Google Season of Docs 2022 Proposal for Casbin
2
star
85

casvisor

An open-source security log auditing & RDP, VNC, SSH bastion platform: https://discord.gg/S5UjpzGZjN
JavaScript
1
star
86

istio-authz

1
star
87

Permap

A permission mapper
Python
1
star
88

awesome-chatgpt

Software and Libraries for OpenAI & ChatGPT & LLM
1
star
89

casvisor-website

Docs site of Casvisor : https://github.com/casbin/casvisor
JavaScript
1
star
90

tikv-watcher

TiKV watcher for Casbin
Go
1
star
91

casdoc

Docs helper based on OpenAI ChatGPT
Go
1
star
92

pycasbin-on-cpp

An authorization library that supports access control models like ACL, RBAC, ABAC in Python, based on C/C++ (Casbin-CPP)
1
star