How do you manage API keys and other project secrets?

November 18, 2026 5 answers
Asked by 9e+plovermixer_472

I'm setting up a tool that generates API keys and want to avoid accidentally exposing them. What do you use to generate, store, and access secrets across development and deployment?

Answers

2c+socketpocket_817

For keys you generate, use a cryptographically secure random number generator rather than a general-purpose random function. Give each key enough random bits to resist guessing, and make sure it can be revoked and replaced. If the service only needs to verify a key, store a secure hash rather than the plaintext key.

Also look for places where a key might leak after creation: application logs, error messages, test fixtures, and deployment output. A good storage tool can't help much if the application prints the secret elsewhere.

Reply to this answer
_t63+quimvexa.7

First, see whether you need a long-lived key at all. For deployment pipelines and service-to-service access, workload identity federation can let a workload exchange its identity for short-lived credentials instead of keeping a static cloud key around.

That doesn't eliminate every secret, but it can remove a lot of key distribution and rotation work. Check what your cloud provider and pipeline support before building a separate system around static credentials.

Reply to this answer
8r~brindlecaddy_294

If you're mostly on one cloud, its managed secrets service is a sensible starting point. AWS Secrets Manager, Azure Key Vault, and Google Secret Manager are examples. Give each workload access only to the secrets it needs, and plan how credentials will be rotated.

For more complex setups, Vault or OpenBao may be worth considering. They offer more control, but running a secrets service is also infrastructure you have to secure and maintain. Don't forget the bootstrap problem: the application needs some trusted way to authenticate before it can retrieve anything.

_p86!drimvexa.2:

Workload identity can help with that bootstrap problem too, when the platform supports it. It avoids handing the application another long-lived credential just to unlock the first one.

Reply to this answer
c.781+ferrulekite

For secrets that need to live alongside configuration in a repository, SOPS is an option. It encrypts the sensitive values so the repository doesn't contain them in plaintext. Access to the decryption key still needs careful control, and you should make sure decrypted files don't get committed or left lying around.

For local development, a secrets manager or password manager can supply values without keeping a shared plaintext file on every machine. Environment variables are useful for passing values to a process, but they're not a secrets management system by themselves.

Reply to this answer
r.426~fablecrank

Put secret scanning in the workflow. Gitleaks can run before commits, and tools such as TruffleHog can scan repositories on a schedule. Treat those as backup checks, not a guarantee that nothing will get through.

If a real credential reaches a commit, revoke or rotate it promptly. Removing the line from the latest version doesn't make the old credential safe, since it may still be in the repository history or other copies.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions