secrets

package
v0.3.0-rc.53 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 31 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 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

View Source
const (
	UseScope    = "secrets:use"
	ManageScope = "accounts:write"
)
View Source
const (
	KindAPI      = "api"
	KindPassword = "password"
	KindToken    = "token"
	KindSSH      = "ssh"
	KindDatabase = "database"
	KindNote     = "note"
)

Credential kinds supported by Beacon's credential vault.

View Source
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.

View Source
const (
	GrantModeUse  = "use"
	GrantModeRead = "read"
)

Grant modes for agent delegations.

Variables

View Source
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 CanManage

func CanManage(p store.Principal) bool

CanManage admits people signed in with owner accounts.

func DeriveAEAD

func DeriveAEAD(key []byte, domain string) (cipher.AEAD, error)

DeriveAEAD derives a domain-separated AES-256-GCM cipher from a 256-bit root key.

func LoadOrCreateKey

func LoadOrCreateKey(path string) ([]byte, error)

LoadOrCreateKey loads the 256-bit master key from path, or creates it atomically with mode 0600 on first start.

func ReadKey

func ReadKey(path string) ([]byte, error)

ReadKey reads a 256-bit key from path, encoded as 64 hexadecimal digits.

func SealValue

func SealValue(a cipher.AEAD, plain []byte, context string) ([]byte, error)

SealValue encrypts plain with AES-256-GCM and binds context as additional authenticated data.

func UnsealValue

func UnsealValue(a cipher.AEAD, box []byte, context string) ([]byte, error)

UnsealValue decrypts box with AES-256-GCM and verifies context as additional authenticated data.

Types

type Bot

type Bot interface {
	Send(context.Context, string) error
}

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 Deps

type Deps struct {
	Store        *store.Store
	AnchorDir    string
	AllowedHosts []string
	Bot          Bot
	Lang         i18n.Lang
	Log          *slog.Logger
	Now          func() time.Time
	RootCAs      *x509.CertPool // nil uses the system trust store
}

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

func (g Grant) EffectiveMode() string

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 Result

type Result struct {
	Status int `json:"status"`
}

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 Open

func Open(key []byte, d Deps) (*Service, error)

func (*Service) AgentChoices

func (s *Service) AgentChoices() []string

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) Get

func (s *Service) Get(p store.Principal, id string) (Credential, error)

Get returns one credential's metadata for an owner or an authorised agent.

func (*Service) History

func (s *Service) History(p store.Principal, id string, limit int) ([]events.Event, error)

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) Revoke

func (s *Service) Revoke(ctx context.Context, p store.Principal, via, id string, version int64, agent string) (Credential, error)

func (*Service) Rotate

func (s *Service) Rotate(ctx context.Context, p store.Principal, via, id string, version int64, value string) (Credential, error)

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

func (s *Service) UpdateSettings(allowedHosts []string, lang i18n.Lang, bot Bot)

UpdateSettings updates the allowed outbound hosts, language and chat echo bot at runtime.

func (*Service) Use

func (s *Service) Use(ctx context.Context, p store.Principal, via, id string) (Result, error)

Use sends one fixed HTTPS request using an API credential. An audit record is committed before the value is unsealed, and no upstream headers, body or secret value are returned to the caller.

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.

Jump to

Keyboard shortcuts

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