sar

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package sar authorises each signed-in user's view by asking the API server SubjectAccessReviews, through a per-identity cache (design §6, D-091, D-100).

Index

Constants

View Source
const (
	// DefaultAllowTTL is an allow's lifetime when Options.AllowTTL is zero.
	DefaultAllowTTL = 60 * time.Second
	// DenyTTL is the longest a deny lives: a stale deny only hides.
	DenyTTL = 5 * time.Minute
	// MinDenyTTL is the shortest: a jittered deny spreads refreshes, a shorter one only asks again sooner.
	MinDenyTTL = 4 * time.Minute
)

Decision lifetimes from the start of the SAR (design §6.2, D-100).

View Source
const (
	// DefaultMaxInFlight is the most SARs sent at once when Options.MaxInFlight is zero.
	DefaultMaxInFlight = 32
	// DefaultRate is the SARs per second when Options.Rate is zero.
	DefaultRate = 100
	// DefaultBurst is the SARs sent above the rate when Options.Burst is zero:
	// one cold page never waits on the bucket.
	DefaultBurst = 500
	// MaxRate is the highest --authz-rate, so the token interval never rounds to 0.
	MaxRate = 10000
)

Default global SAR limits (D-100 item 6).

View Source
const DefaultMaxBytes = 8 << 20

DefaultMaxBytes is the permission cache's byte budget when Options.MaxBytes is zero (D-100).

Variables

View Source
var ErrCheck = errors.New("authorisation check failed")

ErrCheck is a check without a decision. It wraps a fixed category and never names the identity.

View Source
var ErrExpired = errors.New("authorisation: full-read decision expired")

ErrExpired is the error of a full-read decision that expired before it was returned, on the first evaluation and on the one after it.

View Source
var ErrNoIdentity = errors.New("authorisation: no signed-in identity")

ErrNoIdentity is the error of a check on a request without a signed-in identity.

View Source
var ErrOverloaded = fmt.Errorf("%w: overloaded", ErrCheck)

ErrOverloaded is the error of a check that would start a flight past maxFlights.

Functions

This section is empty.

Types

type Attributes

type Attributes struct {
	Verb      string
	Group     string
	Resource  string
	Namespace string
	Name      string
}

Attributes are the resource attributes of one check.

type Authorizer

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

Authorizer decides visibility per signed-in user (design §6.1, D-100): populations by list on the resource in the namespace, named refs by that list, then get on the named object.

func New

func New(o Options) *Authorizer

New returns an Authorizer; call Run to sweep its cache.

func (*Authorizer) Admit

func (a *Authorizer) Admit(r *http.Request) (func(), error)

Admit implements api.Admitter: it waits under r's context for one of the MaxInFlight / 8 admission places, in arrival order (D-116). Too many requests waiting, in all or of r's identity, is ErrOverloaded. A request without an identity can send no SAR, so it is admitted without a place.

func (*Authorizer) Authorize

func (a *Authorizer) Authorize(r *http.Request, ref objects.Ref) bool

Authorize implements api.Authorizer with population semantics: an error is reported for the request and answered as deny.

func (*Authorizer) AuthorizeErr

func (a *Authorizer) AuthorizeErr(r *http.Request, ref objects.Ref) (bool, error)

AuthorizeErr implements api.ErrAuthorizer as the population check: list on ref's resource in its namespace, and a named get only with NamedGetScan. An unmapped kind, or a namespaced kind without a namespace, is denied without a SAR.

func (*Authorizer) AuthorizeNamedErr

func (a *Authorizer) AuthorizeNamedErr(r *http.Request, ref objects.Ref) (bool, error)

AuthorizeNamedErr implements api.NamedAuthorizer: list, then get on the named object, which honours resourceNames grants.

func (*Authorizer) CanList

func (a *Authorizer) CanList(r *http.Request, gk objects.GroupKind, namespace string) (bool, error)

CanList implements api.ListAuthorizer. It asks only list, never a named get; an unmapped kind or an overlong namespace is false.

func (*Authorizer) FullRead

func (a *Authorizer) FullRead(r *http.Request) (bool, error)

FullRead implements api.FullReader: whether the caller may list every served kind cluster-wide. It never returns an expired decision: an expired one is evaluated once more, and ErrExpired follows a second expiry. A "true" is noted with its expiry for the commit wrapper (D-100).

func (*Authorizer) NamedGetScan

func (a *Authorizer) NamedGetScan() bool

NamedGetScan implements api.ListScanner: whether a list denial still asks a named get.

func (*Authorizer) ResolveLists

func (a *Authorizer) ResolveLists(r *http.Request, qs []api.ListQuery) ([]bool, error)

ResolveLists implements api.BatchAuthorizer: each answer is the list half of AuthorizeErr, resolved through the cache batchParallel at a time. An unmapped kind, or a namespaced kind without a namespace, is false without a SAR. It stops at the first error; a request that ends stops queued work and returns its context's error.

func (*Authorizer) Run

func (a *Authorizer) Run(ctx context.Context)

Run sweeps expired decisions every minute until ctx ends.

type Checker

type Checker interface {
	// Check returns the decision, or an error when there is none; an error is never a deny.
	Check(ctx context.Context, id oidc.Identity, a Attributes) (bool, error)
}

Checker asks whether an identity may perform a verb on a resource.

type Kind

type Kind struct {
	Group      string
	Resource   string
	Namespaced bool
}

Kind is the resource a group and kind map to.

type Kinds

type Kinds interface {
	// Lookup returns the resource of group and kind; false means unmapped.
	Lookup(group, kind string) (Kind, bool)
	// All returns every mapped kind and a key that changes when the set does.
	All() (kinds []Kind, key string)
}

Kinds maps the kinds Snellius serves to their resources.

type KubeChecker

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

KubeChecker checks through the authorization.k8s.io/v1 SubjectAccessReview API.

func NewKubeChecker

func NewKubeChecker(kube kubernetes.Interface) *KubeChecker

NewKubeChecker returns a Checker backed by the cluster's SubjectAccessReview API.

func (*KubeChecker) Check

func (k *KubeChecker) Check(ctx context.Context, id oidc.Identity, a Attributes) (bool, error)

Check implements Checker (design §6.3): allowed is allow, not allowed is deny, and an evaluation error, HTTP error or timeout is ErrCheck.

type Options

type Options struct {
	Checker Checker
	Kinds   Kinds
	// AllowTTL bounds an allow from the start of its SAR; zero means DefaultAllowTTL.
	AllowTTL time.Duration
	Clock    clock.WithTicker
	// Metrics receives the authz series; nil keeps them unexported.
	Metrics *obs.Registry
	// IdentityFrom returns the signed-in identity; nil means session.IdentityFrom.
	IdentityFrom func(context.Context) (oidc.Identity, bool)
	// NamedGetScan adds a named get to population checks the list denies (D-100).
	NamedGetScan bool
	// MaxBytes bounds the permission cache, decisions and full reads together; zero means DefaultMaxBytes.
	MaxBytes int64
	// MaxInFlight, Rate and Burst bound the SARs sent across requests: at once,
	// per second, and at once above the rate (D-100). Zero means the Default value.
	MaxInFlight, Rate, Burst int
}

Options configure an Authorizer.

Jump to

Keyboard shortcuts

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