All Projects → foodora → kong-plugin-jwt-crafter

foodora / kong-plugin-jwt-crafter

Licence: MIT license
Kong plugin to automatically issue a JWT token if consumer is authenticated and has a JWT credential

Programming Languages

lua
6591 projects
shell
77523 projects

Projects that are alternatives of or similar to kong-plugin-jwt-crafter

Middleware Acl
middleware-acl Access Control Library RBAC casbin
Stars: ✭ 155 (+342.86%)
Mutual labels:  acl
Adonis Acl
demo app: https://github.com/enniel/adonis-acl-blog-demo
Stars: ✭ 195 (+457.14%)
Mutual labels:  acl
Rbac
Hierarchical Role-Based Access Control for Node.js
Stars: ✭ 254 (+625.71%)
Mutual labels:  acl
Vue Browser Acl
Easy user access control in Vue for better UX. Build on top of the browser-acl package.
Stars: ✭ 162 (+362.86%)
Mutual labels:  acl
Acl Papers
paper summary of Association for Computational Linguistics
Stars: ✭ 189 (+440%)
Mutual labels:  acl
Caddy Authz
Caddy-authz is a middleware for Caddy that blocks or allows requests based on access control policies.
Stars: ✭ 221 (+531.43%)
Mutual labels:  acl
Negroni Authz
negroni-authz is an authorization middleware for Negroni
Stars: ✭ 152 (+334.29%)
Mutual labels:  acl
TradeTheEvent
Implementation of "Trade the Event: Corporate Events Detection for News-Based Event-Driven Trading." In Findings of ACL2021
Stars: ✭ 64 (+82.86%)
Mutual labels:  acl
Awesome Iam
👤 Identity and Access Management Knowledge for Cloud Platforms
Stars: ✭ 186 (+431.43%)
Mutual labels:  acl
Chi Authz
chi-authz is an authorization middleware for Chi
Stars: ✭ 248 (+608.57%)
Mutual labels:  acl
Acl Anthology
Data and software for building the ACL Anthology.
Stars: ✭ 168 (+380%)
Mutual labels:  acl
Security
🔑 Provides authentication, authorization and a role-based access control management via ACL (Access Control List)
Stars: ✭ 180 (+414.29%)
Mutual labels:  acl
Tengine
Tengine is a lite, high performance, modular inference engine for embedded device
Stars: ✭ 4,012 (+11362.86%)
Mutual labels:  acl
Lock Laravel
This package is a Laravel 5 driver for Lock
Stars: ✭ 161 (+360%)
Mutual labels:  acl
kong-plugin-url-rewrite
Kong API Gateway plugin for url-rewrite purposes
Stars: ✭ 43 (+22.86%)
Mutual labels:  kong-plugin
Think Authz
An authorization library that supports access control models like ACL, RBAC, ABAC in ThinkPHP 6.0 .
Stars: ✭ 155 (+342.86%)
Mutual labels:  acl
Angular Acl
Role-based permissions for AngularJS
Stars: ✭ 200 (+471.43%)
Mutual labels:  acl
loopback-component-mq
Loopback Component for working with a Message Queue
Stars: ✭ 19 (-45.71%)
Mutual labels:  acl
spicedb
Open Source, Google Zanzibar-inspired fine-grained permissions database
Stars: ✭ 3,358 (+9494.29%)
Mutual labels:  acl
Bouncer
Eloquent roles and abilities.
Stars: ✭ 2,763 (+7794.29%)
Mutual labels:  acl

JWT Crafter Kong plugin

Build Status

This plugin adds the possibility to generate a JWT token within Kong itself, eliminating the need for a upstream service doing the token generation.

The JWT plugin included in Kong has two main features: storing JWT secrets per consumer and verifying tokens when proxying to upstream services. It is missing the capability to generate a token based on successful authentication.

This plugin needs two other plugins to work:

  • the JWT plugin itself, it uses it to fetch the JWT credential where the consumer's signing secret is stored
  • any authentication plugin (e.g. Basic authentication, JWT, OAuth2); a consumer must be authenticated to generate a token

It also uses the ACL plugin and embeds all the consumer ACLs inside the token claims section. Upstream services can then decode the token and use the ACLs from the token to authorize users within app code.

Tests run against Kong 0.9.x and 0.10.x.

Example

Create an API and a consumer with a JWT credential (not token), add Basic auth to the API:

# Create sign in API
curl -XPOST -H 'Content-Type: application/json' -d '{"uris": "/sign_in", "upstream_url": "http://localhost", "name": "sign_in_api"}' localhost:8001/apis

# Create consumer
curl -XPOST -H 'Content-Type: application/json' -d '{"username": "test"}' localhost:8001/consumers

# Create JWT credential for consumer
curl -XPOST -H 'Content-Type: application/json' localhost:8001/consumers/{consumer_id_from_above}/jwt

# Create basic auth credentials for consumer
curl -XPOST -d 'username=user' -d 'password=pass' localhost:8001/consumers/{consumer_id_from_above}/basic-auth

# Enable basic auth for sign in API
curl -XPOST -d 'name=basic-auth' localhost:8001/apis/{api_id_from_above}/plugins

Note: the upstream_url of the API is irrelevant, the plugin short circuits the response and returns the token directly from Kong. Just make sure to enter a URL which can resolve on DNS, otherwise Kong complains. This is a known limitation of Kong.

Enable the JWT crafter plug-in:

curl -X POST -d 'name=jwt-crafter' localhost:8001/apis/{api_id_from_above}/plugins

Putting it all together, calling the created API authenticated using Basic authentication will yield the following response:

# user:pass is base64 encoded
curl -H 'Authorization: basic dGVzdDp0ZXN0' localhost:8000/sign_in
{
  "token_type": "Bearer",
  "expires_in": 28800,
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW0iOiJ0ZXN0Iiwic3ViIjoiYzNiODMzMDgtMWYyNS00M2VmLWExN2MtOWNjNTBlOGI3OWQ2IiwiaXNzIjoiNmIzOWYzNzhjNzQzNGUyMmIzZjg4N2Q2ZTMzNDgwOTkiLCJleHAiOjE0OTU5MTAwODMsInJvbCI6WyJhYWEiLCJiYmIiXX0.yMufTuFi7aKpJeDYGiiR0en035w3G_MNHtQO4xkIKdU"
}

Decoded token:

{
  "alg": "HS256",
  "typ": "JWT"
}
{
  "nam": "test", // Credential username or user ID
  "sub": "c3b83308-1f25-43ef-a17c-9cc50e8b79d6", // Consumer ID
  "iss": "6b39f378c7434e22b3f887d6e3348099", // JWT credential key (issuer)
  "exp": 1495910051, // Valid until
  "rol": [ // ACLs of the consumer from Kong
    "aaa",
    "bbb"
  ]
}

Installation

Install the rock when building your Kong image/instance:

luarocks install kong-plugin-jwt-crafter

Add the plugin to your custom_plugins section in kong.conf, the KONG_CUSTOM_PLUGINS is also available.

custom_plugins = jwt-crafter

Configuration

All configuration options are optional

key default value description
expires_in 8 * 60 * 60 validity of token in seconds

Limitations

Currently, the plugin loads the first HS256 JWT credential of the consumer. It does not include other signing algorithms or a possibility to specify which consumer JWT credential should be used to sign the key if the consumer has multiple credentials.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].