server

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 56 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 server is the product's HTTP surface: the JSON API, the embedded UI, the scan runner and the scheduler.

Index

Constants

This section is empty.

Variables

View Source
var ErrBlocked = errors.New("target address is not allowed")

ErrBlocked is wrapped by every refusal.

Functions

func AuditActionOf

func AuditActionOf(route string) (kind, action string)

AuditActionOf is the object kind and action an audited route records (tests).

func AuditCoverage

func AuditCoverage(route string) string

AuditCoverage reports, for tests, which table a route is in: "audited", "self" or "".

func TLSConfig

func TLSConfig(certs []tls.Certificate) *tls.Config

TLSConfig is the configuration of the server's own HTTPS listener (PRD-007 REQ-SS-1). It is what this product's own rules call good: TLS 1.2 and 1.3 only; in TLS 1.2 only ECDHE suites with authenticated encryption (no CBC, no RSA key transport, no 64-bit ciphers); in TLS 1.3 Go's suites, and Go's default groups, which offer the hybrid X25519MLKEM768 first. A test scans a listener built from this with the product's own scanner and expects no finding.

Types

type AnchorCert

type AnchorCert struct {
	Cert *x509.Certificate
	SHA  string
}

AnchorCert is a parsed CA certificate accepted as a private anchor.

func ParseAnchors

func ParseAnchors(pemText []byte, max int) ([]AnchorCert, error)

ParseAnchors reads PEM text under the certificate-only rules: any private-key block refuses the whole upload (it is counted, never decoded), and every certificate must be a CA. It returns the certificates or a reason.

type BulkResult

type BulkResult struct {
	Line   int        `json:"line"`
	Input  string     `json:"input"`
	Status string     `json:"status"` // added | duplicate | invalid
	Reason string     `json:"reason,omitempty"`
	Asset  *assetView `json:"asset,omitempty"`
}

BulkResult is the outcome for one line of a bulk add (AC-01.2).

type CollectorBinary

type CollectorBinary struct {
	OS       string `json:"os"`
	Arch     string `json:"arch"`
	Filename string `json:"filename"`
	Size     int64  `json:"sizeBytes"`
	SHA256   string `json:"sha256"`
	// Primary is true for the binary built for the platform this server itself runs on: the
	// obvious one to offer first, since it is very likely also the platform of the machine
	// being inventoried.
	Primary bool `json:"primary"`
	// contains filtered or unexported fields
}

CollectorBinary is one collector binary this server found on disk and can serve.

type Config

type Config struct {
	Store  *store.Store
	Runner *Runner
	Guard  Guard

	// Token, if set, is required as a bearer token on every API call. With no
	// token the API is unauthenticated and the server must be bound to loopback
	// (the caller enforces that), and the Host header is checked to defeat DNS
	// rebinding.
	Token string
	// AllowedHosts are extra Host header values accepted when no token is set.
	AllowedHosts []string
	// TrustedProxies are the reverse proxies whose X-Forwarded-For header names the real client,
	// for rate limits and the sign-in log. A request from any other peer is taken at its word.
	TrustedProxies []*net.IPNet

	// Sign-in (ADR-0018, UX-REVIEW-008 S3) is off by default and turned on in Settings, which keeps
	// the choice in the store. RequireLogin forces it on (--sign-in on) and ForbidLogin forces it
	// off (--sign-in off); neither can then be changed in the interface. With sign-in on, every API
	// call needs a signed-in session or the automation Token.
	RequireLogin bool
	ForbidLogin  bool
	// AllowOpen says sign-in may be off: the server listens on loopback only, or the operator
	// accepted an open server on the network (--open-network). Without it, Settings cannot turn
	// sign-in off.
	AllowOpen bool
	// SetupCode is the one-time code that creates the first administrator; printed by serve.
	SetupCode string
	// SetupCodeExpires is when the setup code stops working (zero: never, for tests).
	SetupCodeExpires time.Time
	// SecureCookies marks the session cookie Secure on every response. Without it the cookie is
	// Secure when the request came over TLS or a proxy sent X-Forwarded-Proto: https.
	SecureCookies bool
	// SessionIdle and SessionMax end a session after inactivity and in any case (defaults 30 min, 12 h).
	SessionIdle, SessionMax time.Duration

	Version            string
	RegistryRetrieved  string
	EvalVersion        string
	MaxConcurrentScans int
	Log                *slog.Logger
	Now                func() time.Time
}

