app

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 32 Imported by: ? 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

Index

Constants

View Source
const (
	KeystoreService    = "enbu"
	DefaultEnvironment = "default"
)

Variables

This section is empty.

Functions

func CloseIdentities added in v0.9.0

func CloseIdentities(ids []agecrypto.Identity)

CloseIdentities releases native references, TPM objects, sessions and devices.

func IsNotFoundError

func IsNotFoundError(err error) bool

func IsNotInitializedError

func IsNotInitializedError(err error) bool

func LoadIdentities added in v0.9.0

func LoadIdentities(store IdentityStore, workspaceID string) ([]agecrypto.Identity, error)

Types

type App

type App struct {
	Storage       storage.Store
	StorageURL    string
	InitStorage   *config.StorageConfig
	TokenProvider TokenProvider
	Identities    IdentityStore
	RepoDetector  RepoDetector
	Git           gitprovider.Client
	Events        EventHandler
	RepositoryDir string
	// CheckpointDir holds the local rollback checkpoints. Empty means the
	// per-user data directory.
	CheckpointDir string
	// CacheDir holds what this device keeps to avoid fetching again: heads of
	// stored revisions and the history index. Empty means the per-user data
	// directory. Nothing in it is trusted or secret.
	CacheDir string
	// AcceptNewGenesis lets InitializeRepository replace the genesis this
	// device pinned for the workspace with the one enbu.toml names. Only a
	// person who confirmed the workspace was re-founded sets it.
	AcceptNewGenesis bool
}

func New

func New() *App

func (*App) AddSecret

func (a *App) AddSecret(ctx context.Context, env, key, value string) (err error)

func (*App) ApproveMember added in v0.9.0

func (a *App) ApproveMember(ctx context.Context, deviceID string) (err error)

ApproveMember adds a pending device to the workspace Control as a member, or for a member's pending key update replaces its recipient, then re-encrypts every environment for the new recipient set. The caller is expected to have shown the device's fingerprint to the admin.

func (*App) CompactHistory added in v0.9.0

func (a *App) CompactHistory(ctx context.Context, env string, keep int) (result *CompactResult, err error)

CompactHistory deletes the revisions of env older than the latest keep, so storage and the time to read an environment stop growing with its history. Only a workspace admin may compact, on a backend that can delete.

