cedar

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: 10 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 cedar implements authorization.Authorizer with the Cedar policy language (github.com/cedar-policy/cedar-go).

For every request the Engine reads the policy text and the request-scoped entity JSON from its sources, so policy changes take effect immediately and no state is cached. Inputs are bounded (1 MiB of policies, 1 MiB of entities, entity identifiers, context depth and size) and validated; duplicate or invalid entity UIDs, mixed-type context sets and unsupported context value types are rejected. Evaluation is default-deny: a decision is allowed only when a permit policy matches, no forbid policy matches and no policy failed to evaluate. Diagnostic reasons and errors list policy IDs only, in deterministic order.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Effect added in v0.2.0

type Effect int

Effect is what a matching Policy does with a request.

const (
	// Permit allows a matching request unless a Forbid policy also matches.
	Permit Effect = iota + 1
	// Forbid denies a matching request regardless of any Permit policy.
	Forbid
)

type Engine

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

Engine evaluates Cedar policies against request-scoped entities. It is safe for concurrent use when its sources are.

func New

func New(options Options) (*Engine, error)

New validates the required policy and entity sources.

func (*Engine) Authorize

func (e *Engine) Authorize(ctx context.Context, request authorization.Request) (authorization.Decision, error)

Authorize evaluates one request. Every ambiguous or invalid input fails closed with an error from package authorization. Request.Context accepts bool, string, int64, []string, []any and map[string]any values.

type Options

type Options struct {
	Policies authorization.PolicySource
	Entities authorization.EntitySource
}

Options configures an Engine.

type Policies added in v0.2.0

type Policies []Policy

Policies is an authorization.PolicySource that renders its policies as Cedar text on every call. Entity types and IDs are validated with the rules Engine applies to requests, and IDs are always quoted and escaped, so policies may be built from untrusted IDs. Policies returns authorization.ErrInvalidSource for an empty list, an unknown Effect, a missing resource type or an invalid entity; an Engine reading it then fails closed with authorization.ErrSource. Policies is safe for concurrent use if the policies and the entities they point to are not modified.

func (Policies) Policies added in v0.2.0

func (p Policies) Policies(ctx context.Context) ([]byte, error)

Policies renders the policies as Cedar text.

type Policy added in v0.2.0

type Policy struct {
	Effect    Effect
	Principal *authorization.Principal
	Action    *authorization.Action
	Resource  authorization.Resource
}

Policy is a Cedar policy whose scope is built from the same values as an authorization.Request.

  • Principal: nil matches any principal; a value matches exactly that principal.
  • Action: nil matches any action; a value matches exactly that action.
  • Resource is required and must have a Type. An empty ID matches every resource of that type; a non-empty ID matches exactly that resource.

For example,

Policy{
	Effect:    Permit,
	Principal: &authorization.Principal{Type: "User", ID: "alice"},
	Action:    &authorization.Action{ID: "read"},
	Resource:  authorization.Resource{Type: "Document"},
}

is the Cedar policy

permit(principal == User::"alice", action == Action::"read", resource is Document);

Policies with conditions or hierarchy scopes are written as Cedar text and supplied through another authorization.PolicySource.

Jump to

Keyboard shortcuts

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