Config configures the HTTP server.

type FlatFinding

type FlatFinding struct {
	AssetID   int64  `json:"assetId"`
	AssetName string `json:"assetName"`
	AssetKind string `json:"assetKind"`

	// Key identifies the finding within its asset: a rule ID ("CIPHER.RC4") for
	// a TLS finding, or "pqc:<algorithm name>" for a host algorithm verdict.
	Key         string          `json:"key"`
	Title       string          `json:"title"`
	Detail      string          `json:"detail,omitempty"`
	Severity    string          `json:"severity,omitempty"`
	Category    string          `json:"category,omitempty"`
	Evidence    string          `json:"evidence,omitempty"`
	Class       string          `json:"class,omitempty"`
	Citations   []eval.Citation `json:"citations,omitempty"`
	Remediation string          `json:"remediation,omitempty"`

	Status *store.FindingStatus `json:"status,omitempty"`
}

FlatFinding is one triageable finding, from either a TLS scan's evaluation or a host's CBOM algorithm classification. The two source systems have different shapes — an eval.Finding carries a severity tier; a host's pqc-derived verdict only has a vulnerable/safe class — so this never claims a host finding has a severity it doesn't have: Severity is set only for TLS findings, Class only for host findings.

type Guard

type Guard struct {
	AllowLoopback bool
	// Scope, when set, limits scans further to the operator's --scan-allow list.
	Scope *Scope
	// contains filtered or unexported fields
}

Guard decides which addresses a scan may connect to. A scanner that dials user-supplied targets is an SSRF vector, so the rule is enforced where it cannot be bypassed: on the actual remote address of every connection, in the dialer's Control hook (after DNS, before connect), which also defeats DNS rebinding.

Refused always: unspecified, multicast, broadcast and link-local addresses (which includes the 169.254.169.254 cloud-metadata endpoint), plus a few well-known metadata addresses outside those ranges. Loopback is refused unless AllowLoopback is set. Private (RFC 1918) ranges are allowed: scanning internal systems is the point of a self-hosted tool.

func (Guard) CheckIP

func (g Guard) CheckIP(ip net.IP) error

CheckIP returns nil if a scan may connect to ip.

func (Guard) CheckLiteral

func (g Guard) CheckLiteral(host string) error

CheckLiteral checks a host that is an IP literal; names are checked when they are resolved and again when connected to.

func (Guard) CheckTarget

func (g Guard) CheckTarget(ctx context.Context, host string) error

CheckTarget decides whether an endpoint may be added (REQ-AC-1, add-time). An address must be allowed by the Guard and, with a scope, be inside it. A name must be under a scope domain or, failing that, resolve only to addresses inside the scope's networks; it is checked again on every connection.

func (Guard) Control

func (g Guard) Control(_, address string, _ syscall.RawConn) error

Control is a net.Dialer Control hook that refuses blocked remote addresses at connect time.

func (Guard) Dial

func (g Guard) Dial(ctx context.Context, network, addr string) (net.Conn, error)

Dial is a dial function that enforces the guard on the real connection.

func (Guard) ForTarget

func (g Guard) ForTarget(host string) Guard

ForTarget is the Guard for one scan of host: when a scope is set and host is not under one of its domains, every address the scan connects to must also be inside one of its networks.

func (Guard) LookupIP

func (g Guard) LookupIP(ctx context.Context, host string) ([]net.IP, error)

LookupIP resolves a name and refuses it if any address it resolves to is blocked, so a name pointing at an internal service fails with a clear reason before any connection is attempted.

type HostAlgorithm

type HostAlgorithm struct {
	Name       string          `json:"name"`
	OID        string          `json:"oid,omitempty"`
	Class      string          `json:"class"`
	MatchedBy  string          `json:"matchedBy"`
	Rationale  string          `json:"rationale"`
	Basis      []pqc.Reference `json:"basis"`
	ProvidedBy []string        `json:"providedBy"` // package names; capability, not observed use
}

