It wasn’t stolen with brute force. It wasn’t a zero-day. It was sitting in plain sight, committed to a public repo, tied to a service account with full production access. The postmortem was simple: the wrong people had the wrong permissions for the wrong amount of time.
API tokens and service accounts are the invisible keys to everything. They don’t get tired. They don’t change jobs. They don’t forget to log out. They connect services to each other without a human in the loop. This power makes them the riskiest part of your infrastructure when not handled with care.
A service account exists to let code act like a user. It might trigger builds, deploy a new release, run a database migration, or sync data. The account is only as safe as the token attached to it. Once that token is exposed, whoever has it can act as the service — without limits. That’s why best practices for API tokens and service accounts are not optional.
The first rule is scoping. Grant the smallest set of permissions to each service account. If a token only needs read access to one S3 bucket and nowhere else, anything more is fuel for future breaches. The second rule is rotation. Tokens should expire on their own. No token should exist forever. A short lifespan turns a disaster into a minor incident.