static

package
v8.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package static provides an authorization.PolicyResolver whose policy is fixed at construction.

This is the default backend, and the one to reach for until something forces otherwise: it needs no database, no migrations, and no configuration, and it resolves without I/O. Policy lives wherever the caller declares its roles — as Go constants, or as YAML loaded into a config struct.

Graduate to authorization/database when roles themselves must become editable data: when an operator has to define a new role, or change what an existing one grants, without shipping a release. Reassigning a principal's roles does not require it — role assignments belong to the consumer either way.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Resolver)

Option configures a Resolver.

func WithLogger

func WithLogger(logger logging.Logger) Option

WithLogger attaches a logger, which the Resolver uses only to warn about a policy that will deny everything.

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver resolves role names against a policy fixed at construction.

func NewResolver

func NewResolver(roles []authorization.Role, opts ...Option) (*Resolver, error)

NewResolver builds a Resolver over roles, expanding inheritance once.

It returns an error for a malformed policy — an unnamed role, a duplicate, a parent that is not defined, or an inheritance cycle — so that a policy mistake fails at startup rather than as a puzzling denial later.

Zero roles is valid and produces a resolver that denies everything. That is deliberate: the zero-value configuration has to build, or the default provider would not be usable without setup. It logs a warning, because a service that denies every request is more likely to be a missing configuration than an intent.

func (*Resolver) PermissionsForRoles

func (r *Resolver) PermissionsForRoles(_ context.Context, roles ...string) (*authorization.PermissionSet, error)

PermissionsForRoles returns the union of the effective permissions of the named roles. It never returns an error: the policy is already validated and resolution touches nothing outside this process.

func (*Resolver) Roles

Roles returns every role in the policy. The returned value shares nothing with the Resolver's state, so a caller cannot edit the live policy through it.

Jump to

Keyboard shortcuts

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