Secrets management is a set of practices and systems developers use to generate, store, distribute, and retire credentials. Examples include an application programming interface (API) key inside a serverless function or a database password in a connection pool. Secrets management limits who and what can read a given value, for how long, and under what conditions. Secret exposure is a growing problem, with nearly 24 million new hardcoded secrets added to public GitHub commits in 2024.
Below, we’ll discuss the types of secrets developers manage, how storage and access work, and how Stripe Projects can help provision separate API keys for each project a developer or team creates.
Key takeaways
Application programming interface (API) keys, access tokens, database credentials, certificates, and encryption keys each carry their own risks and lifespans.
Scoped credentials, scheduled rotation, and audit logging limit the damage a single exposed secret can cause.
Autonomous tools that call application programming interfaces (APIs) and infrastructure need distinct, scoped, and revocable access rather than broad account permissions.
Why do secrets management best practices matter?
Secrets management covers how you generate, store, distribute, and retire the credentials your applications (apps) depend on. Good secrets management limits the damage from a compromised credential by making its access clear and easy to revoke. Poor secrets management can allow anyone who finds a single leaked value to access production systems.
What types of secrets do developers need to protect?
There are a few common categories for secrets, and each functions slightly differently.
Here’s what secrets management typically covers:
Application programming interface (API) keys: These authenticate your application to a third-party service such as a payment provider or mapping API. They typically don’t expire on their own, so a leaked key often grants full account access until someone manually revokes it.
Access tokens: Open authorization (OAuth) access tokens and JavaScript Object Notation (JSON) Web Tokens carry a user’s or service’s permissions, usually with a shorter lifespan than API keys. They show up in mobile apps, single sign-on flows, and service-to-service calls.
Database credentials: Usernames, passwords, and connection strings for systems such as PostgreSQL, MySQL, or MongoDB sit in configuration files and connection pools. These are often duplicated across several environments at once.
Certificates and private keys: Transport Layer Security (TLS) certificates and Secure Shell (SSH) keys verify identity and secure connections between servers. Expired or improperly stored certificates cause outages just as often as they cause breaches.
Encryption keys: Keys that encrypt data at rest or in transit are managed by services such as Amazon Web Services Key Management Service (AWS KMS) or HashiCorp Vault’s transit engine. Losing one can mean losing access to the data it protects.
Environment variables: These aren’t secrets on their own. They’re the delivery mechanism many applications use to pull secrets into a running process, and they’re an easy way to leak a value into a log file or crash report.
These secrets show up across different environments: local development machines, Continuous Integration and Continuous Delivery (CI/CD) pipelines, cloud infrastructure, and production systems. A value locked down tight in one environment can sit wide open in another.
How does secrets management work?
Secrets management replaces hardcoded values with a lookup. Instead of writing a database password directly into your code, your application asks a centralized store for it at runtime, and that store decides whether to release it.
Environment variables are simpler. Container orchestration systems let you inject secrets as environment variables or mounted files at deploy time, which keeps them out of your codebase but doesn’t encrypt them once they land inside a running container. Configuration management systems land somewhere in between: they protect a secret in transit and inside your configuration repository, but you’re still responsible for how the receiving system handles it after that.
Centralized credential management platforms build rotation, versioning, and audit trails on top of storage. When your code needs a secret, it authenticates to the platform through a service account, an Identity and Access Management (IAM) role, or a short-lived token, and it’s given a scoped, time-limited credential instead of a static one. That enables a team to cut off access for a single service without touching every other credential in the system.
What are some best practices for secrets management?
Good secrets management depends on habits a team sticks to over time.
These practices show up in nearly every rigorous framework:
Grant least-privilege access: Give each service or person only the specific secrets they need, scoped to specific environments and actions. A Continuous Integration (CI) pipeline that deploys to staging should never hold the same credentials as one that deploys to production.
Rotate secrets on a schedule: Long-lived API keys and database passwords should rotate regularly and immediately after any employee offboarding or suspected exposure. Automated rotation removes the excuse to skip it.
Set expiration on tokens: Short-lived tokens that expire in minutes or hours limit the damage window if one leaks. OAuth access tokens are usually paired with longer-lived refresh tokens instead of one static value.
Log every access request: Audit logs should record which identity accessed which secret, when, and from where. That way, you can answer whether a credential was compromised during an incident instead of guessing.
Separate secrets by environment: Development, staging, and production should each have their own credentials stored in their individual vaults or namespaces. A test database password should never work against the production database.
Share secrets through the vault, not through chat or email: Pasting a credential into Slack or a support ticket puts it in a system that wasn’t built to protect it. Many secrets management platforms support temporary, revocable sharing links instead.
Scan for exposed credentials on every commit: Scanners such as GitHub secret scanning, TruffleHog, and Gitleaks check commits and pull requests for accidental credential exposure before or right after a merge.
Remove leaked secrets from version history: Revoke the exposed credential first, since deleting it from git history doesn’t help if the old value still works. Tools such as git filter-repo or BFG Repo-Cleaner can then strip it from past commits, though anyone who cloned the repository earlier still has a copy.
What are the risks of poor secrets management?
GitGuardian’s annual research on public GitHub commits has found that 15% of commit authors leaked a secret in 2024. The immediate risk is unauthorized access. A leaked database credential can be found, and automated scanners can search public repositories within minutes of a push.
Beyond the initial exposure, a stolen key that goes unnoticed can sit active for months, since many businesses have a process for catching login failures but not one for catching unauthorized use of a credential that’s technically valid. An attacker who gets in this way doesn’t need to bypass authentication at all; they already have it.
Poor secrets management also creates risk that has nothing to do with a criminal. Expired certificates cause outages. Rotated credentials that didn’t get updated everywhere break integrations at random times. And teams that share secrets informally, through email or a shared document, can lose track of who actually has access.
How does secrets management apply to AI agents and development workflows?
AI coding agents change the calculus because they often need real credentials to do real work, such as calling an API, querying a database, or deploying code. An agent executes instructions at machine speed, so a poorly scoped credential can cause damage across several systems before anyone notices.
That risk grows with the number of tools an agent can call. An agent connected to a payment API, a cloud provider, and an internal ticketing system needs distinct, scoped credentials for each one, not a single set of broad permissions that covers everything. Without that separation, a single compromised agent session can impact far more than intended.
Stripe Projects addresses part of this for developers building on Stripe. It can provision separate API keys for each project a developer or team creates, scoped to that project’s data and environment. A key used by one agent or application doesn’t carry access to another. Stripe Projects handles provisioning, credential storage, and billing for third-party infrastructure services.
How do you choose the right secrets management tools?
The right choice depends on your infrastructure.
A few questions quickly narrow the list:
Does it integrate with your identity provider? A system that can’t authenticate against your existing Identity and Access Management (IAM) or single sign-on (SSO) setup adds a second identity system to manage. That usually means weaker access control.
Does it support automated rotation for the services you use? Native rotation for common databases and cloud services saves the manual work of building and maintaining rotation scripts yourself.
Can it enforce short-lived, scoped credentials? Static, long-lived secrets are the pattern you’re trying to move away from. A system that only stores values without issuing dynamic ones solves half the problem.
Does it produce audit logs you can actually use? Logs that record access without enough detail to reconstruct an incident don’t help much when you need them.
How does it handle the secrets your AI tools need? If agents or automated workflows request credentials, check whether the system can scope and expire those separately from human access.
How Stripe Projects can help
Stripe Projects lets developers and their AI agents add services, generate credentials, and manage billing from the command line interface (CLI).
Stripe Projects helps you:
Provision third-party services from the command line: Use one workflow to add services, manage credentials, and upgrade plans, instead of different tools and workflows for every provider. Manage hosting, databases, auth, AI, and more without needing dashboards, config files, or infrastructure code.
Sync credentials automatically: Keep environment variables portable across local setups, machines, teammates, and agents—no copy-pasting application programming interface (API) keys.
Manage billing from the CLI or your coding agent: Set up billing details once and securely share them with third-party services. Upgrade and downgrade tiers, monitor usage, and manage subscriptions from the CLI.
Learn more about how Stripe Projects helps simplify app provisioning, or copy and paste this command into your terminal to get started today:
brew install stripe/stripe-cli/stripe && stripe plugin install projects && npx skills add https://github.com/stripe/ai --skill stripe-projects -y -g
The content in this article is for general information and education purposes only and should not be construed as legal or tax advice. Stripe does not warrant or guarantee the accurateness, completeness, adequacy, or currency of the information in the article. You should seek the advice of a competent attorney or accountant licensed to practice in your jurisdiction for advice on your particular situation.