authz

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 17 Imported by: 0 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 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

View Source
var ErrNotAuthorized = errors.New("not authorized")

ErrNotAuthorized is wrapped by every refusal from this package.

Functions

func LoadScopeFile

func LoadScopeFile(file string) (config.Scope, error)

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

func Gate(target *url.URL, opts Options) (*Grant, error)

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

func (g *Grant) Permits(u *url.URL, method string) error

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

func (g *Grant) Scope() config.Scope

Scope returns a copy of the authorized scope. A nil or zero Grant returns the empty scope.

func (*Grant) Source

func (g *Grant) Source() string

Source is "scope-file", "config" or "interactive". It is empty for a nil or zero Grant.

func (*Grant) Statement

func (g *Grant) Statement() string

Statement returns the operator's authorization statement, if any.

func (*Grant) Summary

func (g *Grant) Summary() string

Summary is one line for the ledger and reports, e.g. "hosts localhost:8081; paths /; safe methods only; max 400 requests (scope-file ./scope.toml)".

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.

Jump to

Keyboard shortcuts

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