Blog
  • AI Gateway
  • AI Security
  • AIOps
  • API Security
  • API Gateway
    • API Management
    • API Development
    • API Design
    • Automation
    • Service Mesh
    • Insomnia
    • View All Blogs
  1. Home
  2. Blog
  3. Enterprise
  4. Simplifying PCI Compliance With Kong Gateway
Enterprise
June 9, 2021
5 min read

Simplifying PCI Compliance With Kong Gateway

Amit Mahbubani
Topics
API GatewayKong Gateway
Share on Social

More on this topic

eBooks

Maturity Model for API Management

eBooks

Federated API Management: Accelerating Innovation with Autonomy and Oversight

See Kong in action

Accelerate deployments, reduce vulnerabilities, and gain real-time visibility. 

Get a Demo

Razorpay is a payments processor that's required to comply with PCI guidelines. This article will explain how we developed a custom Lua plugin to simplify PCI compliance with Kong Gateway.

PCI Compliance: A Quick Overview

The Payment Card Industry Data Security Standard (PCI-DSS) is a set of requirements to ensure that all companies that process, store or transmit card information maintain a secure environment. Every system component that processes, stores or transmits such information comes under the PCI system scope. Such companies are required to undergo annual audits where the system under scope is reviewed and certified.

Companies adhering to PCI-DSS requirements need to design secure and compliant systems that are easy to audit and develop on. A key consideration in these designs would be to limit the scope of the systems that come under PCI scope.

Leveraging Kong for the Ideal PCI Compliant Architecture

If your systems need to work with credit card information, an ideal architecture with PCI compliance in mind would be exposing a minimal number of system components to this information in its raw form. Here's an example of what that would look like with Kong:

Kong Gateway PCI handler plugin architecture


The diagram above shows that the components exposed to card data are limited to Kong itself and a tokenization service. Microservices upstream receive a tokenized version of the card data and are hence out of PCI scope. Other upstream services that need to access raw card information, such as those that communicate with third-party payment gateway APIs, can do so by exchanging the token on the tokenizer. By accessing card data, these services are also brought under PCI scope. Let's break this down.

The Tokenization Service

This service replaces sensitive card information with a unique, randomly generated identifier called a token. The system can then pass this token onto upstream services without exposing card data. The tokenization service itself is out of the scope of this article. It's enough to think of it as an abstraction that provides two operations: tokenize and detokenize. In production environments, this service needs to be highly secure and PCI compliant itself. At Razorpay, we use Hashicorp's Vault for this purpose.

The PCI Handler Plugin

The plugin is a new custom Kong plugin that you would need to enable on API routes that accept card data. Its key functions are:

1. Payload Introspection – A request payload may not always have card data. The plugin will first introspect incoming request payloads to determine whether card data is present and if further action is required. Payload attribute details are available as plugin configuration.

2. Validation – This is the basic input validation of the card attributes in the payload.

3. Handle Tokenization – The system makes an API request to the tokenization service with card attributes. Then, it captures the token response.

Payload Transformation – The plugin transforms the request payload to replace the sensitive card attributes with the token. The new attribute is a plugin configuration.

Configuring Kong

1. Installing Kong

Install a basic version of Kong by following the guide for your system. Alternatively, you can clone our template starter repo, which is what we're doing next.

Note: this works with Docker.

This makes Kong Admin APIs available on 127.0.0.1:8001, whereas the service APIs are accessible on 127.0.0.1:8000. Verify if everything's up and running: curl -i http://127.0.0.1:8001/status.

2. Create the PCI Handler Plugin

You can write Kong plugins in Lua, Go or JavaScript. It's easy to create custom plugins with Kong's plugin development kit (PDK). Let's create a lightweight version of the pci-handler plugin with Lua:

The below snippet shows the general layout of a plugin that works with the access phase.

You can find the whole source code for this plugin here. You should store plugin files in a new directory under path – <path-to-project>/kong-plugins/pci-handler/…

Note: this is for demonstration purposes only, not intended for production use.

2. Enable and Attach the Plugin on Kong

The plugin can be attached to Kong by editing the kong.conf config file.

1. Add the plugin path to the lua_package_path key

2. Add the plugin name to the "plugins" list: plugins = bundled,pci-handler

3. Reload kong for changes to take effect. If you're using the kong-template starter kit, you can do this by running the following command: docker-compose exec kong kong reload

3. Set Up the Tokenization and Upstream Services

Given below are two snippets to set up sample tokenization and upstream services with NodeJs.

kong-services/tokenizer/index.js:

kong-services/upstream-example/index.js:

With the above setup, we now have these microservices running:

1. "Tokenizer" service, on port 8885

2. "upstream-example" service, on port 8881

4. Define Service and Routes, and Enable the Plugin

Define the upstream-example service on Kong:

1. Create the service

2. Define a route, attached to the service

3. Attach the plugin

5. Get This All Running

Let's hit the /payments endpoint on the upstream-example service via Kong:

You should see a response as follows.

