• Stars
    star
    430
  • Rank 101,083 (Top 2 %)
  • Language
    Lua
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

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

Repository Details

OIDC plugin for Kong

What is Kong OIDC plugin

Join the chat at https://gitter.im/nokia/kong-oidc

Continuous Integration: Build Status Coverage Status

kong-oidc is a plugin for Kong implementing the OpenID Connect Relying Party (RP) functionality.

It authenticates users against an OpenID Connect Provider using OpenID Connect Discovery and the Basic Client Profile (i.e. the Authorization Code flow).

It maintains sessions for authenticated users by leveraging lua-resty-openidc thus offering a configurable choice between storing the session state in a client-side browser cookie or use in of the server-side storage mechanisms shared-memory|memcache|redis.

It supports server-wide caching of resolved Discovery documents and validated Access Tokens.

It can be used as a reverse proxy terminating OAuth/OpenID Connect in front of an origin server so that the origin server/services can be protected with the relevant standards without implementing those on the server itself.

Introspection functionality add capability for already authenticated users and/or applications that already posses acces token to go through kong. The actual token verification is then done by Resource Server.

How does it work

The diagram below shows the message exchange between the involved parties.

alt Kong OIDC flow

The X-Userinfo header contains the payload from the Userinfo Endpoint

X-Userinfo: {"preferred_username":"alice","id":"60f65308-3510-40ca-83f0-e9c0151cc680","sub":"60f65308-3510-40ca-83f0-e9c0151cc680"}

The plugin also sets the ngx.ctx.authenticated_consumer variable, which can be using in other Kong plugins:

ngx.ctx.authenticated_consumer = {
    id = "60f65308-3510-40ca-83f0-e9c0151cc680",   -- sub field from Userinfo
    username = "alice"                             -- preferred_username from Userinfo
}

Dependencies

kong-oidc depends on the following package:

Installation

If you're using luarocks execute the following:

 luarocks install kong-oidc

You also need to set the KONG_PLUGINS environment variable

 export KONG_PLUGINS=oidc

Usage

Parameters