The revision keep-1 steps behind the current one (following each revision's first parent) becomes the floor: it and every revision descending from it stay. Everything else is deleted, after a signed record listing it is published, so other devices accept that those revisions are gone instead of reporting a rollback. The environment must have one head; concurrent heads are merged with sync first.

func (*App) CreateEnvironment

func (a *App) CreateEnvironment(name string) (err error)

func (*App) CreateIdentity added in v0.9.0

func (a *App) CreateIdentity() (info identity.PublicInfo, warning string, err error)

func (*App) CurrentEnvironment

func (a *App) CurrentEnvironment() (name string, err error)

func (*App) DefaultStorageURL added in v0.9.0

func (a *App) DefaultStorageURL() (_ string, err error)

DefaultStorageURL is the storage a new workspace gets when none is given: a GHCR repository beside the GitHub repository named by the origin remote. It is used once, when init writes enbu.toml, and never derived again.

func (*App) DeleteEnvironment

func (a *App) DeleteEnvironment(name string) (err error)

func (*App) DeleteEnvironmentPurging added in v0.9.0

func (a *App) DeleteEnvironmentPurging(ctx context.Context, name string) (purged int, err error)

DeleteEnvironmentPurging deletes an environment and its stored revisions. Every check runs first, so a deletion that would be refused never deletes secrets: the revisions go only when the environment can really be removed, and the environment stays in enbu.toml until they are gone so a failure halfway can simply be repeated.

func (*App) DeleteSecret

func (a *App) DeleteSecret(ctx context.Context, env, key string) (err error)

func (*App) DiagnoseIdentity added in v0.9.0

func (a *App) DiagnoseIdentity() identity.Diagnosis

func (*App) DiffHistory

func (a *App) DiffHistory(ctx context.Context, env string, fromIdx, toIdx int) (diff *Diff, err error)

func (*App) EditSecret

func (a *App) EditSecret(ctx context.Context, env, key, value string) (err error)

func (*App) IdentityInfo added in v0.9.0

func (a *App) IdentityInfo() (info identity.PublicInfo, err error)

func (*App) ImportSecrets added in v0.9.0

func (a *App) ImportSecrets(ctx context.Context, env string, secrets map[string]string, overwrite bool) (result *ImportResult, err error)

ImportSecrets adds every key of secrets to env in one signed state. A key that already exists with the same value is left alone; one with another value is refused unless overwrite is set, so an import never changes a secret nobody meant to change.

func (*App) InitializeRepository

func (a *App) InitializeRepository(ctx context.Context) (result *InitResult, err error)

func (*App) ListConflicts added in v0.9.0

func (a *App) ListConflicts(ctx context.Context, env string) (set *ConflictSet, err error)

ListConflicts returns the keys of env that are waiting for a decision.

func (*App) ListEnvironments

func (a *App) ListEnvironments() (envs []EnvInfo, err error)

func (*App) ListHistory

func (a *App) ListHistory(ctx context.Context, env string) (history []HistoryEntry, err error)

ListHistory lists the retained revisions of env that changed its secrets, oldest first. It is a change log bounded by what storage still holds, not an audit log. Revisions that only re-encrypted the same content are left out, as are revisions this device cannot decrypt (written before it was a member).

Telling those apart needs each revision decrypted once. What was learned is kept in a local index (two flags per revision, never content), so later listings decrypt only revisions that are new since.

func (*App) ListJoinRequests added in v0.9.0

func (a *App) ListJoinRequests(ctx context.Context) (requests []JoinRequestInfo, err error)

ListJoinRequests returns verified requests from devices that are not yet principals, newest first. Invalid requests are skipped: they are only hints. Storage listing order says nothing about which request is newest, so a device that asked twice with different keys material appears once per distinct recipient and the admin chooses.

func (*App) ListMembers added in v0.9.0

func (a *App) ListMembers(ctx context.Context) (members []MemberInfo, err error)

ListMembers returns the principals of the verified Control.

func (*App) ListSecrets

func (a *App) ListSecrets(ctx context.Context, env string) (result map[string]string, err error)

func (*App) LoadWorkspaceIdentities added in v0.9.0

func (a *App) LoadWorkspaceIdentities() (ids []agecrypto.Identity, err error)

func (*App) PullSecrets

func (a *App) PullSecrets(ctx context.Context, env string) (data []byte, output string, count int, err error)

func (*App) PullSecretsData added in v0.8.0

func (a *App) PullSecretsData(ctx context.Context, env string) (result *PulledSecrets, err error)

func (*App) PullSecretsToFile

func (a *App) PullSecretsToFile(ctx context.Context, env string) (err error)

func (*App) PullSecretsToFileWith added in v0.9.0

func (a *App) PullSecretsToFileWith(ctx context.Context, env string, replace bool) (written *WrittenFile, err error)

PullSecretsToFileWith writes the environment's secrets to its output file, followed by a marker. Variables below the marker that enbu does not store are kept there and reported, unless replace is set; variables above it were written by an earlier pull and leave the file once the environment no longer has them. A file without a marker was written before enbu wrote one, or by hand: its variables that some retained revision of the environment held are enbu's own and leave the file too, and the rest are kept. A file that cannot be read as dotenv is not overwritten without replace.

func (*App) PurgeIncarnation added in v0.9.0

func (a *App) PurgeIncarnation(ctx context.Context, incarnation string) (deleted int, err error)

PurgeIncarnation deletes the stored revisions of an environment that was deleted without --purge, which only forgot where they are. The incarnation is the one switch --delete printed (it is also in enbu.toml's git history). An incarnation that a current environment still uses is refused.

func (*App) ReadConfig

func (a *App) ReadConfig() (content string, err error)

func (*App) RemoveMember added in v0.9.0

func (a *App) RemoveMember(ctx context.Context, deviceID string) (err error)

RemoveMember removes a principal and re-encrypts every environment without its recipient. Plaintext the member already obtained cannot be revoked.

func (*App) RenameEnvironment

func (a *App) RenameEnvironment(oldName, newName string) (err error)

func (*App) ResolveControlFork added in v0.9.0

func (a *App) ResolveControlFork(ctx context.Context) (err error)

ResolveControlFork joins competing Control heads. Two admins changed the members at the same time; the resolution keeps only principals every head lists and admin rights every head grants, so nothing is granted by chance. Anyone it dropped, or anything it did not grant, is added again afterwards by a normal approval.

func (*App) ResolveSecrets added in v0.9.0

func (a *App) ResolveSecrets(ctx context.Context, env string, seen []string, choices map[string]SecretChoice) (err error)

ResolveSecrets settles every conflicted key of env and publishes the result as a revision that merges all heads. Every conflict must be settled at once: a merge revision holds one value per key. seen is ConflictSet.Heads from the listing the choices were made from; if the heads are different now, nothing is published and the person looks again.

func (*App) RestoreHistory

func (a *App) RestoreHistory(ctx context.Context, env string, idx int) (err error)

RestoreHistory publishes the content of a retained revision as a new revision.

func (*App) SetAdmin added in v0.9.0

func (a *App) SetAdmin(ctx context.Context, deviceID string, admin bool) (err error)

SetAdmin grants or revokes the membership-admin flag. It does not change which secrets a member can read.

func (*App) SetRepositoryDir

func (a *App) SetRepositoryDir(dir string)

func (*App) SwitchEnvironment

func (a *App) SwitchEnvironment(name string) (err error)

func (*App) SwitchPrevious

func (a *App) SwitchPrevious() (name string, err error)

func (*App) SyncSecrets

func (a *App) SyncSecrets(ctx context.Context, env string) (err error)

func (*App) UpgradeIdentity added in v0.9.0

func (a *App) UpgradeIdentity(ctx context.Context) (result *KeyUpdateResult, err error)

UpgradeIdentity gives this device a post-quantum (hybrid ML-KEM-768) encryption key. The device asks to swap its recipient with a request signed by its own signing key; an admin approves it like a join request, which re-encrypts every environment. An admin's own update is applied directly.

func (*App) WorkspaceID added in v0.9.0

func (a *App) WorkspaceID() (id string, err error)

func (*App) WriteConfig

func (a *App) WriteConfig(content string) (err error)

type CompactResult added in v0.9.0

type CompactResult struct {
	Kept    int `json:"kept"`    // revisions kept: the latest ones and what they merged
	Removed int `json:"removed"` // revisions deleted from storage
}

CompactResult says what a compaction removed.

type ConflictCandidate added in v0.9.0

type ConflictCandidate struct {
	Value   string `json:"value"`
	Deleted bool   `json:"deleted"`
}

type ConflictSet added in v0.9.0

type ConflictSet struct {
	// ID is a short name for Heads, for a person to repeat back when deciding.
	ID        string           `json:"id"`
	Heads     []string         `json:"heads"`
	Conflicts []SecretConflict `json:"conflicts"`
}

ConflictSet is what a person looked at when deciding: the conflicted keys and the heads they were computed from. ResolveSecrets must be given the same Heads, so a value that appeared since is shown to the person rather than swept away by a choice made without seeing it.

type Diff

type Diff struct {
	Added    []string `json:"added"`
	Removed  []string `json:"removed"`
	Modified []string `json:"modified"`
}

type EnvInfo

type EnvInfo struct {
	Name      string `json:"name"`
	IsCurrent bool   `json:"current"`
	// Incarnation names the environment's stored revisions. Keep it if the
	// environment is deleted without --purge: it is how they are found later.
	Incarnation string `json:"incarnation,omitempty"`
}

type EventHandler

type EventHandler interface {
	OnProgress(msg string)
	OnStepProgress(step ProgressStep)
	OnConflictRetry(attempt, maxAttempts int)
}

type HistoryEntry

type HistoryEntry struct {
	Index     int       `json:"index"`
	Timestamp time.Time `json:"timestamp"`
	Tag       string    `json:"tag"`
}

type IdentityStore added in v0.9.0

type IdentityStore interface {
	Create(workspaceID string) (identity.Identity, identity.PublicInfo, string, error)
	Load(workspaceID string) (identity.Identity, error)
	Info(workspaceID string) (identity.PublicInfo, error)
	Doctor() identity.Diagnosis
	// The signing key is a separate keypair from the encryption identity.
	CreateSigner(workspaceID string) (signing.Signer, identity.SignerInfo, string, error)
	LoadSigner(workspaceID string) (signing.Signer, error)
	SignerInfo(workspaceID string) (identity.SignerInfo, error)
}

type ImportResult added in v0.9.0

type ImportResult struct {
	Environment string   `json:"environment"`
	Added       []string `json:"added"`
	Updated     []string `json:"updated"`
	Unchanged   []string `json:"unchanged"`
}

ImportResult names what one import did to an environment.

type InitResult

type InitResult struct {
	PublicKey   string `json:"public_key"`
	Username    string `json:"username"`
	Environment string `json:"environment"`
	WorkspaceID string `json:"workspace_id"`
	// ControlGenesis is the genesis this device trusts for the workspace.
	ControlGenesis string `json:"control_genesis"`
	Storage        string `json:"storage"`
	KeyCreated     bool   `json:"key_created"`
	Mode           string `json:"mode"`
	HasSecrets     bool   `json:"has_secrets"`
	CanDecrypt     *bool  `json:"can_decrypt"`
	DeviceID       string `json:"device_id"`
	Fingerprint    string `json:"fingerprint"`
	// Founded is set when this init created the workspace's genesis Control.
	Founded bool `json:"founded"`
	// Pending is set when this device is not yet in the workspace Control; an
	// admin must approve it.
	Pending bool `json:"pending"`
	// ReplacedGenesis is the genesis this device trusted before
	// AcceptNewGenesis replaced it, or "".
	ReplacedGenesis string   `json:"replaced_genesis,omitempty"`
	Warnings        []string `json:"-"`
}

type JoinRequestInfo added in v0.9.0

type JoinRequestInfo struct {
	DeviceID    string    `json:"device_id"`
	Fingerprint string    `json:"fingerprint"`
	Recipient   string    `json:"recipient"`
	Algorithm   string    `json:"algorithm"`
	RequestedAt time.Time `json:"requested_at"`
	// KeyUpdate is set for a member asking to replace its recipient, as
	// `enbu identity upgrade` does, rather than a new device asking to join.
	KeyUpdate bool `json:"key_update"`
}

type KeyUpdateResult added in v0.9.0

type KeyUpdateResult struct {
	Backend     string `json:"backend"`
	Algorithm   string `json:"algorithm"`
	Recipient   string `json:"recipient"`
	DeviceID    string `json:"device_id"`
	Fingerprint string `json:"fingerprint"`
	// Pending is set while an admin still has to approve the new key. Until
	// then this device decrypts with either key.
	Pending  bool     `json:"pending"`
	Warnings []string `json:"-"`
}

type MemberInfo added in v0.9.0

type MemberInfo struct {
	DeviceID    string `json:"device_id"`
	Fingerprint string `json:"fingerprint"`
	Recipient   string `json:"recipient"`
	Algorithm   string `json:"algorithm"`
	Admin       bool   `json:"admin"`
	Self        bool   `json:"self"`
	// PostQuantum is set when the member's recipient is a hybrid ML-KEM key.
	// Secrets are post-quantum only while every member's is.
	PostQuantum bool `json:"post_quantum"`
}

type ProgressStep added in v0.7.4

type ProgressStep struct {
	Op     string `json:"op"`     // "add" | "pull" | "sync" | "delete"
	Step   string `json:"step"`   // "encrypt" | "push" | "pull_secrets" | "pull_recipients" | "reencrypt" | "decrypt" | "write"
	Status string `json:"status"` // "start" | "done"
}

type PulledSecrets added in v0.8.0

type PulledSecrets struct {
	Environment string
	Output      string
	Secrets     map[string]string
}

type RepoDetector

type RepoDetector interface {
	LoadRepo() (owner, repo string, err error)
}

type ResolvedEnvironment

type ResolvedEnvironment struct {
	Name   string
	Output string
}

type SecretChoice added in v0.9.0

type SecretChoice struct {
	Value  string
	Delete bool
}

SecretChoice settles one conflicted key with a value, or by deleting it.

type SecretConflict added in v0.9.0

type SecretConflict struct {
	Key        string              `json:"key"`
	Candidates []ConflictCandidate `json:"candidates"`
}

SecretConflict is a key that concurrent edits changed differently. Nothing is chosen for the user: they pick one candidate, or give a new value.

type TokenProvider

type TokenProvider interface {
	LoadToken() (accessToken string, username string, err error)
}

type WrittenFile added in v0.9.0

type WrittenFile struct {
	Output string   // the file, as configured for the environment
	Count  int      // secrets written
	Kept   []string // variables of the previous file that enbu does not store
	// Removed are variables an earlier pull wrote that the environment no
	// longer has; they are not kept, so a deleted secret leaves the file.
	Removed []string
}

WrittenFile describes what a pull wrote.

func (*WrittenFile) Messages added in v0.9.0

func (w *WrittenFile) Messages() []string

Messages tells the user what the pull kept and removed besides the secrets.

Directories

Path Synopsis
Package apptest provides in-memory doubles shared by tests that need an app.IdentityStore.
Package apptest provides in-memory doubles shared by tests that need an app.IdentityStore.

Jump to

Keyboard shortcuts

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