HostAlgorithm is one algorithm found in a host's CBOM with its verdict.

type HostCoverage

type HostCoverage struct {
	OS        string           `json:"os,omitempty"`
	Privilege string           `json:"privilege,omitempty"` // user | admin | root
	Note      string           `json:"note,omitempty"`
	Sensors   []SensorCoverage `json:"sensors"`
	NotSeen   []string         `json:"notSeen"`
	Redacted  bool             `json:"redacted,omitempty"` // the host name is a stable label, not the real one
}

HostCoverage says how complete an uploaded inventory is: which privilege it ran with, what each sensor covered and what none of them could see. Its absence (an older or third-party CBOM) means "not recorded", never "complete".

type HostLegacy

type HostLegacy struct {
	Name       string   `json:"name"`
	Status     string   `json:"status"`
	Basis      string   `json:"basis"`
	ProvidedBy []string `json:"providedBy"`
}

HostLegacy is one retired or broken algorithm found on a host.

type HostSummary

type HostSummary struct {
	Name         string          `json:"name"`
	Producer     string          `json:"producer,omitempty"`
	Components   int             `json:"components"`
	Packages     int             `json:"packages"`
	Vulnerable   int             `json:"vulnerable"`
	Safe         int             `json:"safe"`
	Unclassified []string        `json:"unclassified"`
	Algorithms   []HostAlgorithm `json:"algorithms"`
	Timestamp    string          `json:"timestamp,omitempty"`
	// Coverage is how complete the inventory is; nil when the CBOM does not say.
	Coverage *HostCoverage `json:"coverage,omitempty"`
	// Legacy lists algorithms the CBOM marks as retired or broken for classical
	// reasons, each with the source it cites. This is separate from the post-quantum
	// verdict: MD5 is not "quantum-vulnerable", it is unsafe against today's computers.
	Legacy []HostLegacy `json:"legacy"`
}

HostSummary is the analysis of an uploaded CBOM.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner executes queued scans and triggers scheduled ones.

func NewRunner

func NewRunner(st *store.Store, guard Guard, opts RunnerOptions) *Runner

NewRunner creates a runner. Call Start to begin work.

func (*Runner) CABundle

func (r *Runner) CABundle() []AnchorCert

CABundle returns the server-wide private CA bundle.

func (*Runner) CRLLookups added in v0.4.1

func (r *Runner) CRLLookups() bool

CRLLookups reports whether this runner's scans fetch the CRLs certificates name: the effective value, Settings over the command line.

func (*Runner) Cancel

func (r *Runner) Cancel(scanID int64)

Cancel stops a running scan. (A queued scan is simply marked canceled in the store.)

func (*Runner) Evaluate

func (r *Runner) Evaluate(rep *tlsprobe.Report, assetID int64) eval.Evaluation

Evaluate judges a report for an asset with every input the server has.

func (*Runner) EvaluateSSH

func (r *Runner) EvaluateSSH(rep *sshprobe.Report) eval.Evaluation

EvaluateSSH judges an SSH report with the server's clock.

func (*Runner) HTTPChecks

func (r *Runner) HTTPChecks() bool

HTTPChecks reports whether this runner's scans send the HTTP-layer check (HSTS): the effective value, Settings over the command line.

func (*Runner) Notify

func (r *Runner) Notify()

Notify tells idle workers there is queued work.

func (*Runner) Reevaluate

func (r *Runner) Reevaluate(scanID int64, why string) (ev eval.Evaluation, err error)

Reevaluate recomputes a completed scan's evaluation from its stored report with the current anchors, reference data and time. The report is untouched.

A panic while evaluating is returned as an error: this runs at startup over every stored report, and one report the rules choke on must not keep the server from starting.

func (*Runner) ReevaluateOutdated

func (r *Runner) ReevaluateOutdated() int

ReevaluateOutdated re-evaluates the latest completed scan of every endpoint whose stored evaluation was made by an earlier rule set, so the current view never shows a conclusion the current rules would not draw. Older scans keep the evaluation they were given (history shows what was concluded then). It returns how many changed.

func (*Runner) ReevaluateSystem

