Creating and Installing Custom Lua Plugins in Kong

Get up and running with custom Kong plugins in minutes.

Andrew Scott
Jan 13, 2020 · 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 +756K people. Follow to join our community.

Andrew Scott

Written by

Founder @OchronaSec | PANW, ex Expanse, ex Tenable | DevSecOps | Automation | All views are my own... and awesome

The Startup

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

Andrew Scott

Written by

Founder @OchronaSec | PANW, ex Expanse, ex Tenable | DevSecOps | Automation | All views are my own... and awesome

The Startup

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

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

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