app

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 34 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 app is the product facade. CLI and MCP are thin wrappers around it.

Index

Constants

View Source
const (
	DefaultOrg   = protocol.LocalOrgID
	DefaultHuman = "self"
)
View Source
const (
	SessionPrefix = "ses_"

	SessionTTLDefault = 15 * time.Minute
	SessionTTLMax     = time.Hour
)

Variables

View Source
var (
	ErrTOTPEnrollDenied = errors.New("app: totp enroll denied")

	ErrAgentRevoked = errors.New("app: agent revoked")
)
View Source
var (
	ErrForbidden        = errors.New("app: forbidden")
	ErrSessionExpired   = errors.New("app: session expired")
	ErrSessionRevoked   = errors.New("app: session revoked")
	ErrSessionExhausted = errors.New("app: session uses exhausted")
)
View Source
var ErrBillingDisabled = errors.New("app: billing checkout not configured")

ErrBillingDisabled — checkout/reporting needs the Vortex wiring (VEIL_VORTEX_* envs) plus VEIL_VORTEX_PRICE_ID for the plan price.

View Source
var ErrExists = errors.New("app: vault already exists")
View Source
var ErrIdentityUnavailable = errors.New("app: identity plane unavailable")

ErrIdentityUnavailable marks dependency failures in the identity plane (Keto membership, Hydra verification) — distinct from bad credentials so API callers see 503-unavailable instead of a misleading 401.

View Source
var ErrInviteLimit = errors.New("app: invite rate limit")

ErrInviteLimit is returned when an inviter or a recipient address has hit the invite ceiling for the window. The API maps it to 429.

View Source
var ErrUnauthorized = errors.New("app: unauthorized")

ErrUnauthorized marks token/principal resolution failure on verbs that distinguish it from a bad argument — the API maps it to 401, not 400.

Functions

func Accept

func Accept(dir string, priv, blob []byte) error

Accept writes device.key and a wrap. Not a second vault. Not plaintext master. Copy vault.db and config.json yourself. This is not sync.

func IsSessionToken

func IsSessionToken(raw string) bool

Types

type App

type App struct {
	Dir       string
	OrgID     string
	HumanID   string
	Store     store.Store
	Auditor   audit.Auditor
	Broker    *broker.Broker
	Human     HumanVerifier
	Workload  *workload.Checker
	Members   MemberCheck
	Provision Provisioner
	Invites   Inviter
	OrgAdmin  OrgAdmin
	Notify    RequestNotify
	// Push wakes registered phone devices on a filed ask — the same
	// RequestNotify shape as email, fanned out next to it. Nil when the
	// APNs envs are unset.
	Push RequestNotify
	// BillingCustomers is the merchant-scoped Vortex client — nil when the
	// VEIL_VORTEX_* envs are unset (billing off; dev and tests unaffected).
	BillingCustomers *billing.Client
	// contains filtered or unexported fields
}

func Init

func Init(dir string) (*App, error)

func Open

func Open(dir string) (*App, error)

func OpenOrInit

func OpenOrInit(dir string) (*App, error)

OpenOrInit opens an existing vault, or creates one when there is no key material. A stray vault.db without wraps or master.key is not "empty" — Init would hit ErrExists and Open would print the misleading master.key miss that Railway crash-looped on.

func OpenPostgres

func OpenPostgres(dsn string) (*App, error)

OpenPostgres opens a stateless origin backed by a Postgres DSN. The deployment KEK is read from the VEIL_KEK environment variable (hex) and seals per-org master keys in org_keys. VEIL_MASTER_KEY is the pre-multi-org legacy: when set, it is seeded once as this org's wrapped master and can be removed afterward.

func (*App) AddAgent

func (a *App) AddAgent(name string) (protocol.Principal, error)

AddAgent registers an agent under the local vault's planted human.

func (*App) AddAgentFor

