NEW! Protect privileged credentials with time-bound credential leasing, automated password rotation, and access rules: Learn how >

Bitwarden Blog

Secrets management best practices

published :

Whether a team runs a single Kubernetes cluster or juggles a dozen continuous integration/continuous delivery (CI/CD) pipelines across cloud providers, credentials multiply faster than anyone can track them. Common secrets include:

  • Secure Shell (SSH) keys

  • Transport Layer Security (TLS) certificates

  • Encryption keys

  • Database passwords

  • Application programming interface (API) keys

These credentials tend to spread across code, config files, chat threads, and local machines faster than any team can govern manually. This pattern, known as secret sprawl, is the main driver behind avoidable credential exposure.

Secrets management best practices address secret sprawl directly and hold up regardless of the specific tools, cloud providers, or deployment models a team uses. The table below outlines vault best practices for secrets management, the risk each practice reduces, and where it delivers the most value.

Teams starting this work should prioritize one step: moving plaintext secrets out of local environment and configuration files and into a secure secrets manager. That single move closes off the most common entry point for credential leaks and lays the foundation for the practices that follow.

Centralize secrets in a vault

Centralized storage is the prerequisite for every other practice in this article, and the Secrets Manager overview covers how this works in practice. Policy enforcement, access reviews, and revocation only work when secrets live in one place instead of scattered across repositories, CI/CD variables, chat threads, and local developer machines. Consolidating secrets into a single encrypted store makes the vault the single source of truth, and makes it easy to answer a basic security question at any given moment: who has access to what.

Isolating development, staging, and production secrets, even within the same vault, keeps a compromise in a lower environment from cascading into production, where the consequences are more severe.

Enforce least privilege access

Centralizing secrets solves where they live; least privilege access solves who and what can reach them. Least privilege access means scoping permissions to the smallest set a given workload needs, rather than granting broad access at the repository or team level, an approach covered in more depth in securing agent access with secrets management. When permissions are scoped this narrowly, a single compromised workload cannot reach systems or secrets outside its intended purpose:

  • A deploy job needs the credentials required to push a release, nothing more.

  • A migration job needs database write access for the duration of the migration, not indefinite standing access.

  • A read-only reporting service should never hold write-level credentials it will never use.

Scope access by workload and time

Granting access by workload, rather than by team, keeps each service, job, or automation limited to only the secrets it needs. A payment processing service and a logging service that happen to sit on the same team do not need access to each other's credentials, and scoping access this way prevents that overlap from becoming an attack surface. The same scoping logic applies to time: a static credential persists indefinitely, but a short-lived credential for a runner or automation job, one that expires after a single job run, leaves nothing behind once that job completes.

Automate revocation

Access that outlives its purpose is one of the most common gaps in least privilege enforcement. Automating revocation, to the extent the platform supports it, closes this gap - but automation only works if expiration is configured at the time the credential is issued, not left to a default of indefinite access. When a contractor's engagement ends, a workload is decommissioned, or a token reaches its expiration date, access should end automatically rather than waiting for a manual cleanup process.

Remove hardcoded secrets from code

Scoped access controls only work if credentials actually pass through the vault instead of bypassing it. Hardcoded secrets are one of the most common ways credentials end up exposed, whether through an API key committed to a public repository or a database password left in a configuration file that ships inside a container image. This risk is explored further in software supply chain security best practices.

Addressing this risk starts with secret scanning: at the pre-commit stage, in pull requests, across full Git history, and within build pipelines, to catch secrets before they reach production. Scanning commits and build artifacts catches leaked credentials that a quick code review overlooks, including secrets buried in old commits.

Scanning alone is not enough. The lasting fix is retrieving secrets at runtime, whether that runtime is a CI job, a container, or an application on startup, instead of storing them in code at all. This keeps credentials entirely out of version control, container images, logs, and build output, and shifts the goal from catching exposed secrets after the fact to preventing them from existing in the codebase in the first place.

Rotate secrets and monitor access

Centralizing, scoping, and removing hardcoded secrets reduces exposure at a point in time. Secrets rotation and audit logging keep that protection current as systems and teams change.

Secrets rotation replaces credentials on a defined schedule or after a triggering event, such as a departing team member or a suspected compromise, so no single password or key stays valid indefinitely. Manual rotation is easy to defer under deadline pressure.

This is why teams increasingly move toward dynamic secrets: credentials generated on demand for a specific task or session and automatically expired once that task completes. A database credential issued only for the length of a migration job, for example, never becomes a long-lived liability sitting in a config file.

Audit logging closes the visibility gap that scattered secrets create. A centralized log of who accessed which secret, when, and from where turns "who has access to what" into a question a team can answer in seconds, and gives security teams the trail needed during an investigation or compliance review.

