{"modulePath":"github.com/asteroid-computing/go-lambda-edge","version":"v0.1.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package authz\n\nPackage authz authorizes explicit caller, action and resource facts using immutable rules. It does not authenticate, evaluate AWS IAM policies, resolve application grants automatically or write HTTP responses.\n\nConstruct rules once and share them across requests. Custom checks must be concurrency-safe, honor their context and return false, nil for ordinary denial. Every callback error becomes [ErrUnavailable](#ErrUnavailable). All and Any evaluate left to right and stop on an observed error; keep mandatory application guards outside alternative permission branches.\n\nAuthorize requires a nonanonymous caller even for a permissive custom check. Identity constructors validate facts but do not authenticate them: establish the caller through a trusted producer before authorization. Complete selection and authorization before executing the same action/resource or committing an HTTP response, including a stream.\n\n## Variables\n\n```go\nvar (\n\t// ErrInvalidConfiguration means a rule constructor rejected its arguments, or [Rule.Authorize] was called on a zero Rule or with a nil context.\n\tErrInvalidConfiguration = errors.New(\"authz: invalid configuration\")\n\n\t// ErrInvalidRequest means the [Request] has an empty or non-UTF-8 action or a non-UTF-8 resource.\n\t// No check runs.\n\tErrInvalidRequest = errors.New(\"authz: invalid request\")\n\n\t// ErrUnauthenticated means the request caller is anonymous.\n\t// No check runs, even a permissive custom one.\n\tErrUnauthenticated = errors.New(\"authz: unauthenticated\")\n\n\t// ErrDenied means the rule evaluated without error and did not match.\n\tErrDenied = errors.New(\"authz: denied\")\n\n\t// ErrUnavailable means a [CheckFunc] returned an error, whatever its boolean result.\n\t// Evaluation stops at that node rather than trying another branch.\n\tErrUnavailable = errors.New(\"authz: unavailable\")\n)\n```\nAuthorization errors contain no request facts or callback diagnostics. Match them with [errors.Is](/errors#Is).\n\n## Types\n\n```go\ntype CheckFunc func(ctx context.Context, request Request) (bool, error)\n```\nCheckFunc decides whether a request matches. Return false, nil for denial; any error becomes [ErrUnavailable](#ErrUnavailable), even when accompanied by true. Checks run synchronously, must honor ctx and must be safe for concurrent use when shared. The caller owns dependency deadlines. Panics propagate.\n\n```go\ntype Request struct {\n\tCaller   identity.Caller\n\tAction   string\n\tResource string\n}\n```\nRequest supplies facts passed by value to each check. Action must be nonempty UTF-8; Resource is optional UTF-8. Both compare exactly without normalization and have application-defined meaning. A resource-aware check must reject an absent Resource. Caller is explicit, not read from context.\n\n```go\ntype Rule struct {\n\t// contains filtered or unexported fields\n}\n```\nRule holds immutable private configuration. Copies may be shared concurrently. The zero value is unconfigured and never allows. Construction performs no I/O and never invokes callbacks. A rule is limited to depth 32 (a leaf has depth 1) and 1,024 expanded nodes, counting each occurrence of a shared subtree.\n\n```go\nfunc All(rules ...Rule) (Rule, error)\n```\nAll requires every child to match, evaluating left to right. It stops on the first nonmatch or error. Empty, unconfigured or oversized trees return [ErrInvalidConfiguration](#ErrInvalidConfiguration). The input slice is copied.\n\n```go\nfunc Any(rules ...Rule) (Rule, error)\n```\nAny requires one child to match, evaluating left to right. It stops on the first match or error; an error never falls through to another permission path. Empty, unconfigured or oversized trees return [ErrInvalidConfiguration](#ErrInvalidConfiguration). The input slice is copied. Mandatory guards belong in an outer All.\n\n```go\nfunc Check(check CheckFunc) (Rule, error)\n```\nCheck constructs a rule from a nonnil callback. A nil callback returns [ErrInvalidConfiguration](#ErrInvalidConfiguration). Reusing a check does not deduplicate its evaluation.\n\n```go\nfunc CognitoGroups(issuer string, required ...string) (Rule, error)\n```\nCognitoGroups requires all supplied exact cognito:groups values from the exact issuer. Flattened gateway strings remain unavailable and never match. Groups are distinct from scopes and application grants. Issuer and each required value must be nonempty UTF-8; an empty list or invalid value returns [ErrInvalidConfiguration](#ErrInvalidConfiguration). The input slice is copied.\n\n```go\nfunc IAMPrincipal(principalARN string) (Rule, error)\n```\nIAMPrincipal matches the full caller ARN literally, including path and session. A root ARN matches only that root caller, not the account. Valid literal \\* and ? in user paths retain their meaning as characters. Unsupported caller forms (including bare role ARNs) return [ErrInvalidConfiguration](#ErrInvalidConfiguration), following NewIAM's grammar. This does not evaluate AWS IAM permissions or bind a unique identity across deletion and recreation of the principal.\n\n```go\nfunc IAMRoleSessions(partition, accountID, roleName string) (Rule, error)\n```\nIAMRoleSessions matches assumed-role callers with the exact partition, account and role name, allowing any valid session name. Invalid components, wildcards and role paths return [ErrInvalidConfiguration](#ErrInvalidConfiguration). This is a role-name policy: recreating the same role name can match again. It does not bind a unique role ID, identify the original actor, fabricate a role ARN or evaluate IAM policies.\n\n```go\nfunc JWTClient(issuer, clientID string) (Rule, error)\n```\nJWTClient matches an exact issuer and client\\_id, without interpreting audience or subject as a client ID or inferring a machine grant. Both arguments must be nonempty UTF-8 or construction returns [ErrInvalidConfiguration](#ErrInvalidConfiguration).\n\n```go\nfunc JWTScopes(issuer string, required ...string) (Rule, error)\n```\nJWTScopes requires all supplied exact OAuth scope tokens from the exact issuer. It does not interpret wildcards. Missing or unavailable scopes do not match. Issuer must be nonempty UTF-8 and required must contain at least one valid RFC 6749 scope token, otherwise construction returns [ErrInvalidConfiguration](#ErrInvalidConfiguration). The input slice is copied. Use Any for alternative scope requirements.\n\n```go\nfunc JWTSubject(issuer, subject string) (Rule, error)\n```\nJWTSubject matches an exact issuer and subject. Both must be nonempty UTF-8 or construction returns [ErrInvalidConfiguration](#ErrInvalidConfiguration). A subject does not prove a human identity. Wrong kind or missing subject does not match.\n\n```go\nfunc Sources(allowed ...identity.Source) (Rule, error)\n```\nSources matches any supplied nonanonymous producer. Empty lists, SourceNone and unknown sources return [ErrInvalidConfiguration](#ErrInvalidConfiguration). Source is trusted-code attribution, not an unforgeable credential. Combine this broad predicate with permission checks. The input slice is copied.\n\n```go\nfunc (r Rule) Authorize(ctx context.Context, request Request) error\n```\nAuthorize returns nil only for an explicit allow. It checks rule/context configuration, cancellation, request validity and a nonanonymous caller in that order. No check runs for an anonymous or invalid request. Nonmatches return [ErrDenied](#ErrDenied); all callback errors are sanitized to [ErrUnavailable](#ErrUnavailable). Cancellation is checked between nodes and before returning, and returns ctx.Err(), never context.Cause. No results are cached or installed in context.\n\n","path":"github.com/asteroid-computing/go-lambda-edge/authz","name":"authz","synopsis":"Package authz authorizes explicit caller, action and resource facts using immutable rules.","isRedistributable":true}
