api

package
v0.0.0-...-55a4408 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: AGPL-3.0 Imports: 43 Imported by: 0

Documentation

Overview

Package api glues the storage primitives behind the Privasys Drive REST surface. The handlers are intentionally thin — every operation has a matching public function in the underlying packages so the manifest-tool surface (tools.go) can call them directly without going through HTTP.

Index

Constants

This section is empty.

Variables

View Source
var ErrVaultKeyStale = errors.New("tenant vault key unavailable; re-arm via POST /v1/me/tenant/key")

ErrVaultKeyStale means the tenant's vault MEK could not be loaded (typically the stored attestation token expired since the last re-arm). It is recoverable: the owner re-arms via POST /v1/me/tenant/key with a fresh grant bundle. Callers surface it as 409 with a machine-readable code so a client auto-re-arms rather than treating it as a hard failure.

Functions

This section is empty.

Types

type MEKProvider

type MEKProvider interface {
	Provision(ctx context.Context, b vaultmek.Bundle) (vaultmek.Ref, error)
	Load(ctx context.Context, ref vaultmek.Ref) ([]byte, error)
	Unwrap(ctx context.Context, ref vaultmek.Ref, ciphertext, iv []byte) ([]byte, error)
	// RefreshTees is the data owner's measurement approval: replace the
	// key's pinned TEE profile with the grant's (the app's current
	// measurement), authenticated as the key owner.
	RefreshTees(ctx context.Context, ref vaultmek.Ref, grant, ownerBearer string) error
	// Regenerate re-creates the tenant's key (same material) at the next
	// handle generation under a fresh grant — the renewal for the vault's
	// fixed expires_at, and the ride off a retiring constellation.
	Regenerate(ctx context.Context, ref vaultmek.Ref, b vaultmek.Bundle) (vaultmek.Ref, error)
}

MEKProvider is the vault-side of per-tenant keys and sealed credentials (vaultmek.Client in production; faked in tests).

type Principal

type Principal struct {
	Sub   string
	Via   authVia
	ID    *oidc.Identity   // non-nil for users
	Grant *grants.Grant    // non-nil for app principals
	Env   *grants.Envelope // non-nil for app principals
	// Bearer is the caller's raw platform token, kept for the bearer
	// path alone. Funding a recipient's attribute disclosure is an act
	// the control plane attributes to the caller's OWN account, which it
	// resolves from the token, so Drive has to present the caller's
	// token rather than its app identity. Empty on every other path,
	// which is why a sealed-session sharer cannot fund a share.
	Bearer string
	// AIGrant marks an assistant principal that came from a files.ai grant
	// rather than the trusted assistant enclave: it acts for the holder who
	// minted the grant, may read and search their AI scope, and nothing more
	// (no open_link, no settings changes).
	AIGrant bool
}

Principal is an authenticated caller: a platform user (OIDC bearer or sealed-transport session) or a third-party app presenting an AppGrant token.

func (*Principal) IsAssistant

func (p *Principal) IsAssistant() bool

IsAssistant reports whether p is the confidential-AI assistant enclave acting on behalf of a user (§8.7 RAG-in-enclave). Such a principal may run only the AI-scoped RAG surface: it reads the tenant's AI-scoped node set and the shares the user opened through it, and its one act is open_link, which gives the user what clicking the link would (assistantshares.go). It never writes content.

func (*Principal) IsUser

func (p *Principal) IsUser() bool

IsUser reports whether p is a user (OIDC bearer or sealed session).

type SealedBucketCred

type SealedBucketCred struct {
	// KeyRef addresses the operator key on the constellation (handle,
	// endpoints, MRENCLAVE, attestation server + token).
	KeyRef vaultmek.Ref `json:"key_ref"`
	// CiphertextB64 / IvB64 are the sealed credential (raw-url base64).
	CiphertextB64 string `json:"ciphertext_b64"`
	IvB64         string `json:"iv_b64"`
	// ContentType labels the credential for the object backend
	// (e.g. "gcs-sa-json", "s3-keypair", "ovh-token").
	ContentType string `json:"content_type"`
	// Bucket is the target bucket name (plaintext metadata, not secret);
	// the sealed plaintext holds only the credential material.
	Bucket string `json:"bucket"`
}