func (a *App) AddAgentFor(owner protocol.Principal, name string) (protocol.Principal, error)

AddAgentFor registers an agent owned by the calling human, in their org.

func (*App) AddGrant

func (a *App) AddGrant(agentID, itemID string, level protocol.GrantLevel) (protocol.Grant, error)

func (*App) AddGroup

func (a *App) AddGroup(actor protocol.Principal, name string) (protocol.Group, error)

AddGroup creates an org group — owner-administered like grants.

func (*App) AddItem

func (a *App) AddItem(name, uri string, secret []byte) (protocol.Item, error)

func (*App) AgentFromOIDC

func (a *App) AgentFromOIDC(ctx context.Context, rawToken string) (protocol.Principal, error)

func (*App) Approve

func (a *App) Approve(grantID string, ttl time.Duration) (protocol.Approval, error)

func (*App) ApproveOIDC

func (a *App) ApproveOIDC(ctx context.Context, grantID, rawToken string, ttl time.Duration) (protocol.Approval, error)

ApproveOIDC is Approve with a Hydra ID token. An approval mints the credential release — the same owner-scope as administering the grant. Planted `self` is the laptop stand-in when no issuer is configured.

func (*App) ApproveRequest

func (a *App) ApproveRequest(reqID string, ttl time.Duration) (protocol.ApprovalRequest, error)

ApproveRequest resolves one pending ask locally — the approval lands only while the ask is open; a lost race is ErrRequestResolved, no side effects.

func (*App) ArchiveItem

func (a *App) ArchiveItem(name string) error

func (*App) ArchiveItemFor

func (a *App) ArchiveItemFor(actor protocol.Principal, name string) error

func (*App) AttachTOTP

func (a *App) AttachTOTP(p protocol.Principal, itemID, seed string) error

func (*App) BillingCheckoutURL

func (a *App) BillingCheckoutURL(ctx context.Context, orgID string) (string, error)

BillingCheckoutURL mints the org's hosted upgrade link — the owner clicks it, pays, and the subscription webhook flips the plan. Provisions the billing link lazily so orgs that predate billing (or hit a provisioning outage) can still upgrade. ErrBillingDisabled when checkout isn't wired.

func (*App) BindWorkload

func (a *App) BindWorkload(agentID, issuer, subject, audience string) (protocol.Workload, error)

func (*App) BindWorkloadFor

func (a *App) BindWorkloadFor(actor protocol.Principal, agentID, issuer, subject, audience string) (protocol.Workload, error)

BindWorkloadFor enrolls a workload identity on behalf of actor — owner only, same bar as grants: binding an auth method to a foreign agent is a grant-adjacent write.

func (*App) BindWorkloadForWithClaims

func (a *App) BindWorkloadForWithClaims(actor protocol.Principal, agentID, issuer, subject, audience string, claims map[string][]string) (protocol.Workload, error)

func (*App) BindWorkloadWithClaims

func (a *App) BindWorkloadWithClaims(agentID, issuer, subject, audience string, claims map[string][]string) (protocol.Workload, error)

func (*App) CanCreateGrant

func (a *App) CanCreateGrant(p protocol.Principal) (bool, error)

func (*App) ChildEnv

func (a *App) ChildEnv(ctx context.Context, agentID string) ([]string, error)

func (*App) Close

func (a *App) Close() error

func (*App) CreateSession

func (a *App) CreateSession(actor protocol.Principal, agentID string, ttl time.Duration, maxUses int) (protocol.Session, string, error)

func (*App) DeleteItem

func (a *App) DeleteItem(name string) error

func (*App) DeleteItemFor

func (a *App) DeleteItemFor(actor protocol.Principal, name string) error

func (*App) DeleteMe

func (a *App) DeleteMe(ctx context.Context, rawToken string) error

DeleteMe is the human kill-switch: drop both tuple legs and the humans row — the token resolves nothing from this point. A sole owner cannot leave an org with members in it: promote someone, or delete the org.

