Introducing a new way to review your PRs.

Read the announcement

bunkerity / bunkerweb

🛡️ Open-source and cloud-native Web Application Firewall (WAF)

View on GitHub

19 documents · Updated Nov 23, 2026

docs / configuration-orchestration

Configuration orchestration

BunkerWeb keeps its running protection state aligned with external systems through two cooperating services. Autoconf observes an orchestrator and writes the discovered instances, sites, settings, and custom configuration to the shared database. The scheduler turns that state into runtime files, sends it to BunkerWeb instances, reloads them, and runs recurring maintenance work.

System boundary

The shared database is the hand-off point between discovery and runtime control. External objects are not sent directly to Nginx; they are normalized into BunkerWeb state first. The scheduler then treats that state as the source for generated configuration and job input.

flowchart LR
    E[Docker, Swarm, or Kubernetes] --> A[Autoconf]
    A --> D[(Shared database)]
    D --> S[Scheduler]
    S --> G[Generated configuration and runtime data]
    G --> B[BunkerWeb instances]
    S --> J[Recurring and one-time jobs]
    J --> D
    J --> G

This split lets external changes and scheduled work use the same state model. It also gives the scheduler a place to validate, delay, retry, or fall back when an instance or database is not ready.

References: src/…/main.py• L54-85 src/…/Config.py• L176-273 src/…/main.py• L1463-1484

External configuration flow

Autoconf selects a controller for the active environment, waits for usable BunkerWeb instances, and applies an initial snapshot before it watches for changes. Docker and Swarm use container or service events. Kubernetes uses resource watches for pods, services, configuration data, secrets, and the selected Ingress or Gateway resources. See Autoconf ingestion for the source-specific flow.

The controller converts external objects into three kinds of state:

  • Instances, which identify BunkerWeb processes that can receive configuration.
  • Services, which describe protected host names and their settings.
  • Custom configuration, which carries supported configuration files or extra settings.

Each accepted change is compared with the last applied snapshot. The controller batches nearby events and waits for the scheduler to finish an in-progress apply before it saves a new snapshot. The scheduler then sees database change markers and performs the runtime update.

References: src/…/Controller.py• L96-121 src/…/Controller.py• L173-197 src/…/DockerController.py• L260-330 src/…/KubernetesController.py• L537-581 src/…/KubernetesController.py• L715-827

Configuration sources

The supported source shapes differ by platform, but they express the same BunkerWeb model. Docker and Swarm labels identify instances, sites, and custom configuration. Kubernetes annotations and resources express sites and routes, while ConfigMaps provide settings or custom configuration. Ingress and Gateway API controllers also resolve backends and TLS secrets before they create service state.

The controllers limit what they manage by configured namespaces, classes, and ignore rules. Invalid settings, unsupported configuration types, missing backends, and incomplete TLS data are excluded rather than written as active runtime state. Kubernetes can retry a backend that appears after the first event, so an ordering delay does not permanently discard a route.

References: src/…/DockerController.py• L103-191 src/…/SwarmController.py• L104-183 src/…/KubernetesController.py• L450-510 src/…/IngressController.py• L73-243 src/…/GatewayController.py• L428-459 src/…/KubernetesController.py• L843-916

Database hand-off

Autoconf stores normalized instance data, service settings, and custom configuration in the database. It marks the related changes for the scheduler instead of applying files itself. The scheduler claims those markers before it reads the next snapshot, which prevents a new write during processing from being lost.

Both services account for database readiness and read-only state. Autoconf waits while the scheduler is applying a configuration. The scheduler avoids writes when the database is read-only and retries connection recovery when possible. Autoconf retains pending changes and plugin signals until their database notification succeeds, so a partial apply remains eligible for retry. Sensitive values are redacted before configuration values are written to Autoconf logs.

References: src/…/Config.py• L13-50 src/…/Config.py• L74-87 src/…/Config.py• L229-248 src/…/Config.py• L306-364 src/…/main.py• L777-794 src/…/main.py• L928-945 src/…/main.py• L1930-1944 src/…/JobScheduler.py• L695-724

Runtime synchronization

The scheduler turns the database snapshot into generated Nginx configuration, custom configuration files, plugin files, and job cache files. It sends these artifacts to reachable BunkerWeb instances, asks each instance to test and reload them, and records instance health from the responses.

When a generation or reload fails, the previous working configuration remains the preferred fallback. If a saved failover copy exists, the scheduler can send that copy and reload it. A successful cycle creates a fresh failover backup for later recovery. Reloads that are accepted but not yet confirmed stay pending until a later health check confirms their readiness.

sequenceDiagram
    participant DB as Shared database
    participant S as Scheduler
    participant I as BunkerWeb instance
    DB->>S: Change markers and configuration snapshot
    S->>S: Generate runtime files
    S->>I: Send configuration and cache
    S->>I: Test and reload
    I-->>S: Success or failure
    S->>DB: Update instance state and change markers
    S->>S: Save working state or use failover state

The same path handles startup and later changes. Startup first waits for an instance to answer, then runs one-time jobs around the initial configuration. Later changes set work flags for the next reload cycle. A job can request a second render when it creates an input used by the generated configuration.

