Creating and Installing Custom Lua Plugins in Kong

Get up and running with custom Kong plugins in minutes.

Andrew Scott
Jan 13 · 8 min read
Image for post
Image for post
Based on photo by Boudewijn Huysmans on Unsplash

What is Kong?

Image for post
Image for post
An overly-simplified API Gateway Diagram
Image for post
Image for post

Kong Plugins

Writing a Custom Plugin

<plugin-name>
├── kong
│ └── plugins
│ └── <plugin-name>
│ ├── handler.lua
│ └── schema.lua
└── <plugin-name>-<version>.rockspec

handler.lua

schema.lua

<plugin_name>-<version>.rockspec

Running Kong

Dockerfile

docker-compose.yml

Other Scripts and Configs

Our Custom Plugin

handler.lua

schema.lua

header_filter.lua

hide-token-1.0.0.rockspec

Installing the Plugin

Testing

Image for post
Image for post
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< Content-Length: 17
< Connection: keep-alive
< X-Powered-By: Express
< SECRET-TOKEN: MUH SECRETZ
< NOT-SO-SECRET: abc123
< ETag: W/"11-xthkVpV/BvEyfleURt8wQpCqVD8"
< Date: Sun, 12 Jan 2020 16:52:20 GMT
< X-Kong-Upstream-Latency: 1528
< X-Kong-Proxy-Latency: 11
< Via: kong/1.4.3
<
* Connection #0 to host 0.0.0.0 left intact
{"status":"A-OK"}
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< Content-Length: 17
< Connection: keep-alive
< X-Powered-By: Express
< NOT-SO-SECRET: abc123
< ETag: W/"11-xthkVpV/BvEyfleURt8wQpCqVD8"
< Date: Sun, 12 Jan 2020 16:54:07 GMT
< X-Kong-Upstream-Latency: 2322
< X-Kong-Proxy-Latency: 14
< Via: kong/1.4.3
<
* Connection #0 to host 0.0.0.0 left intact
{"status":"A-OK"}

Conclusion


The Startup

Medium's largest active publication, followed by +707K people. Follow to join our community.

Andrew Scott

Written by

Engineer @Expanseinc, ex @TenableSecurity | Founder @OchronaSec | DevSecOps | Automation | All views are my own.. and awesome

The Startup

Medium's largest active publication, followed by +707K people. Follow to join our community.

Andrew Scott

Written by

Engineer @Expanseinc, ex @TenableSecurity | Founder @OchronaSec | DevSecOps | Automation | All views are my own.. and awesome

The Startup

Medium's largest active publication, followed by +707K people. Follow to join our community.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store