Documentation
¶
Overview ¶
Package database implements the dynamic database credentials engine (LLD §4.B, Phase 2).
Index ¶
- Variables
- func BuildConnectionURL(data map[string]any, config map[string]any) (string, error)
- type CredsRequest
- type CredsResult
- type DefaultSQLRunner
- type Engine
- func (e *Engine) CleanupExpired(ctx context.Context, limit int) (int, error)
- func (e *Engine) GenerateCredentials(ctx context.Context, req CredsRequest) (*CredsResult, error)
- func (e *Engine) GetRole(ctx context.Context, name string) (*domainsecrets.DatabaseRole, error)
- func (e *Engine) Name() string
- func (e *Engine) Renew(ctx context.Context, leaseID string, ttlSeconds int) (*CredsResult, error)
- func (e *Engine) RenewExpiring(ctx context.Context, grace time.Duration, limit int) (int, error)
- func (e *Engine) RevokeLease(ctx context.Context, leaseID string) (*RevokeResult, error)
- func (e *Engine) SaveRole(ctx context.Context, cfg RoleConfig) error
- func (e *Engine) SetSQLRunner(runner SQLRunner)
- type RegistryAdapter
- type RevokeResult
- type RoleConfig
- type SQLRunner
Constants ¶
This section is empty.
Variables ¶
var AllowFileAdminURLs = true
AllowFileAdminURLs permits sqlite:/file: admin DSNs (lab/tests). Production wiring sets this false (W86-17).
Functions ¶
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 ¶
func NewEngine( roles repository.DatabaseRoleRepository, leases repository.LeaseRepository, secrets repository.SecretRepository, cryptoSvc *crypto.Service, ) *Engine
NewEngine constructs a database credentials engine.
func (*Engine) CleanupExpired ¶
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) RenewExpiring ¶
RenewExpiring renews active leases expiring within the grace window.
func (*Engine) RevokeLease ¶
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 ¶
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.
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.