References: src/…/main.py• L307-348 src/…/main.py• L736-762 src/…/main.py• L816-869 src/…/main.py• L928-1080 src/…/main.py• L1582-1739

Scheduled work

The scheduler runs plugin-defined jobs in addition to configuration publication. A job declares whether it runs once, every minute, hour, day, or week, and whether its result requires a reload. The scheduler discovers valid jobs from core, external, and licensed plugin definitions. See Scheduler jobs for the job lifecycle and cadence.

The job model separates work from publication. A job can update a cache, create a certificate, download a data set, or report a release. When a job changes runtime inputs, the scheduler regenerates and publishes the affected state, then retries publication with backoff if an instance is unavailable. Startup job deferral is bounded so recurring jobs still become registered even when the first configuration push cannot complete.

Work classPurposeRuntime effect
One-time jobsPrepare startup data such as plugin downloads or an API certificateMay cause a second configuration render after the job creates its input
Recurring jobsRefresh data such as GeoIP databases or release informationMay request a reload or update only stored job state
Health checksDetect loading, unavailable, or restarted instancesRe-send current configuration when an instance needs it

References: src/…/JobScheduler.py• L189-242 src/…/JobScheduler.py• L407-475 src/…/main.py• L960-1077 src/…/main.py• L1869-2005 src/…/plugin.json• L8-43

Job publication

The scheduler runs jobs through a controlled cycle so jobs validate against the configuration that instances actually received. It can hold one-time jobs briefly when generation or delivery fails, but it eventually runs them to avoid leaving recurring jobs unscheduled. Failed publication stays pending and uses increasing delays instead of creating a tight retry loop. A job that reports changed publication inputs triggers one later render rather than an unchanged second reload.

References: src/…/main.py• L816-889 src/…/JobScheduler.py• L420-539 src/…/main.py• L1180-1213 src/…/main.py• L1493-1580

Operational health

Autoconf and the scheduler publish health markers for their process-level liveness. Kubernetes watches use separate markers so one broken watch cannot be hidden by another healthy watch. The scheduler health check also tracks whether each BunkerWeb instance answers and whether it needs its configuration again after a restart.

These checks protect the synchronization loop rather than replace it. A lost watch, stuck database call, failed generation, or unreachable instance causes retries, a health failure, or failover so stale state is visible and recoverable. Health checks resend all runtime folders before reloading an instance that reports loading or needs configuration.

References: src/…/main.py• L70-90 src/…/Controller.py• L248-311 src/…/KubernetesController.py• L620-713 src/…/main.py• L1338-1547

Change checklist

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

  • Keep the database change markers aligned with the scheduler flags that trigger generation, job reruns, and instance endpoint refresh.
  • Preserve the event-to-snapshot contract when adding a new external resource: initial discovery, event filtering, deletion handling, and health or status updates must agree.
  • Keep custom configuration type names consistent across source ingestion, database storage, generated directories, and the instance upload endpoint.
  • When a job changes files used by templates, keep its reload or regeneration signal aligned with the publication cycle.
  • When changing instance health or retry behavior, check both startup delivery and the later health-check recovery path.
  • When changing settings validation or log output, keep forced re-checks and secret redaction aligned with all configuration sources.
  • When changing cleanup behavior, keep pending and plugin signals aligned with database acknowledgment.

Important failure modes

TriggerConsequenceGuard
Database is not initialized or is read-onlyNew external state or job results cannot become activeAutoconf waits; the scheduler skips unsafe writes and retries database access
Configuration generation failsThe last working configuration remains activeGeneration failure uses backoff and does not reload the new partial output
No BunkerWeb instance is reachableConfiguration and job publication cannot completeDelivery is deferred, then health checks retry instances that answer later
Kubernetes watch exhausts its retriesChanges for that resource stop arrivingThe watch marker is removed so the liveness check can restart autoconf
Referenced backend or TLS secret is missingThe affected route or certificate is not appliedThe controller skips invalid data and retries delayed backends when they appear
Autoconf saves state but cannot acknowledge the database changeThe scheduler may not receive the signal for the new statePending changes and plugin signals remain queued for a later apply
Reload is accepted but readiness is not confirmedThe scheduler could treat a not-yet-live generation as activeReload state stays pending until health polling confirms it

Key files

FileWhy to read it
src/…/main.pyShows controller selection, readiness wait, initial apply, and event processing.
src/…/Config.pyShows how discovered state becomes database configuration and change markers.
src/…/Controller.pyShows the shared lifecycle for discovery, initial synchronization, and settings re-checks.
src/…/DockerController.pyShows the Docker event and label ingestion model.
src/…/KubernetesController.pyShows Kubernetes watches, event filtering, retries, and backend recovery.
src/…/IngressController.pyShows how Ingress objects become protected services.
src/…/GatewayController.pyShows how Gateway API routes and listener data become protected services.
src/…/main.pyShows configuration generation, publication, health checks, failover, and the main change loop.
src/…/JobScheduler.pyShows job discovery, cadence, execution, reload signals, and publication retries.
src/…/plugin.jsonShows the core job schedule and the meaning of one-time versus recurring work.