database

package
v0.5.1 Latest Latest
Warning

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

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

Documentation

Overview

Package database implements the dynamic database credentials engine (LLD §4.B, Phase 2).

Index

Constants

This section is empty.

Variables

View Source
var AllowFileAdminURLs = true

AllowFileAdminURLs permits sqlite:/file: admin DSNs (lab/tests). Production wiring sets this false (W86-17).

Functions

func BuildConnectionURL

func BuildConnectionURL(data map[string]any, config map[string]any) (string, error)

BuildConnectionURL assembles a PostgreSQL connection URL from KV admin credential fields.

Types

type CredsRequest

type CredsRequest struct {
	Role      string
	TTL       string
	TTLSecond int
	// TokenID is the hashed client token that issued the lease (cascade revoke).
	TokenID string
	// Tenant is optional namespace for lease ID scoping (W64-01).
	Tenant string
	// TenantMode enables lease ID prefixing.
	TenantMode bool
}

CredsRequest configures credential generation.

type CredsResult

type CredsResult struct {
	LeaseID    string
	Username   string
	Password   string
	Role       string
	TTLSeconds int
	MaxTTL     int
	ExpiresAt  time.Time
	Statements []string
	Warnings   []string
}

CredsResult contains generated credentials and lease metadata.

type DefaultSQLRunner

type DefaultSQLRunner struct{}

DefaultSQLRunner uses database/sql.

func (DefaultSQLRunner) ExecStatements

func (DefaultSQLRunner) ExecStatements(ctx context.Context, connectionURL string, statements []string) error

ExecStatements opens a connection and runs each statement.

type Engine

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

Engine generates short-lived database credentials with lease tracking.

func NewEngine

NewEngine constructs a database credentials engine.

func (*Engine) CleanupExpired

func (e *Engine) CleanupExpired(ctx context.Context, limit int) (int, error)

CleanupExpired revokes leases that have passed their expiration time.

func (*Engine) GenerateCredentials

func (e *Engine) GenerateCredentials(ctx context.Context, req CredsRequest) (*CredsResult, error)

GenerateCredentials creates ephemeral credentials bound to a lease.

func (*Engine) GetRole

func (e *Engine) GetRole(ctx context.Context, name string) (*domainsecrets.DatabaseRole, error)

GetRole returns role configuration.

func (*Engine) Name

func (e *Engine) Name() string

Name returns the engine identifier.

func (*Engine) Renew

func (e *Engine) Renew(ctx context.Context, leaseID string, ttlSeconds int) (*CredsResult, error)

Renew extends an active lease TTL.

func (*Engine) RenewExpiring

func (e *Engine) RenewExpiring(ctx context.Context, grace time.Duration, limit int) (int, error)

RenewExpiring renews active leases expiring within the grace window.

func (*Engine) RevokeLease

func (e *Engine) RevokeLease(ctx context.Context, leaseID string) (*RevokeResult, error)

RevokeLease revokes a lease and its stored credentials.

func (*Engine) SaveRole

func (e *Engine) SaveRole(ctx context.Context, cfg RoleConfig) error

SaveRole stores or updates role configuration.

func (*Engine) SetSQLRunner

func (e *Engine) SetSQLRunner(runner SQLRunner)

SetSQLRunner overrides the SQL executor (tests).

type RegistryAdapter

type RegistryAdapter struct {
	*Engine
}

RegistryAdapter wraps the database engine for engine.Registry registration.

func NewRegistryAdapter

func NewRegistryAdapter(engine *Engine) RegistryAdapter

NewRegistryAdapter constructs a SecretEngine adapter for the database engine.

func (RegistryAdapter) Get

func (a RegistryAdapter) Get(_ context.Context, _ string) (map[string]any, error)

Get is not supported; database credentials are generated via roles.

func (RegistryAdapter) Put

func (a RegistryAdapter) Put(_ context.Context, _ string, _ map[string]any) error

Put is not supported; database credentials are generated via roles.

type RevokeResult

type RevokeResult struct {
	RevocationStatements []string `json:"revocation_statements,omitempty"`
}

RevokeResult contains optional client-mode revocation SQL (W36-19).

type RoleConfig

type RoleConfig struct {
	Name                 string
	TTLSeconds           int
	DefaultTTL           int
	MaxTTL               int
	Period               int
	Renewable            *bool
	MaxLeases            int
	UsernamePrefix       string
	DefaultUsername      string
	CreationStatements   []string
	RevocationStatements []string
	ExecutionMode        string
	AdminCredentialsPath string
	Config               map[string]any
}

RoleConfig configures a database credential role.

type SQLRunner

type SQLRunner interface {
	ExecStatements(ctx context.Context, connectionURL string, statements []string) error
}

SQLRunner executes SQL statements against a database.

Jump to

Keyboard shortcuts

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