Documentation
¶
Overview ¶
Package credentials coordinates externally issued, short-lived database credentials. It never implements a vault or persists credential values.
Index ¶
- Variables
- func ReadPrivateFile(path string, limit int64) ([]byte, error)
- func Schema(d Dialect) ([]string, error)
- type ActiveChecker
- type Binding
- type Dialect
- type Grant
- type Keyring
- type LeaseStatus
- type Manager
- func (m *Manager) BindingRevision(bindingID string) (string, error)
- func (m *Manager) Execute(ctx context.Context, o Owner, bindingID string, ...) (*Record, error)
- func (m *Manager) Get(ctx context.Context, tenant, id string) (*Record, error)
- func (m *Manager) Reconcile(ctx context.Context, limit int) (int, error)
- func (m *Manager) ReferenceFor(o Owner, bindingID string) (string, error)
- func (m *Manager) Renew(ctx context.Context, o Owner, id string) (*Record, error)
- func (m *Manager) Revoke(ctx context.Context, o Owner, id string) (*Record, error)
- func (m *Manager) Search(ctx context.Context, tenant string, limit int) ([]*Record, error)
- type Owner
- type Provider
- type Record
- type SQLStore
- func (s *SQLStore) CAS(ctx context.Context, r *Record, expected int64) (*Record, error)
- func (s *SQLStore) Create(ctx context.Context, r *Record) (*Record, bool, error)
- func (s *SQLStore) Get(ctx context.Context, tenant, id string) (*Record, error)
- func (s *SQLStore) ListUnresolved(ctx context.Context, limit int) ([]*Record, error)
- func (s *SQLStore) Search(ctx context.Context, tenant string, limit int) ([]*Record, error)
- type State
- type Store
- type UserPassword
- type VaultConfig
- type VaultProvider
- func (p *VaultProvider) Issue(ctx context.Context) (Grant, error)
- func (p *VaultProvider) Lookup(ctx context.Context, handle string) (LeaseStatus, error)
- func (p *VaultProvider) Renew(ctx context.Context, handle string, increment time.Duration) (Grant, error)
- func (p *VaultProvider) Revision(consumer string, maxTTL, increment time.Duration) string
- func (p *VaultProvider) Revoke(ctx context.Context, handle string) error
Constants ¶
This section is empty.
Variables ¶
var ( 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 ReadPrivateFile ¶
ReadPrivateFile rejects links and group/world permissions. It rechecks the opened inode so replacing the path between Lstat and Open fails closed.
Types ¶
type ActiveChecker ¶
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 Grant ¶
type Grant struct {
Handle string
TTL time.Duration
Renewable bool
Credential UserPassword
}
func (Grant) MarshalJSON ¶
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 ¶
LoadKeyring reads an operator-mounted 0600 JSON keyring with base64 keys: {"active":"key-1","keys":{"key-1":"<base64 32 bytes>"}}.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewManager ¶
func (*Manager) BindingRevision ¶
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) Reconcile ¶
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 ¶
ReferenceFor permits action correlation before policy without issuing or fetching any credential. ActionID is a server-generated random request ID.
func (*Manager) Renew ¶
Renew requires the original exact owner to remain active. Provider TTL is authoritative; the requested increment is never treated as a grant.
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 {
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.
type SQLStore ¶
type SQLStore struct {
// contains filtered or unexported fields
}
func (*SQLStore) ListUnresolved ¶
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 VaultProvider ¶
type VaultProvider struct {
// contains filtered or unexported fields
}
func NewVaultProvider ¶
func NewVaultProvider(cfg VaultConfig) (*VaultProvider, error)
func (*VaultProvider) Lookup ¶
func (p *VaultProvider) Lookup(ctx context.Context, handle string) (LeaseStatus, error)