graph

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package graph contains code related to evaluation of authorization models through graph traversals.

Package graph is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCycleDetected = errors.New("a cycle has been detected")
)
View Source
var (
	ErrResolutionDepthExceeded = errors.New("resolution depth exceeded")
)

Functions

func ContextWithResolutionDepth added in v0.2.5

func ContextWithResolutionDepth(parent context.Context, depth uint32) context.Context

ContextWithResolutionDepth attaches the provided graph resolution depth to the parent context.

func ResolutionDepthFromContext added in v0.2.5

func ResolutionDepthFromContext(ctx context.Context) (uint32, bool)

ResolutionDepthFromContext returns the current graph resolution depth from the provided context (if any).

Types

type CachedCheckResolver added in v1.3.1

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

CachedCheckResolver attempts to resolve check sub-problems via prior computations before delegating the request to some underlying CheckResolver.

func NewCachedCheckResolver added in v1.3.1

func NewCachedCheckResolver(delegate CheckResolver, opts ...CachedCheckResolverOpt) *CachedCheckResolver

NewCachedCheckResolver constructs a CheckResolver that delegates Check resolution to the provided delegate, but before delegating the query to the delegate a cache-key lookup is made to see if the Check sub-problem has already recently been computed. If the Check sub-problem is in the cache, then the response is returned immediately and no re-computation is necessary. NOTE: the ResolveCheck's resolution data will be set as the default values as we actually did no database lookup

func (*CachedCheckResolver) Close added in v1.3.1

func (c *CachedCheckResolver) Close()

Close will deallocate resource allocated by the CachedCheckResolver It will not deallocate cache if it has been passed in from WithExistingCache

func (*CachedCheckResolver) ResolveCheck added in v1.3.1

type CachedCheckResolverOpt added in v1.3.1

type CachedCheckResolverOpt func(*CachedCheckResolver)

CachedCheckResolverOpt defines an option that can be used to change the behavior of cachedCheckResolver instance.

func WithCacheTTL added in v1.3.1

func WithCacheTTL(ttl time.Duration) CachedCheckResolverOpt

WithCacheTTL sets the TTL (as a duration) for any single Check cache key value.

func WithExistingCache added in v1.3.1

WithExistingCache sets the cache to the specified cache. Note that the original cache will not be stopped as it may still be used by others. It is up to the caller to check whether the original cache should be stopped.

func WithLogger added in v1.3.1

func WithLogger(logger logger.Logger) CachedCheckResolverOpt

WithLogger sets the logger for the cached check resolver

func WithMaxCacheSize added in v1.3.1

func WithMaxCacheSize(size int64) CachedCheckResolverOpt

WithMaxCacheSize sets the maximum size of the Check resolution cache. After this maximum size is met, then cache keys will start being evicted with an LRU policy.

type CachedResolveCheckResponse added in v1.3.1

type CachedResolveCheckResponse struct {
	Allowed bool
}

CachedResolveCheckResponse is very similar to ResolveCheckResponse except we do not store the ResolutionData. This is due to the fact that the resolution metadata will be incorrect as data is served from cache instead of actual database read.

type CheckFuncReducer added in v0.3.5

type CheckFuncReducer func(ctx context.Context, concurrencyLimit uint32, handlers ...CheckHandlerFunc) (*ResolveCheckResponse, error)

CheckFuncReducer defines a function that combines or reduces one or more CheckHandlerFunc into a single CheckResponse with a maximum limit on the number of concurrent evaluations that can be in flight at any given time.

type CheckHandlerFunc added in v0.3.5

type CheckHandlerFunc func(ctx context.Context) (*ResolveCheckResponse, error)

CheckHandlerFunc defines a function that evaluates a CheckResponse or returns an error otherwise.

type CheckResolver added in v0.3.5

type CheckResolver interface {
	ResolveCheck(ctx context.Context, req *ResolveCheckRequest) (*ResolveCheckResponse, error)
	Close()
}

CheckResolver represents an interface that can be implemented to provide recursive resolution of a Check.

func NewLocalChecker added in v0.3.5

