authorization

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 2 Imported by: ? modules, 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 authorization defines protocol-neutral authorization contracts: a Request of principal, action and resource entities plus context, an Authorizer that returns a Decision, and the PolicySource and EntitySource interfaces an implementation reads from. Package cedar provides the Cedar implementation.

The package does not import package authentication; callers map an authenticated principal to a request entity themselves.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidConfiguration reports invalid constructor options.
	ErrInvalidConfiguration = errors.New("authorization: invalid configuration")
	// ErrInvalidRequest reports a malformed or unbounded request.
	ErrInvalidRequest = errors.New("authorization: invalid request")
	// ErrSource reports that a policy or entity source failed.
	ErrSource = errors.New("authorization: source unavailable")
	// ErrInvalidSource reports policies or entities that are empty, oversized
	// or malformed.
	ErrInvalidSource = errors.New("authorization: invalid source")
)

Sentinel errors returned by authorizers. A non-nil error always means the request is not authorized.

Functions

This section is empty.

Types

type Action added in v0.2.0

type Action struct {
	ID string
}

Action identifies what the principal wants to do, for example "read". Its Cedar entity type is always Action, so Action{ID: "read"} is the Cedar entity Action::"read".

type Authorizer

type Authorizer interface {
	Authorize(context.Context, Request) (Decision, error)
}

Authorizer evaluates an authorization request.

type Decision

type Decision struct {
	Allowed bool
	Reasons []string
	Errors  []string
}

Decision is a deterministic authorization result.

type EntitySource

type EntitySource interface {
	Entities(context.Context, Request) ([]byte, error)
}

EntitySource supplies Cedar entity JSON for one request.

type PolicySource

type PolicySource interface {
	Policies(context.Context) ([]byte, error)
}

PolicySource supplies Cedar policy text.

type Principal added in v0.2.0

type Principal struct {
	Type string
	ID   string
}

Principal identifies who makes a request, for example the Cedar entity User::"alice": Type "User", ID "alice". Type is a Cedar entity type such as "User" or "App::User"; ID is any non-empty UTF-8 string.

type Request

type Request struct {
	Principal Principal
	Action    Action
	Resource  Resource
	Context   map[string]any
}

Request contains only authorization inputs. It is independent of authentication.

type Resource added in v0.2.0

type Resource struct {
	Type string
	ID   string
}

Resource identifies what the action applies to, for example Document::"report": Type "Document", ID "report".

Directories

Path Synopsis
Package cedar implements authorization.Authorizer with the Cedar policy language (github.com/cedar-policy/cedar-go).
Package cedar implements authorization.Authorizer with the Cedar policy language (github.com/cedar-policy/cedar-go).

Jump to

Keyboard shortcuts

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