Keeper Security is a cybersecurity company that provides an identity security platform for humans, machines and AI agents. Built on a zero-trust and zero-knowledge architecture, Keeper
To securely manage API keys, store secret keys in an encrypted secrets manager and restrict retrieval to authorized people and applications. Keep secret keys out of source code and publicly distributed applications, use separate keys for each application and environment and grant only the API permissions each integration needs. Establish rotation and expiration procedures based on the provider’s capabilities, monitor API usage for unusual activity and prepare to revoke exposed keys promptly at the issuing service.
Exposed API keys can enable unauthorized data access, data changes or unexpected usage charges, depending on their permissions. Encryption helps protect stored keys, but access controls and protections for the systems that retrieve and use them are also necessary. Least-privilege permissions limit what an attacker can do with a stolen key. Usage monitoring and prompt revocation help teams detect misuse and stop further use of compromised credentials.
How API keys get exposed and exploited
An API key is a unique identifier that may identify a caller or authenticate requests to an API, depending on how the service uses it. This guide focuses on secret API credentials that should remain confidential.
GitHub reported that more than 39 million secrets were leaked across its platform in 2024. That total covers secrets broadly, including API keys and tokens. Organizations should review where these credentials are stored, who can retrieve them and how quickly exposed credentials can be revoked.
How API keys become exposed
Keys embedded in source code or configuration files can spread through repository commits, code reviews and copied files. Plaintext messages, shared documents and debugging logs create additional exposure routes. Secret keys packaged inside browser or mobile applications may also be accessible to people analyzing those applications.
Keys can also be stolen from the systems that store or use them. In its January 2023 incident report, CircleCI described how an attacker stole an employee’s authenticated SSO session, accessed production systems and exfiltrated customer environment variables, tokens and keys.
How attackers exploit exposed API keys
An attacker who obtains a valid key may be able to send requests within its authorized scope. A key that permits customer-record retrieval could expose personal information; one with write permissions could allow unauthorized changes. Misuse of a metered API can also generate unexpected charges. The key’s permissions and the API’s other access controls determine what is possible.
AWS reported a strong correlation between ransomware activity against Amazon S3 objects in November and December 2024 and exposed customer-managed IAM keys. Organizations need to reduce exposure and limit what a compromised key can do. For broader weaknesses in API authentication and authorization, see our guide that explains what API vulnerabilities are.
Eight ways to securely manage API keys
A storage decision alone will not account for a departing employee or an application update. Build these practices into the key’s lifecycle, from issuance to retirement.
1. Identify each API key’s purpose and owner
Record the service, purpose, environment, owner, storage location, permissions, expiration and dependent applications. An entry such as “production billing integration” helps the team identify which process to check when the credential changes.
Keep secret values out of the inventory; record a reference to their protected location instead. Define who can issue and approve keys. When a key is no longer needed, revoke it at its provider and update the inventory.
2. Centralize API keys in encrypted storage
Choose storage based on encryption, access controls and how the team will update and revoke credentials. Establish approved storage locations and retrieval methods instead of scattering values across personal notes and shared files.
| Method | Main role | What to consider |
|---|---|---|
| Plaintext documents or messages | Manual distribution | Copies persist and recipients are difficult to track |
| Environmental variables | Delivering values to a running application | They do not automatically provide encrypted storage or prevent logging. |
| Secrets manager | Encrypted storage and authorized retrival | Its access credentials and permissions also need protection. |
Environment variables can keep values out of source code, but the files that populate them and the execution environment still need protection. Assess storage and delivery separately, including where a plaintext value remains after retrieval.
3. Retrieve keys at runtime instead of hardcoding them
For applications and CI/CD pipelines, consider retrieving secrets through an authorized process at runtime rather than embedding them in code or container images. A deployment job can retrieve only the key it needs without distributing that value to everyone who can read the code.
Keep secret keys out of browser and mobile application bundles; use an authorized backend where appropriate. Protect the credentials used to connect to the secrets manager and prevent retrieved values from reaching logs or build artifacts. Our explanation of what an API integration is provides context for these connections.
4. Restrict permissions and access sources to the minimum required
Configure both who can retrieve a stored key and what the retrieved key can do. A process that reads billing data does not need permission to delete records or administer users. Use the provider’s permission scopes to authorize only the required operations.
At the secrets manager, restrict the records each application can retrieve. Where supported, use IP allowlists as an additional restriction alongside credential protection and API authorization.
5. Use separate keys for development, testing and production
Reusing a production key in development can turn an exposed development file into a route to live data. Issue separate keys and separate the services and data each environment can access.
Where practical, separate credentials by application or business function too. This makes usage easier to attribute and helps the team decide which key to disable when a problem occurs.
6. Establish expiration and rotation procedures
Set expiration where supported and assign an owner and schedule for replacement. Base the interval on permissions, data sensitivity, provider capabilities and organizational risk. A single fixed interval will not suit every API key.
For routine rotation, create a replacement, update dependent applications, verify operation and revoke the old credential. Check whether the provider supports a transition with two active keys. Suspected exposure requires prompt revocation rather than waiting for the routine schedule.
7. Monitor usage and keep keys out of logs
Review provider-side usage and audit logs for unusual access times, request spikes, unexpected operations and charges. Define who receives alerts and who can authorize revocation. Check whether billing controls only notify the team or can actually stop usage.
Secret-retrieval logs and provider-side API usage logs show different activity. Storage-system logs alone may not reveal how a copied key is being used. Mask credentials in authentication headers, errors and debugging output so that investigation tools do not create another exposure route.
8. Establish access and offboarding rules for teams and vendors
Define how access is requested, approved and granted. Use approved storage and retrieval methods instead of distributing plaintext values through email or chat. Protect the human accounts that administer secrets with controls such as multi-factor authentication.
When someone changes roles, leaves the organization or finishes a contract, review both personal access and the applications or automation they configured. Transfer ownership and remove unnecessary access. If the person may have copied a key, assess whether it also needs replacement or revocation at the provider.
What to do if an API key is exposed
Deleting a file will not stop someone from using a key they already copied. When exposure is confirmed or suspected, use the following response sequence.
- Revoke the key at its provider. Identify the service and credential, then disable it through the provider’s console or API. Assess service impact while taking action to stop misuse.
- Issue a replacement and update dependent systems. Give the replacement only the permissions required. Store it securely, update applications and pipelines, and reload or restart workloads where necessary.
- Verify that the old key no longer works. Confirm that legitimate processes work with the replacement and that the exposed credential is rejected. Changing the stored value alone does not complete revocation.
- Investigate usage and impact. Review provider logs and charges for unauthorized operations and potentially accessed information. Identify affected customers or processes and follow the organization’s reporting procedures.
- Fix the exposure route. Investigate repositories, configuration, logs, sharing practices and compromised endpoints. Check whether other credentials escaped through the same route and change the handling process.
How Keeper supports secure API key management
Keeper Secrets Manager and KeeperPAM help organizations manage API keys through secure storage, controlled access and rotation for supported credentials. These capabilities help teams reduce key exposure while giving authorized people and applications access to the secrets they need.
Securely store and retrieve keys with Keeper Secrets Manager
Keeper Secrets Manager® (KSM) manages secrets such as API keys and provides authorized applications and workloads with access through SDKs, CLI tools and integrations. This reduces the need to embed credentials in code or configuration files.
For example, a billing application can be authorized to retrieve only its required record at runtime. KSM decrypts secrets locally on the authorized client; Keeper’s cloud does not hold the keys needed to read that content. The consuming application still needs controls against logging or otherwise exposing the retrieved value.
Manage access for people and applications
Human access uses Keeper Vault sharing, teams and enterprise authentication and policies. KSM uses application and client identities to control access to stored API keys and other secrets. KSM can restrict access to selected records or shared folders and provide read-only access where editing is unnecessary.
Design boundaries around the workload, such as separate KSM applications for production and testing. If a client configuration is compromised, that client can be revoked. External API keys it already retrieved require a separate response at their issuing provider.
Automate supported credential rotation with KeeperPAM
KeeperPAM® can rotate credentials on demand or on a schedule through configured integrations. Built-in examples include AWS access keys and Azure Client Secret rotation.
The documented workflow uses KeeperPAM Gateway to execute actions against the target. Check the integration, required permissions and how dependent applications receive the replacement. Storing a key in KSM alone does not automatically configure rotation for every provider.
Strengthen your API key security with Keeper
Start by locating keys in code and shared files and identifying their owners. If you combine KSM storage and retrieval with supported KeeperPAM rotation, include provider-side permissions and usage monitoring in the operating procedure. To discuss a configuration for your applications and development environment, request a custom Keeper Secrets Manager demo.
Frequently asked questions
What happens if an API key is leaked?
Depending on its permissions, an exposed key can allow data retrieval, unauthorized changes or misuse of metered services. The impact depends on the credential’s scope, expiration and the provider’s other access controls.
Is storing API keys in environment variables enough to keep them secure?
Environment variables keep values out of source code, but security also depends on the configuration files and execution environment. Restrict which processes can access them and prevent their values from appearing in logs.
Is deleting an exposed API key from GitHub enough to make it safe?
No. The key may remain in history or copies. Revoke or replace it at the provider first, then investigate remaining copies and the process that allowed it into the repository.
How often should API keys be rotated?
Choose an interval based on the provider, permissions, data sensitivity and organizational risk. Use expiration where supported and prepare a tested replacement process. Respond to suspected exposure immediately, regardless of the routine schedule.
What should you do first if you discover an API key leak?
Identify the affected key and prioritize revocation at its provider. Assess dependent services while moving to a replacement, then investigate unauthorized use and the exposure route.