engine

package
v0.0.23 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 5 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingAuthClaims = status.Error(codes.Code(AuthErrorCodeMissingAuthClaims), "context missing authz claims")
	ErrInvalidClaims     = status.Error(codes.Code(AuthErrorCodeInvalidClaims), "invalid claims")
)

Functions

func ContextWithAuthClaims

func ContextWithAuthClaims(parent context.Context, claims *AuthClaims) context.Context

ContextWithAuthClaims injects the provided AuthClaims into the parent context.

func Register

func Register(typ Type, f FactoryFunc) error

Register an authz engine factory function

func Unregister

func Unregister(typ Type) bool

Unregister removes a registered factory by Type. It returns true if a factory was removed. Use with caution in concurrent environments (primarily intended for tests).

Types

type Action

type Action string

type Actions

type Actions []Action

func MakeActions

func MakeActions(actions ...Action) Actions

type AuthClaims

type AuthClaims struct {
	Subjects *[]string
	Pairs    *Pairs
	Projects *[]string

	Tenant   *Tenant
	Tenants  *[]string
	Subject  *Subject
	Action   *Action
	Resource *Resource
	Project  *Project
}

func AuthClaimsFromContext

func AuthClaimsFromContext(ctx context.Context) (*AuthClaims, bool)

AuthClaimsFromContext extracts the AuthClaims from the provided ctx (if any).

type AuthErrorCode

type AuthErrorCode int32
const (
	AuthErrorCodeMissingAuthClaims AuthErrorCode = 2001
	AuthErrorCodeInvalidClaims     AuthErrorCode = 2002
)

type Authorizer

type Authorizer interface {
	Name() string

	ProjectsAuthorized(ctx context.Context, subjects Subjects, action Action, resource Resource, projects Projects) (Projects, error)

	FilterAuthorizedPairs(ctx context.Context, subjects Subjects, pairs Pairs) (Pairs, error)

	FilterAuthorizedProjects(ctx context.Context, subjects Subjects) (Projects, error)

	IsAuthorized(ctx context.Context, subjects Subject, action Action, resource Resource, project Project) (bool, error)
}

Authorizer 定义鉴权决策与批量过滤能力。

type Engine

type Engine interface {
	Authorizer
}

Engine 定义所有鉴权引擎必须提供的只读决策能力。

func NewEngine

func NewEngine(ctx context.Context, typ Type, options ...any) (Engine, error)

NewEngine creates a new authz Engine based on the registered FactoryFunc for the given Type.

type FactoryFunc

type FactoryFunc func(ctx context.Context, options ...any) (Engine, error)

func GetFactory

func GetFactory(typ Type) (FactoryFunc, bool)

GetFactory returns a registered FactoryFunc for a given Type and whether it existed. Safe for concurrent use.

type Pair

type Pair struct {
	Resource Resource `json:"resource"`
	Action   Action   `json:"action"`
}

func MakePair

func MakePair(res, act string) Pair

type Pairs

type Pairs []Pair

func MakePairs

func MakePairs(pairs ...Pair) Pairs

type PolicyMap

type PolicyMap map[string]interface{}

type PolicyWriter added in v0.0.20

type PolicyWriter interface {
	SetPolicies(ctx context.Context, policies PolicyMap, roles RoleMap) error
}

PolicyWriter 定义可选的策略更新能力。

type Project

type Project string

type Projects

type Projects []Project

func MakeProjects

func MakeProjects(projects ...Project) Projects

type Resource

type Resource string

type Resources

type Resources []Resource

func MakeResources

func MakeResources(resources ...Resource) Resources

type RoleMap

type RoleMap map[string]interface{}

type Subject

type Subject string

type Subjects

type Subjects []Subject

func MakeSubjects

func MakeSubjects(subs ...Subject) Subjects

type Tenant

type Tenant string

Tenant 表示授权策略匹配使用的租户编码。

type Tenants

type Tenants []Tenant

Tenants 表示授权策略匹配使用的租户编码集合。

func MakeTenants

func MakeTenants(tenants ...Tenant) Tenants

MakeTenants 创建租户编码集合。

type Type

type Type string

Type 表示鉴权引擎类型。

const (
	// Noop 表示不执行鉴权的空实现。
	Noop Type = "noop"
	// Casbin 表示 Casbin 鉴权引擎。
	Casbin Type = "casbin"
	// Cerbos 表示 Cerbos PDP 鉴权引擎。
	Cerbos Type = "cerbos"
	// Opa 表示 Open Policy Agent 鉴权引擎。
	Opa Type = "opa"
	// Zanzibar 表示 Zanzibar 关系型鉴权引擎。
	Zanzibar Type = "zanzibar"
)

func ListFactories

func ListFactories() []Type

ListFactories returns a slice of currently registered Types.

type Writer

type Writer = PolicyWriter

Writer 是 PolicyWriter 的兼容别名。

Directories

Path Synopsis
casbin module

Jump to

Keyboard shortcuts

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