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 CheckGrant(ctx context.Context, a Authorizer, r *role.Role, scope meta.Owner) error
- func IsAdmin(ctx context.Context) bool
- func SharedCatalogKind(kind string) bool
- func Singular(p string) string
- type AlwaysAllowAuthenticated
- type Authorizer
- type RBAC
- type Resource
- type Scoper
- type Snapshot
Constants ¶
This section is empty.
Variables ¶
var ErrForbidden = errors.New("authz: forbidden")
ErrForbidden is returned when an authenticated actor lacks permission. Mapped to HTTP 403.
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
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
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
SharedCatalogKind reports whether kind (the singular handlers pass) is shared catalog data that no user, team or project may own.
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 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.
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.