Documentation
¶
Overview ¶
Package authz defines the authorization interface.
The framework provides only the interface and a function adapter. Concrete implementations (Casbin, OPA, custom logic) are provided by the application or optional sub-packages — the blessed implementation is authz/casbin (Phase 6).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Authorizer ¶
type Authorizer interface {
// Authorize checks whether subject may perform action on object.
Authorize(ctx context.Context, subject, object, action string) (bool, error)
}
Authorizer makes authorization decisions for the global / single-tenant case. Multi-tenant deployments wanting per-domain policy should additionally implement DomainAuthorizer; chok's middleware RequireAuthzInDomain does a type assertion and fails closed (500) when the configured Authorizer doesn't satisfy that interface.
type AuthorizerFunc ¶
AuthorizerFunc adapts a plain function into an Authorizer. It does NOT implement DomainAuthorizer — multi-tenant routes need either a real Casbin enforcer or a custom struct that wires both methods.
type DomainAuthorizer ¶ added in v0.1.4
type DomainAuthorizer interface {
Authorizer
AuthorizeInDomain(ctx context.Context, subject, domain, object, action string) (bool, error)
}
DomainAuthorizer is the optional multi-tenant extension of Authorizer. Implementations that want to be usable with middleware.RequireAuthzInDomain MUST implement both Authorize (from Authorizer) and AuthorizeInDomain. The casbin-backed *casbinAuthorizer satisfies both naturally; pure-function AuthorizerFunc adapters stay at single-tenant Authorize.
Empty domain ("") is treated as the global scope by both the middleware (it normalizes "" → "*") and the casbin Service layer. Implementations that don't normalize internally still interoperate correctly because middleware.RequireAuthz forwards a literal "" via Authorize, never AuthorizeInDomain.
type DomainAuthorizerFunc ¶ added in v0.1.4
type DomainAuthorizerFunc func(ctx context.Context, subject, domain, object, action string) (bool, error)
DomainAuthorizerFunc adapts a plain function into a DomainAuthorizer. Useful for tests that want a one-line stub against tenant-scoped middleware. The Authorize method (single-tenant) is implemented by forwarding with domain="".
func (DomainAuthorizerFunc) Authorize ¶ added in v0.1.4
Authorize implements the Authorizer half of DomainAuthorizer by passing an empty domain through.
func (DomainAuthorizerFunc) AuthorizeInDomain ¶ added in v0.1.4
func (f DomainAuthorizerFunc) AuthorizeInDomain(ctx context.Context, sub, dom, obj, act string) (bool, error)
AuthorizeInDomain implements the DomainAuthorizer half.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package casbin doc.go is intentionally empty — the package-level godoc lives at the top of options.go where Builder, Service, and the Options type are introduced.
|
Package casbin doc.go is intentionally empty — the package-level godoc lives at the top of options.go where Builder, Service, and the Options type are introduced. |