Documentation
¶
Overview ¶
Package authz is the authorized-scope gate for live targets. Spackle may send traffic to a running application only when the operator has stated that they own it or are authorized to test it, and Gate is the only way to obtain the Grant that the live-request code requires. A gate cannot stop an operator who lies; it makes authorization explicit, recorded and bounded.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotAuthorized = errors.New("not authorized")
ErrNotAuthorized is wrapped by every refusal from this package.
Functions ¶
func LoadScopeFile ¶
LoadScopeFile reads a scope file (TOML). Keys may be at the top level or under [scope]: hosts, path_prefixes, allow_unsafe_methods, max_requests, requests_per_second, statement. Unknown keys are an error. The returned scope is validated and has its defaults and caps applied.
Types ¶
type Grant ¶
type Grant struct {
// contains filtered or unexported fields
}
Grant is proof that a scope was authorized. The zero value permits nothing. Its fields are unexported: only Gate can make a usable one. A copy enforces the same scope as the original, since nothing in it is mutated after Gate.
func Gate ¶
Gate decides whether target may be tested. Precedence: ScopeFile, then Config, then an interactive confirmation. A source that is present but does not cover the target is a refusal: Gate never falls through to the next source, so a wrong scope file cannot be papered over by a prompt. It returns ErrNotAuthorized (wrapped) when authorization is missing or does not cover the target.
func (*Grant) Permits ¶
Permits reports whether a request to u with the given method is inside the grant. Every refusal wraps ErrNotAuthorized. Call it for each request, including each redirect hop, since a redirect can leave the scope.
func (*Grant) Scope ¶
Scope returns a copy of the authorized scope. A nil or zero Grant returns the empty scope.
func (*Grant) Source ¶
Source is "scope-file", "config" or "interactive". It is empty for a nil or zero Grant.
type Options ¶
type Options struct {
// ScopeFile is the path given with --authorize. Empty when not given.
ScopeFile string
// Config is the [scope] table from spackle.toml; its Hosts are empty when not configured.
Config config.Scope
// Yes is true for --yes and CI mode: never prompt.
Yes bool
// Interactive is true when stdin is a terminal a human can answer on.
Interactive bool
Stdin io.Reader
Stderr io.Writer
}
Options control how authorization is obtained.