Documentation Index
Fetch the complete documentation index at: https://kosli-mintlify-rotate-api-keys-tutorial.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Introduction
Rotating API keys regularly is a security best practice that limits the blast radius of a leaked or compromised credential. This tutorial walks you through rotating a Kosli service account API key with zero downtime, using either the Kosli web app or the API directly.Prerequisites
- A Kosli shared organization with at least one service account and an existing API key.
- Administrator access to the organization that owns the service account.
- An inventory of every system (CI pipelines, runtime reporters, scripts, secrets managers, etc.) that uses the API key you plan to rotate.
How rotation works
When you rotate a service account API key, Kosli:- Generates a new API key immediately and returns its value once.
- Keeps the old key valid for a configurable grace period (default: 24 hours).
- Automatically revokes the old key when the grace period expires.
Rotate a key from the Kosli web app
- Log in to Kosli and select the organization that owns the service account.
- Go to Settings → Service accounts in the left navigation.
- Open the service account whose key you want to rotate.
- Find the key in the API Keys list and click Rotate.
- Choose a grace period for the old key, then confirm.
- Copy the new key value immediately and store it in your secrets manager — it will not be shown again.
Rotate a key via the API
You can also rotate keys programmatically, which is useful for automating periodic rotation from your CI or a secrets manager.Roll the new key out
While the old key is still valid, update every consumer to use the new key:- CI/CD pipelines: Update the
KOSLI_API_TOKENsecret in GitHub Actions, GitLab CI, Jenkins, CircleCI, etc. - Runtime reporters: Update Kubernetes secrets used by the Kosli Kubernetes reporter, and roll the relevant pods.
- Local config files: Update any Kosli CLI config files that hard-code the token.
- Secrets managers: Update the value in AWS Secrets Manager, HashiCorp Vault, GCP Secret Manager, Azure Key Vault, or wherever you store the token.
Verify the old key is decommissioned
Once every consumer is on the new key, you can either wait for the grace period to elapse or revoke the old key immediately:Recommended rotation cadence
- Service accounts: rotate at least every 90 days, and immediately if you suspect a leak.
- After offboarding: rotate any key an offboarded user could have accessed.
- After incidents: rotate any key potentially exposed by a security incident, regardless of cadence.