Introducing a new way to review your PRs.

Read the announcement

techarohq / anubis

Weighs the soul of incoming HTTP requests to stop AI crawlers

View on GitHub

19 documents · Updated Nov 23, 2026

docs / configuration-loading

Configuration loading and validation

Configuration loading turns a YAML policy file into the typed settings that Anubis uses for request rules, thresholds, data stores, logs, metrics, GeoIP data, and honeypots. It reads local or built-in policy sources, applies safe defaults, expands imported rules, and rejects invalid settings before the server starts.

Loading lifecycle

The loading lifecycle separates file parsing from system setup. lib/…/config.go first decodes the file into a file-shaped model, validates its values, then returns a typed Config; lib/…/policy.go converts that model into live stores, checkers, loggers, GeoIP data, and threshold programs.

The main stages are:

  1. lib/config.Load reads YAML from the supplied reader. An explicit policy path is used when present; otherwise lib.LoadPoliciesOrDefault opens the built-in policy.
  2. File-level validation checks required rule data and each configured subsystem. Errors are collected so one load can report several bad settings.
  3. Imports are opened and flattened into ordinary bot rules. Imported files can come from the local file system or the embedded (data)/ policy tree.
  4. Missing thresholds use the default threshold that challenges requests with a positive weight.
  5. policy.ParseConfig creates the runtime resources and performs checks that need registered challenge methods, extensions, stores, or external data.

This diagram shows how configuration moves from YAML to the running policy.

flowchart LR
    A[YAML policy] --> B[Decode and apply defaults]
    B --> C[Validate typed settings]
    C --> D[Expand imports]
    D --> E[Build runtime policy]
    E --> F[Create store, logger, GeoIP, metrics, and checkers]
    F --> G[Serve requests]

References: lib/…/config.go• L308-481 lib/…/import.go• L86-155 lib/config.go• L64-113 lib/…/policy.go• L80-148

Rule and threshold configuration

Bot rules describe request signals and the action or weight change that follows. A rule needs a name, one or more supported match inputs, and a known action; its regular expressions, CIDRs, remote address URL, challenge settings, and expressions must also be valid.

Rules can use a direct expression string or an all or any list. The loader turns a list into a combined expression, while the policy layer compiles it for request checks. ALLOW, DENY, CHALLENGE, WEIGH, and DEBUG_BENCHMARK are the supported rule actions.

Thresholds convert the accumulated request weight into a final decision. Each threshold needs a name and expression. A CHALLENGE threshold must include challenge settings, and thresholds cannot use WEIGH; when the file has no thresholds, the loader supplies the legacy positive-weight challenge behavior.

References: lib/…/config.go• L35-53 lib/…/config.go• L57-201 lib/…/expressionorlist.go• L17-129 lib/…/threshold.go• L10-78 lib/…/thresholds.go• L9-31 lib/…/policy.go• L150-289

Import resolution

Imports let a policy reuse rule sets without copying them into the main file. An import points to a local path or to an embedded (data)/ path; a glob can select several files, and matches are sorted in natural order before their rules are combined.

Imported files use the same bot-rule shape as the parent file and can contain further imports. The loader rejects missing files, empty glob matches, unsupported recursive or brace glob patterns, parse errors, and invalid rules. A rule entry cannot define both a bot and an import.

References: lib/…/import.go• L20-31 lib/…/import.go• L33-83 lib/…/import.go• L86-155 data/…/default-config.yaml• L1-33

Typed operational settings

The typed configuration model gives each operational area a clear contract. Optional blocks are validated only when present, while the loader supplies defaults for the in-memory store, standard logging, honeypot behavior, status codes, and DNS cache TTLs.

AreaPurposeImportant validation or default
StoreKeeps policy-related runtime stateThe backend must be registered, and its parameter object must pass backend validation. The default backend is memory.
LoggingSelects standard output or file loggingFile logging needs a file name and non-negative rotation limits. A log level in the file takes precedence over the flag level.
MetricsExposes operational metricsThe bind address and network are required. TCP networks or Unix sockets are supported; Unix sockets also need an octal mode.
HoneypotEnables an extra trap flow for suspicious clientsThe only accepted enabled implementation is naive. Disabled honeypots do not need an implementation.
DNSControls forward and reverse lookup cache timeForward and reverse TTLs cannot be negative. The default for each is 300 seconds.
Status codesSets responses for challenge and deny actionsBoth values must be HTTP status codes from 100 through 599.

