Kong Authorization
kong-authz is a Kong plugin that does request authorization with lua-casbin. You define models and policies as usual; the plugin enforces them on Kong routes.
Prerequisites
- Kong
- 4daysorm-adapter (optional, for database-backed policy storage)
- luasql-adapter (optional, for database-backed policy storage)
інформація
By default, policies are loaded from files. To use database-backed policies, install either 4daysorm-adapter or luasql-adapter.
Installation
Install Casbin's system dependencies:
- For systems with
apt:
sudo apt install gcc libpcre3 libpcre3-dev
- For Alpine-based systems:
sudo apk add gcc pcre pcre-dev libc-dev
Install Casbin's latest release from LuaRocks:
sudo luarocks install casbin
Install the kong-authz plugin:
sudo luarocks install https://raw.githubusercontent.com/casbin-lua/kong-authz/master/kong-authz-0.0.1-1.rockspec
Add the plugin to your kong.conf by appending kong-authz (comma-separated) to the plugins variable:
# kong.conf
plugins = bundled, kong-authz
Start or restart Kong:
kong start [-c /path/to/kong.conf]
Configuration
Configure this plugin at the service, API, or global level through the Kong Admin API.
File-Based Policy Storage
Configure globally with file-based policies:
curl -i -X POST \
--url http://localhost:8001/plugins/ \
--data 'name=kong-authz' \
--data 'config.model_path=/path/to/model_path.conf' \
--data 'config.policy_path=/path/to/policy_path.csv' \
--data 'config.username=user'
Database Policy Storage with LuaSQL
Configure for a specific service using the LuaSQL adapter:
curl -i -X POST \
--url http://localhost:8001/services/example-service/plugins/ \
--data 'name=kong-authz' \
--data 'config.model_path=/mnt/kong/examples/authz_model.conf' \
--data 'config.username=user' \
--data 'config.adapter=luasql' \
--data 'config.db_info.db_type=mysql' \
--data 'config.db_info.database=casbin' \
--data 'config.db_info.username=root' \
--data 'config.db_info.password=********' \
--data 'config.db_info.host=127.0.0.1' \
--data 'config.db_info.port=3306'