Integrate secrets management into CI/CD and Kubernetes

Rotation and audit logging only keep credentials trustworthy if the systems consuming those credentials also retrieve them at runtime instead of storing them statically. That same principle extends into automated pipelines and container orchestration, where secrets pass through many hands without a person ever seeing them.

Kubernetes is a powerful platform for running distributed applications, but it does not solve secrets management on its own. Kubernetes only base64-encodes secrets by default. Without a dedicated secrets management layer, sensitive values sit in pipeline configuration or cluster manifests longer than necessary.

Pairing CI/CD and Kubernetes with a centralized secrets manager addresses this directly, reflecting core best practices for secrets management in CI/CD environments.

Authenticate pipelines with scoped machine identities

Rather than storing static, long-lived credentials as pipeline variables, pipelines can authenticate with the following approach:

  • Use machine identities through workload identity federation or OpenID Connect (OIDC) where possible, favoring credentials that expire automatically instead of static, indefinitely-valid tokens.

  • Fetch only the secrets a given job needs, for the duration of that job.

  • Discard those secrets once the job completes, so nothing static remains to leak.

Secure secrets inside Kubernetes

Protecting Kubernetes secrets takes more than the platform's built-in secret objects. Role-based access control (RBAC) limits which workloads and users can read secrets in the first place, end-to-end encryption protects values at rest and in transit, and an external secrets operator that syncs from a vault keeps the cluster's secrets aligned with the source of truth rather than duplicated and managed separately.

How Bitwarden Secrets Manager supports these best practices

Bitwarden Secrets Manager operationalizes the practices covered in this article, bringing centralized storage, scoped access, secret rotation, secret removal from code, and CI/CD integration together as concrete product capabilities. From a single centralized vendor, teams get:

  • Unlimited secret storage

  • End-to-end encryption for every value

  • An open source codebase available for review

  • API documentation for developers

  • Software development kits (SDKs) for custom implementations

Bitarden Secrets Manager machine accounts authenticate via scoped access tokens, which can be revoked instantly and optionally set to expire, reducing the exposure window of a long-lived credential.

The Bitwarden Secrets Manager command-line interface (CLI) is the primary way to inject secrets into applications and infrastructure via authenticated machine identities, and SDKs let developers build custom integrations. Native integrations with GitHub Actions, Ansible, Terraform, GitLab CI/CD, Jenkins, and Kubernetes let teams inject secrets into virtually any pipeline without custom scripting for each one.

Bitwarden Secrets Manager publishes its source code publicly, where third-party auditing firms and security researchers regularly examine it. This transparency lets security teams verify how the product works and extend it with confidence, and simplifies vendor due diligence for teams operating under compliance requirements.

Bitwarden Secrets Manager is a zero-knowledge encryption solution. Client-side encryption and decryption mean sensitive values never reach Bitwarden servers unencrypted, and Bitwarden team members cannot see the secrets stored in a vault, a distinction most secrets management solutions do not offer. Bitwarden Secrets Manager supports both cloud-hosted and self-hosted deployments, so the practices in this article apply whether a team runs in the cloud or on premises.

Get started with Bitwarden Secrets Manager and start centralizing credentials today.

FAQ

What is secrets management? Secrets management is the practice of securely storing, accessing, and controlling credentials like API keys, passwords, certificates, and tokens, rather than leaving them in code, config files, or chat threads.

What are the most important secrets management best practices? The core practices are centralizing secrets in a vault, enforcing least privilege access, removing hardcoded secrets from code, rotating secrets on a regular basis, and integrating secrets management into CI/CD and Kubernetes.

What is the difference between secrets rotation and dynamic secrets? Secrets rotation replaces existing credentials on a schedule or after a triggering event. Dynamic secrets go a step further by generating short lived credentials on demand for a specific task, then automatically expiring them once that task is complete.

How does least privilege access reduce risk? Least privilege access limits each workload, job, or service to only the secrets it needs. If one workload is compromised, the attacker cannot use it to reach systems or secrets outside that narrow scope.

Why aren't native Kubernetes secrets enough? Kubernetes secrets are only base64-encoded by default, not encrypted, and Kubernetes does not include built-in rotation, centralized audit logging, or robust workload-level access scoping. A dedicated secrets manager adds those controls.

How does Bitwarden Secrets Manager fit into a CI/CD pipeline? Bitwarden Secrets Manager connects to tools like GitHub Actions, GitLab CI/CD, Jenkins, Ansible, Terraform, and Kubernetes, letting pipelines authenticate with machine identities and fetch secrets at runtime instead of storing them as static pipeline variables.

Back to Blog

Get started with Bitwarden today.