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.
3 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:
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.

- 3,461
- 1
- 16
- 38

- 96
- 1
- 3
-
How are you running the `luarocks` command directly within the Docker container? I get tons of permissions errors that prevent me from installing a luarock after `exec`ing into the container – bananabrann Mar 23 '20 at 19:28
-
looks like it's outdated since kong 2.0 – Ali Ghanavatian May 30 '20 at 07:48
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.

- 363
- 3
- 10
-
This assumes that the plugins are on LuaRocks, which might not be the case for custom plugins. – Muizz Mahdy Jan 04 '21 at 21:27
-
1@MuizzMahdy No. See the readme for "Curated list of plugins", if you provide only the sources packed as a rock, it can create a local LuaRocks server, and there is need to make your code public. – Tieske Jan 05 '21 at 22:19
I suggest using this repository's example for building a Kong docker image with your custom plugin.

- 798
- 2
- 8
- 24