instances

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 17 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 instances resolves the per-request Dilion instance.

An "instance" is a fully isolated database (auth.* + dilion_*). Multi-instance operation is an embedder customisation (ports.InstanceResolver + dilion.WithInstanceResolver): the built-in daemon and every example run a single instance under ports.DefaultInstanceID, served by StaticResolver, and behave exactly as they did before instances existed.

Instance selection is the embedder's business: there is no built-in HTTP routing. The embedder puts the instance id on the context with ports.ContextWithInstance (typically in its own middleware) and every Dilion component below resolves its resources from that context through a Registry.

Token↔instance binding, on the other hand, is Dilion's: each instance signs and verifies access tokens with its own key material (InstanceResolver.JWT), so a token minted for instance A fails verification at instance B — and at anything else (PostgREST, a resource server) that trusts B's JWKS or secret. A claim-based check could never give that guarantee, because verifiers outside Dilion's middleware only look at the signature.

Caching: constructed per-instance objects (the privacy Engine and the token service) are cached by instance id and never invalidated. A resolver must therefore return stable results for a given id — changing the pool, KMS, keys, policy or PII field definitions behind an id requires a restart.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownInstance = errors.New("instances: unknown instance")

ErrUnknownInstance is returned when a context selects an instance the resolver does not serve.

Functions

func Current

func Current(ctx context.Context) string

Current returns the instance id selected on ctx.

func InstanceTombstoneKey added in v0.0.5

func InstanceTombstoneKey(key []byte, id string) []byte

InstanceTombstoneKey derives an instance's tombstone key — which keys its erasure registry and blind search index — from the deployment's. Sharing one key would make the same person's tombstone and search tokens identical in every instance, so anyone holding two instances' databases could link them without any key. The default instance keeps the deployment key itself, so a single-instance deployment's existing data stays valid.

Types

type Config

type Config struct {
	Resolver ports.InstanceResolver
	// AuthConfig supplies the deployment-wide token settings (TTL, audience)
	// of every instance's token service; the key material comes from the
	// resolver. nil means auth.DefaultConfig().
	AuthConfig *auth.Config
	// Hooks, Clock, Connectors and TombstoneKey are deployment-wide and shared
	// by every instance's privacy Engine.
	Hooks        *hooks.Registry
	Clock        ports.Clock
	Connectors   map[string]ports.Connector
	TombstoneKey []byte
	Logger       *slog.Logger
	// OutboundNetworks are the private networks every instance's privacy
	// webhook destinations may reach (netguard).
	OutboundNetworks netguard.Networks
	// PollInterval and RetentionInterval pace every instance's privacy
	// workers (privacy.EngineDeps); zero means the privacy defaults.
	PollInterval      time.Duration
	RetentionInterval time.Duration
	// Metrics is shared by every instance's privacy Engine; nil records
	// nothing.
	Metrics *metrics.Metrics
}

Config are the cross-instance dependencies of the Registry. Everything instance-specific (pool, KMS, policy, PII field definitions) comes from the resolver instead.

type PoolFunc

type PoolFunc func(context.Context) (*pgxpool.Pool, error)

PoolFunc resolves the database pool of the instance selected on ctx. It is the narrow dependency the request-path packages (auth, api, iam, audit) take instead of a fixed *pgxpool.Pool.

type Registry

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

Registry resolves instance resources from a context and owns the lazily constructed per-instance objects.

func New

func New(cfg Config) (*Registry, error)

New builds a Registry over a resolver.

func (*Registry) Engine

func (r *Registry) Engine(ctx context.Context) (*privacy.Engine, error)

Engine returns the compliance engine of the instance selected on ctx, constructing it on first use. Engines are cached per instance id forever.

func (*Registry) EngineFor

func (r *Registry) EngineFor(ctx context.Context, id string) (*privacy.Engine, error)

EngineFor returns an explicit instance's compliance engine.

func (*Registry) KMS

