secrets

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 18 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

View Source
const MinRedactLen = 4

MinRedactLen is the shortest secret value that is redacted. Shorter values would corrupt ordinary output (a secret "1" would blank every digit one).

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 Redactor added in v0.3.4

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

Redactor removes the exact values of secrets that were injected into a command from its output. It also matches the standard and URL-safe base64 encodings of each value, since `echo $SECRET | base64` is the obvious way to get around a plain match. It cannot catch arbitrary transformations (hex, reversed, split across lines), so it limits accidental leaks; it is not a guarantee against a command that is trying to exfiltrate the value.

func NewRedactor added in v0.3.4

func NewRedactor(secrets map[string]string) *Redactor

NewRedactor builds a redactor for the given secret name -> value map. It returns nil when there is nothing to redact; a nil Redactor is valid and is a no-op.

func (*Redactor) Redact added in v0.3.4

func (r *Redactor) Redact(s string) string

Redact returns s with every secret value replaced.

func (*Redactor) Writer added in v0.3.4

func (r *Redactor) Writer(w io.Writer) io.WriteCloser

Writer wraps w so everything written through it is redacted, including secrets that arrive split across several Write calls. Close must be called once the command finished to flush the held-back tail.

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