authz

package
v0.10.7 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 10 Imported by: 1 module, 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

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

Constants

This section is empty.

Variables

View Source
var ErrForbidden = errors.New("authz: forbidden")

ErrForbidden is returned when an authenticated actor lacks permission. Mapped to HTTP 403.

View Source
var ErrUnauthenticated = errors.New("authz: unauthenticated")

ErrUnauthenticated is returned when the call has no actor in context. Mapped to HTTP 401 by the control-plane middleware.

Functions

func CheckGrant added in v0.10.0

func CheckGrant(ctx context.Context, a Authorizer, r *role.Role, scope meta.Owner) error

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).

func IsAdmin added in v0.10.0

func IsAdmin(ctx context.Context) bool

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 SharedCatalogKind added in v0.10.3

func SharedCatalogKind(kind string) bool

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

func Singular(p string) string

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.

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.

func (AlwaysAllowAuthenticated) Authorize

Authorize implements Authorizer.

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 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.

func (RBAC) Authorize added in v0.10.0

func (r RBAC) Authorize(ctx context.Context, action string, res Resource) error

Authorize implements Authorizer.

func (RBAC) Visible added in v0.10.0

func (r RBAC) Visible(ctx context.Context, kind, id string, owner meta.Owner) bool

Visible implements Scoper. Seeing one row is exactly the get verb on it, so list filtering and per-row reads can never disagree.

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.

Jump to

Keyboard shortcuts

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