Oussama Elkhdadi
Oussama Elkhdadi

Reputation: 113

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.

Upvotes: 7

Views: 10462

Answers (3)

Tieske
Tieske

Reputation: 406

you can generate a new docker image containing the plugin using https://github.com/Kong/docker-kong/tree/master/customize

See the example (https://github.com/Kong/docker-kong/blob/master/customize/example.sh) on how to do this without having the source code publicly available on LuaRocks.

Upvotes: 2

Muizz Mahdy
Muizz Mahdy

Reputation: 808

I suggest using this repository's example for building a Kong docker image with your custom plugin.

Upvotes: 1

HyunDeok Choi
HyunDeok Choi

Reputation: 96

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.

Upvotes: 8

Related Questions