Add Secrets to Vault

You can store Linux usernames and passwords in Hashicorp Vault, and the workflow is very clean once you get the hang of it. I am working to improve automation and reproducibility in my homelab infrastructure, using Vault as the single source of truth for credentials.

You may find more detailed documentation directly from hashicorp.
KV – Secrets Engines | Vault | HashiCorp Developer
SSH secrets engine | Vault | HashiCorp Developer


1. Make sure KV v2 is enabled

Most Vault installs already have this, but if not:

You only do this once.


2. Add a Linux server credential (username + password)

Let’s say you want to store credentials for a server called web01.

Option A — Store username + password as separate fields
Option B — Store multiple accounts under one server
Option C — Store credentials for multiple servers

You can structure the paths however you want. A common pattern is:

Example:


3. Verify the secret was stored

Or for a subpath:


4. List secrets under a path

Or deeper:


5. Use these secrets in Ansible (no hardcoding)

Here’s how you pull the password at runtime:

Then use it:

This keeps your playbooks clean and your Git repo free of secrets.


6. Rotate passwords easily

When you want to rotate a password:

Then run your Ansible playbook again to push the new password to the server.

This gives you a simple, reproducible rotation workflow.


Recommended structure for Linux credentials

A clean, scalable pattern:

Example:

This makes it easy to:

  • Rotate per‑host credentials
  • Rotate per‑account credentials
  • Pull secrets dynamically in Ansible
  • Keep everything organized\
List Secrets

Enable SSH Secrets Engine

Use Vault as an SSH Certificate Authority (SSH CA)

This is the enterprise‑grade way to handle SSH.
No private keys stored.
No long‑lived credentials.
No distributing keys.
No passphrases.
No hardcoding.

Vault issues short‑lived SSH certificates on demand.


SSH Certificates (Vault SSH CA)
How it works
  • Users still generate their own keypair.
  • Instead of distributing public keys, they send the public key to Vault.
  • Vault signs it using its SSH CA private key.
  • Vault returns an SSH certificate with:
    • username/principal
    • allowed hosts
    • TTL/expiration
    • role restrictions
    • critical options
    • extensions (e.g., permit-agent-forwarding)
Servers trust only ONE thing:

The CA public key, placed in:

And referenced in:

What this solves
  • Zero key distribution Users keep their private key; servers trust the CA.
  • No static authorized_keys files.
  • No more authorized_keys files Servers don’t store user keys anymore.
  • Short‑lived access Certificates expire automatically (minutes/hours).
  • Instant revocation Disable a Vault role → all issued certs become useless.
  • Centralized identity Vault enforces who can request what.
  • Metadata baked into the cert Principals, TTL, restrictions, etc.

It’s the same model GitHub, Google, and large enterprises use.


Setting Up Vault SSH CA

Vault’s SSH secrets engine does not generate SSH keypairs for users.

Instead, Vault acts as an SSH Certificate Authority (SSH CA).

That means:

  • Vault holds a single private key (the signing key)
  • Vault uses that private key to sign users’ public keys
  • The resulting output is an SSH certificate, not a raw keypair

This signing key is the CA private key that proves the certificate is legitimate.


The workflow in simple terms
1. User generates their own SSH keypair

On their machine:

2. User sends the public key to Vault

Vault signs it:

3. Vault returns an SSH certificate

This certificate is signed using the CA private key stored at:

You can list the public key with the command:

4. Your servers trust the CA public key

Placed in:

And referenced in sshd_config:

5. When a user connects

The server checks:

  • Is the certificate signed by the CA?
  • Is it still valid?
  • Does it match allowed principals?
  • Does it match allowed roles?

If yes → login allowed
If no → rejected


Key insight

The Vault SSH signing key is the CA private key.
It signs certificates — it does NOT generate or validate user keypairs.

Your servers trust the CA public key, not the user’s key.


1. Enable the SSH secrets engine
2. Generate a CA keypair
3. Install the CA public key on your servers

Add to /etc/ssh/sshd_config:

Restart SSH:


4. Create a signing role

Admin role

Ansible/Dev role


5. Generate and Sign SSH Keys

Generate new SSH key pair:

Verify the cert if needed

*Note: Connecting with ssh using the cert is as simple as putting the id_ed25519-cert.pub key in the same directory as the private key as long as it shares the same base name.


Clou-Init with CA key

This guide has an example cloud-init snippit

HashiCorp Vault SSH Certificate Authority: Complete Setup Guide


Click here for a guide on configuring Authentication using Authentik in vault.

Leave a Reply

Your email address will not be published. Required fields are marked *