Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add a customized kong plugin into dockerized kong

I have a KONG container running and I want to add a customized plugin to it, specifically a JWT crafter. I've downloaded the plugin but I don't know how to make it start with my KONG container. so please if anyone have been into the same position or know any route to follow, it will be very helpful.

like image 961
Oussama Elkhdadi Avatar asked May 17 '18 12:05

Oussama Elkhdadi


People also ask

What is plugin in Kong?

Kong Gateway is a Lua application designed to load and execute Lua or Go modules, which we commonly refer to as plugins.

What is a docker plugin?

A plugin is a process running on the same or a different host as the docker daemon, which registers itself by placing a file on the same docker host in one of the plugin directories described in Plugin discovery. Plugins have human-readable names, which are short, lowercase strings.


1 Answers

I tried to do same thing but could not found well-describe answer yet. You can configure simple helloworld plugin as below: (https://github.com/brndmg/kong-plugin-hello-world)

Local 'plugin' directory structure on Docker host:

plugin directory structure

Then you can mount local /plugins directory and let kong load custom 'helloworld' plugin from /plugins directory

1) using environment variables

$ docker run -d --name kong --network=kong-net \
-e "KONG_DATABASE=cassandra" \
-e "KONG_PG_HOST=kong-database" \ 
-e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \
**-e "KONG_LUA_PACKAGE_PATH=/plugins/?.lua" \
-e "KONG_CUSTOM_PLUGINS=helloworld" \ ** 
...
-e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" \
**-v "/plugins:/plugins" \**
-p 8080:8000 -p 8443:8443 -p 8001:8001 -p 8444:8444 kong:latest

Then, you can see configured custom plugin on http://[kong-url]:8001/

..
"custom_plugins": [
"helloworld"
],
..

2) Or, you can simple mount your custom kong.conf file which describes plugins you want.

/etc/kong/kong.conf

plugins = bundled,helloworld,jwt-crafter

(It seems that second option is better for latest version of Kong because 'kong_custom_plugin' configuration prints 'deprecation' warning)

For the JWT crafter, https://github.com/foodora/kong-plugin-jwt-crafter it seems that the plugin is not maintained well so that installation using luarocks failed with errors.

$ luarocks install kong-plugin-jwt-crafter
....
kong-plugin-jwt-crafter 1.0-0 depends on lua-resty-jwt ~> 0.1.10-1 (not installed)

Error: Could not satisfy dependency lua-resty-jwt ~> 0.1.10-1: No results matching query were found.

Instead, you can directly to add 'resty-jwt' to official docker image, to resolve dependency, which is not included in official image. and copy "JWT crafter" into "/plugins" directory, and load.

(Inside docker container)

 luarocks install lua-resty-jwt

Hope this helps.

like image 200
HyunDeok Choi Avatar answered Oct 06 '22 01:10

HyunDeok Choi