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 ¶
- Variables
- func Current(ctx context.Context) string
- func InstanceTombstoneKey(key []byte, id string) []byte
- type Config
- type PoolFunc
- type Registry
- func (r *Registry) Engine(ctx context.Context) (*privacy.Engine, error)
- func (r *Registry) EngineFor(ctx context.Context, id string) (*privacy.Engine, error)
- func (r *Registry) KMS(ctx context.Context) (ports.KMS, error)
- func (r *Registry) KMSFor(ctx context.Context, id string) (ports.KMS, error)
- func (r *Registry) List(ctx context.Context) ([]string, error)
- func (r *Registry) PIIFields(ctx context.Context) ([]byte, error)
- func (r *Registry) PolicyYAML(ctx context.Context) ([]byte, error)
- func (r *Registry) Pool(ctx context.Context) (*pgxpool.Pool, error)
- func (r *Registry) PoolFor(ctx context.Context, id string) (*pgxpool.Pool, error)
- func (r *Registry) PrivacyService(ctx context.Context) (privacy.Service, error)
- func (r *Registry) Resolver() ports.InstanceResolver
- func (r *Registry) Tokens(ctx context.Context) (*auth.TokenService, error)
- func (r *Registry) TokensFor(ctx context.Context, id string) (*auth.TokenService, error)
- func (r *Registry) Verify(ctx context.Context, token string) (*ports.Claims, error)
- type StaticResolver
- func (s *StaticResolver) ID() string
- func (s *StaticResolver) JWT(_ context.Context, instanceID string) (ports.JWTKeys, error)
- func (s *StaticResolver) KMS(_ context.Context, instanceID string) (ports.KMS, error)
- func (s *StaticResolver) List(context.Context) ([]string, error)
- func (s *StaticResolver) PIIFields(_ context.Context, instanceID string) ([]byte, error)
- func (s *StaticResolver) PolicyYAML(_ context.Context, instanceID string) ([]byte, error)
- func (s *StaticResolver) Pool(_ context.Context, instanceID string) (*pgxpool.Pool, error)
Constants ¶
This section is empty.
Variables ¶
var ErrUnknownInstance = errors.New("instances: unknown instance")
ErrUnknownInstance is returned when a context selects an instance the resolver does not serve.
Functions ¶
func InstanceTombstoneKey ¶ added in v0.0.5
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 ¶
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 (*Registry) Engine ¶
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) PIIFields ¶
PIIFields resolves the fixed PII field definitions of the instance on ctx.
func (*Registry) PolicyYAML ¶
PolicyYAML resolves the compliance policy document of the instance on ctx.
func (*Registry) Pool ¶
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) PrivacyService ¶
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
Tokens returns the token service of the instance selected on ctx, constructing it on first use. Its signature is auth.TokenFunc.
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.