HMAC Authentication
Overview
HMAC (Hash-based Message Authentication Code) authentication ensures secure API access by verifying the integrity and authenticity of requests.
- Uses cryptographic hashing to validate request headers and payloads.
- Requires clients to include a signature generated with a shared secret.
- Protects against tampering and replay attacks.
Flow of authentication:
- Client generates an HMAC signature using a shared secret.
- Signature and additional headers are sent with the API request.
- Kong verifies the signature and processes the request if valid.
Lab Environment
This lab tests a Kong API Gateway deployment using a FastAPI endpoint. To simplify, both the containerized Kong API Gateway and the FastAPI endpoint are installed locally on a Windows 10 machine. A Docker Compose file is used to deploy Kong, along with other applications like Prometheus, Zipkin, the ELK Stack, and more.
Make sure that you have installed Docker Desktop.
Simply installing Docker in WSL2 without Docker Desktop may introduce some issue when configuring the communication between the containerized Kong API Gateway and the FastAPI application that is installed on the local host.
Pre-requisites
- Postman
- Setup the Kong API Gateway
- Setup the FastAPI Endpoint
- Kong Manager OSS Access
- Create the Routes and Services
- Create the Consumer
Enable the HMAC Auth Plugin
To enable the plugin, go to Kong Manager > Plugins > New Plugin > Select HMAC Authentication.

Set this plugin as a global plugin and enable the Validate Request Body option.
Under Advanced parameters, enter the following details. Click Save afterwards.
| Field | Value |
|---|---|
| Instance Name | hmac-authentication |
| Algorithms | hmac-sha256 |
| Clock Skew | 3600 |
Under Enforce Headers, add the following:
datedummy
It should now appear in the plugin list.

Conflicting Global Authentication Methods
When enabling authentication plugins, make sure that only one is enabled globally. This is because when two plugins are globally enabled, any consumer request must satify both authentication methods. To make it granular, you can also configure the each plugin to be Scoped and specify the specific service or routes that will be using it. This is a better way to ensure that gateway services won't be trying all global plugins.
Order of Execution:
- Kong evaluates all enabled authentication plugins for a request.
- If multiple plugins are enabled, each plugin checks its respective credentials in the request.
- If any authentication method fails, Kong denies the request with a
401 Unauthorizederror.