authz

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 30 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

Index

Constants

View Source
const (

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

	RoleOwner  = "owner"
	RoleEditor = "editor"
	RoleViewer = "viewer"

	RoleController       = "controller"
	RoleEgressGateway    = "egress_gateway"
	RoleIngressRouter    = "ingress_router"
	RoleAtelet           = "atelet"
	RoleAPIServerSidecar = "api_server_sidecar"

	RelationCanCreateAtespace       = "can_create_atespace"
	RelationCanListAtespaces        = "can_list_atespaces"
	RelationCanCreateActor          = "can_create_actor"
	RelationCanListActors           = "can_list_actors"
	RelationCanCreateActorTemplate  = "can_create_actor_template"
	RelationCanListActorTemplates   = "can_list_actor_templates"
	RelationCanCreateWorker         = "can_create_worker"
	RelationCanListWorkers          = "can_list_workers"
	RelationCanGet                  = "can_get"
	RelationCanUseTemplate          = "can_use_template"
	RelationCanUpdate               = "can_update"
	RelationCanDelete               = "can_delete"
	RelationCanResume               = "can_resume"
	RelationCanSuspend              = "can_suspend"
	RelationCanRevert               = "can_revert"
	RelationCanDrain                = "can_drain"
	RelationCanListActorAssignments = "can_list_actor_assignments"
	RelationCanCreateAccessPolicy   = "can_create_access_policy"
	RelationCanGetAccessPolicy      = "can_get_access_policy"
	RelationCanUpdateAccessPolicy   = "can_update_access_policy"
	RelationCanDeleteAccessPolicy   = "can_delete_access_policy"
	RelationCanCreateEgressPolicy   = "can_create_egress_policy"
	RelationCanGetEgressPolicy      = "can_get_egress_policy"
	RelationCanUpdateEgressPolicy   = "can_update_egress_policy"
	RelationCanDeleteEgressPolicy   = "can_delete_egress_policy"
	RelationCanCreateTag            = "can_create_tag"
	RelationCanListTags             = "can_list_tags"
	RelationCanUseTag               = "can_use_tag"
	RelationCanMintActorJWT         = "can_mint_actor_jwt"
)

Variables

View Source
var ErrNilTransaction = errors.New("authz: policy tuple writes require a non-nil pgx.Tx")

ErrNilTransaction is returned by PolicyManager tuple writes called without a PostgreSQL transaction.

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 ActorObject

func ActorObject(atespace, name string) string

ActorObject formats an actor as an OpenFGA object string.

func ActorTemplateObject

func ActorTemplateObject(atespace, name string) string

ActorTemplateObject formats an actor template as an OpenFGA object string.

func AtespaceObject

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 FormatMember

func FormatMember(member string) (string, error)

FormatMember validates a policy member string (such as "user:alice@example.com") and returns the percent-encoded OpenFGA user string. Control characters are rejected because OpenFGA does not accept them in tuple user IDs.

func IsBypassed

func IsBypassed(ctx context.Context) bool

IsBypassed reports whether ctx has authorization checks bypassed.

func New

func New(ctx context.Context, pool *pgxpool.Pool, fgaServer *server.Server, bootstrapOwners []string, system SystemPrincipals) (*Authorizer, *PolicyManager, error)

New provisions the default OpenFGA store and authorization model via EnsureStoreAndModel and returns the read-path Authorizer and write-path PolicyManager. bootstrapOwners are principal IDs (with or without the "user:" prefix) that the Authorizer treats as owners of global:root on every check, independent of any stored AccessPolicy.

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 StreamServerInterceptor added in v1.0.0

func StreamServerInterceptor() grpc.StreamServerInterceptor

StreamServerInterceptor returns a gRPC stream interceptor that denies every streaming RPC not in streamRules.

func TagObject

func TagObject(atespace, name string) string

TagObject formats a tag as an OpenFGA object string.

func TxFromContext

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

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

func UnaryServerInterceptor

func UnaryServerInterceptor(authorizer *Authorizer) grpc.UnaryServerInterceptor

UnaryServerInterceptor returns a gRPC unary interceptor that enforces per-RPC permissions registered in defaultRPCPermissions using authorizer. An RPC with no rule is denied.

func WithBypass

func WithBypass(ctx context.Context) context.Context

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

func WorkerObject

func WorkerObject(name string) string

WorkerObject formats a worker name as an OpenFGA object string. Workers are global-scoped.

Types

type Authorizer

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

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 (global:root as parent_global of every atespace and worker, and each atespace as parent_atespace of its actors, actor templates and tags) and the caller's bootstrap owner and system role grants, if any, are injected as OpenFGA ContextualTuples at evaluation time rather than persisted in the tuple table.

type PolicyManager

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

PolicyManager writes OpenFGA tuples for access policy and atespace mutations within the caller's PostgreSQL transaction.

func (*PolicyManager) DeleteAtespacePolicies

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

DeleteAtespacePolicies removes all OpenFGA tuples associated with an atespace within tx. The tuple deletions commit or roll back with tx.

func (*PolicyManager) ReconcileAtespaceBindings

func (m *PolicyManager) ReconcileAtespaceBindings(ctx context.Context, tx pgx.Tx, name string, bindings []*ateapi.Binding) error

ReconcileAtespaceBindings reconciles the OpenFGA role bindings on an atespace within tx. The tuple changes commit or roll back with tx.

func (*PolicyManager) ReconcileGlobalBindings

func (m *PolicyManager) ReconcileGlobalBindings(ctx context.Context, tx pgx.Tx, bindings []*ateapi.Binding) error

ReconcileGlobalBindings reconciles the OpenFGA role bindings on global:root within tx. The tuple changes commit or roll back with tx.

type SystemPrincipals

type SystemPrincipals struct {
	ControllerSPIFFEID       string
	EgressGatewaySPIFFEIDs   []string
	IngressRouterSPIFFEID    string
	AteletSPIFFEID           string
	APIServerSidecarSPIFFEID string
}

SystemPrincipals holds the mTLS SPIFFE IDs of Substrate's own components. The Authorizer grants each one its system component role on global:root on every check, independent of any stored AccessPolicy.

Jump to

Keyboard shortcuts

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