func (r *Runner) ReevaluateSystem(systemID int64, why string) int

ReevaluateSystem re-evaluates the latest completed scan of every endpoint of a system (after its anchors change). It returns how many were re-evaluated.

func (*Runner) ScanConfig added in v0.5.1

func (r *Runner) ScanConfig() ScanConfig

ScanConfig is the effective scan configuration, for the API.

func (*Runner) Start

func (r *Runner) Start(ctx context.Context)

Start launches the workers and the scheduler. They stop when ctx is done.

func (*Runner) Wait

func (r *Runner) Wait()

Wait blocks until every worker has stopped.

type RunnerOptions

type RunnerOptions struct {
	// Workers is how many scans may run at once (default 2).
	Workers int
	// Scan holds the per-scan limits (timeout, connection concurrency and budget).
	Scan tlsprobe.Options
	// SchedulerInterval is how often due scheduled scans are looked for (default 10s).
	SchedulerInterval time.Duration
	// ScanTimeout bounds one whole scan (default 10 minutes).
	ScanTimeout time.Duration
	// MaintenanceInterval is how often derived data is repaired (store.Maintain): a graph
	// left stale by a failed projection is rebuilt and orphans are swept (default 5 minutes).
	MaintenanceInterval time.Duration
	Now                 func() time.Time
	// CABundle is the server-wide private CA bundle (--ca-bundle), applied to
	// every evaluation as "your CA bundle" (REQ-TTRS-2).
	CABundle []AnchorCert
	// CRLPrivate is the command line's --revocation-private: whether CRL lookups may reach
	// private and loopback addresses. Settings can override it (scansettings.go).
	CRLPrivate bool
	// Log receives what the runner could not do: a store write that failed, a scan that
	// panicked. Default: discarded.
	Log *slog.Logger
}

RunnerOptions configures the scan runner.

type ScanConfig added in v0.5.1

type ScanConfig struct {
	HTTPChecks bool `json:"httpChecks"`
	CRL        bool `json:"crlLookups"`
	CRLPrivate bool `json:"crlPrivate"`
	// Defaults are the command line's values, shown so "reset" is meaningful.
	Defaults struct {
		HTTPChecks bool `json:"httpChecks"`
		CRL        bool `json:"crlLookups"`
		CRLPrivate bool `json:"crlPrivate"`
	} `json:"defaults"`
	// Overridden names the values Settings changed from the command line.
	Overridden []string `json:"overridden"`
}

ScanConfig is the effective scan configuration and where each value comes from.

type Scope

type Scope struct {
	// contains filtered or unexported fields
}

Scope limits what may be scanned beyond the Guard's fixed rules (PRD-007 REQ-AC-1): the operator's --scan-allow list of networks (a CIDR or a single address) and domains (a name and every name under it). An empty scope allows everything the Guard allows.

A target is in scope when its name is under one of the domains, or when every address it connects to is inside one of the networks. The networks are enforced where the Guard is, on the real remote address of every connection, so a name that is changed to point elsewhere after it was added is refused when the scan connects.

func ParseScope

func ParseScope(entries []string) (*Scope, error)

ParseScope reads --scan-allow entries: "10.0.0.0/8", "192.0.2.7", "example.com" or ".example.com" (the two domain forms mean the same).

func (*Scope) Empty

func (sc *Scope) Empty() bool

Empty reports whether the scope allows everything the Guard allows.

func (*Scope) Entries

func (sc *Scope) Entries() []string

Entries are the scope as the operator wrote it.

type SensorCoverage

type SensorCoverage struct {
	Sensor string `json:"sensor"`
	Status string `json:"status"` // complete | partial | unsupported | failed
	Reason string `json:"reason,omitempty"`
	Denied int    `json:"denied,omitempty"`
	Scope  string `json:"scope,omitempty"`
}

SensorCoverage is what one sensor covered on the host, as the collector recorded it.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the HTTP handler and its dependencies.

func New

func New(cfg Config) *Server

New builds the server.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the full handler chain.

func (*Server) Routes

func (s *Server) Routes() []string

Routes lists every registered API route as "METHOD /path" with {name} placeholders, in registration order.

Jump to

Keyboard shortcuts

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