Documentation
¶
Overview ¶
Package secrets stores encrypted credentials (passwords, API tokens, SSH keys, database secrets, notes and destination-bound HTTPS endpoints) for people and their delegated agents. Every secret is protected at rest with AES-256-GCM and a rollback-anchored signed head, and every use, reveal or delegated read commits an immutable audit record before plaintext is unsealed.
Index ¶
- Constants
- Variables
- func CanManage(p store.Principal) bool
- func DeriveAEAD(key []byte, domain string) (cipher.AEAD, error)
- func LoadOrCreateKey(path string) ([]byte, error)
- func ReadKey(path string) ([]byte, error)
- func SealValue(a cipher.AEAD, plain []byte, context string) ([]byte, error)
- func UnsealValue(a cipher.AEAD, box []byte, context string) ([]byte, error)
- type Bot
- type Credential
- type Deps
- type Grant
- type NewCredential
- type Result
- type RevealedCredential
- type Service
- func (s *Service) AgentChoices() []string
- func (s *Service) Create(ctx context.Context, p store.Principal, via string, in NewCredential) (Credential, error)
- func (s *Service) Delete(ctx context.Context, p store.Principal, via, id string, version int64) error
- func (s *Service) Get(p store.Principal, id string) (Credential, error)
- func (s *Service) History(p store.Principal, id string, limit int) ([]events.Event, error)
- func (s *Service) List(p store.Principal) ([]Credential, error)
- func (s *Service) ReadSecret(ctx context.Context, p store.Principal, via, id, reason string) (RevealedCredential, error)
- func (s *Service) Reveal(ctx context.Context, p store.Principal, via, id string) (RevealedCredential, error)
- func (s *Service) Revoke(ctx context.Context, p store.Principal, via, id string, version int64, ...) (Credential, error)
- func (s *Service) Rotate(ctx context.Context, p store.Principal, via, id string, version int64, ...) (Credential, error)
- func (s *Service) SetGrant(ctx context.Context, p store.Principal, via, id string, version int64, ...) (Credential, error)
- func (s *Service) SetGrantWithMode(ctx context.Context, p store.Principal, via, id string, version int64, ...) (Credential, error)
- func (s *Service) Update(ctx context.Context, p store.Principal, via, id string, version int64, ...) (Credential, error)
- func (s *Service) UpdateSettings(allowedHosts []string, lang i18n.Lang, bot Bot)
- func (s *Service) Use(ctx context.Context, p store.Principal, via, id string) (Result, error)
- type UpdateCredential
Constants ¶
const ( UseScope = "secrets:use" ManageScope = "accounts:write" )
const ( KindAPI = "api" KindPassword = "password" KindToken = "token" KindSSH = "ssh" KindDatabase = "database" KindNote = "note" )
Credential kinds supported by Beacon's credential vault.
const ( PolicyNever = "never" // human custody only; agents cannot see, use or read PolicyUse = "use" // granted agents may invoke server-side HTTPS use without seeing plaintext PolicyRead = "read" // granted agents with a read grant may unseal the value with an audited reason )
Agent access policies per credential.
const ( GrantModeUse = "use" GrantModeRead = "read" )
Grant modes for agent delegations.
Variables ¶
var ( Kinds = []string{KindPassword, KindAPI, KindToken, KindSSH, KindDatabase, KindNote} Policies = []string{PolicyNever, PolicyUse, PolicyRead} ErrAccess = errors.New("the current identity has no access to this team credential") ErrInput = errors.New("the credential or grant details are invalid") ErrConflict = errors.New("the credential changed; reload it and try again") ErrState = errors.New("the team credential store cannot be verified") ErrAnchorPending = errors.New("the credential change was written to the database; its rollback anchor is awaiting verification") ErrUpstream = errors.New("the configured service could not be reached") )
Functions ¶
func DeriveAEAD ¶
DeriveAEAD derives a domain-separated AES-256-GCM cipher from a 256-bit root key.
func LoadOrCreateKey ¶
LoadOrCreateKey loads the 256-bit master key from path, or creates it atomically with mode 0600 on first start.
Types ¶
type Credential ¶
type Credential struct {
ID string `json:"id"`
Name string `json:"name"`
Kind string `json:"kind,omitempty"`
Vault string `json:"vault,omitempty"`
Username string `json:"username,omitempty"`
URL string `json:"url,omitempty"`
Endpoint string `json:"endpoint,omitempty"`
Method string `json:"method,omitempty"`
HeaderName string `json:"header_name,omitempty"`
Note string `json:"note,omitempty"`
Policy string `json:"policy,omitempty"`
Version int64 `json:"version"`
Updated time.Time `json:"updated"`
Grants []Grant `json:"grants,omitempty"`
}
Credential is the metadata a caller may see. Plaintext values are never included here.
func (Credential) EffectiveKind ¶
func (c Credential) EffectiveKind() string
EffectiveKind returns the item's kind, defaulting to "api" for legacy HTTPS credentials.
func (Credential) EffectivePolicy ¶
func (c Credential) EffectivePolicy() string
EffectivePolicy returns the item's agent policy, defaulting to "use" for "api" items and "never" otherwise.
type Grant ¶
type Grant struct {
Agent string `json:"agent"`
Owner string `json:"owner"`
Created time.Time `json:"agent_created"`
Mode string `json:"mode,omitempty"` // use (default) or read
Until time.Time `json:"until"`
}
Grant identifies one specific Agent account and its delegated mode and expiry.
func (Grant) EffectiveMode ¶
EffectiveMode returns the grant's mode, defaulting to "use" for earlier records.
type NewCredential ¶
type NewCredential struct {
Name string `json:"name"`
Kind string `json:"kind,omitempty"`
Vault string `json:"vault,omitempty"`
Username string `json:"username,omitempty"`
URL string `json:"url,omitempty"`
Endpoint string `json:"endpoint,omitempty"`
Method string `json:"method,omitempty"`
HeaderName string `json:"header_name,omitempty"`
Note string `json:"note,omitempty"`
Policy string `json:"policy,omitempty"`
Value string `json:"value"`
}
NewCredential creates a credential item in the vault.
type RevealedCredential ¶
type RevealedCredential struct {
ID string `json:"id"`
Name string `json:"name"`
Kind string `json:"kind"`
Vault string `json:"vault,omitempty"`
Username string `json:"username,omitempty"`
URL string `json:"url,omitempty"`
Endpoint string `json:"endpoint,omitempty"`
Note string `json:"note,omitempty"`
Value string `json:"value"`
}
RevealedCredential carries an unsealed secret after its audit record has been durably committed.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func (*Service) AgentChoices ¶
func (*Service) Create ¶
func (s *Service) Create(ctx context.Context, p store.Principal, via string, in NewCredential) (Credential, error)
func (*Service) Delete ¶
func (s *Service) Delete(ctx context.Context, p store.Principal, via, id string, version int64) error
Delete removes a credential from the database and the signed rollback-anchored head.
func (*Service) History ¶
History returns recent audited uses, reveals and delegated reads recorded in UsesLog.
func (*Service) List ¶
func (s *Service) List(p store.Principal) ([]Credential, error)
List returns all items to an owner, and only live, explicitly delegated items to an agent.
func (*Service) ReadSecret ¶
func (s *Service) ReadSecret(ctx context.Context, p store.Principal, via, id, reason string) (RevealedCredential, error)
ReadSecret unseals a credential for an owner or an agent holding a live "read" grant on a "read"-policy item. Agents must provide an explicit audit reason; the audit event is committed before unsealing.
func (*Service) Reveal ¶
func (s *Service) Reveal(ctx context.Context, p store.Principal, via, id string) (RevealedCredential, error)
Reveal unseals a credential for a signed-in human owner after durably committing an audit event.
func (*Service) SetGrant ¶
func (s *Service) SetGrant(ctx context.Context, p store.Principal, via, id string, version int64, agent string, until time.Time) (Credential, error)
SetGrant delegates "use" access to an agent for up to 90 days.
func (*Service) SetGrantWithMode ¶
func (s *Service) SetGrantWithMode(ctx context.Context, p store.Principal, via, id string, version int64, agent, mode string, until time.Time) (Credential, error)
SetGrantWithMode delegates "use" or "read" access to an agent for up to 365 days, subject to the credential's policy.
func (*Service) Update ¶
func (s *Service) Update(ctx context.Context, p store.Principal, via, id string, version int64, in UpdateCredential) (Credential, error)
Update modifies credential metadata, agent policy and optionally rotates the stored secret.
func (*Service) UpdateSettings ¶
UpdateSettings updates the allowed outbound hosts, language and chat echo bot at runtime.
type UpdateCredential ¶
type UpdateCredential struct {
Name *string `json:"name,omitempty"`
Vault *string `json:"vault,omitempty"`
Username *string `json:"username,omitempty"`
URL *string `json:"url,omitempty"`
Endpoint *string `json:"endpoint,omitempty"`
Method *string `json:"method,omitempty"`
HeaderName *string `json:"header_name,omitempty"`
Note *string `json:"note,omitempty"`
Policy *string `json:"policy,omitempty"`
Value *string `json:"value,omitempty"`
}
UpdateCredential modifies metadata, policy and optionally rotates the secret value.