How to Catch Stolen API Keys with Honey Tokens
Stolen keys usually go unnoticed until the damage is done. See how to plant a decoy AWS credential next to your real secrets in Infisical, use it the way an attacker would, and get the alert that tells you exactly what to rotate.
Looking to improve your secret management processes?Talk to an expert
How to Catch Stolen API Keys with Honey Tokens
When API keys get stolen, it usually goes unnoticed. The attacker copies the keys out of your stack and starts using them, and nothing tells you that someone who should not have those keys is making calls with them. You find out later, from a security advisory, a cloud bill, or a customer, long after the keys were taken.
A honey token closes that gap. It is a fake credential planted right next to your real ones. Nothing in your stack uses it, so the first time anyone does, you know an attacker has your secrets. Infisical now has honey tokens built in, and on Infisical Cloud you do not even have to connect an AWS account to create one.
Why credential theft is the attack to plan for
Many of the biggest attacks this year were credential harvesting attacks, and they followed the same shape.
In March, someone took over the npm account of the lead maintainer of Axios, one of the most downloaded packages on npm, and published two malicious versions. On install, the package swept the machine for SSH keys, AWS, GCP, and Azure credentials, Kubernetes configs, and `.env` files.
In November, two malicious versions of Microsoft's agent-framework package landed on PyPI. They ran a credential stealer that pulled Azure, AWS, GCP, and other secrets out of environment variables and config files while the framework kept working normally.
The same month, attackers used thousands of hijacked GitHub accounts to open pull requests against tens of thousands of repositories, pulling credentials out of CI pipelines along the way.
In each case the attacker got real keys, and the owners of those keys found out much later.
Rotation is the response, not the detection
If a key leaks, rotating it is the right move, and centralizing secrets in a secrets manager is what makes automated rotation practical. But rotation is something you do after you know you have been hit. If you do not know, the stolen key keeps working until the next scheduled rotation.
A honey token tells you that an attacker has stolen and used your keys, so you can rotate right away instead of weeks later.
How Infisical-managed honey tokens work
Infisical creates a fake IAM user in an AWS account, then creates an access key for that user. That key pair is what lets someone make calls to AWS as that user. The user gets zero permissions. It cannot read, create, or delete anything.
Infisical then stores that access key as secrets in your project, right next to your real secrets, under the same names you would normally give AWS credentials. When someone uses the keys, AWS rejects the call because the user has no permissions. But AWS still logs the attempt, and Infisical watches that log.
On Infisical Cloud, these fake users live in an AWS account that Infisical manages for you, so there is no connection to create and nothing to deploy. If you would rather use your own AWS account, you create an AWS connection and manage the decoy users yourself. That is a one-time setup an organization admin does once.
Creating a honey token
Start in the environment and folder that holds the secrets your application actually uses, in this case production. Add a new honey token, pick the environment, and choose the Infisical-managed AWS account.
Next you choose the names for the decoy credentials. The defaults are `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`, which is exactly what real AWS credentials are called. Anyone sifting through the project would have no way to tell these apart from live keys.
Then give the honey token a name and description. Only you and your team see these. Finally, decide who gets alerted when the token is triggered. For a test, one email address is enough. In practice you would add every org admin, or route the alert to Slack, a webhook, or PagerDuty. The usage doc covers the alert options.
Once created, the decoy keys are ordinary secrets in that folder. That matters for one reason: they go wherever the folder goes. If you sync the folder out to GitHub Actions, AWS Parameter Store, or a Kubernetes cluster, the honey token is synced out too. If someone steals the secrets from any of those places, they steal the tripwire with them.
Triggering it like an attacker would
The first thing an attacker usually does with a stolen AWS key is check whose it is. GetCallerIdentity needs no permissions at all, so the call succeeds even for a user with none.
Run it with the decoy keys and the honey token fires. The alert email arrives marked critical and includes the provider, the environment and secret path, the action that was called, the source IP, the AWS region, and the event time. Back in the Infisical dashboard, the honey token shows as triggered.
Managing alerts and events
Infisical sends one email per honey token every 24 hours, so an attacker hammering the key does not flood your inbox. The honey token's detail view lists every individual event regardless, so you can see the full sequence of calls.
If the trigger turns out to be a teammate testing something, reset the honey token and it goes back to active. If it was real, you already know which folder the attacker reached, because the decoy sits beside the production secrets. That tells you exactly what to rotate.
When you are done with a honey token, revoke it. Deleting it removes the IAM user and the access key from AWS.
Where to put them
Put one honey token in every environment, in every folder that has credentials worth stealing. The first time someone uses a key taken from one of those places, you get an alert, and you know what to rotate.
For a longer walkthrough of the feature when it first shipped, including the self-managed AWS setup, see the earlier honey tokens video.
Starting with Infisical is simple, fast, and free.