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 / management-services

Management services

BunkerWeb provides a management plane for changing configuration, viewing state, and running operational actions without handling proxied traffic directly. The management API, Web UI, and command-line interface share the same stored state and control contracts so that an action from one interface can be seen and continued by the others.

Management plane

The management plane is the operator-facing part of BunkerWeb. It turns user intent into stored configuration or an operation on one or more BunkerWeb instances, while the runtime and scheduler apply the resulting state.

Administration interfaces

Each interface serves a different operating context. The Management API is the service-to-service and automation boundary. The Web user interface is the guided browser experience. The Administration command-line interface supports shell-based work and plugin commands.

References: src/…/main.py• L176-190 src/…/main.py• L105-127 src/…/main.py• L17-23

Shared state

The database is the shared source for configuration and management records. It covers services, settings, instances, plugins, custom configurations, jobs, and change markers. Interfaces read this state before they display or change it, so a change remains available after the process that made it ends. The database service also detects temporary connection loss and can fall back to a read-only connection, which lets management surfaces report state without pretending that writes succeeded. The shared database model is defined by src/…/Database.py and its related models.

References: src/…/Database.py• L25-49 src/…/Database.py• L260-339 src/…/Database.py• L805-872 src/…/Database.py• L902-963 src/…/dependencies.py• L25-34

Configuration and operation flows

Management actions have two main outcomes. A configuration action changes shared desired state. An operational action asks a local or remote instance to perform work such as reload, stop, ban, or unban.

Configuration changes

The interfaces validate and persist configuration through shared database rules. A saved change records that downstream state needs attention. The scheduler and runtime then use that state to produce or load the active gateway configuration.

This diagram shows the high-level path from an operator action to active gateway state.

flowchart LR
    Operator[Operator or automation]
    Interfaces[API, Web UI, or CLI]
    State[(Shared configuration state)]
    Scheduler[Scheduler and change processing]
    Runtime[Runtime gateway]

    Operator --> Interfaces
    Interfaces --> State
    State --> Scheduler
    Scheduler --> Runtime
    Runtime --> State

The service model keeps each service's settings tied to its service identity. Services can be created, renamed, removed, or moved between draft and online states when their ownership allows it. Custom configuration snippets follow the same service scope and remain protected when another source owns them.

References: src/…/services.py• L58-72 src/…/services.py• L91-129 src/…/configs.py• L61-95 src/…/Database.py• L551-575

Operational actions

Operational actions use the internal instance API as the control path. When more than one instance is known, the shared caller sends the request to each target and reports whether all targets completed it. A busy instance is retried because it may be applying another valid change rather than being unavailable.

This diagram shows how one management request can reach the local instance or a group of registered instances.

sequenceDiagram
    participant Client as Management client
    participant Control as Management service
    participant State as Shared state
    participant Caller as Instance caller
    participant Nodes as BunkerWeb instances

    Client->>Control: Request an operation
    Control->>State: Read targets and operation data
    State-->>Control: Local or registered instances
    Control->>Caller: Build the target set
    Caller->>Nodes: Send operation
    Nodes-->>Caller: Result or busy response
    Caller-->>Control: Aggregate result
    Control-->>Client: Normalized response

The API exposes both state management and operations for instances, bans, jobs, caches, plugins, and services. The CLI uses the same API caller for actions that must reach instances, while it uses the scheduler database for workflows that need central state.

References: src/…/deps.py• L9-34 src/…/core.py• L19-52 src/…/ApiCaller.py• L59-136 src/…/CLI.py• L332-369

Shared interfaces

The interfaces share a small set of rules that keep administration consistent. These rules matter more than the screen, command, or route used to start an action.

Ownership and editability

Every managed setting or service has an origin, or method, that identifies the system allowed to maintain it. UI and API edits are treated as human-managed state. Sources such as Autoconf or the scheduler can retain control, which prevents a manual edit from being silently replaced by the next automated pass.

The same rule applies to deletion and rename actions. An interface must not claim ownership of a service or custom configuration that another source still defines.

References: src/…/Database.py• L175-181 src/…/Database.py• L624-648 src/…/Database.py• L551-575 src/…/services.py• L146-169 src/…/configs.py• L237-259

Draft and online state

A draft service is stored configuration that is not yet part of the active online set. Management services can inspect both states, but a conversion to online state is a deliberate change that must be accepted by the owner of the service. This lets operators prepare configuration before exposing it to traffic.

References: src/…/services.py• L237-253 src/…/services.py• L123-165 src/…/services.py• L20-55

Authentication and access control

The API and Web UI protect different entry points with credentials and session controls. The API can issue short-lived Biscuit tokens and can apply resource permissions. It can also restrict source IPs, Host headers, and request rates before a management route runs. The Web UI uses a signed session with login, CSRF protection, and optional second-factor checks. Its session store can use Redis with a local file fallback, so a temporary Redis problem does not automatically end the management surface. These controls protect both stored state and actions sent to instances.

