credentials

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 27 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package credentials coordinates externally issued, short-lived database credentials. It never implements a vault or persists credential values.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnavailable     = errors.New("credential lifecycle unavailable")
	ErrConflict        = errors.New("credential lifecycle conflict")
	ErrNotFound        = errors.New("credential lease not found")
	ErrStaleOwner      = errors.New("credential lease owner is no longer active")
	ErrAlreadyIssued   = errors.New("credential issuance or use already attempted")
	ErrIssuanceUnknown = errors.New("credential issuance outcome unknown; do not retry")
	ErrCleanupPending  = errors.New("credential cleanup is not provider-confirmed")
	ErrConsumerFailed  = errors.New("credential consumer failed; inspect action evidence")
)

Functions

func IsReconciliationCheck added in v0.8.0

func IsReconciliationCheck(ctx context.Context) bool

IsReconciliationCheck distinguishes background liveness inspection from an attempt to release credentials. Only Manager.Reconcile stamps this context.

func ReadPrivateFile

func ReadPrivateFile(path string, limit int64) ([]byte, error)

ReadPrivateFile rejects links and group/world permissions. It rechecks the opened inode so replacing the path between Lstat and Open fails closed.

func Schema

func Schema(d Dialect) ([]string, error)

Schema is installed by the control plane's ordinary migration runner. There is deliberately no startup auto-migration or separate database of secrets.

Types

type ActiveChecker

type ActiveChecker func(context.Context, Owner, string) error

ActiveChecker rechecks tenant, exact run incarnation/generation, action authority and registered consumer binding. Revoke deliberately does not use it: a superseded attempt's exact old lease still requires cleanup.

type Binding

type Binding struct {
	ID             string
	Revision       string
	ConsumerID     string
	MaxTTL         time.Duration
	RenewIncrement time.Duration
	Provider       Provider
	Retired        bool
}

Binding is operator-registered. Provider and revision are frozen for this binding's lifetime. Keep retired revisions registered until cleanup completes.

type Dialect

type Dialect string
const (
	SQLite   Dialect = "sqlite"
	Postgres Dialect = "postgres"
	MySQL    Dialect = "mysql"
)

type Grant

type Grant struct {
	RequestID  string
	Handle     string
	TTL        time.Duration
	Renewable  bool
	Credential UserPassword
}

func (Grant) GoString

func (g Grant) GoString() string

func (Grant) MarshalJSON

func (Grant) MarshalJSON() ([]byte, error)

func (Grant) String

func (Grant) String() string

type Keyring

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

Keyring protects only provider cleanup handles. It is not a secret store. Keep old keys available until their leases have confirmed cleanup.

func LoadKeyring

func LoadKeyring(path string) (*Keyring, error)

LoadKeyring reads an operator-mounted 0600 JSON keyring with base64 keys: {"active":"key-1","keys":{"key-1":"<base64 32 bytes>"}}.

func NewKeyring

func NewKeyring(active string, keys map[string][]byte) (*Keyring, error)

type LeaseStatus

type LeaseStatus struct {
	Found     bool
	TTL       time.Duration
	Renewable bool
}

type Manager

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

func NewManager

func NewManager(store Store, keys *Keyring, bindings []Binding, check ActiveChecker) (*Manager, error)

func (*Manager) BindingRevision

func (m *Manager) BindingRevision(bindingID string) (string, error)

BindingRevision lets the connector target contract include the immutable registered provider role, rather than trusting a mutable binding ID alone.

func (*Manager) Execute

func (m *Manager) Execute(ctx context.Context, o Owner, bindingID string, consume func(context.Context, UserPassword) error) (*Record, error)

Execute releases credentials only after durable issuance and one-time use records and two current-authority checks. The callback is a trusted consumer, never arbitrary agent code. It is called at most once for this owner/binding.

func (*Manager) Get

func (m *Manager) Get(ctx context.Context, tenant, id string) (*Record, error)

func (*Manager) Reconcile

func (m *Manager) Reconcile(ctx context.Context, limit int) (int, error)

Reconcile never repeats issuance or tool execution. It recovers known handles by lookup and exact revocation; a lost issuance handle stays explicitly unknown.

func (*Manager) ReferenceFor

func (m *Manager) ReferenceFor(o Owner, bindingID string) (string, error)

ReferenceFor permits action correlation before policy without issuing or fetching any credential. ActionID is a server-generated random request ID.

func (*Manager) Renew

func (m *Manager) Renew(ctx context.Context, o Owner, id string) (*Record, error)

Renew requires the original exact owner to remain active. Provider TTL is authoritative; the requested increment is never treated as a grant.

func (*Manager) Revoke

func (m *Manager) Revoke(ctx context.Context, o Owner, id string) (*Record, error)

Revoke accepts an old attempt's exact lease owner, without granting it access to a newer lease. Only sync provider confirmation makes the record revoked.

func (*Manager) Search

func (m *Manager) Search(ctx context.Context, tenant string, limit int) ([]*Record, error)

type Owner

type Owner struct {
	TenantID         string `json:"tenant_id"`
	RunID            string `json:"run_id"`
	RunIncarnationID string `json:"run_incarnation_id"`
	Generation       int64  `json:"generation"`
	ActionID         string `json:"action_id"`
	ConsumerID       string `json:"consumer_id"`
}

Owner must come from trusted assignment and durable action context, never agent-provided arguments. RunIncarnationID distinguishes reused run IDs.