Parameter Default Required description
name true plugin name, has to be oidc
config.client_id true OIDC Client ID
config.client_secret true OIDC Client secret
config.discovery https://.well-known/openid-configuration false OIDC Discovery Endpoint (/.well-known/openid-configuration)
config.scope openid false OAuth2 Token scope. To use OIDC it has to contains the openid scope
config.ssl_verify false false Enable SSL verification to OIDC Provider
config.session_secret false Additional parameter, which is used to encrypt the session cookie. Needs to be random
config.introspection_endpoint false Token introspection endpoint
config.timeout false OIDC endpoint calls timeout
config.introspection_endpoint_auth_method client_secret_basic false Token introspection auth method. resty-openidc supports `client_secret_(basic
config.bearer_only no false Only introspect tokens without redirecting
config.realm kong false Realm used in WWW-Authenticate response header
config.logout_path /logout false Absolute path used to logout from the OIDC RP

Enabling

To enable the plugin only for one API:

POST /apis/<api_id>/plugins/ HTTP/1.1
Host: localhost:8001
Content-Type: application/x-www-form-urlencoded
Cache-Control: no-cache

name=oidc&config.client_id=kong-oidc&config.client_secret=29d98bf7-168c-4874-b8e9-9ba5e7382fa0&config.discovery=https%3A%2F%2F<oidc_provider>%2F.well-known%2Fopenid-configuration

To enable the plugin globally:

POST /plugins HTTP/1.1
Host: localhost:8001
Content-Type: application/x-www-form-urlencoded
Cache-Control: no-cache

name=oidc&config.client_id=kong-oidc&config.client_secret=29d98bf7-168c-4874-b8e9-9ba5e7382fa0&config.discovery=https%3A%2F%2F<oidc_provider>%2F.well-known%2Fopenid-configuration

A successful response:

HTTP/1.1 201 Created
Date: Tue, 24 Oct 2017 19:37:38 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.11.0

{
    "created_at": 1508871239797,
    "config": {
        "response_type": "code",
        "client_id": "kong-oidc",
        "discovery": "https://<oidc_provider>/.well-known/openid-configuration",
        "scope": "openid",
        "ssl_verify": "no",
        "client_secret": "29d98bf7-168c-4874-b8e9-9ba5e7382fa0",
        "token_endpoint_auth_method": "client_secret_post"
    },
    "id": "58cc119b-e5d0-4908-8929-7d6ed73cb7de",
    "enabled": true,
    "name": "oidc",
    "api_id": "32625081-c712-4c46-b16a-5d6d9081f85f"
}

Upstream API request

The plugin adds a additional X-Userinfo, X-Access-Token and X-Id-Token headers to the upstream request, which can be consumer by upstream server. All of them are base64 encoded:

GET / HTTP/1.1
Host: netcat:9000
Connection: keep-alive
X-Forwarded-For: 172.19.0.1
X-Forwarded-Proto: http
X-Forwarded-Host: localhost
X-Forwarded-Port: 8000
X-Real-IP: 172.19.0.1
Cache-Control: max-age=0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
Upgrade-Insecure-Requests: 1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4
Cookie: session=KOn1am4mhQLKazlCA.....
X-Userinfo: eyJnaXZlbl9uYW1lIjoixITEmMWaw5PFgcW7xbnEhiIsInN1YiI6ImM4NThiYzAxLTBiM2ItNDQzNy1hMGVlLWE1ZTY0ODkwMDE5ZCIsInByZWZlcnJlZF91c2VybmFtZSI6ImFkbWluIiwibmFtZSI6IsSExJjFmsOTxYHFu8W5xIYiLCJ1c2VybmFtZSI6ImFkbWluIiwiaWQiOiJjODU4YmMwMS0wYjNiLTQ0MzctYTBlZS1hNWU2NDg5MDAxOWQifQ==
X-Access-Token: eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJGenFSY0N1Ry13dzlrQUJBVng1ZG9sT2ZwTFhBNWZiRGFlVDRiemtnSzZRIn0.eyJqdGkiOiIxYjhmYzlkMC1jMjlmLTQwY2ItYWM4OC1kNzMyY2FkODcxY2IiLCJleHAiOjE1NDg1MTA4MjksIm5iZiI6MCwiaWF0IjoxNTQ4NTEwNzY5LCJpc3MiOiJodHRwOi8vMTkyLjE2OC4wLjk6ODA4MC9hdXRoL3JlYWxtcy9tYXN0ZXIiLCJhdWQiOlsibWFzdGVyLXJlYWxtIiwiYWNjb3VudCJdLCJzdWIiOiJhNmE3OGQ5MS01NDk0LTRjZTMtOTU1NS04NzhhMTg1Y2E0YjkiLCJ0eXAiOiJCZWFyZXI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zM0Y2JiNTk2Iiwic3ViIjoiYTZhNzhkOTEtNTQ5NC00Y2UzLTk1NTUtODc4YTE4NWNhNGI5IiwidHlwIjoiSUQifQ==

Development

Running Unit Tests

To run unit tests, run the following command:

./bin/run-unit-tests.sh

This may take a while for the first run, as the docker image will need to be built, but subsequent runs will be quick.

Building the Integration Test Environment

To build the integration environment (Kong with the oidc plugin enabled, and Keycloak as the OIDC Provider), you will first need to find your computer's IP, and assign that to the environment variable IP. Finally, you will run the ./bin/build-env.sh command. Here's an example:

export IP=192.168.0.1
./bin/build-env.sh

To tear the environment down:

./bin/teardown-env.sh

More Repositories

1

danm

TelCo grade network management in a Kubernetes cluster
Go
374
star
2

RED

RED - Robot Editor
Java
343
star
3

TPMCourse

Dockerfile
141
star
4

CloudFlow

A workflow visualization tool for OpenStack Mistral (https://github.com/openstack/mistral)
TypeScript
94
star
5

CPU-Pooler

A Device Plugin for Kubernetes, which exposes the CPU cores as consumable Devices to the Kubernetes scheduler.
Go
92
star
6

awkcc

C
81
star
7

ntt

Modern tools for TTCN-3
Go
68
star
8

srlinux-container-image

Freely distributed official SR Linux container image
Shell
61
star
9

twampy

Python tools for TWAMP and TWAMP light (STAMP)
Python
59
star
10

moler

Moler – library to help build automated tests
Python
58
star
11

7x50_YangModels

49
star
12

ts-serialize-closures

TypeScript Serialization module
TypeScript
44
star
13

wireless-suite

Python
40
star
14

akka-typed-persistence

Event sourcing for Akka Typed
Scala
40
star
15

pysros

Python
40
star
16

ansible-networking-collections

Python
39
star
17

adcs-issuer

Go
39
star
18

code-compass

a contextual search engine for software packages built on import2vec embeddings (https://www.code-compass.com)
Jupyter Notebook
38
star
19

SReXperts

Python
38
star
20

Avro-Schema-Generator

Tool which generates Avro schemas and Java bindings from XML schemas.
Java
37
star
21

robotframework-autoitlibrary

Python
33
star
22

codesearch

Models and datasets for annotated code search.
Jupyter Notebook
33
star
23

ClickNF

C++
30
star
24

consumer-rate-limiting

A consumer rate limiting plugin for Kong (https://getkong.org/)
Lua
30
star
25

pygnmi

Python tools for gNMI
Python
26
star
26

SROS-grpc-services

SROS grpc services
Python
23
star
27

atom-netconf

NETCONF package for the ATOM Editor
CoffeeScript
22
star
28

5g-network-emulator

C++
22
star
29

intel-nuc-router

Scripts to configure an Intel NUC to act as a router
Shell
22
star
30

AttestationEngine

An experimental (but fully functional) Remote Attestation Engine and Applications for TPM2.0 based systems (cloud, edge, IoT etc)
Go
21
star
31

mesos-scala-api

Scala API for Mesos
Scala
21
star
32

etcd-cpp-api

C++ API for etcd
C++
21
star
33

skilltree

A tool to build and share visualised skill-trees
JavaScript
19
star
34

vscode-netconf

TypeScript
18
star
35

LogGPT

Python
18
star
36

jspy

Tool which displays the component properties of any java Swing application.
Java
17
star
37

k8s-ipam

Go
17
star
38

vault_keystone_plugin

A Keystone secret plugin for Vault (https://www.vaultproject.io/)
Go
16
star
39

PyVenvManage

PyVenvManage is a plugin for managing the Python interpreter of Pycharm Projects
Java
16
star
40

minifold

Minifold is a Python module able to interact with various data sources (e.g. CSV, LDAP, SQL, twitter, etc.) and to query/combine/aggregate them with database-like operators.
Python
16
star
41

restful

A powerful RESTful framework for Go.
Go
15
star
42

cppJNI

A C++-Java communication framework, which aim to simplify usage of Java code in C++ code.
C++
15
star
43

git-changelog-generator

Git Changelog Generator
Python
14
star
44

nsp-workflow

Jinja
14
star
45

srlinux-yang-models

Shell
13
star
46

gitcache-ssh

Simple SSH based Git cache
Go
12
star
47

time-series-data-collector

Time series data collector / exporter
Java
12
star
48

vscode-ttcn3

An extension for VS Code which provides support for the TTCN-3 language.
TypeScript
12
star
49

nokia-deployer

Python
11
star
50

web-assembly-self-certifying-compilation-framework

OCaml
10
star
51

OSSMediator

Go
10
star
52

BYONND

Build Your Own Neural Network Design
TypeScript
10
star
53

wiredis

A C++ client for Redis (https://redis.io/)
C++
10
star
54

ncm-issuer

cert-manager extension for integration with Nokia NetGuard Certificate Manager
Go
10
star
55

koredump

REST API for accessing coredumps in Kubernetes cluster.
Python
9
star
56

NCBounds

Python
8
star
57

saltstack-formulas

Saltstack states for various components
SaltStack
8
star
58

PyBGL

PyBGL is a python module allowing to manipulate graphs and common algorithms.
Python
8
star
59

rcm-bluez

Remote Connection Manager (RCM) for Bluetooth
C
8
star
60

unixgame-challenges

Python
8
star
61

7x50_protobufs

8
star
62

sros-ansible

8
star
63

ONAP-VESPA

VESPA: VES-Prometheus Adapter for ONAP
Go
7
star
64

YangModels

7
star
65

samtools

Python tools for the SAM-O interface (NBI for Nokia NSP)
Python
7
star
66

srlinux-ansible-collection

Jinja
7
star
67

causal-digital-twin

Jupyter Notebook
7
star
68

containerd-bench-security

Shell
7
star
69

corteca-cli

Go
7
star
70

regexp-learner

A python module allowing to learn patterns by issuing queries and learning from counter examples.
Python
7
star
71

danm-utils

Go
6
star
72

nlc2cmd-submission-hubris

Jupyter Notebook
6
star
73

networkexposure

6
star
74

netconf-examples

6
star
75

vscode-workflow-manager

TypeScript
6
star
76

pandas-extras

Extension package for the popular Pandas library
Python
5
star
77

radish-bdd-extensions

Python
5
star
78

dynamic-local-pv-provisioner

Go
5
star
79

LearningStore

An application to manage trainings
JavaScript
5
star
80

industrial-application-framework

Go
5
star
81

subcarrier-power-allocation-noma-solver

Python
5
star
82

armadillo-with-fixed-point-support

C++
5
star
83

argocd-krm-plugin-examples

Smarty
5
star
84

Augustus

C
5
star
85

SliM

SliM is a system for efficient NFV state transfers using a statelet interface that we have implemented as an add-on to the Data Plane Development Kit (DPDK), a high-performance packet I/O library. We have evaluated SliM in a testbed and present results that show its benefits in terms of lower delays and lower packet-loss rates.
C
5
star
86

corteca-toolchain

Dockerfile
5
star
87

integratedimputation

Python
4
star
88

ue-nib-library

A library that works together with Nokia’s UEEC xApp
Go
4
star
89

domino-library

Reuse-lib of C++
C++
4
star
90

protobufs

4
star
91

genIndustrialNetTraffic

Python
4
star
92

sonic-platform

Python
4
star
93

crl-remotescript

Library for remote shell commands, SCP, SFTP and Telnet.
Python
4
star
94

clocktick_jumps

A program that detects sudden jumps in different clocks to detect platform latencies
C
4
star
95

ldap-tgen

An LDAP (Lightweight Directory Access Protocol) traffic generator. It can be used for ldap server load testing.
C
4
star
96

NSP-Integration-Bootstrap

Nokia Network Service Platform (NSP) APIs are now exposed and public on nsp.developer.nokia.com . This project gives users, customers and partners a place to start. It provides them with starting sample code and client libraries that they can use to quickly start calling NSP APIs.
Python
4
star
97

vscode-intent-manager

JavaScript
4
star
98

srlinux-ndk-go

Shell
3
star
99

crl-interactivesessions

This project contains collection of pexpect based Robot Framework test libraries.
Python
3
star
100

ECG-PPG-integrated-electronic-stethoscope

C
3
star