SealedBucketCred is a BYO cloud-bucket credential a tenant sealed under a vault "wrapped-secret" operator key (an Aes256GcmKey whose policy grants Drive's app TEE Unwrap only — never Wrap or DeleteKey). The tenant/owner sealed the plaintext with an in-enclave Wrap RPC to the vault; Drive stores only the ciphertext and unwraps it in-enclave per session, so the platform, the operator and a non-promoted build never see the credential.

type Server

type Server struct {
	Store    *store.Store
	Backend  objectstore.Backend
	Grants   *grants.Repo
	Verifier oidc.Verifier
	MEK      []byte // single tenant MEK for `--dev`. Production: fetched per tenant from vault.

	// Revoked rejects tokens whose IdP session was revoked (long-lived
	// API keys). Nil disables the check.
	Revoked *oidc.RevokedSet

	// AttrRef reads the IdP's canonical attribute referential, which is
	// what tells a government-backed attribute key from the self-asserted
	// twin that answers the same question for free. Nil where no issuer is
	// configured, which is fail-closed everywhere an attribute can be
	// billed: a share requiring one is refused rather than stored at an
	// assurance nobody chose.
	AttrRef *attrref.Client

	// MEKs provisions and loads per-tenant vault-held MEKs. Nil
	// disables vault-held tenant keys (tenants stay on the instance
	// MEK).
	MEKs MEKProvider

	// Platform is the enclave-manager environment (empty off-platform).
	Platform platform.Env
	// StateDir persists the instance config (the sealed /data volume on
	// the platform).
	StateDir string
	// DevMode relaxes the configure-authz role check (dev verifier runs
	// without platform roles).
	DevMode bool
	Version string
	// WebDir holds the UI's static export (webui.go); empty serves the API
	// only.
	WebDir string
	// contains filtered or unexported fields
}

Server bundles the handlers + their dependencies.

func (*Server) CurrentConfig

func (s *Server) CurrentConfig() *config.Config

CurrentConfig returns the active config, or nil before configure.

func (*Server) Handler

func (s *Server) Handler(manifestPath string) http.Handler

Handler returns the full HTTP surface: health/status/configure, the REST API under /v1, the manifest tools under /tools, and the manifest document endpoints.

func (*Server) InstallConfig

func (s *Server) InstallConfig(c *config.Config)

InstallConfig sets the in-memory config without persisting (boot-time re-apply of an already-persisted config).

func (*Server) Notifier

func (s *Server) Notifier() *notify.Client

Notifier returns the wallet-push client, building it lazily from the current config's control-plane base URL and the app's manager-minted identity. Nil when either is unavailable (off-platform / unconfigured): notifications degrade to silence, never to an error.

func (*Server) Routes

func (s *Server) Routes() http.Handler

Routes returns the HTTP handler with all REST routes mounted under /v1.

func (*Server) SetConfig

func (s *Server) SetConfig(c *config.Config) error

SetConfig installs (and persists) the instance configuration.

func (*Server) StartExpirySweep

func (s *Server) StartExpirySweep(ctx context.Context, interval time.Duration)

StartExpirySweep runs the session-attachment GC (§8.7 intent A): every interval it deletes nodes whose expiry has passed, cascading their index rows. Stops when ctx is cancelled. Safe to call once at boot.

func (*Server) StartIndexer

func (s *Server) StartIndexer()

StartIndexer starts the background indexer's worker and retry sweep at boot. Without this, the sweep only starts on the first post-boot upload (Enqueue), and a restarted deployment with a backlog but no new uploads never drains its queue. No-op without pgvector (SQLite dev, CI).

func (*Server) Tools

func (s *Server) Tools() http.Handler

Tools returns the manifest-tool invocation surface: the plain-JSON POST endpoints the privasys.json tools point at. Each is a thin wrapper over the same internals as the REST surface, with identical auth (OIDC bearer or AppGrant) and access checks.

func (*Server) WaitBackground

func (s *Server) WaitBackground()

WaitBackground blocks until in-flight background writes (access metrics) have drained. Call before closing the store.

type WorkspaceFile

type WorkspaceFile struct {
	Path string `json:"path"`
	Size int64  `json:"size"`
	Mode string `json:"mode,omitempty"`
	Blob string `json:"blob"`
}

WorkspaceFile is one entry of a workspace manifest.

type WorkspaceManifest

type WorkspaceManifest struct {
	Version int             `json:"version"`
	App     string          `json:"app,omitempty"`
	SavedAt string          `json:"saved_at,omitempty"`
	Files   []WorkspaceFile `json:"files"`
}

WorkspaceManifest is the snapshot description the runtime writes.

Jump to

Keyboard shortcuts

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