authz

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// GlobalRootObject is the singleton global scope object identifier in OpenFGA.
	GlobalRootObject = "global:root"

	RelationCanCreateAtespace = "can_create_atespace"
	RelationCanListAtespaces  = "can_list_atespaces"
	RelationCanGet            = "can_get"
	RelationCanDelete         = "can_delete"
)

Variables

View Source
var ErrNoTransactionInContext = errors.New("authz datastore: active pgx.Tx required in context")

ErrNoTransactionInContext is returned by ReadPage and Write when called without an active pgx.Tx injected via ContextWithTx.

Functions

func AtespaceObject added in v0.3.0

func AtespaceObject(name string) string

AtespaceObject formats an atespace name as an OpenFGA object string.

func ContextWithTx

func ContextWithTx(ctx context.Context, tx pgx.Tx) context.Context

ContextWithTx injects an active pgx.Tx into ctx.

func EnsureStoreAndModel

func EnsureStoreAndModel(ctx context.Context, pool *pgxpool.Pool, fgaServer *server.Server) (string, string, error)

EnsureStoreAndModel ensures the default OpenFGA store and checked-in authorization model are provisioned on fgaServer (serialized across replicas via a PostgreSQL advisory lock on pool) and returns the provisioned (storeID, modelID).

func IsBypassed added in v0.3.0

func IsBypassed(ctx context.Context) bool

IsBypassed reports whether ctx has authorization checks bypassed.

func New added in v0.3.0

func New(ctx context.Context, pool *pgxpool.Pool, fgaServer *server.Server) (*Authorizer, *PolicyManager, error)

New provisions the default OpenFGA store and authorization model via EnsureStoreAndModel and returns the read-path Authorizer and write-path PolicyManager.

func NewOpenFGAServer

func NewOpenFGAServer(pool *pgxpool.Pool) (*server.Server, error)

NewOpenFGAServer creates an embedded OpenFGA server backed by a transaction-aware PostgreSQL datastore on pool. Calling Close on the returned server stops OpenFGA's background workers without closing the caller-owned pool.

func TxFromContext

func TxFromContext(ctx context.Context) (pgx.Tx, bool)

TxFromContext retrieves the active pgx.Tx from ctx, if present.

func UnaryServerInterceptor added in v0.3.0

func UnaryServerInterceptor(authorizer *Authorizer) grpc.UnaryServerInterceptor

UnaryServerInterceptor returns a gRPC unary interceptor that enforces per-RPC permissions registered in defaultRPCPermissions using authorizer.

func WithBypass added in v0.3.0

func WithBypass(ctx context.Context) context.Context

WithBypass returns a context that bypasses runtime authorization checks (for internal system reconcilers).

Types

type Authorizer added in v0.3.0

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

Authorizer is the read-only policy decision point that evaluates runtime OpenFGA permissions against Substrate's store and authorization model.

func (*Authorizer) Check added in v0.3.0

func (a *Authorizer) Check(ctx context.Context, relation, object string) error

Check verifies that the principal in ctx has relation on object. Structural hierarchy links (such as global:root as parent_global of every atespace) are injected as OpenFGA ContextualTuples at evaluation time rather than persisted in the tuple table.

type PolicyManager added in v0.3.0

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

PolicyManager manages authorization tuple writes and lifecycle cleanup in OpenFGA.

func (*PolicyManager) DeleteAtespacePolicies added in v0.3.0

func (m *PolicyManager) DeleteAtespacePolicies(ctx context.Context, name string) error

DeleteAtespacePolicies removes all tuples associated with an atespace in OpenFGA in batches of maxTuplesPerWrite.

Callers (such as atepg.DeleteAtespace) must pass a ctx carrying an active pgx.Tx via ContextWithTx(ctx, tx). Both m.fgaServer.Read (which dispatches to transactionalDatastore.ReadPage) and m.fgaServer.Write (which dispatches to transactionalDatastore.Write) extract and execute on that pgx.Tx, failing with ErrNoTransactionInContext if no transaction is present in ctx.

Jump to

Keyboard shortcuts

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