Coder Social home page Coder Social logo

tieske / kong-upstream-jwt Goto Github PK

View Code? Open in Web Editor NEW

This project forked from optum/kong-upstream-jwt

0.0 2.0 0.0 1.06 MB

A plugin for Kong which adds a signed JWT to HTTP Headers to backend requests

License: Apache License 2.0

Lua 100.00%

kong-upstream-jwt's Introduction

Kong Upstream JWT Plugin

Overview

This plugin will add a signed JWT into the HTTP Header JWT or config.header of proxied requests through the Kong gateway. The purpose of this, is to provide means of Authentication, Authorization and Non-Repudiation to API providers (APIs for which Kong is a gateway).

In short, API Providers need a means of cryptographically validating that requests they receive were A. proxied by Kong, and B. not tampered with during transmission from Kong -> API Provider. This token accomplishes both as follows:

  1. Authentication & Authorization - Provided by means of JWT signature validation. The API Provider will validate the signature on the JWT token (which is generating using Kong's RSA x509 private key), using Kong's public key. This public key can be maintained in a keystore, or sent with the token - provided API providers validate the signature chain against their truststore.
  2. Non-Repudiation - SHA256 is used to hash the body of the HTTP Request Body, and the resulting digest is included in the payloadhash element of the JWT body. API Providers will take the SHA256 hash of the HTTP Request Body, and compare the digest to that found in the JWT. If they are identical, the request remained intact during transmission.

Supported Kong Releases

Kong >= 1.0.x

Installation

Recommended:

$ luarocks install kong-upstream-jwt

Other:

$ git clone https://github.com/Optum/kong-upstream-jwt.git /path/to/kong/plugins/kong-upstream-jwt
$ cd /path/to/kong/plugins/kong-upstream-jwt
$ luarocks make *.rockspec

JWT Token

The following is an example of the contents of the decoded JWT token:

Header:

{
  "x5c": ["...der-encoded cert data..."],
  "alg": "RS256",
  "typ": "JWT",
  "kid": "..conf.key_id.." // Only present if conf.key_id configuration variable set
}

Payload:

{
  "aud": "kong-service-name", // The Kong Service Name
  "iss": "issuer", // Only set if issuer configuration variable available
  "iat": 1550258274, // Only set if issuer configuration variable available
  "exp": 1550258334, // 1 minute exp time
  "jti": "d4f10edb-c4f0-47d3-b7e0-90a30a885a0b", // Unique to every request - UUID
  "consumername": "consumer-username", // Consumer Username
  "consumerid": "consumer-id", // Consumer ID
  "payloadhash": "...sha256 hash of request payload..."
}

Configuration

Private and Public Keys

The plugin requires that Kong's private key be accessible in order to sign the JWT. We also include the x509 cert in the x5c JWT Header for use by API providers to validate the JWT.

JWT Issuer

JWT Issuer allows for the iss field to be set within the JWT token.

More information about JWT claims can be found here

Optional Plugin schema configurations:

private_key_location = "/path/to/kong/ssl/privatekey.key"
public_key_location = "/path/to/kong/ssl/kongpublickey.cer"
issuer = "issuer"
key_id = "keyId"
header = "JWT" //If you want to set the header key to something other than JWT
include_credential_type = false //Controls "Bearer " + JWT or just JWT in header

The first contains the path to your .key file, the second specifies the path to your public key in DER format .cer file.

Backwards Compatibility

To maintain backwards compatibility, support for passing the key locations through environment variables is also available. We access these via Kong's overriding environment variables KONG_SSL_CERT_KEY for the private key as well as KONG_SSL_CERT_DER for the public key.

If not already set, these can be done so as follows:

$ export KONG_SSL_CERT_KEY="/path/to/kong/ssl/privatekey.key"
$ export KONG_SSL_CERT_DER="/path/to/kong/ssl/kongpublickey.cer"

One last step is to make the environment variables accessible by an nginx worker. To do this, simply add these line to your nginx.conf

env KONG_SSL_CERT_KEY;
env KONG_SSL_CERT_DER;

Maintainers

jeremyjpj0916
rsbrisci

Feel free to open issues, or refer to our Contribution Guidelines if you have any questions.

kong-upstream-jwt's People

Contributors

jeremyjpj0916 avatar rsbrisci avatar brianwyka avatar row1govender avatar amyschoen avatar gilmansean avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.