Documentation
¶
Overview ¶
Package authz answers "can this actor perform this action on this resource?" — a deliberate seam so the v1 always-allow implementation can later be swapped for Casbin / OpenFGA / Keto without touching call sites.
Handlers call:
if err := d.Authz.Authorize(ctx, "policy.write", authz.Resource{...}); err != nil {
return nil, err
}
before mutating state. Today the call is a near-no-op for any authenticated caller; tomorrow it gates the action against per-org permissions, ABAC predicates, or whatever the SaaS tier needs.
Index ¶
- Variables
- func Admin(ctx context.Context, a Authorizer) bool
- func CheckGrant(ctx context.Context, a Authorizer, r *role.Role, scope meta.Owner) error
- func Explains(a Authorizer) bool
- func IsAdmin(ctx context.Context) bool
- func MatchedBinding(snap Snapshot, x rbac.Explanation) (*rolebinding.RoleBinding, bool)
- func OrganizationAdminOnly(kind string) bool
- func OrganizationKind(kind string) bool
- func Plural(kind string) string
- func SharedCatalogKind(kind string) bool
- func Singular(p string) string
- func SystemMeansOrganization(kind string, stored meta.Owner) bool
- type AlwaysAllowAuthenticated
- type Authorizer
- type Explainer
- type RBAC
- type Resource
- type Scoper
- type Snapshot
Constants ¶
This section is empty.
Variables ¶
var ErrForbidden = coreauthz.ErrForbidden
ErrForbidden is returned when an authenticated actor lacks permission. Mapped to HTTP 403.
var ErrNoExplanation = errors.New("authz: this authorizer does not explain its decisions")
ErrNoExplanation is Explain's error from an authorizer that cannot say why it decides, such as the single-user one, which allows every authenticated caller everything.
var ErrUnauthenticated = coreauthz.ErrUnauthenticated
ErrUnauthenticated is returned when the call has no actor in context. Mapped to HTTP 401 by the control-plane middleware.
Functions ¶
func Admin ¶ added in v0.30.0
func Admin(ctx context.Context, a Authorizer) bool
Admin reports whether the caller in ctx administers the deployment under a: IsAdmin, or, under RBAC, a binding of the built-in admin role at the global scope, which already grants every verb everywhere. It is the notion of admin organization rows are guarded by.
func CheckGrant ¶ added in v0.10.0
CheckGrant reports whether the caller may bind r at scope. Every (kind, verb) the role's rules cover is authorized against the caller with the binding's scope as the resource owner; the first one the caller does not hold refuses the binding. A wildcard rule expands to the full closed vocabulary, so binding a wildcard role requires holding everything. Admins are exempt, and so is a nil authorizer (a loader running as the deployment itself).
It goes through a rather than the engine's own grant check, so a wrapping authorizer (audit) and single-user mode see every probe.
func Explains ¶ added in v0.11.0
func Explains(a Authorizer) bool
Explains reports whether a can answer an access review. A wrapper may implement Explainer only to delegate, so it is unwrapped (via an Unwrap() Authorizer method) down to the authorizer that decides.
func IsAdmin ¶ added in v0.10.0
IsAdmin reports whether the caller in ctx holds the bootstrap admin identity (the break-glass token or the admin role). Exported for the few call sites outside this package that must relax a rule for an operator — they are not authorization decisions and must not grow into one.
func MatchedBinding ¶ added in v0.11.0
func MatchedBinding(snap Snapshot, x rbac.Explanation) (*rolebinding.RoleBinding, bool)
MatchedBinding returns the RoleBinding row behind an explanation's binding: the first of the subject's bindings with that role and scope, which is the one the evaluation read first.
func OrganizationAdminOnly ¶ added in v0.30.0
OrganizationAdminOnly reports whether the organization's rows of kind (the singular handlers pass) are for admins alone.
func OrganizationKind ¶ added in v0.30.0
OrganizationKind reports whether rows of kind (the singular handlers pass) may be owned by the organization.
func Plural ¶ added in v0.20.0
Plural renders a Resource.Kind as its API plural, the inverse of Singular.
func SharedCatalogKind ¶ added in v0.10.3
SharedCatalogKind reports whether kind (the singular handlers pass) is shared catalog data that no user, team or project may own.
func Singular ¶ added in v0.10.0
Singular maps an API plural back to the Resource.Kind handlers set. Exported for app/audit, which reconstructs a resource from the request path when a handler refuses before authorizing.
func SystemMeansOrganization ¶ added in v0.30.0
SystemMeansOrganization reports whether a system owner written for a row of kind (the singular handlers pass) names the organization. stored is the owner of the row it would write, empty for a new one: a rate limit stored system-owned is one of the built-ins, which stay system.
Types ¶
type AlwaysAllowAuthenticated ¶
type AlwaysAllowAuthenticated struct{}
AlwaysAllowAuthenticated is the v1 implementation: any authenticated caller (user session or admin-token bypass) is granted any action. Unauthenticated callers are rejected.
This exists so handler call sites are permanent. Swap the concrete type when multi-tenant work lands; handlers stay the same.
type Authorizer ¶
type Authorizer interface {
Authorize(ctx context.Context, action string, resource Resource) error
}
Authorizer is the policy-decision interface. Authorize returns nil to allow, ErrForbidden/ErrUnauthenticated to deny, or any other error to signal a backend failure (which the middleware should treat as 500, not 403 — failure to authorize is not the same as denial).
type Explainer ¶ added in v0.11.0
type Explainer interface {
Explain(ctx context.Context, a *actor.Actor, action string, res Resource) (rbac.Explanation, error)
}
Explainer is an optional interface an Authorizer implements to answer an access review: the decision Authorize would make for a, who need not be the caller in ctx, and why.
type RBAC ¶ added in v0.10.0
type RBAC struct{ Snap func() Snapshot }
RBAC is the role-based authorizer: a decision is the intersection of the actor's subjects, the RoleBindings naming them, and the scope chain of the row being touched. Default deny.
Everything it reads comes from the in-memory catalog snapshot; Snap is catalog.Catalog.Current. The auth/rbac engine evaluates; relay's shortcuts are the product rules it is handed.
type Resource ¶
type Resource struct {
Kind string // "provider", "policy", "model", ...
ID string // resource id, if known (UUID)
Name string // resource slug, if id is not known
// Owner is the target row's provenance, populated by handlers that
// have already fetched the row (mutations authorize twice as cheaply
// as fetching twice). Nil means "owner unknown" — owner-aware
// implementations must fail closed on mutations, not open.
Owner *meta.Owner
}
Resource describes the target of an authorization check. Fields are optional; populate what the action needs.
type Scoper ¶ added in v0.8.0
type Scoper interface {
// Visible reports whether the current actor may see a row of kind
// with the given id and owner in lists and reads. id is the row's own
// metadata.id — it is what puts a scope-defining row (Team, Project)
// inside the scope it defines; pass "" when there is no row.
Visible(ctx context.Context, kind, id string, owner meta.Owner) bool
}
Scoper is an optional interface an Authorizer may implement to gate per-row visibility in list/read paths, where per-row Authorize calls would be the wrong shape. Handlers filter rows through Visible when the configured Authorizer implements it; an Authorizer that doesn't (the default AlwaysAllowAuthenticated) leaves reads unfiltered.
type Snapshot ¶ added in v0.10.0
type Snapshot interface {
// ScopeChainFor returns the scopes the identified row lives in, most
// specific first, always ending in the global scope. A Team or Project
// row is inside the scope it defines; every other kind resolves from
// its owner alone.
ScopeChainFor(kind, id string, o *meta.Owner) []meta.Owner
// RoleBindingsForSubject returns the bindings naming a subject string.
RoleBindingsForSubject(subject string) []*rolebinding.RoleBinding
// ProjectsInTeam returns the team's projects, so a binding at a project
// can answer for the team row above it.
ProjectsInTeam(teamID string) []*project.Project
// Role returns an enabled Role by id.
Role(id string) (*role.Role, bool)
}
Snapshot is the slice of the catalog snapshot the evaluator reads. Declared here rather than imported: app/catalog reaches app/authz through the boot seed (catalog → seed → apply → authz), so importing it back would close a cycle. *catalog.Snapshot satisfies this as-is.