func (*App) DeleteOrg

func (a *App) DeleteOrg(ctx context.Context, rawToken string) (store.PurgeReport, error)

DeleteOrg is teardown: kill every access path first (Keto tuples), then purge every vault row for the org in one transaction. Audit rows survive — teardown must not erase the record of what happened.

func (*App) DemoteOwner

func (a *App) DemoteOwner(ctx context.Context, rawToken, memberID string) error

DemoteOwner strips the owners tuple — the last owner cannot be demoted or the org has no one who can administer it.

func (*App) FillLogin

func (a *App) FillLogin(p protocol.Principal, uuid string, mintTotp bool) (FillEntry, error)

FillLogin decrypts one item. mintTotp puts a 6-digit code in TOTP instead of "*".

func (*App) FillLogins

func (a *App) FillLogins(p protocol.Principal, rawURL string) ([]FillEntry, error)

func (*App) FillPasskeyGet

func (a *App) FillPasskeyGet(p protocol.Principal, origin string, publicKey json.RawMessage) (json.RawMessage, error)

func (*App) FillPasskeyRegister

func (a *App) FillPasskeyRegister(p protocol.Principal, origin string, publicKey json.RawMessage, extraURIs []string) (json.RawMessage, error)

func (*App) FillSync

func (a *App) FillSync(p protocol.Principal, since string) ([]FillSyncRow, string, error)

FillSync is the replica pull. Human only. since is reserved; this cut is a full pull.

func (*App) FillTOTP

func (a *App) FillTOTP(p protocol.Principal, itemID string, now time.Time) (string, error)

func (*App) GrantSubject

func (a *App) GrantSubject(actor protocol.Principal, kind protocol.SubjectKind, subject, itemID string, level protocol.GrantLevel, expires *time.Time) (protocol.Grant, error)

GrantSubject is GrantUntil widened to a subject kind (VEIL-20): an agent or human is the same direct grant; a group subject makes an org-owned item plus this grant the shared vault — one row instead of one grant per member. level=deny writes the explicit block that beats inherited allows.

func (*App) GrantUntil

func (a *App) GrantUntil(actor protocol.Principal, grantee, itemID string, level protocol.GrantLevel, expires *time.Time) (protocol.Grant, error)

GrantUntil grants grantee access to itemID on behalf of actor. The grant lives in the item's org; a grantee outside it is not a grantee, and an agent owned by a different human is not the actor's to delegate.

func (*App) GroupAddMember

func (a *App) GroupAddMember(actor protocol.Principal, groupName string, kind protocol.PrincipalKind, memberID string) error

func (*App) GroupMemberList

func (a *App) GroupMemberList(actor protocol.Principal, groupName string) ([]protocol.GroupMember, error)

GroupMemberList returns a group's members — owner-administered.

func (*App) GroupRemoveMember

func (a *App) GroupRemoveMember(actor protocol.Principal, groupName string, kind protocol.PrincipalKind, memberID string) error

func (*App) Groups

func (a *App) Groups(actor protocol.Principal) ([]protocol.Group, error)

Groups returns the org's groups — owner-administered surface.

func (*App) ImportItems

func (a *App) ImportItems(p protocol.Principal, rows []oneimport.Row) (ImportResult, error)

func (*App) InjectFile

func (a *App) InjectFile(src, dest string, pairs []string) error

func (*App) InviteHuman

func (a *App) InviteHuman(ctx context.Context, rawToken, email string) (InviteResult, error)

InviteHuman is the private-alpha gate: a verified, provisioned human invites an email into their org. The identity and recovery link live in Kratos; owner-ness is enforced by the Inviter (Keto) inside glue.

func (*App) ItemsForAgent

func (a *App) ItemsForAgent(agentID string) ([]protocol.Item, error)

func (*App) ItemsForPrincipal

func (a *App) ItemsForPrincipal(p protocol.Principal) ([]protocol.Item, error)

