Documentation
¶
Overview ¶
Package urlpolicy decides whether a URL taken from app config may be used, against allowlists a control plane operator configures per category.
The CLI and ctl-api both evaluate URLs with this package, so a URL that passes `nuon apps validate` is not rejected by the server for a matching reason.
Index ¶
- Variables
- func ReservedRunnerEnvVar(name string) bool
- type Category
- type CategoryConfig
- type Config
- type Entry
- type Mode
- type ParseOptions
- type Policy
- func (p *Policy) AnyRestricted() bool
- func (p *Policy) Check(category Category, field, rawURL string) *Violation
- func (p *Policy) CheckRunnerEnvVar(field, name string) *Violation
- func (p *Policy) Entries(category Category) []string
- func (p *Policy) Mode() Mode
- func (p *Policy) OnWarn(fn func(Violations))
- func (p *Policy) RedirectCheck(category Category, field string) func(target *url.URL) error
- func (p *Policy) ReportWarnings(violations Violations)
- func (p *Policy) Restricted(category Category) bool
- type Violation
- type Violations
Constants ¶
This section is empty.
Variables ¶
var Categories = []Category{ CategoryRunnerAPI, CategoryPublicAPI, CategoryRunnerBootstrap, CategoryStackTemplates, CategoryConfigFetch, }
Categories lists every category in a stable order.
Functions ¶
func ReservedRunnerEnvVar ¶
ReservedRunnerEnvVar reports whether a runner env var name could redirect the runner's traffic or credentials, or change which runner build runs.
Types ¶
type Category ¶
type Category string
Category groups app-config URLs by what the URL is trusted to do. The lists are separate so that allowing a template bucket does not also allow that bucket to receive the runner token.
const ( // CategoryRunnerAPI covers the API the runner sends its token to. CategoryRunnerAPI Category = "runner_api" // CategoryPublicAPI covers the API the install stack phones home to. CategoryPublicAPI Category = "public_api" // CategoryRunnerBootstrap covers scripts that run on the runner host or as // the phone-home function. CategoryRunnerBootstrap Category = "runner_bootstrap" // CategoryStackTemplates covers templates the customer's cloud deploys. CategoryStackTemplates Category = "stack_templates" // CategoryConfigFetch covers files ctl-api fetches while parsing a config. CategoryConfigFetch Category = "config_fetch" )
type CategoryConfig ¶
type CategoryConfig struct {
// Entries are the operator's entries. A category with none is not
// restricted.
Entries []string
// Builtins are added once the category is restricted, so an operator does
// not have to restate the origins a stock app config points at. They never
// restrict a category on their own.
Builtins []string
}
CategoryConfig is the input for one category.
type Config ¶
type Config struct {
// Mode defaults to ModeEnforce.
Mode Mode
AllowHTTP bool
Categories map[Category]CategoryConfig
}
Config is the input for New.
type Entry ¶
type Entry struct {
// contains filtered or unexported fields
}
Entry is one allowlist entry: a URL prefix. A bare host is deliberately not the unit of trust, because hosts such as raw.githubusercontent.com or s3.amazonaws.com serve content from anyone.
func ParseEntry ¶
func ParseEntry(raw string, opts ParseOptions) (Entry, error)
ParseEntry parses an allowlist entry. The accepted forms are:
https://bucket.s3.us-west-2.amazonaws.com/ origin plus path prefix https://raw.githubusercontent.com/acme/runner/ owner-scoped prefix https://*.example.com/templates/ any subdomain of example.com example.com shorthand for https://example.com/
type ParseOptions ¶
type ParseOptions struct {
// AllowHTTP admits http entries. Only local development sets it.
AllowHTTP bool
}
ParseOptions controls how entries and candidate URLs are parsed.
type Policy ¶
type Policy struct {
// contains filtered or unexported fields
}
Policy is the effective, parsed policy. The zero value and a nil *Policy restrict nothing.
func FromEffective ¶
FromEffective rebuilds a policy from the effective entries a control plane serves, so a client matches URLs exactly as that control plane does. The entries already include built-ins. Categories this build does not know are skipped: it has no fields mapped to them.
func (*Policy) AnyRestricted ¶
AnyRestricted reports whether any category has an allowlist.
func (*Policy) Check ¶
Check returns a violation when the category is restricted and rawURL does not fall under any of its entries. field names the config field, for the message. An empty rawURL is never a violation: the field is unset.
func (*Policy) CheckRunnerEnvVar ¶
CheckRunnerEnvVar returns a violation for a reserved runner env var. The denylist applies only once the operator has restricted the runner API, which is how they opt into locking the runner down.
func (*Policy) Entries ¶
Entries returns the effective entries for a category in canonical form: built-ins first, then the operator's. It is empty for an unrestricted category.
func (*Policy) OnWarn ¶
func (p *Policy) OnWarn(fn func(Violations))
OnWarn registers the function ReportWarnings calls. Set it once at startup, before the policy is shared.
func (*Policy) RedirectCheck ¶
RedirectCheck returns the check a fetch of an allowed URL runs on each redirect target, so an allowed location cannot send the fetch off-list. In enforce mode an off-list target is an error. In warn mode it is reported through ReportWarnings and the redirect is followed. It returns nil when the category is not restricted.
func (*Policy) ReportWarnings ¶
func (p *Policy) ReportWarnings(violations Violations)
ReportWarnings hands violations found in ModeWarn to the registered function.
func (*Policy) Restricted ¶
Restricted reports whether the category has an allowlist. An unrestricted category accepts any URL.
type Violation ¶
type Violation struct {
Category Category `json:"category"`
Field string `json:"field"`
Value string `json:"value"`
Reason string `json:"reason"`
}
Violation is one config value the policy does not allow.
type Violations ¶
type Violations []Violation
Violations is a list of violations that reads as one error.
func (Violations) Error ¶
func (v Violations) Error() string