NewLocalChecker constructs a LocalChecker that can be used to evaluate a Check request locally.

type EdgeCondition added in v1.3.2

type EdgeCondition int

type LocalChecker added in v0.3.5

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

func (*LocalChecker) Close added in v1.3.1

func (c *LocalChecker) Close()

Close is a noop

func (*LocalChecker) ResolveCheck added in v0.3.5

func (c *LocalChecker) ResolveCheck(
	ctx context.Context,
	req *ResolveCheckRequest,
) (*ResolveCheckResponse, error)

ResolveCheck resolves a node out of a tree of evaluations. If the depth of the tree has gotten too large, evaluation is aborted and an error is returned. The depth is NOT increased on computed usersets.

type LocalCheckerOption added in v1.3.0

type LocalCheckerOption func(d *LocalChecker)

func WithCachedResolver added in v1.3.1

func WithCachedResolver(opts ...CachedCheckResolverOpt) LocalCheckerOption

func WithMaxConcurrentReads added in v1.3.0

func WithMaxConcurrentReads(limit uint32) LocalCheckerOption

WithMaxConcurrentReads see server.WithMaxConcurrentReadsForCheck

func WithResolveNodeBreadthLimit added in v1.3.0

func WithResolveNodeBreadthLimit(limit uint32) LocalCheckerOption

WithResolveNodeBreadthLimit see server.WithResolveNodeBreadthLimit

type MockCheckResolver added in v1.3.1

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

MockCheckResolver is a mock of CheckResolver interface.

func NewMockCheckResolver added in v1.3.1

func NewMockCheckResolver(ctrl *gomock.Controller) *MockCheckResolver

NewMockCheckResolver creates a new mock instance.

func (*MockCheckResolver) Close added in v1.3.1

func (m *MockCheckResolver) Close()

Close mocks base method.

func (*MockCheckResolver) EXPECT added in v1.3.1

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockCheckResolver) ResolveCheck added in v1.3.1

ResolveCheck mocks base method.

type MockCheckResolverMockRecorder added in v1.3.1

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

MockCheckResolverMockRecorder is the mock recorder for MockCheckResolver.

func (*MockCheckResolverMockRecorder) Close added in v1.3.1

Close indicates an expected call of Close.

func (*MockCheckResolverMockRecorder) ResolveCheck added in v1.3.1

func (mr *MockCheckResolverMockRecorder) ResolveCheck(ctx, req interface{}) *gomock.Call

ResolveCheck indicates an expected call of ResolveCheck.

type RelationshipEdge added in v1.3.2

type RelationshipEdge struct {
	Type RelationshipEdgeType

	// The edge is directed towards this node, which can be like group:*, or group, or group:member
	TargetReference *openfgav1.RelationReference

	// If the type is TupleToUsersetEdge, this defines the TTU condition
	TuplesetRelation string

	TargetReferenceInvolvesIntersectionOrExclusion bool
}

RelationshipEdge represents a possible relationship between some source object reference and a target user reference. The possibility is realized depending on the tuples and on the edge's type.

func (RelationshipEdge) String added in v1.3.2

func (r RelationshipEdge) String() string

type RelationshipEdgeType added in v1.3.2

type RelationshipEdgeType int
const (
	// DirectEdge defines a direct connection between a source object reference
	// and some target user reference.
	DirectEdge RelationshipEdgeType = iota
	// TupleToUsersetEdge defines a connection between a source object reference
	// and some target user reference that is co-dependent upon the lookup of a third object reference.
	TupleToUsersetEdge
	// ComputedUsersetEdge defines a direct connection between a source object reference
	// and some target user reference. The difference with DirectEdge is that DirectEdge will involve
	// a read of tuples and this one will not.
	ComputedUsersetEdge
)

func (RelationshipEdgeType) String added in v1.3.2

func (r RelationshipEdgeType) String() string

type RelationshipGraph added in v1.3.2

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

RelationshipGraph represents a graph of relationships and the connectivity between object and relation references within the graph through direct or indirect relationships.

func New added in v1.3.2

