Intekhab Rizvi

Chapter 4 / 28

Understanding Shamir's Secret Sharing and Rekeying Vault

HashiCorp Vault For Beginners9 min read

In the last chapter, we briefly touched on Vault’s initialization process and the concept of unseal keys. Now it’s time to dig deeper.

This chapter explains the role of Shamir’s Secret Sharing, the meaning and significance of key shares, how to rekey Vault, and what happens when things go wrong — like losing too many key shares. We’ll also address a common concern: Does the person initializing Vault see all the keys? (Spoiler: there’s a way to avoid that.)

What is Shamir’s Secret Sharing?

HashiCorp Vault uses a cryptographic algorithm called Shamir’s Secret Sharing to protect its master key. Instead of storing one master key (which would be a single point of failure), Shamir’s algorithm splits the key into multiple pieces, known as key shares.

These shares are distributed among multiple trusted parties. To reconstruct the master key (and unseal Vault), only a subset of those shares is needed — not all of them.

By default:

  • Vault creates 5 key shares
  • The threshold to unseal is set to 3 shares

This means any 3 of the 5 key holders can come together to unseal Vault. This is both secure and practical — it avoids a single person becoming a bottleneck while still ensuring no one can unseal the Vault alone.

Why Use Key Shares at All?

Because trust is not binary.

With Shamir’s Secret Sharing, no single person holds all the power. It also lets you distribute trust across a team, organization, or even across countries if needed.

This becomes especially valuable in enterprise or compliance-driven environments where:

  • Shared custody is a regulatory requirement
  • Insider threat mitigation is essential
  • Multi-party approvals are part of the access policy

But Wait — Doesn’t the Person Who Initializes Vault See All the Keys?

Yes — by default, when you run vault operator init, all the unseal keys are printed to your screen. Whoever ran the command sees every key. This is risky. You’re relying on that one person to distribute the keys securely, not screenshot them, and not keep copies.

That’s where PGP encryption comes in.

Using PGP to Securely Distribute Key Shares

You can prevent the initializer from seeing the raw unseal keys by providing PGP public keys during initialization.

Vault will:

  • Encrypt each key share with a corresponding PGP key
  • Return only the encrypted blobs
  • So only the intended key holders — who have the matching private keys — can decrypt and access their unseal key

Here’s how:

vault operator init \
  -key-shares=5 \
  -key-threshold=3 \
  -pgp-keys="pgp1.asc,pgp2.asc,pgp3.asc,pgp4.asc,pgp5.asc"

Each file (pgp1.asc, etc.) should contain the ASCII-armored public key for one of your trusted operators.

The creation of a GPG public key is covered in detail in Chapter 28.

The output will look something like this:

Unseal Key 1: vault::pgp::TUVTVEVSU0VDUkVUV0lUSFZBVUxURk9STk8x...
Unseal Key 2: vault::pgp::QUJDREVGR0hJSktMTU5PUFFSU1RVVldY...

Only the intended person can decrypt their share using their private PGP key, like this:

echo "<key>" | base64 -d | gpg -d

This makes the initialization process zero-trust for the initializer. They never see the actual unseal keys.

Customizing Key Shares and Thresholds

You can customize the number of shares and the unseal threshold with or without PGP. Example:

vault operator init -key-shares=7 -key-threshold=4

You can choose any numbers that fit your organization’s security needs, as long as:

  • threshold <= shares
  • You have a secure distribution plan for the shares

What If You Lose Key Shares?

This is where it gets serious.

If you lose more key shares than allowed by your threshold, you are permanently locked out of Vault.
There is no backdoor, no “reset,” no way to recover the Vault without enough shares.

For example: with -key-shares=5 -key-threshold=3, if you lose 3 or more keys, you’re done.

That’s why it's essential to:

  • Back up unseal keys securely
  • Store them in encrypted vaults, HSMs, or offline media
  • Use PGP encryption during init to avoid human errors

Rekeying Vault: Why and How

You may need to rotate unseal keys:

  • A key holder left the team
  • You suspect compromise
  • You’re rotating keys on a compliance schedule

To rotate (rekey) unseal keys:

#init the rekey process

vault operator rekey -init -key-shares=5 -key-threshold=3

vault operator rekey

Then provide the current unseal keys (up to threshold) to complete the process.
\

Vault will generate new keys, and the old ones will stop working. Distribute the new ones securely.

You can also rekey using PGP the same way you initialized:

vault operator rekey -init \
  -key-shares=5 \
  -key-threshold=3 \
  -pgp-keys="pgp1.asc,pgp2.asc,pgp3.asc,pgp4.asc,pgp5.asc"

When Rekeying Won’t Work

  • Too many keys lost: Can’t gather the threshold = no rekey.
  • Vault is sealed and can’t be unsealed: No rekey until Vault is unsealed.
  • Dev Mode: Rekeying is disabled and irrelevant in dev mode.

What If You Lose the Minimum Threshold?

Vault will become inaccessible forever.

There is no recovery path if you lose more keys than the threshold allows. No master override. No root access. Vault isn’t joking around — it prioritizes security and confidentiality over convenience.

Recap

  • Shamir’s Secret Sharing splits the master key into safe, distributed key shares.
  • Use -key-shares and -key-threshold to customize how many are created and required.
  • Losing more than the threshold of unseal keys is unrecoverable.
  • Use PGP encryption during initialization to prevent the initializer from ever seeing unseal keys.
  • Rekeying lets you rotate unseal keys securely — if you still have enough to meet the threshold.

Vault’s security model is airtight — but you have to handle the keys responsibly. In the next chapter, we’ll dive into Vault’s first real use case: storing secrets using the Key-Value secrets engine.