Secrets management
Управление секретами
A way to keep passwords, API keys, and other sensitive credentials out of code and give them only to the people and services that need them. It also covers replacing credentials and revoking access.
What counts as a secret?
A database password, a private TLS key, and an API token are secrets: someone who obtains one may be able to act as the application. A database hostname or port is usually ordinary configuration. Keeping those values separate means a developer can inspect the app's configuration without automatically gaining access to its database. HashiCorp Vault is one tool for secrets management, not another name for the practice.
How it works
A service first proves its identity, for example with a token issued for its Kubernetes service account. The secrets manager then checks which credentials that identity is allowed to obtain. A billing worker might be allowed to fetch its own database credentials but not the signing key used by another service. Stored values are encrypted, requests go over TLS, and audit logs record access without exposing secret values.
Some credentials are static: a vendor API key typically stays valid until it expires or someone replaces or disables it. Others are dynamic: a secrets manager can create a fresh database login on demand and issue it with a limited lifetime. Rotation means replacing a credential and moving its consumers to the replacement. Revocation means making the old credential unusable. Deleting a stored copy does not revoke a key that the issuing system still accepts.
Example: rotating a database login
An order service authenticates to Vault at startup and receives temporary PostgreSQL credentials with read access to the tables it needs. Before the credentials expire, the service gets a fresh login and updates its connection pool. New connections use the fresh credentials while in-flight queries on existing connections finish. The password is never baked into the container image or printed in logs. The same pattern is useful in CI/CD: a deployment job can obtain a short-lived cloud credential instead of relying on a shared key that stays valid between runs.
Common mistakes
- Treating environment variables as a vault. They can deliver a secret to a process, but debug output or diagnostic dumps can still expose it. Base64 encoding is not encryption either.
- Sharing a credential between staging and production. A leak in a test pipeline can then grant access to production.
- Deleting a leaked key from the latest Git commit and calling it fixed. Revoke it at the provider and replace it. Older commits, clones, or build artifacts may still contain a copy.
What interviewers ask
A common question is: “If the app needs credentials to talk to the secrets manager, where do those credentials come from?” Explain how a platform-issued workload identity avoids baking a long-lived bootstrap token into the app. In a system design interview, also discuss what happens when the manager is unavailable: a running instance may be able to keep using credentials that are still valid, while a new instance may be unable to start.