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 / security-and-keystore

Key security and keystore support

The SDK provides an encrypted Solana key vault for storing private keys and using them as signing credentials. The vault keeps private key material protected at rest while exposing public keys for review and making decrypted keys available to transaction flows only after the configured protection method succeeds.

Security model

The vault separates stored key material from the protection method used to unlock it. A vault records the protection type with its encrypted payload, so later access can select the matching passphrase or Google Cloud KMS path.

Encrypted key storage

The vault stores private keys inside an encrypted payload rather than as ordinary JSON fields. Its file format also carries a kind, version, comment, and protection marker. Public keys can be listed without treating the list as proof that the matching private keys are available.

References: vault/vault.go• L24-35 vault/vault.go• L123-173 cmd/…/vault_list.go• L24-38

Protection methods

The SDK supports two protection methods. A passphrase protects the vault with a user-held secret. Google Cloud KMS protects it through a configured cloud key, which lets access depend on cloud credentials and KMS permissions.

MethodTrust boundaryMain access requirement
PassphraseThe operator or local secret storeThe vault passphrase
kms-gcpGoogle Cloud KMSA KMS key path and valid Google Cloud access

The common secret-box interface keeps both methods interchangeable for vault open and seal operations. The command layer rejects unknown methods and requires a KMS key path for kms-gcp.

References: vault/secretboxer.go• L25-53 vault/passphrase.go• L26-77 vault/kmsgcp.go• L35-78 cmd/…/vault_create.go• L60-66

For the passphrase flow and the detailed vault format, see Vault encryption and passphrase protection.

Vault lifecycle

The vault lifecycle moves key material from creation or import to protected storage, then reverses that process only for an operation that needs the keys. This keeps encryption at the boundary where the vault is written and decryption at the boundary where the vault is loaded.

Vault creation and update

The vault create command creates new key pairs or imports private keys. It then applies the selected protection method before writing the vault file with restrictive local file permissions. The vault add command follows the same open, change, seal, and write cycle for an existing vault.

The flow protects the stored form, not every later use of a key. After a successful open, private keys exist in the active process and can be used by signing commands.

This diagram shows how key material enters the vault and becomes available for later signing.

flowchart LR
    A[Create or import private keys] --> B[Select passphrase or KMS protection]
    B --> C[Seal key material]
    C --> D[Write encrypted vault]
    D --> E[Load vault for an operation]
    E --> F[Open with matching protection]
    F --> G[Use keys for signing]

References: cmd/…/vault_create.go• L32-51 cmd/…/vault_create.go• L68-139 cmd/…/vault_add.go• L32-79 vault/vault.go• L67-105 vault/vault.go• L145-172

Vault access

Commands that need a vault load the file, choose its recorded protection method, and open the encrypted key material before continuing. Public-key listing and private-key export use this same access path, so an operator must satisfy the vault protection requirement before either command can read the active key set.

Transaction-related commands can use the loaded vault as their signing provider. The vault therefore acts as the security gate between a stored credential and an operation that can sign on Solana.

References: cmd/…/common.go• L71-97 cmd/…/vault_list.go• L34-38 cmd/…/vault_export.go• L24-32 vault/vault.go• L24-35

KMS integration

The Google Cloud KMS option uses a cloud-managed key to protect the vault's local encryption material. The vault data remains portable as an encoded blob, while opening it requires access to the configured KMS key and the Google Cloud service. Each seal or open operation creates a KMS manager, so Google Cloud authentication and service setup are part of both paths.

KMS trust boundary

KMS access adds an external trust boundary to vault use. Creating or opening a KMS-protected vault can fail before key material is available if Google authentication, the KMS service, the key path, or the required permission is not valid.

The KMS path is selected from the vault's recorded wrap type. A caller must provide the same logical key path when it opens the vault; the system does not fall back to passphrase access for a KMS-protected file.

References: vault/kmsgcp.go• L45-78 vault/kmsgcp.go• L98-125 vault/secretboxer.go• L31-52 cmd/…/common.go• L77-95

KMS data protection

KMS protection combines a local data key with the cloud KMS key. The local key protects the vault payload, while KMS protects the local key. Each encrypted blob carries the wrapped local key and its nonce with the encrypted data. This limits direct exposure of the vault contents and allows repeated operations to reuse the protected local key during the manager's lifetime.

References: vault/kmsgcp.go• L127-181 vault/kmsgcp.go• L187-242

Operational boundaries

The security facilities protect private keys at rest and control when commands can load them. They do not replace access control for the host, the process, the passphrase, Google Cloud credentials, or exported private keys.

Secret handling

Vault creation prompts for a passphrase unless an insecure environment override is present. Private-key import also reads input without showing it on screen. The export command intentionally prints private keys, so it should be treated as a controlled recovery or migration action rather than a normal inspection command.

References: cmd/…/vault_create.go• L110-124 cmd/…/vault_add.go• L86-131 cmd/…/vault_export.go• L24-32 vault/secretboxer.go• L38-50

Change checklist

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

  • Keep the stored protection marker and the factory that resolves it aligned. A new marker without a matching opener makes existing vaults unusable.
  • Keep vault creation and vault loading aligned on the KMS key path source. A vault can be created successfully but fail to open when the path is absent or changed.
  • Preserve the seal-before-write boundary. Writing a vault after keys are added without sealing can leave the file without current protected key material.
  • Revisit command safety when changing export or private-key input. These paths cross from protected storage into terminal-visible or process-resident secrets.
  • Keep the KMS blob fields and local data-key handling aligned. A change to the wrapped key, nonce, or encrypted payload contract can make existing KMS-protected vaults unreadable.

Important failure modes

TriggerConsequenceGuard
Wrong passphraseThe vault does not open and no usable key set is returned.Use the passphrase that protected the vault; see Vault encryption and passphrase protection.
Missing KMS key pathKMS boxer setup fails before the vault can open or seal.Configure the KMS key path for every KMS-protected operation.
Missing or invalid vault fileCommands that require the vault stop before signing or key display.Keep the configured vault file available and readable.
KMS authentication, service, or permission failureKMS-protected key material remains unavailable.Check Google Cloud access and permission to use the configured key.
Changed or malformed KMS blobThe local data key or vault payload cannot be recovered.Preserve the blob version, wrapped key, nonce, and encrypted data contract.
Export command used in an unsafe terminal or logPrivate keys become visible outside the encrypted vault.Limit export to controlled handling and protect command output.

Key files

FileWhy to read it
vault/vault.goDefines the vault boundary, protected file shape, and seal/open lifecycle.
vault/secretboxer.goDefines the shared protection contract and selects the protection method.
vault/passphrase.goShows the passphrase protection behavior.
vault/kmsgcp.goShows the Google Cloud KMS protection boundary and data-key flow.
cmd/…/vault_create.goShows how operators create or import protected vaults.
cmd/…/common.goShows the common load-and-open path used by commands.
cmd/…/vault_add.goShows how existing vaults are opened, changed, and re-sealed.
cmd/…/vault_export.goShows the deliberate path that exposes private keys.