Documentation
¶
Overview ¶
Package checker defines the monitor type plugins (Konzept 11.2, FA-CHK-01). Voters and probes run the same plugins. All network access goes through the Dialer in Env, so the SSRF policy applies to every check (FA-CHK-04).
Index ¶
- Variables
- func ValidateHost(host string, policy AddressPolicy) error
- type AddressPolicy
- type AssertionError
- type BlockPrivate
- type BlockedError
- type CapabilityRequirer
- type Checker
- type Dialer
- type Env
- type ErrorClass
- type FieldError
- type Registry
- type Result
- type Status
- type StatusCodeError
- type TLSError
- type Target
- type TargetLister
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
var Default = NewRegistry()
Default is the process-wide registry.
var ErrNonCanonicalIP = errors.New("non-canonical IP address notation")
ErrNonCanonicalIP is matched by ValidateHost errors for IP addresses in an ambiguous notation.
var ErrSSRFBlocked = errors.New("address blocked by SSRF protection")
ErrSSRFBlocked is matched by errors for connections the address policy denies.
var ErrUnknownType = errors.New("unknown monitor type")
ErrUnknownType is returned for a monitor type without a registered checker.
Functions ¶
func ValidateHost ¶
func ValidateHost(host string, policy AddressPolicy) error
ValidateHost checks a destination host before it is saved (ADR 0030, FA-SEC-SSRF, PF-29a). It is the save-time companion of the dial-time check in Dialer and never resolves names: a name can change its addresses at any time, so only the dial-time check decides for names.
Always rejected, whatever the policy:
- IPv6 zones ("fe80::1%eth0"): a tenant has no business naming an interface of the node.
- Hosts that look like an IPv4 address but are not one in canonical dotted-decimal form ("0x7f.1", "2130706433", "0177.0.0.1", "127.1", "127.0.0.1."). Resolvers disagree on these: the Go resolver looks them up as names, inet_aton reads them as addresses. A host "looks like IPv4" when its last label is a number, the WHATWG URL rule browsers use; no real top-level domain is numeric. The check runs on the IDNA form too, because net/http maps full-width digits to ASCII.
With a policy, IP literals are also checked against it, so a blocked address such as 169.254.169.254 is rejected when the monitor or channel is saved instead of failing every check.
Types ¶
type AddressPolicy ¶
type AddressPolicy interface {
// Check returns a *BlockedError for forbidden addresses.
Check(ip netip.Addr) error
}
AddressPolicy decides whether a destination IP may be contacted.
type AssertionError ¶
type AssertionError struct{ Msg string }
AssertionError marks a response that arrived but did not meet an expectation (keyword, JSON path, response time).
func (*AssertionError) Error ¶
func (e *AssertionError) Error() string
type BlockPrivate ¶
type BlockPrivate struct{}
BlockPrivate denies loopback, private, link-local (including cloud metadata at 169.254.169.254), CGNAT, multicast, reserved and the IPv6 forms that embed IPv4 addresses (Pflichtenheft FA-SEC-SSRF).
type BlockedError ¶
BlockedError reports a denied destination.
func (*BlockedError) Error ¶
func (e *BlockedError) Error() string
func (*BlockedError) Is ¶
func (e *BlockedError) Is(target error) bool
Is makes errors.Is(err, ErrSSRFBlocked) work.
type CapabilityRequirer ¶
type CapabilityRequirer interface {
RequiredCapability() string
}
CapabilityRequirer is implemented by checkers that need a node capability, e.g. ICMP (FA-CHK-31).
type Checker ¶
type Checker interface {
// Type is the stable key, e.g. "http".
Type() string
// Name is the display name, e.g. "HTTP(S)".
Name() string
// ConfigSchema is the JSON Schema (draft 2020-12) of the configuration; the
// UI renders its form from it (Konzept 11.2).
ConfigSchema() json.RawMessage
// Validate checks semantic rules the schema cannot express. It runs after
// schema validation.
Validate(cfg json.RawMessage) error
// Check runs once. ctx carries the monitor timeout; when it ends, the check
// must return and leave no goroutines behind (FA-CHK-02).
Check(ctx context.Context, env *Env, cfg json.RawMessage) Result
}
Checker is a monitor type plugin.
type Dialer ¶
type Dialer struct {
// Policy may be nil, which allows every address (SSRF protection off).
Policy AddressPolicy
}
Dialer is the single entry point for outgoing connections of checkers and notifications (FA-CHK-04). The policy is evaluated in net.Dialer.Control, i.e. on the IP the socket actually connects to, after DNS resolution and for every redirect hop; DNS rebinding cannot bypass it (FA-SEC-SSRF, PF-29a).
type Env ¶
type Env struct {
// Dialer is the only way a checker may open network connections.
Dialer *Dialer
// UserAgent identifies the monitor, e.g. "Pulsequorum/1.2.0" (FA-CHK-13).
UserAgent string
// ICMPMode is the ICMP socket mode detected at startup: "privileged",
// "unprivileged" or "off" (FA-CHK-31).
ICMPMode string
// Now is the wall clock of the node, used for certificate validity and
// expiry decisions; nil means time.Now. Latencies stay monotonic (ADR 0020).
Now func() time.Time
}
Env carries the dependencies of a check.
type ErrorClass ¶
type ErrorClass string
ErrorClass tells whether a failure came from the target or from the way to it (FA-CHK-03, PF-14).
const ( ClassNone ErrorClass = "" ClassDNS ErrorClass = "dns" ClassConnect ErrorClass = "connect" ClassTLS ErrorClass = "tls" ClassTimeout ErrorClass = "timeout" ClassHTTPStatus ErrorClass = "http_status" ClassAssertion ErrorClass = "assertion" ClassSSRFBlocked ErrorClass = "ssrf_blocked" ClassInternal ErrorClass = "internal" )
Error classes; the values are part of the API and the protobuf contract.
func Classify ¶
func Classify(err error) ErrorClass
Classify maps an error to an ErrorClass (FA-CHK-03). The order matters: specific causes win over the generic network errors that wrap them.
type FieldError ¶
FieldError is one configuration problem.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds the available checkers. Default is the process-wide registry the built-in checkers register with at init time; it is the only global state allowed by the conventions (CLAUDE.md).
func (*Registry) Register ¶
Register adds a checker and compiles its schema. It panics on a duplicate type or an invalid schema, which are programming errors.
func (*Registry) Validate ¶
func (r *Registry) Validate(typ string, cfg json.RawMessage) error
Validate checks cfg against the type's JSON Schema, then its semantic rules, then the notation of its destination hosts (ValidateHost without a policy). Problems are reported as *ValidationError.
func (*Registry) ValidateTargets ¶
func (r *Registry) ValidateTargets(typ string, cfg json.RawMessage, policy AddressPolicy) error
ValidateTargets checks the destination hosts of a monitor configuration with ValidateHost. Validate already does this without a policy; the API calls ValidateTargets with the node's policy when SSRF protection is on. Checkers without TargetLister have no targets.
type Result ¶
type Result struct {
Status Status
LatencyMs int
Message string
ErrorClass ErrorClass
// Details holds type-specific data such as the status code, the resolved
// IP, phase timings or the TLS expiry.
Details map[string]any
}
Result is the outcome of one check.
type Status ¶
type Status int
Status is the outcome of a single check on a single node.
Check outcomes; the values match store.CheckStatus and the protobuf enum.
type StatusCodeError ¶
StatusCodeError marks an unexpected HTTP status code.
func (*StatusCodeError) Error ¶
func (e *StatusCodeError) Error() string
type TLSError ¶
type TLSError struct{ Err error }
TLSError marks failures of the certificate check done by a checker itself.
type Target ¶
type Target struct {
// Field is the JSON pointer of the configuration field, e.g. "/url".
Field string
// Host is the host name or IP literal (IPv6 with or without brackets).
Host string
}
Target is one destination host named in a monitor configuration.
type TargetLister ¶
type TargetLister interface {
// Targets returns the destination hosts of cfg. cfg has passed the
// checker's schema and Validate.
Targets(cfg json.RawMessage) ([]Target, error)
}
TargetLister is implemented by checkers whose configuration names hosts that the check connects to. The registry validates them with ValidateHost (ADR 0030). A query name that is only looked up, never contacted, is not a target.
type ValidationError ¶
type ValidationError struct {
Fields []FieldError
}
ValidationError lists configuration problems by JSON pointer (FA-MON-02).
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Directories
¶
| Path | Synopsis |
|---|---|
|
Package builtin registers all built-in monitor types with checker.Default.
|
Package builtin registers all built-in monitor types with checker.Default. |
|
Package dnscheck implements the DNS monitor type (FA-CHK-40/41).
|
Package dnscheck implements the DNS monitor type (FA-CHK-40/41). |
|
Package httpcheck implements the HTTP(S) monitor type (FA-CHK-10..15).
|
Package httpcheck implements the HTTP(S) monitor type (FA-CHK-10..15). |
|
Package icmpcheck implements the ICMP (ping) monitor type (FA-CHK-30/31).
|
Package icmpcheck implements the ICMP (ping) monitor type (FA-CHK-30/31). |
|
Package tcpcheck implements the TCP monitor type (FA-CHK-20).
|
Package tcpcheck implements the TCP monitor type (FA-CHK-20). |