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 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 (*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.
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.