References: lib/…/config.go• L308-425 lib/…/store.go• L12-43 lib/…/logging.go• L16-57 lib/…/logging.go• L59-124 lib/…/metrics.go• L30-80 lib/…/honeypot.go• L10-44 lib/config.go• L484-520

Metrics access controls

Metrics can use TLS and basic authentication in addition to a network listener. TLS validation checks that the certificate and key files can be read, that the key pair is valid, and that an optional CA file contains a certificate; basic authentication requires both a user name and a password.

References: lib/…/metrics.go• L83-169

GeoIP settings

GeoIP settings connect bot rules to MaxMind ASN and country data. The top-level GeoIP block must define at least one database, and each database needs a path; country databases may select country or registered_country, while ASN databases cannot set a country field.

Automatic updates use a MaxMind account ID and the name of an environment variable that holds the license key. The update interval defaults to 24 hours and cannot be shorter than one hour. An override endpoint must be an absolute HTTP or HTTPS URL.

Country codes in bot rules must contain two letters and are normalized to lower case. ASN rules reject private-use ASNs. If a rule needs GeoIP data that is not configured, policy loading warns and does not add that check; if the configured database itself cannot load, policy parsing fails.

References: lib/…/geoip.go• L10-35 lib/…/asn.go• L8-43 lib/…/geoip_databases.go• L11-95 lib/…/geoip_databases.go• L107-218 lib/…/policy.go• L116-145 lib/…/policy.go• L217-233

Configuration failure boundaries

Configuration errors appear at two boundaries. File-level errors cover YAML shape, required values, ranges, regular expressions, paths, and relationships between fields; runtime validation covers resources that are only known after parsing, such as registered stores, challenge algorithms, extensions, GeoIP databases, and compiled expressions.

The loader returns an error instead of a partial policy when validation fails. Some missing optional runtime data produces a warning and removes only the dependent rule check, so operators must treat warnings about absent GeoIP data or ASN logging as behavior changes rather than parse failures.

References: lib/…/config.go• L323-384 lib/…/config.go• L434-481 lib/config.go• L88-110 lib/…/policy.go• L116-145 lib/…/policy.go• L264-298

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep file-level defaults aligned with the runtime consumers that read the typed Config.
  • When adding a challenge algorithm or extension, update the final validation path so valid names are also registered at runtime.
  • When changing an import path or glob rule, preserve support for both local files and embedded (data)/ policies.
  • When changing GeoIP fields, check both database validation and bot-rule behavior when the matching database is absent.
  • When changing store parameters, keep the config validator and the selected store factory's parameter contract aligned.
  • When changing logging or metrics file options, preserve the early readability and format checks that prevent startup failures.

Important failure modes

TriggerConsequenceGuard
An import path or glob matches no fileThe policy cannot loadUse an existing local path or embedded (data)/ path. Do not use recursive ** or brace alternation.
A file rule sets both user_agent_regex and path_regexThe rule is rejectedChoose one of these two primary match forms.
File logging lacks parameters or a file nameLogging setup cannot startSet a valid file target and rotation settings when sink is file.
Metrics TLS files are missing or do not form a key pairMetrics setup is rejectedCheck certificate, key, and optional CA files before startup.
GeoIP auto-update names an unset license-key variableGeoIP validation failsSet the named environment variable before starting the service.
A rule uses GeoIP or ASN matching without its databaseThat match check is skipped and a warning is loggedConfigure the matching GeoIP database or remove the dependent rule.
A configured challenge algorithm or extension is not registeredFinal policy validation failsUse names provided by the active challenge and extension registries.

Key files

FileWhy to read it
lib/…/config.goDefines the file schema, load order, defaults, and top-level validation.
lib/…/import.goExplains local, embedded, and glob-based rule imports.
lib/…/policy.goShows the boundary between typed settings and live runtime resources.
lib/…/store.goDefines store backend selection and parameter validation.
lib/…/logging.goDefines logging sinks and file rotation settings.
lib/…/metrics.goDefines metrics listeners, TLS, and basic authentication checks.
lib/…/geoip_databases.goDefines GeoIP database and automatic update requirements.
lib/…/threshold.goDefines threshold defaults and final decision rules.
data/…/default-config.yamlShows how the built-in policy combines imports with direct rules.