References: src/…/main.py• L61-140 src/…/main.py• L176-204 src/…/config.py• L30-61 src/…/main.py• L674-719 src/…/main.py• L721-849 src/…/main.py• L977-1008

Interface relationships

The three interfaces are separate entry points into one management model. They are not interchangeable in every context, so the right choice depends on whether the caller needs a stable service boundary, guided operator work, or local shell access.

Management API

The API is the programmatic control plane. It returns normalized success and error responses and groups resources by management concern. It also provides health probes and publishes an OpenAPI description so automation can discover the same boundary that operators use. Read Management API for its service boundary, startup path, utility layer, and persistence relationship.

References: src/…/main.py• L43-57 src/…/main.py• L139-171 src/…/main.py• L176-235 src/…/core.py• L35-52

Web user interface

The Web UI is the browser control surface for operators. It presents service, configuration, instance, job, report, plugin, cache, and ban views over the shared state. It also manages browser sessions and can refresh UI plugin behavior as stored plugin state changes. Plugin hooks and pages extend the same browser surface, while a failed security hook denies the request instead of silently serving an incomplete page. Read Web user interface for its service structure and operator flow.

References: src/…/main.py• L81-125 src/…/main.py• L389-424 src/…/main.py• L426-663 src/…/main.py• L721-857 src/…/dependencies.py• L30-52

Administration command-line interface

The CLI is the shell control surface for local administration and plugin-provided commands. It can fan out ban actions to known instances and can run commands that require scheduler-side database access. The bwcli helper is a thin launcher for the shared CLI program. Read Administration command-line interface for its command and helper contracts.

References: src/…/bwcli• L1-5 src/…/main.py• L22-103 src/…/CLI.py• L125-220 src/…/CLI.py• L592-664

Change checklist

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

  • Keep the API resource contract aligned with the UI and CLI use of services, custom configurations, bans, and instances.
  • Preserve method ownership rules when adding a new write path. A default-filled scheduler pass must not erase a UI or API edit.
  • Preserve change markers when a write affects configuration, custom configurations, instances, plugins, or UI plugins. These markers drive later refresh work.
  • Keep service rename and delete behavior aligned with the source that owns the service. A manual rename must not create a stale row for an automated source.
  • Keep instance fan-out behavior aligned with busy responses. A temporary busy state must not become a false node failure.
  • Keep API host and source allowlists aligned with internal control-plane calls. A new restriction must not block the scheduler's internal host or API path.
  • Keep UI session storage and cookie rules aligned when changing Redis use, local fallback, session lifetime, or CSRF handling.
  • Keep API and UI authentication changes aligned with their session or token checks and with internal control-plane calls.

Important failure modes

TriggerConsequenceGuard
A write uses the wrong ownership methodA later automated pass can overwrite the change or restore an old service definitionShared method compatibility and service ownership checks
A service is renamed without updating its prefixed settingsThe service identity and its settings no longer refer to the same targetService rename builds a complete renamed configuration before saving
An instance returns busy while applying another changeA healthy instance can be reported as down and a multi-instance operation can fail earlyBounded retries for busy responses in the shared API caller
The database is read-only or unavailableConfiguration changes are not saved and the UI can show stale stateDatabase read/write checks and read-only mode reporting
API source, Host, or token settings reject a control-plane requestInternal or operator management calls receive an access errorAPI settings include an internal host path and explicit authentication checks
Redis becomes unavailable after UI startupSession reads or writes can fail and operators can lose the browser control surfaceResilient session storage falls back to the local session cache
UI plugin hooks fail during a context refreshA page can run without a security or policy hookFailed hook loading installs a fail-closed request guard

Key files

FileWhy to read it
src/…/main.pyDefines the API's role as the control plane, shared response behavior, access boundary, and management resource groups.
src/…/deps.pyShows how the API resolves the local instance and registered remote instances.
src/…/services.pyShows the service lifecycle and the ownership-aware configuration save boundary.
src/…/configs.pyShows the shared scope and ownership rules for custom configuration.
src/…/Database.pyDefines the shared state model, method compatibility, database availability modes, and change markers.
src/…/ApiCaller.pyDefines multi-instance operation fan-out and busy-instance retry behavior.
src/…/main.pyShows the Web UI application boundary, sessions, authentication, plugin context, and fail-closed hook loading.
src/…/dependencies.pyShows the Web UI's shared database, configuration, and plugin state services.
src/…/main.pyShows the CLI command boundary and its process result contract.
src/…/CLI.pyShows how the CLI connects to shared state, instances, Redis, and plugin commands.