func (*App) ListSessions

func (a *App) ListSessions(actor protocol.Principal) ([]protocol.Session, error)

func (*App) Match

func (a *App) Match(p protocol.Principal, rawURL string) ([]protocol.Item, error)

Match lists fill candidates for a URL. Metadata only. Never Secret().

func (*App) MayWriteItem

func (a *App) MayWriteItem(p protocol.Principal, item protocol.Item) (bool, error)

func (*App) Offer

func (a *App) Offer(peerPub []byte) ([]byte, error)

Offer wraps master to a second device's public key. nacl box. The blob is not JSON. The grant does not get a copy. Master is not a file.

func (*App) OwnsVault

func (a *App) OwnsVault(p protocol.Principal) (bool, error)

func (*App) PrincipalFromOIDC

func (a *App) PrincipalFromOIDC(ctx context.Context, rawToken string) (protocol.Principal, error)

PrincipalFromOIDC is origin identity. Session lease first. Bound agent next. Else Hydra human plus Keto membership. Grants stay in the vault.

func (*App) PrincipalFromSession

func (a *App) PrincipalFromSession(rawToken string) (protocol.Principal, error)

func (*App) PromoteOwner

func (a *App) PromoteOwner(ctx context.Context, rawToken, memberID string) error

PromoteOwner grants an existing member the owners tuple.

func (*App) ProvisionHuman

func (a *App) ProvisionHuman(ctx context.Context, rawToken string) (protocol.Principal, error)

ProvisionHuman is signup. A verified human with no vault row gets an org (new UUID), an org master minted and sealed under the KEK via EnsureOrgKey, Keto owner+member tuples, and the Kratos organization_id stamp — all the same join key. Idempotent: a planted human returns their existing org, and a retry after a mid-flight failure resumes from the anchored humans row rather than minting a second org.

func (*App) PutItem

func (a *App) PutItem(opts ItemOpts) (protocol.Item, error)

func (*App) PutItemFor

func (a *App) PutItemFor(p protocol.Principal, opts ItemOpts) (protocol.Item, error)

func (*App) RecordFillEvents

func (a *App) RecordFillEvents(p protocol.Principal, evs []FillEventReport) error

func (*App) RemoveMember

func (a *App) RemoveMember(ctx context.Context, rawToken, memberID string) error

RemoveMember offboards a member: drops the Keto tuple and the humans row — their token stops resolving immediately. Owners cannot be removed this way; demote first (or delete the org).

func (*App) RenewSession

func (a *App) RenewSession(actor protocol.Principal, id string) (protocol.Session, error)

func (*App) RevokeAgent

func (a *App) RevokeAgent(actor protocol.Principal, agentID string) error

func (*App) RevokeSession

func (a *App) RevokeSession(actor protocol.Principal, id string) (protocol.Session, error)

func (*App) RotateDue

func (a *App) RotateDue(now time.Time, maxItems int) (int, error)

RotateDue rotates up to maxItems items whose sealed NextRotateAt watermark is due at now. Egress contract (AGENTS.md rule 9): zero Postgres writes and zero outbound provider calls when no item is due; bounded to maxItems per invocation so a backlog drains across ticks without a burst.

func (*App) RotateItem

func (a *App) RotateItem(actor protocol.Principal, name string) (protocol.Item, error)

RotateItem swaps an item's credential server-side: the provider's key-management API mints a replacement, the new secret is verified and sealed in place — item id and grants are untouched, agents keep calling Use. Retire of the old provider key is best-effort and audited either way. Owner-only: rotation is vault administration, not a grant.

func (*App) RotateItemWith

func (a *App) RotateItemWith(actor protocol.Principal, name string, opts RotateOpts) (protocol.Item, error)

func (*App) SecurityReport

func (a *App) SecurityReport(ctx context.Context, p protocol.Principal, check health.Checker) (health.Report, error)