type Provider

type Provider interface {
	Issue(context.Context) (Grant, error)
	Renew(context.Context, string, time.Duration) (Grant, error)
	Revoke(context.Context, string) error
	Lookup(context.Context, string) (LeaseStatus, error)
}

Provider does not retry issuance. A timed-out GET can have issued a real credential, so callers must retain an unknown record instead of issuing again.

type Record

type Record struct {
	IssueRequestID     string     `json:"vault_issue_request_id,omitempty"`
	LastRenewRequestID string     `json:"vault_last_renew_request_id,omitempty"`
	ID                 string     `json:"lease_ref"`
	Owner              Owner      `json:"owner"`
	BindingID          string     `json:"binding_id"`
	BindingRevision    string     `json:"binding_revision"`
	State              State      `json:"state"`
	Version            int64      `json:"version"`
	CreatedAt          time.Time  `json:"created_at"`
	UpdatedAt          time.Time  `json:"updated_at"`
	OperationDeadline  time.Time  `json:"operation_deadline"`
	ExpiresAt          time.Time  `json:"expires_at"`
	GrantedTTLSeconds  int64      `json:"granted_ttl_seconds"`
	Renewable          bool       `json:"renewable"`
	UseStartedAt       *time.Time `json:"use_started_at,omitempty"`
	CleanupRequested   bool       `json:"cleanup_requested"`
	ReasonCode         string     `json:"reason_code,omitempty"`
	ProtectedHandle    string     `json:"-"`
}

Record is safe for metadata views. ProtectedHandle is internal encrypted cleanup material and must never appear in JSON, logs or public DTOs.

func (Record) GoString

func (r Record) GoString() string

func (Record) String

func (r Record) String() string

type SQLStore

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

func NewPGXStore

func NewPGXStore(pool *pgxpool.Pool) (*SQLStore, error)

func NewSQLStore

func NewSQLStore(db *sql.DB, d Dialect) (*SQLStore, error)

func (*SQLStore) CAS

func (s *SQLStore) CAS(ctx context.Context, r *Record, expected int64) (*Record, error)

func (*SQLStore) Create

func (s *SQLStore) Create(ctx context.Context, r *Record) (*Record, bool, error)

func (*SQLStore) Get

func (s *SQLStore) Get(ctx context.Context, tenant, id string) (*Record, error)

func (*SQLStore) ListUnresolved

func (s *SQLStore) ListUnresolved(ctx context.Context, limit int) ([]*Record, error)

func (*SQLStore) Search

func (s *SQLStore) Search(ctx context.Context, tenant string, limit int) ([]*Record, error)

Search is tenant-scoped in SQL, not a post-filter of a global bounded page. It intentionally never selects the private protected_handle column.

type State

type State string
const (
	StateIssuing           State = "issuance_intent"
	StateActive            State = "active"
	StateIssuanceUnknown   State = "issuance_unknown"
	StateNotIssued         State = "not_issued"
	StateRenewing          State = "renewal_intent"
	StateRenewalUnknown    State = "renewal_unknown"
	StateRevoking          State = "revocation_intent"
	StateRevocationUnknown State = "revocation_unknown"
	StateRevoked           State = "revoked"
)

type Store

type Store interface {
	Create(context.Context, *Record) (*Record, bool, error)
	Get(context.Context, string, string) (*Record, error)
	CAS(context.Context, *Record, int64) (*Record, error)
	ListUnresolved(context.Context, int) ([]*Record, error)
	Search(context.Context, string, int) ([]*Record, error)
}

Store mutations are compare-and-swap. Create is unique on the complete owner and binding ID even if configuration changes; replay must return created=false. SQL tables have no run FK so old leases can still be cleaned after retention.

type UserPassword

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

UserPassword is deliberately not serializable or printable. Only a trusted executor callback may access these ephemeral credential values.

func NewUserPassword

func NewUserPassword(username, password string) (UserPassword, error)

NewUserPassword is for trusted provider implementations, not request parsing.

func (UserPassword) GoString

func (u UserPassword) GoString() string

func (UserPassword) MarshalJSON

func (UserPassword) MarshalJSON() ([]byte, error)

func (UserPassword) String

func (UserPassword) String() string

func (UserPassword) Values

func (u UserPassword) Values() (string, string)

type VaultConfig

type VaultConfig struct {
	Address               string `json:"address"`
	Namespace             string `json:"namespace,omitempty"`
	TokenFile             string `json:"-"`
	Mount                 string `json:"mount"`
	Role                  string `json:"role"`
	AllowInsecureLoopback bool   `json:"-"`
}

type VaultProvider

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

func NewVaultProvider

func NewVaultProvider(cfg VaultConfig) (*VaultProvider, error)

func (*VaultProvider) Issue

func (p *VaultProvider) Issue(ctx context.Context) (Grant, error)

func (*VaultProvider) Lookup

func (p *VaultProvider) Lookup(ctx context.Context, handle string) (LeaseStatus, error)

func (*VaultProvider) Renew

func (p *VaultProvider) Renew(ctx context.Context, handle string, increment time.Duration) (Grant, error)

func (*VaultProvider) Revision

func (p *VaultProvider) Revision(consumer string, maxTTL, increment time.Duration) string

Revision identifies the configured provider and role, not resolved secrets.

func (*VaultProvider) Revoke

func (p *VaultProvider) Revoke(ctx context.Context, handle string) error

Jump to

Keyboard shortcuts

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