kms

package
v0.0.0-...-2ff081f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package kms provides a unified KMS provider interface for MongoDB CSFLE. Implementations are in subpackages: aws, azure, gcp, local.

Example:

var p kms.Provider = aws.New(accessKey, secretKey, keyArn)
creds := p.Credentials()
defer p.Clear() // securely clear credentials

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidCredentials indicates that the provided credentials are invalid or incomplete
	ErrInvalidCredentials = errors.New("invalid credentials")

	// ErrInvalidKey indicates that the provided key is invalid or malformed
	ErrInvalidKey = errors.New("invalid key")

	// ErrConfigurationError indicates a configuration problem with the provider
	ErrConfigurationError = errors.New("configuration error")
)

Base error categories for KMS operations

Functions

func HasCustomTLS

func HasCustomTLS(p Provider) bool

HasCustomTLS returns true if the provider requires custom TLS configuration

func HasMasterKey

func HasMasterKey(p Provider) bool

HasMasterKey returns true if the provider supports master key functionality

func IsFullyFeatured

func IsFullyFeatured(p Provider) bool

IsFullyFeatured returns true if the provider supports all optional features

func NewKeyLengthError

func NewKeyLengthError(provider string, got, expected int) error

NewKeyLengthError creates a ValidationError for invalid key length

func NewMissingCredentialError

func NewMissingCredentialError(provider, field string) error

NewMissingCredentialError creates a ValidationError for missing credential fields

Types

type CredentialError

type CredentialError struct {
	Provider   string // Name of the provider
	Operation  string // The operation that failed (e.g., "retrieve", "store", "clear")
	Reason     string // Human-readable reason for the failure
	Underlying error  // Optional underlying error
}

CredentialError represents an error with credential handling

func (CredentialError) Error

func (e CredentialError) Error() string

Error implements the error interface

func (CredentialError) Unwrap

func (e CredentialError) Unwrap() error

Unwrap returns the underlying error

type Credentials

type Credentials map[string]map[string]any

Credentials is a map of provider name to a map of key name to value. It represents the authentication credentials for a KMS provider.

Example structure:

{
  "aws": {
    "accessKeyId": "AKIA...",
    "secretAccessKey": "...",
    "sessionToken": "..." // optional
  }
}

type Key

type Key map[string]any

Key is a map of key name to value that represents a master key configuration for a KMS provider. The structure varies by provider.

Examples:

  • AWS: {"key": "arn:aws:kms:region:account:key/key-id", "region": "us-east-1"}
  • Azure: {"keyName": "mykey", "keyVaultEndpoint": "https://vault.vault.azure.net"}
  • GCP: {"projectId": "my-project", "location": "global", "keyRing": "ring", "keyName": "key"}

type KeyError

type KeyError struct {
	Provider   string // Name of the provider
	Operation  string // The operation that failed (e.g., "retrieve", "decrypt", "encrypt")
	KeyID      string // Identifier of the key (may be redacted)
	Reason     string // Human-readable reason for the failure
	Underlying error  // Optional underlying error
}

KeyError represents an error with key operations

func (KeyError) Error

func (e KeyError) Error() string

Error implements the error interface

func (KeyError) Unwrap

func (e KeyError) Unwrap() error

Unwrap returns the underlying error

type Provider

type Provider interface {
	// Core provider functionality (required)
	Name() string
	Credentials() Credentials
	Clear()

	// Optional functionality (can return nil if not supported)
	MasterKey() Key         // Returns nil if provider doesn't support master keys
	TLSConfig() *tls.Config // Returns nil if provider doesn't need custom TLS
}

Provider represents a unified KMS provider interface. This interface replaces the complex hierarchy of Provider, MasterKey, TLSConfig, etc. All providers implement this single interface, using nil returns for unsupported features.

type ValidationError

type ValidationError struct {
	Provider string // Name of the provider where validation failed
	Field    string // Name of the field that failed validation
	Value    string // The invalid value (may be redacted for sensitive fields)
	Reason   string // Human-readable reason for the failure
}

ValidationError reports a field-level validation failure for a KMS provider. It wraps ErrConfigurationError via [Unwrap].

func (ValidationError) Error

func (e ValidationError) Error() string

Error implements the error interface

func (ValidationError) Unwrap

func (e ValidationError) Unwrap() error

Unwrap returns the underlying error category

Directories

Path Synopsis
Package kmsaws provides AWS KMS integration for MongoDB CSFLE.
Package kmsaws provides AWS KMS integration for MongoDB CSFLE.
Package kmsazure provides Azure Key Vault integration for MongoDB CSFLE.
Package kmsazure provides Azure Key Vault integration for MongoDB CSFLE.
Package factory creates kms.Provider instances from config.MongoKMS configuration, routing to the appropriate cloud or local KMS implementation (AWS, Azure, GCP, local).
Package factory creates kms.Provider instances from config.MongoKMS configuration, routing to the appropriate cloud or local KMS implementation (AWS, Azure, GCP, local).
Package kmsgcp provides Google Cloud KMS integration for MongoDB CSFLE.
Package kmsgcp provides Google Cloud KMS integration for MongoDB CSFLE.
Package kmslocal provides local key management for MongoDB CSFLE.
Package kmslocal provides local key management for MongoDB CSFLE.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL