backendapi

package
v2.4.6 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: AGPL-3.0 Imports: 44 Imported by: 0

Documentation

Overview

Package backendapi is the backend-plane admin HTTP API.

It exposes operator endpoints (dict / acl / quota / folder / user / mailbox / ...) against the local backend's storage and pkg/dict instances. One instance runs per backend tag (or one per standalone deployment).

Concerns split:

yarilo-director hosts /api/director/...      (ring / backends / users / peers)
yarilo-backend-api hosts /api/backend/<service>/...  (dict / acl / quota / ...)

Different binaries because director state lives in director's process memory and backend state (NFS + dicts) lives in backend pods; in a multi-pod cluster these are physically separate, so they cannot be combined.

Wire protocol: JSON over HTTPS. Endpoints mirror internal/director's /api/director/... surface so the yarctl CLI can speak both with identical machinery (bearer-token auth, IP allow-list, application/json bodies).

Streaming endpoints (currently dict/iterate) use NDJSON, one JSON object per line, so the CLI can display without buffering the whole response.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	Addr        string
	TLSConfig   *tls.Config
	Token       string
	AllowedNets []*net.IPNet
	Dicts       map[string]dict.Dict

	Mailbox            mailbox.MailboxBackend
	Index              mailbox.IndexBackend
	Resolver           *mailbox.Resolver
	NamespaceMailboxes map[string]mailbox.MailboxBackend
	Namespaces         []config.NamespaceConfig
	Locker             locks.Locker
	SpecialUseDefaults map[string]string
	MetadataDict       dict.Dict
	QuotaDict          dict.Dict
	// SharedDict is the owner-discovery registry (#1168), same handle the IMAP
	// side writes through; nil disables discovery.
	SharedDict dict.Dict
	// QuotaCloneDicts names the dicts (subset of Dicts) that quota_clone mirrors
	// usage into. Exposed read-only via /api/backend/quota/clone/* for operators
	// to inspect the fan-out. From cfg.Quota.CloneDicts.
	QuotaCloneDicts []string

	// WardenAddr / WardenTLS configure the connection to yarilo-warden for the
	// WHO endpoint. Empty Addr disables /who (returns 501). Same TLS config the
	// rest of internal cluster traffic uses.
	WardenAddr string
	WardenTLS  *tls.Config

	// PodIP is this backend pod's IP (from the POD_IP env / status.podIP).
	// /who scopes to sessions routed to THIS backend by default, matching each
	// warden session's Backend field against it. Empty (env not injected)
	// disables the scoping; /who then behaves as if --all was set.
	PodIP string

	// Router says which pod keeps a user, to forward a request there (#2053);
	// nil runs every request where it lands, as without a director.
	Router UserRouter
	// PeerTLS and PeerPort reach another pod's backend-api for that forward.
	PeerTLS  *tls.Config
	PeerPort string

	// AuthClient is the live yarilo-auth master-protocol client. When nil,
	// /api/backend/user/info skips the userdb-enrichment block and
	// /api/backend/user/iterate returns 503. main.go owns the lifecycle
	// (Close on shutdown); the Server only reads through it.
	AuthClient *authclient.Client

	// MailboxByDriver, when set, constructs a MailboxBackend for a named driver
	// (e.g. "mdbox", "sdbox"). Used when a per-user mail_location specifies a
	// different driver than the global opts.Mailbox. Backends are cached; the
	// factory is called once per distinct driver string.
	MailboxByDriver func(driver string) mailbox.MailboxBackend

	// FTSClient dials the yarilo-fts service for the operator fts surface
	// (status / rescan / optimize). Nil disables those endpoints (501).
	FTSClient ftsproto.Client
	// FTSChain expands a lookup's text the way IMAP SEARCH does; nil refuses it.
	FTSChain ftsquery.Expander
}

Options configures Server.

Dicts is the live map opened by the host process; the server hands out pointers to those objects via lookups keyed by name. Mailbox / Index / Resolver / NamespaceMailboxes / Locker / SpecialUseDefaults / MetadataDict / Namespaces are the same shape session binaries accept; backend-api opens per-user handles on demand from those (see userctx.go) so admin requests reach the same on-disk layout the session path uses.

Token is the shared admin secret; empty disables auth (test/dev only). AllowedNets, when non-empty, restricts which client IPs may reach the API.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the backend-API HTTP server. Construct with New, then call Serve (mTLS-terminated TLS listener) or ListenAndServe (plain).

func New

func New(opts Options) *Server

func (*Server) Handler

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

Handler returns the underlying mux, for tests that drive the server via httptest.Server without spinning up Serve.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context) error

Serve starts the HTTP server. When opts.TLSConfig is non-nil the listener is TLS-terminated (k8s deployments); plain TCP is for local dev. Blocks until ctx is cancelled or the underlying server returns.

type UserRouter

type UserRouter interface {
	Lookup(user string) (string, error)
}

UserRouter says where a user lives. Lookup answers the backend's IP; an error means the director could not be asked.

func NewDirectorRouter

func NewDirectorRouter(addr, tag string, tlsCfg *tls.Config) UserRouter

NewDirectorRouter routes by the director at addr; nil when addr is empty, which is a deployment without one, where every call runs where it lands.

type WardenEndpoint

type WardenEndpoint struct {
	Addr      string
	TLSConfig *tls.Config
}

WardenEndpoint is the slice of Options consumed by the who route; separate type so CLI/tests avoid the full Server.

Jump to

Keyboard shortcuts

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