func (r *Registry) KMS(ctx context.Context) (ports.KMS, error)

KMS resolves the KMS of the instance selected on ctx.

func (*Registry) KMSFor

func (r *Registry) KMSFor(ctx context.Context, id string) (ports.KMS, error)

KMSFor resolves an explicit instance's KMS.

func (*Registry) List

func (r *Registry) List(ctx context.Context) ([]string, error)

List enumerates the known instance ids.

func (*Registry) PIIFields

func (r *Registry) PIIFields(ctx context.Context) ([]byte, error)

PIIFields resolves the fixed PII field definitions of the instance on ctx.

func (*Registry) PolicyYAML

func (r *Registry) PolicyYAML(ctx context.Context) ([]byte, error)

PolicyYAML resolves the compliance policy document of the instance on ctx.

func (*Registry) Pool

func (r *Registry) Pool(ctx context.Context) (*pgxpool.Pool, error)

Pool resolves the pool of the instance selected on ctx. Its signature is PoolFunc, so it can be handed straight to auth/api/iam/audit.

func (*Registry) PoolFor

func (r *Registry) PoolFor(ctx context.Context, id string) (*pgxpool.Pool, error)

PoolFor resolves an explicit instance's pool.

func (*Registry) PrivacyService

func (r *Registry) PrivacyService(ctx context.Context) (privacy.Service, error)

PrivacyService is the api.ServiceProvider form of Engine.

func (*Registry) Resolver

func (r *Registry) Resolver() ports.InstanceResolver

Resolver exposes the underlying resolver.

func (*Registry) Tokens added in v0.0.4

func (r *Registry) Tokens(ctx context.Context) (*auth.TokenService, error)

Tokens returns the token service of the instance selected on ctx, constructing it on first use. Its signature is auth.TokenFunc.

func (*Registry) TokensFor added in v0.0.4

func (r *Registry) TokensFor(ctx context.Context, id string) (*auth.TokenService, error)

TokensFor returns an explicit instance's token service. Services are cached per instance id forever, like engines.

func (*Registry) Verify added in v0.0.4

func (r *Registry) Verify(ctx context.Context, token string) (*ports.Claims, error)

Verify checks a token against the key material of the instance selected on ctx (ports.TokenVerifier for internal/api).

type StaticResolver

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

StaticResolver is a ports.InstanceResolver over one fixed set of resources. It backs the single-instance default: WithPool/WithDSN, WithKMS, the JWT settings of auth.Config, WithPolicyYAML and WithPIIFieldsYAML are wrapped under ports.DefaultInstanceID.

func NewStaticResolver

func NewStaticResolver(id string, pool *pgxpool.Pool, kms ports.KMS, jwt ports.JWTKeys, policyYAML, piiFieldsYAML []byte) *StaticResolver

NewStaticResolver builds a resolver serving exactly one instance id. An empty id defaults to ports.DefaultInstanceID. policyYAML and piiFieldsYAML may be nil (built-in policies / free-form PII fields).

func (*StaticResolver) ID

func (s *StaticResolver) ID() string

ID is the single instance id this resolver serves.

func (*StaticResolver) JWT added in v0.0.4

func (s *StaticResolver) JWT(_ context.Context, instanceID string) (ports.JWTKeys, error)

func (*StaticResolver) KMS

func (s *StaticResolver) KMS(_ context.Context, instanceID string) (ports.KMS, error)

func (*StaticResolver) List

func (s *StaticResolver) List(context.Context) ([]string, error)

func (*StaticResolver) PIIFields

func (s *StaticResolver) PIIFields(_ context.Context, instanceID string) ([]byte, error)

func (*StaticResolver) PolicyYAML

func (s *StaticResolver) PolicyYAML(_ context.Context, instanceID string) ([]byte, error)

func (*StaticResolver) Pool

func (s *StaticResolver) Pool(_ context.Context, instanceID string) (*pgxpool.Pool, error)

Jump to

Keyboard shortcuts

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