func New(typesystem *typesystem.TypeSystem) *RelationshipGraph

New returns a RelationshipGraph from an authorization model. The RelationshipGraph should be used to introspect what kind of relationships between object types can exist. To visualize this graph, use https://github.com/jon-whit/openfga-graphviz-gen

func (*RelationshipGraph) GetPrunedRelationshipEdges added in v1.3.2

func (g *RelationshipGraph) GetPrunedRelationshipEdges(target *openfgav1.RelationReference, source *openfgav1.RelationReference) ([]*RelationshipEdge, error)

GetPrunedRelationshipEdges finds all paths from a source to a target and then returns all the edges at distance 0 or 1 of the source in those paths. If the edges from the source to the target pass through a relationship involving intersection or exclusion (directly or indirectly), then GetPrunedRelationshipEdges will just return the first-most edge involved in that rewrite.

Consider the following model:

type user type document

relations
  define allowed: [user]
  define viewer: [user] and allowed

The pruned relationship edges from the 'user' type to 'document#viewer' returns only the edge from 'user' to 'document#viewer' and with a 'RequiresFurtherEvalCondition'. This is because when evaluating relationships involving intersection or exclusion we choose to only evaluate one operand of the rewrite rule, and for each result found we call Check on the result to evaluate the sub-condition on the 'and allowed' bit.

func (*RelationshipGraph) GetRelationshipEdges added in v1.3.2

func (g *RelationshipGraph) GetRelationshipEdges(target *openfgav1.RelationReference, source *openfgav1.RelationReference) ([]*RelationshipEdge, error)

GetRelationshipEdges finds all paths from a source to a target and then returns all the edges at distance 0 or 1 of the source in those paths.

type ResolutionMetadata added in v0.3.5

type ResolutionMetadata struct {
	Depth uint32

	// Number of calls to ReadUserTuple + ReadUsersetTuples + Read.
	// Thinking of a Check as a tree of evaluations:
	// If the solution is "allowed=true", one path was found. This is the value in the leaf node of that path, plus the sum of the paths that were
	// evaluated and potentially discarded
	// If the solution is "allowed=false", no paths were found. This is the sum of all the reads in all the paths that had to be evaluated
	DatastoreQueryCount uint32
}

type ResolveCheckRequest added in v0.3.5

type ResolveCheckRequest struct {
	StoreID              string
	AuthorizationModelID string
	TupleKey             *openfgav1.TupleKey
	ContextualTuples     []*openfgav1.TupleKey
	Context              *structpb.Struct
	ResolutionMetadata   *ResolutionMetadata
	VisitedPaths         map[string]struct{}
}

func (*ResolveCheckRequest) GetAuthorizationModelID added in v0.3.5

func (r *ResolveCheckRequest) GetAuthorizationModelID() string

func (*ResolveCheckRequest) GetContext added in v1.3.8

func (r *ResolveCheckRequest) GetContext() *structpb.Struct

func (*ResolveCheckRequest) GetContextualTuples added in v0.3.5

func (r *ResolveCheckRequest) GetContextualTuples() []*openfgav1.TupleKey

func (*ResolveCheckRequest) GetResolutionMetadata added in v0.3.5

func (r *ResolveCheckRequest) GetResolutionMetadata() *ResolutionMetadata

func (*ResolveCheckRequest) GetStoreID added in v0.3.5

func (r *ResolveCheckRequest) GetStoreID() string

func (*ResolveCheckRequest) GetTupleKey added in v0.3.5

func (r *ResolveCheckRequest) GetTupleKey() *openfgav1.TupleKey

type ResolveCheckResponse added in v0.3.5

type ResolveCheckResponse struct {
	Allowed            bool
	ResolutionMetadata *ResolutionMetadata
}

func (*ResolveCheckResponse) GetAllowed added in v1.3.1

func (r *ResolveCheckResponse) GetAllowed() bool

func (*ResolveCheckResponse) GetResolutionMetadata added in v1.3.1

func (r *ResolveCheckResponse) GetResolutionMetadata() *ResolutionMetadata

Jump to

Keyboard shortcuts

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