SecurityReport is the vault health report — weak, reused, and optionally breached passwords across what the principal can see. Human only, like fill: the report reads sealed material in-process and emits metadata only. check is nil for the default offline report; pass health.HIBP{}.Check to opt into k-anonymity breach lookup.

func (*App) StartRotationTicker

func (a *App) StartRotationTicker()

StartRotationTicker runs RotateDue once per hour (max 20 due items/tick). Egress rate (AGENTS.md rule 9): 0 bytes/tick when no item has next_rotate_at <= now; bounded to <=20 provider rotations/hour when due.

func (*App) UnbindWorkloadFor

func (a *App) UnbindWorkloadFor(actor protocol.Principal, agentID, issuer, subject string) error

func (*App) UpdateItem

func (a *App) UpdateItem(name string, replaceURIs, addURIs, tags []string, login string, token []byte) (protocol.Item, error)

func (*App) UpdateItemFor

func (a *App) UpdateItemFor(actor protocol.Principal, name string, replaceURIs, addURIs, tags []string, login string, token []byte) (protocol.Item, error)

UpdateItemFor is UpdateItem attributed to an explicit actor — the HTTP layer's write-gated path.

func (*App) Use

func (a *App) Use(ctx context.Context, agentID, itemID, method, rawURL string) (protocol.UseResult, error)

func (*App) UseCheck

func (a *App) UseCheck(ctx context.Context, agentID, itemID, method, rawURL string) (protocol.UseResult, error)

UseCheck evaluates a Use without executing it: grant + approval checks run (and the need_approval ask is filed) but no use is claimed and the secret is never touched. Agents pre-flight with it; humans see the ask.

func (*App) UseFetch

func (a *App) UseFetch(ctx context.Context, agentID, itemID string, fetch protocol.Fetch) (protocol.UseResult, error)

func (*App) UseFetchSession

func (a *App) UseFetchSession(ctx context.Context, rawToken, itemID string, fetch protocol.Fetch) (protocol.UseResult, error)

func (*App) UseSession

func (a *App) UseSession(ctx context.Context, rawToken, itemID, method, rawURL string) (protocol.UseResult, error)

func (*App) VerifyIssuer

func (a *App) VerifyIssuer(ctx context.Context, actor protocol.Principal, issuer string) (workload.VerifyResult, error)

VerifyIssuer dry-runs an OIDC issuer discovery for actor (owner-only).

func (*App) VerifyItem

func (a *App) VerifyItem(ctx context.Context, actor protocol.Principal, name string) (string, error)

VerifyItem dry-runs an item's credential (WIF jwt-bearer exchange, OAuth refresh, or provider rotator Verify) without revealing the secret. Owner-only.

func (*App) WorkloadsForAgent

func (a *App) WorkloadsForAgent(actor protocol.Principal, agentID string) ([]protocol.Workload, error)

func (*App) WriteFile

func (a *App) WriteFile(name, dest string) error

type FillEntry

type FillEntry struct {
	Login    string
	Name     string
	Password string
	UUID     string
	TOTP     string
}

FillEntry is native-host material. Not protocol.Item. Not MCP. Login is the fill username from the sealed envelope. Empty if unset. Never fall back to item.Name on the URL form. TOTP is "*" when a seed exists so KeePassXC-Browser will call get-totp. FillLogin(mintTotp) puts a 6-digit code instead. Never the seed.

type FillEventReport

type FillEventReport struct {
	UUID     string
	Kind     string
	MintTOTP bool
	At       time.Time
}

FillEventReport is a client-reported disclosure. When the fill host serves a secret from the sealed replica instead of calling origin, it attests the release here so the audit feed sees the same row an online fill writes. At is the client's fill time — a queued report can land long after it happened. Kind is the client's claim; for a known item the store's kind wins. Unknown or cross-org uuids still record, under the reporter's org — a lost audit is worse than a row that cannot name its item's true kind.

