Introducing a new way to review your PRs.

Read the announcement

solana-foundation / solana-go

Go SDK library and RPC client for the Solana Blockchain

View on GitHub

26 documents · Updated Nov 16, 2026

docs / vault-and-passphrase

Vault, passphrase, and KMS integrations

The vault is the local key store for Solana signing. It keeps private keys in an encrypted payload on disk and opens that payload only when a supported secret boxer can prove access to it. This page describes that boundary; see Security and keystore for the wider security model.

Vault record

Persisted vault data

The vault file is a JSON record with a kind, a format version, an optional comment, the name of the protection method, and the protected key payload. The private-key collection is excluded from JSON serialization, so a correctly sealed file persists ciphertext rather than the in-memory key list. The comment and protection method remain visible to anyone who can read the file. References: vault/vault.go• L24-36, vault/vault.go• L123-143

In-memory key material

The vault holds private keys in a KeyBag, which is the signing input used by higher-level Solana operations. Loading a file does not populate that list until the vault is opened; opening decrypts the payload and restores the key list in process memory. Public keys are derived from those private keys for display and for signer selection. References: vault/vault.go• L35-36, vault/vault.go• L145-157, cmd/…/common.go• L77-97

Secret boxing

Boxer contract

Secret boxing is the boundary between vault data and a protection system. A SecretBoxer seals bytes into a string, opens that string back into bytes, and reports the protection type so the vault can persist enough metadata to choose the same method later. The command layer selects the boxer from the stored type and its current credentials. References: vault/secretboxer.go• L25-53, vault/vault.go• L159-173, cmd/…/common.go• L83-95

Passphrase protection

Passphrase protection derives a key from the supplied passphrase and a new random salt for each seal operation. It uses authenticated secret-box encryption with a random nonce, then stores the salt and nonce with the ciphertext in raw Base64. The passphrase is not stored in the vault, so the same passphrase is required to open it. References: vault/passphrase.go• L26-77, vault/kmsgcp.go• L80-91

The CLI normally reads a passphrase through hidden input. It also accepts SLNC_GLOBAL_INSECURE_VAULT_PASSPHRASE as a non-interactive path for creation and opening. That environment path is an explicit weaker boundary because the secret is supplied through process configuration rather than protected input. References: cmd/…/vault_create.go• L105-124, vault/secretboxer.go• L38-50

Google Cloud KMS protection

The Google Cloud KMS boxer uses a configured KMS key path to protect a locally generated data-encryption key. The application encrypts vault data locally with that data key and stores a KMS-wrapped copy of the data key beside the encrypted data. On open, KMS unwraps the data key and the application uses it to recover the vault payload. References: vault/kmsgcp.go• L35-78, vault/kmsgcp.go• L128-149, vault/kmsgcp.go• L194-242

The KMS manager uses Google default credentials and the Cloud KMS service. KMS therefore controls access to the wrapped data key, while the running process still holds the usable data key and the decrypted private keys during vault use. The manager can reuse data keys in memory, but that cache is not part of the persisted vault record. References: vault/kmsgcp.go• L99-126, vault/kmsgcp.go• L153-184

The KMS payload is a versioned protected record. It carries the wrapped data-encryption key, a fresh nonce, and the authenticated encrypted data, so the same record supplies the material needed for a later open. References: vault/kmsgcp.go• L187-192, vault/kmsgcp.go• L207-219, vault/kmsgcp.go• L222-242

Vault access flow

Creation and update flow

Vault creation either generates new key pairs or imports private keys. It selects passphrase or Google Cloud KMS protection, seals the key list, and writes the result to the configured vault file. Adding keys follows the same open, change, seal, and write cycle, which preserves the vault's existing protection type. References: cmd/…/vault_create.go• L32-51, cmd/…/vault_create.go• L68-139, cmd/…/vault_add.go• L37-78

The diagram shows how plaintext key material moves only through the running process before the sealed record is written.

