Tutorials · DevSecOps & Cloud
How to Keep Passwords and API Keys Out of Code With Vault or OpenBao
Hard-coded passwords end up in Git, chat and backups. Store secrets centrally in HashiCorp Vault or its open-source fork OpenBao, control who can read them and let applications fetch them at runtime.
Before you start
- A Linux server or container platform
- Vault or OpenBao binary (the CLI commands are the same: vault / bao)
Step by step
Try it in dev mode
Dev mode runs in memory with a root token printed on screen. Use it only to learn.
vault server -dev export VAULT_ADDR=http://127.0.0.1:8200
Store a secret
The KV engine stores key/value secrets with versions.
vault kv put secret/billing-app db_password='S3cure-Example' api_key='abc123'Read a secret
Applications and scripts read only the field they need.
vault kv get -field=db_password secret/billing-appLimit access with policies
Give each application read access to its own path only.
# billing-app.hcl path "secret/data/billing-app" { capabilities = ["read"] } vault policy write billing-app billing-app.hcl
Authenticate applications properly
Use AppRole, Kubernetes or cloud identity auth instead of long-lived tokens, so each app proves who it is.
Run it in production
Use a production configuration with TLS, integrated storage (Raft) on three nodes, and auto-unseal with a KMS or HSM. Back up the storage and protect the unseal keys.
Rotate secrets
Use dynamic database credentials or scheduled rotation, so a leaked password stops working quickly.
Commands are generic, industry-standard examples. Exact syntax and menu names vary by model and firmware; check your device's manual on the Documentation page.
Pro tips
- Audit logs show who read which secret and when: send them to your SIEM.
- Start with the most sensitive secrets (database, cloud keys, network device admin passwords).
FAQ
Frequently asked questions
Vault or OpenBao?
Vault is from HashiCorp under the Business Source License; OpenBao is a community fork under an open-source licence (MPL 2.0) with compatible commands. Both work for this tutorial.
Keep learning
Related guides
Add security checks to CI
Read more →Secure Docker containers
Read more →Automate with Ansible
Read more →How to Scan Container Images, Code and IaC for Vulnerabilities With Trivy
Trivy is a free scanner for container images, file systems, Git repositories and infrastructure-as-code. Find vulnerable packages and misconfigurations before they reach production.
Read more →How to Generate an SBOM for Your Software and Scan It With Grype
A Software Bill of Materials lists every component in your software. Customers and regulations (such as the EU Cyber Resilience Act) increasingly ask for it. Generate SBOMs with Syft and check them for vulnerabilities with Grype.
Read more →How to Add Security Checks to a CI/CD Pipeline (Secrets, SAST, Dependencies, Images)
Shift security left: catch leaked secrets, insecure code, vulnerable dependencies and risky infrastructure settings automatically on every commit, before anything is deployed.
Read more →Stuck on a step?
Ask Navijin technical support or an authorised partner for help with your configuration.