type FillSyncRow

type FillSyncRow struct {
	Item     protocol.Item
	Material []byte
}

FillSyncRow is one replica pull record. Material is the envelope JSON. Not protocol.Item. Not MCP. Not OpenAPI.

type HumanVerifier

type HumanVerifier interface {
	Subject(ctx context.Context, rawToken string) (string, error)
}

HumanVerifier verifies a human bearer token down to its subject. *human.Verifier is the production impl.

type ImportResult

type ImportResult struct {
	Names []string `json:"names"`
	Count int      `json:"count"`
	// Kind breakdown of what actually imported — "login":47 reads better
	// than a bare count after a 400-row export.
	Kinds map[string]int `json:"kinds,omitempty"`
	// Skipped names already in the vault. Local CLI shows them; the origin
	// ImportResponse schema is names+count only (spec is SDK-locked).
	Skipped []string `json:"skipped,omitempty"`
}

type InviteResult

type InviteResult struct {
	IdentityID  string
	RecoveryURL string
	Emailed     bool
}

InviteResult is what an owner gets back from an invite: the new identity, whether the email went out, and the recovery link when it did not.

type Inviter

type Inviter interface {
	Invite(ctx context.Context, email, actor, orgID string) (InviteResult, error)
}

Inviter creates a Kratos identity plus recovery link under the owner's org. glue.Glue satisfies it via a thin adapter; nil in local vaults.

type ItemOpts

type ItemOpts struct {
	ID           string
	Name         string
	URI          string
	URIs         []string
	Tags         []string
	Kind         protocol.ItemKind
	Token        []byte
	Login        string
	TOTPSeed     []byte
	Refresh      []byte
	TokenURL     string
	ClientID     string
	ClientSecret []byte
	FileName     string
	MIME         string
	File         []byte
	Passkey      []byte
	WIF          *material.WIFOpts
	Owner        protocol.Owner
	// OrgID is the caller's org. Empty falls back to the deployment default —
	// the local vault path; the origin always sets it from the principal.
	OrgID string
}

type MemberCheck

type MemberCheck interface {
	IsMember(ctx context.Context, orgID, identityID string) (bool, error)
	IsOwner(ctx context.Context, orgID, identityID string) (bool, error)
}

MemberCheck is identity-plane owner/member. Keto via glue. Not grants.

type OrgAdmin

type OrgAdmin interface {
	RemoveMember(ctx context.Context, orgID, identityID string) error
	RemoveOwner(ctx context.Context, orgID, identityID string) error
	PromoteOwner(ctx context.Context, orgID, identityID string) error
	RemoveOrgTuples(ctx context.Context, orgID string) error
	ListOwners(ctx context.Context, orgID string) ([]string, error)
}

OrgAdmin is org membership surgery against the identity plane — Keto tuple writes/deletes. glue.Glue satisfies it; nil in local vaults.

type Provisioner

type Provisioner interface {
	ProvisionMember(ctx context.Context, orgID, identityID string) error
	SetIdentityOrg(ctx context.Context, identityID, orgID string) error
	IdentityOrg(ctx context.Context, identityID string) (string, error)
}

Provisioner plants a human's membership in their org: Keto tuples plus the Kratos organization_id stamp. glue.Glue satisfies it; nil in local vaults. IdentityOrg reads the stamp — an invite sets it, and provisioning honors it.

type RequestNotify

type RequestNotify interface {
	NotifyRequest(ctx context.Context, req protocol.ApprovalRequest) error
}

RequestNotify pings org owners when an ask lands — veil-mail via glue; nil in local vaults. Best-effort: the request row is the durable part.

type RotateOpts

type RotateOpts struct {
	ManagementItem    string
	Interval          time.Duration
	ReplacementSecret []byte
}

RotateOpts configures optional separate management-credential authority and automatic rotation interval for an item.

Jump to

Keyboard shortcuts

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