๐Ÿ”’
๐Ÿ”’ Security & Identity with the Larz Stack ยท SEC-101 ยท Session 3 of 5

Managing Secrets with larzvault

API keys, passwords, tokens - every app has secrets, and leaking them is a top cause of breaches. Never put secrets in code; manage them safely, and encrypt them at rest with larzvault.

โฑ 7 min read๐Ÿ“… Updated 2026-07-27๐Ÿ“Š Tables, charts & examples

Every real application has secrets: API keys, database passwords, tokens. Mishandling them - especially hard-coding them or committing them to a repository - is one of the most common and damaging security mistakes there is (leaked keys are routinely scraped from public code within minutes). Managing secrets properly is essential, and larzvault lets you store them encrypted at rest.

Never put secrets in code

The number one rule: secrets do not belong in your source code or version control. Keep them separate and out of the repo.

Don'tDo
Hard-code keys in sourceLoad from environment / config
Commit secrets to gitKeep them out of the repo (.gitignore)
Share secrets in plaintextUse a secrets store / encrypted vault
Reuse one key everywhereScope and rotate keys

Leaked secrets are a top breach cause precisely because it's so easy to slip - a key committed to a public repo can be exploited within minutes by automated scanners. Keeping secrets out of code is the essential first habit.

Encrypt secrets at rest

Beyond keeping secrets out of code, you often need to store them (config, credentials) securely. larzvault encrypts them under a master passphrase.

๐ŸŽฏ
Secrets encrypted, with no downgrade. larzvault stores secrets encrypted with authenticated encryption under a key derived (via scrypt) from a master passphrase, so the stored file is useless without the passphrase, and tampering is detected. Its KDF parameters are authenticated too, preventing downgrade attacks. It's built on larzcrypt, so the crypto underneath is the same standard, verified primitives. You get a simple, safe place to keep secrets at rest - a step up from plaintext config files.

Handle secrets safely

  • Never in code/git - the cardinal rule; use env/config, .gitignore.
  • Encrypt at rest - larzvault under a master passphrase.
  • Scope and rotate - limit each key's power; change them periodically.
  • Rotate if leaked - assume a leaked secret is compromised, replace it.

๐ŸŽฏ Key takeaways

  • Every app has secrets, and leaking them (especially in code/git) is a top breach cause.
  • The cardinal rule: never put secrets in source code or version control - load from env/config.
  • larzvault stores secrets encrypted at rest under a master passphrase (scrypt + authenticated encryption, downgrade-proof).
  • Scope and rotate keys, and treat any leaked secret as compromised - replace it immediately.

Frequently asked

What actually happens if I accidentally commit an API key to a public repo?

Often it's exploited within minutes. Automated bots continuously scan public repositories (and their history) for anything resembling credentials, so a committed key can be found and abused almost immediately - running up cloud bills, accessing data, or worse. Critically, deleting the key in a later commit does NOT fix it, because it remains in the git history and may already be scraped. The correct response to a leaked secret is to rotate it immediately - revoke the exposed key and issue a new one - and then clean up. This is exactly why the rule is to keep secrets out of code entirely (via environment variables, config files that are gitignored, or an encrypted vault), so the accident can't happen in the first place.

How is larzvault different from just using environment variables?

They solve overlapping but different problems. Environment variables keep secrets out of your code and are great for injecting configuration at runtime - and you should use them. larzvault addresses storing secrets securely at rest: sometimes you need to persist credentials or config somewhere (not just have them injected), and a plaintext file is unsafe. larzvault encrypts that store under a master passphrase with authenticated encryption, so the file is useless to anyone without the passphrase and tampering is detected. Think of environment variables as how you deliver secrets to a running process, and larzvault as a safe way to store a collection of secrets encrypted rather than in plaintext. Many setups use both.

Session 3 of 5 complete

Next up: Two-Factor Auth with larztotp & larzqr

Continue to Session 4 โ†’

Related lessons

More in this course

Course home → · Browse all courses →