flowchart LR
    A[Generate or import private keys] --> B[KeyBag in memory]
    B --> C[SecretBoxer seals payload]
    C --> D[Protection type and ciphertext]
    D --> E[Vault JSON file]
    E --> F[Read vault metadata]
    F --> G[Passphrase or KMS access]
    G --> H[Open payload into KeyBag]

Unlock and signing flow

Normal vault-backed commands read the file, select its boxer, and open the encrypted payload before they perform work. Commands can then list derived public keys, export private keys, or use matching private keys to sign a transaction. The vault file itself does not grant signing access without the passphrase or the KMS authorization needed to open it. References: cmd/…/common.go• L71-97, cmd/…/vault_list.go• L24-38, cmd/…/vault_export.go• L24-32, cmd/…/token_registry_register.go• L38-89

Security boundaries

Disk boundary

The safe persistence boundary is the call to seal before the call to write. WriteToFile serializes whatever is currently in the vault object, so callers must not write an unsealed vault that still has keys in its in-memory KeyBag. The file is opened with restrictive 0600 permissions when it is created, but file-system access and backups remain part of the threat boundary. References: vault/vault.go• L123-142, cmd/…/vault_create.go• L131-139, cmd/…/vault_add.go• L68-78

Process and terminal boundary

After opening, private keys are available in process memory to support signing. Public-key listing exposes only derived public keys, while export deliberately prints private keys and must be treated as a secret release. Private-key entry during import or add uses hidden input, but the key still exists in the process before it is sealed. References: vault/vault.go• L107-120, cmd/…/vault_add.go• L86-131, cmd/…/vault_export.go• L24-32

Credential boundary

Passphrase mode depends on possession of the passphrase. KMS mode depends on Google credentials with permission to use the configured Cloud KMS key path. A KMS failure prevents the application from recovering the data key; it does not provide a second local recovery path. References: vault/secretboxer.go• L31-53, vault/kmsgcp.go• L99-115, cmd/…/vault_create.go• L60-66

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the persisted protection type aligned with the boxer factory. A new protection type needs both sealing and opening support.
  • Preserve the vault JSON contract for secretbox_wrap and secretbox_ciphertext. Existing vaults use those fields to select access and recover keys.
  • Keep the KMS blob contract aligned between local encryption and decryption. The wrapped data key, nonce, version, and encrypted data must remain readable as one unit.
  • Review every caller of WriteToFile when changing sealing behavior. Writing before sealing can expose the in-memory private-key list.
  • Treat changes to passphrase input or Google credential use as changes to the vault access boundary. Creation and later opening must use matching rules.

Important failure modes

TriggerConsequenceGuard
Wrong passphraseAuthenticated decryption fails and no key list is restored.Keep the passphrase outside the vault and obtain it again through the protected input path.
Missing or invalid KMS key pathThe boxer cannot be created or KMS cannot wrap or unwrap the data key.Require the configured key path for kms-gcp and grant the runtime Google credentials access to it.
Vault written before SealPrivate keys can be serialized into the JSON file because the key list is only excluded after sealing does not clear it from memory.Seal first, then write; inspect the protection type and ciphertext before persisting.
Malformed or truncated ciphertextBase64, JSON, or authenticated decryption fails and the vault cannot open.Treat the vault file as an atomic protected record and restore it from a known-good copy.
Private-key exportA valid command prints every private key to the terminal.Restrict use of export and protect terminal output, logs, and shell capture.

Key files

FileWhy to read it
vault/vault.goDefines the vault record and the seal, open, read, and write lifecycle.
vault/secretboxer.goDefines the common protection boundary and selects passphrase or KMS access.
vault/passphrase.goShows the passphrase-based protection behavior and stored ciphertext envelope.
vault/kmsgcp.goShows the Google Cloud KMS integration, wrapped data-key model, and protected payload record.
cmd/…/common.goShows how normal commands load and unlock a vault before use.
cmd/…/vault_create.goShows how users create a protected vault.
cmd/…/vault_add.goShows how an existing vault is opened, changed, and re-sealed.
cmd/…/vault_export.goShows the explicit private-key release path.