Documentation
¶
Overview ¶
Package embedded runs SpiceDB's permission engine in-process, without standing up a gRPC server. It is intended for callers that embed SpiceDB as a library and want to issue permission checks directly against a datastore, paying neither network nor gRPC-serialization cost, and passing caveat context as native Go values.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CheckRequest ¶
type CheckRequest struct {
ResourceType string
ResourceID string
Permission string
SubjectType string
SubjectID string
SubjectRelation string // optional; defaults to the ellipsis ("...") relation
CaveatContext map[string]any
}
CheckRequest is a single, fully-consistent permission check. It intentionally mirrors v1.CheckPermissionRequest but uses native Go values (notably map[string]any for caveat context) to avoid the structpb.Struct round-trip the gRPC path pays. Keep its fields in sync with the proto shape.
type CheckResult ¶
type CheckResult struct {
// HasPermission is true when the subject is definitively a member of the permission.
HasPermission bool
// IsConditional is true when membership depends on a caveat that could not be fully
// evaluated because required context was missing (see MissingContext).
IsConditional bool
// MissingContext lists the caveat context fields that were required but not provided.
MissingContext []string
}
CheckResult is the outcome of a check.
type Config ¶
type Config struct {
// Datastore is the datastore to check against. Required. The caller owns its lifecycle.
Datastore datastore.Datastore
// CaveatTypeSet is the caveat type set used to compile and evaluate caveats.
// Defaults to caveattypes.Default.
CaveatTypeSet *caveattypes.TypeSet
// SchemaMode controls how schema is read. The zero value reads legacy per-definition
// schema. Use datalayer.SchemaModeReadNewWriteNew (or *Both) for the unified schema.
SchemaMode datalayer.SchemaMode
// SchemaCacheMaxCostBytes, when > 0, enables an in-memory stored-schema cache of the
// given size in bytes. Caching the stored schema across checks is what allows
// schema-derived caches (e.g. compiled caveats) to persist; strongly recommended when
// SchemaMode reads from the unified schema.
SchemaCacheMaxCostBytes int64
// DispatchConcurrencyLimit, DispatchChunkSize, and MaxDepth use sane defaults if zero.
DispatchConcurrencyLimit uint16
DispatchChunkSize uint16
MaxDepth uint32
}
Config configures a Permissions checker.
type Permissions ¶
type Permissions struct {
// contains filtered or unexported fields
}
Permissions issues in-process permission checks against a datastore.
func NewPermissions ¶
func NewPermissions(cfg Config) (*Permissions, error)
NewPermissions builds an in-process permissions checker from the given config.
func (*Permissions) Check ¶
func (p *Permissions) Check(ctx context.Context, req CheckRequest) (CheckResult, error)
Check runs a single, fully-consistent permission check in-process.
func (*Permissions) Close ¶
func (p *Permissions) Close() error
Close releases resources held by the checker. It does not close the datastore.