secrets

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package secrets provides a pluggable secrets broker for VaultRun.

At run time, callers request named secrets (e.g. "DB_PASSWORD", "API_KEY"). The broker resolves them from the configured backend and injects them as environment variables into the container exec — they are never stored in the database or logged.

Supported backends (configured via SECRETS_PROVIDER env var):

  • "env" — read VAULTRUN_SECRET_<NAME> from the server process environment (default)
  • "vault" — HashiCorp Vault KV v2 via HTTP API
  • "aws" — AWS Secrets Manager via HTTP API (SigV4 signed)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AWSProvider

type AWSProvider struct {
	// contains filtered or unexported fields
}

AWSProvider fetches secrets from AWS Secrets Manager using the AWS REST API.

Configuration env vars (standard AWS SDK env vars are honoured):

AWS_REGION             — AWS region (required if not in instance metadata)
AWS_ACCESS_KEY_ID      — AWS access key (or use instance IAM role)
AWS_SECRET_ACCESS_KEY  — AWS secret key (or use instance IAM role)
AWS_SESSION_TOKEN      — optional session token
SECRETS_AWS_PREFIX     — optional prefix prepended to secret names (default: "vaultrun/")

The secret "DB_PASSWORD" is fetched by secret name "{prefix}DB_PASSWORD". The returned SecretString is used directly.

func NewAWSProvider

func NewAWSProvider(region, prefix string) *AWSProvider

func (*AWSProvider) GetSecret

func (p *AWSProvider) GetSecret(ctx context.Context, name string) (string, error)

func (*AWSProvider) Name

func (p *AWSProvider) Name() string

type EnvProvider

type EnvProvider struct{}

EnvProvider reads secrets from the server's process environment. Each secret named "FOO" is looked up as VAULTRUN_SECRET_FOO. Ideal for development and single-host deployments.

func (*EnvProvider) GetSecret

func (p *EnvProvider) GetSecret(_ context.Context, name string) (string, error)

func (*EnvProvider) Name

func (p *EnvProvider) Name() string

type Provider

type Provider interface {
	// GetSecret returns the plaintext value for the named secret.
	// Returns an error if the secret does not exist or cannot be fetched.
	GetSecret(ctx context.Context, name string) (string, error)

	// Name returns a human-readable backend name for diagnostics (never logs secrets).
	Name() string
}

Provider is the secrets broker interface.

func New

func New() Provider

New returns the configured Provider based on the SECRETS_PROVIDER env var.

  • "vault" → VaultProvider (requires VAULT_ADDR + VAULT_TOKEN)
  • "aws" → AWSProvider (requires AWS_REGION + credentials)
  • ""/"env"→ EnvProvider (default; no external dependencies)

type VaultProvider

type VaultProvider struct {
	// contains filtered or unexported fields
}

VaultProvider fetches secrets from a HashiCorp Vault KV v2 mount.

Configuration env vars:

VAULT_ADDR   — e.g. "https://vault.example.com"
VAULT_TOKEN  — Vault token (service account / app role)
VAULT_MOUNT  — KV v2 mount path (default: "secret")
VAULT_PATH   — base path inside the mount (default: "vaultrun")

The secret "DB_PASSWORD" is fetched from:

GET {VAULT_ADDR}/v1/{VAULT_MOUNT}/data/{VAULT_PATH}/DB_PASSWORD

and the value at data.data.value is returned.

func NewVaultProvider

func NewVaultProvider(addr, token, mount, path string) *VaultProvider

func (*VaultProvider) GetSecret

func (p *VaultProvider) GetSecret(ctx context.Context, name string) (string, error)

func (*VaultProvider) Name

func (p *VaultProvider) Name() string

Jump to

Keyboard shortcuts

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