We see in the response above that the upstream-service simply responded with the request body that it had received. In this case, the card attributes were replaced with a card_token attribute, meaning our pci-handler plugin is working as expected!

You can find all the above code for Kong, the plugin and sample services packaged into one Github repo here.

Fast, Scalable and Secure With Kong

Designing systems that work well with PCI-DSS is not trivial but is important to get right. With the rapid adoption of microservices taking place, delegating such mission-critical components to the API gateway makes a lot of sense. Kong's plugin architecture allowed us to significantly reduce our PCI scope, thereby increasing security and agility.

If you'd like a more in-depth look at some of the things you can build, check out the Plugin Development Guide in Kong's documentation and these resources:

  • The Kong Plugin Development Kit documentation
  • An excellent introduction to Lua
  • Pongo, the Kong plugin test tool
  • A plugin-template to clone
  • The Kong open source plugins and their tests to use as examples

If you have questions or comments, tweet us @RazorpayEngg!

To stay in touch, join the Kong Community.

Once you've successfully set up a custom Lua plugin, you may find these other tutorials helpful:

  • Protecting Services With Kong Gateway Rate Limiting
  • Kong Configurations Using Terraform via GitOps Model
  • Getting Started With Kong Konnect in 10 Minutes

Topics
API GatewayKong Gateway
Share on Social
Amit Mahbubani

Recommended posts

You Might Be Doing API-First Wrong, New Analyst Research Suggests

Kong Logo
EnterpriseSeptember 3, 2025

Ever feel like you're fighting an uphill battle with your API strategy? You're building APIs faster than ever, but somehow everything feels harder. Wasn’t  API-first  supposed to make all this easier?  Well, you're not alone. And now industry analys

Heather Halenbeck

Announcing terraform-provider-konnect v3

Kong Logo
Product ReleasesAugust 22, 2025

It’s been almost a year since we released our  Konnect Terraform provider . In that time we’ve seen over 300,000 installs, have 1.7 times as many resources available, and have expanded the provider to include data sources to enable federated managem

Michael Heap

How to Build a Multi-LLM AI Agent with Kong AI Gateway and LangGraph

Kong Logo
EngineeringJuly 31, 2025

In the last two parts of this series, we discussed How to Strengthen a ReAct AI Agent with Kong AI Gateway and How to Build a Single-LLM AI Agent with Kong AI Gateway and LangGraph . In this third and final part, we're going to evolve the AI Agen

Claudio Acquaviva

72% Say Enterprise GenAI Spending Going Up in 2025, Study Finds

Kong Logo
EnterpriseJune 18, 2025

Survey Says: Google LLMs See Usage Surge, Most OK with DeepSeek in the Workplace Enterprise adoption of large language models (LLMs) is surging. According to Gartner , more than 80% of enterprises will have deployed generative AI (GenAI) applicatio

Eric Pulsifer

5 Steps to Immediately Reduce Kafka Cost and Complexity

Kong Logo
EnterpriseJune 24, 2025

Kafka delivers massive value for real-time businesses — but that value comes at a cost. As usage grows, so does complexity: more clusters, more topics, more partitions, more ACLs, more custom tooling. But it doesn’t have to be that way. If your tea

Umair Waheed

Is Ambient Mesh the Future of Service Mesh?

Kong Logo
EnterpriseJune 30, 2025

A Practical Look at When (and When Not) to Use Ambient Mesh The word on the street is that ambient mesh is the obvious evolution of service mesh technology — leaner, simpler, and less resource-intensive. But while ambient mesh is an exciting develop

Umair Waheed

How to Create a Platform Cross-Charging Model (and Why Not To Do It)

Kong Logo
EnterpriseMay 2, 2025

I'm commonly asked by customers for advice on how they can build a good platform cross-charging model for their organization. And my gut reaction is nearly always "don't." We'll come back to why I think that later, but first let's look at what cross

Steve Roberts

Ready to see Kong in action?

Get a personalized walkthrough of Kong's platform tailored to your architecture, use cases, and scale requirements.

Get a Demo
Powering the API world

Increase developer productivity, security, and performance at scale with the unified platform for API management, AI gateways, service mesh, and ingress controller.

Sign up for Kong newsletter

Platform
Kong KonnectKong GatewayKong AI GatewayKong InsomniaDeveloper PortalGateway ManagerCloud GatewayGet a Demo
Explore More
Open Banking API SolutionsAPI Governance SolutionsIstio API Gateway IntegrationKubernetes API ManagementAPI Gateway: Build vs BuyKong vs PostmanKong vs MuleSoftKong vs Apigee
Documentation
Kong Konnect DocsKong Gateway DocsKong Mesh DocsKong AI GatewayKong Insomnia DocsKong Plugin Hub
Open Source
Kong GatewayKumaInsomniaKong Community
Company
About KongCustomersCareersPressEventsContactPricing
  • Terms•
  • Privacy•
  • Trust and Compliance•
  • © Kong Inc. 2025