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 / web-user-interface

Web user interface

The Web user interface is BunkerWeb's browser-based control plane. It gives operators one place to set protection rules, inspect traffic and system state, manage extensions, and control connected BunkerWeb instances. It stores operator state in the shared database and hands configuration work to the scheduler so the running gateway can apply it.

Service role

The UI is a server-side web application that combines rendered pages with small browser requests. It reads shared configuration and operational data through the database, uses connected instance APIs for live data and actions, and uses Redis when shared metrics or bans are available.

The UI covers the main operator tasks:

  • Set global and per-service settings.
  • Create, edit, export, import, and stage service configurations.
  • Manage custom NGINX and security configuration snippets.
  • View dashboards, reports, bans, logs, jobs, cache files, and instance status.
  • Manage templates and UI plugins.
  • Run selected scheduler jobs and request instance reload or stop actions.
  • Manage the operator profile, sessions, language, theme, and two-factor authentication.
  • Build support data for diagnosis.

The UI does not replace the gateway or scheduler. A saved change becomes shared state first. The scheduler then turns that state into a new runtime configuration and reports whether the change was applied or rolled back.

References: src/…/main.py• L674-907 src/…/dependencies.py• L25-38 src/…/services.py• L77-86 src/…/instances.py• L23-26

Application layer

The application layer owns HTTP routes, page rendering, authentication flow, request checks, and the common request context shown to templates. Flask blueprints group the operator-facing areas so each page has a clear role while the application keeps one session and authorization boundary.

The main page groups are:

AreaOperator purpose
Setup and loginCreate the first administrator, sign in, and complete two-factor checks.
Home and reportsSee service health, request activity, blocked traffic, and trends.
Services and global settingsChange the configuration that defines how BunkerWeb protects traffic.
Instances and jobsCheck connected gateways and ask the scheduler to run work or reload them.
Bans, CrowdSec, and cacheReview or change traffic decisions and stored job output.
Logs and supportRead live logs and collect redacted support data.
Templates and pluginsReuse configuration patterns and extend the UI.
Profile and ProManage account security, license features, and session state.

Most read pages require a signed-in user. Changes that affect shared state use a loading view while the UI waits for the scheduler's state to settle. The page then shows success, warning, or failover information from the shared state rather than claiming that a request alone changed the running gateway.

This diagram shows the operator path from a browser action to the active BunkerWeb configuration.

flowchart LR
    Operator[Operator browser] --> UI[Web UI application]
    UI --> Auth[Session and permission checks]
    UI --> DB[(Shared database)]
    UI --> API[Connected instance APIs]
    UI --> Redis[(Shared metrics and bans)]
    DB --> Scheduler[Scheduler]
    Scheduler --> Runtime[Running BunkerWeb instances]
    Runtime --> DB
    Runtime --> Redis

References: src/…/main.py• L81-126 src/…/main.py• L1263-1483 src/…/home.py• L13-109 src/…/reports.py• L98-107 src/…/support.py• L34-65

Operator workflows

The configuration workflow separates editable state from applied state. An operator can save a service or global setting as a draft when it must be prepared without changing live traffic. A normal save or an activation changes the shared database, and the scheduler applies the resulting configuration.

The UI protects settings owned by another source. For example, an Autoconf-managed service or a template-managed custom configuration cannot be changed as if it were a UI-owned value. This keeps manual actions from silently overriding configuration supplied by another management service.

The main workflow is:

  1. The operator opens a page and the UI reads the current shared state.
  2. The operator submits a validated change, import, plugin update, job request, or instance action.
  3. The UI records the change and starts a background task when the action can take time.
  4. The loading view watches database and task state while the scheduler works.
  5. The UI reports the final applied state or the failover to the last working configuration.

References: src/…/services.py• L299-367 src/…/global_settings.py• L28-75 src/…/utils.py• L28-83 src/…/main.py• L1676-1704

Access and account security

The UI uses database-backed accounts with roles and permissions. The standard roles distinguish administration, writing, and reading. The application checks the signed-in user before protected pages and uses a separate permission check for actions such as plugin management or template changes.

Login creates a server-side session and records the session in the UI database. Failed attempts are tracked by user name and client address so repeated failures can trigger a time-based lock. Optional TOTP two-factor authentication must be completed before normal pages open. The profile page lets an operator change account details, enable or disable TOTP, refresh recovery codes, and revoke other sessions. Recovery codes are stored for one-time use. The session store uses Redis when available and a local persistent cache as a fallback.

References: src/…/login.py• L20-133 src/…/totp.py• L12-42 src/…/profile.py• L69-88 src/…/profile.py• L115-205 src/…/ui_database.py• L87-149 src/…/ui_database.py• L223-248 src/…/ui_database.py• L272-316 src/…/ui_database.py• L435-537 src/…/main.py• L1324-1363 src/…/utils.py• L492-619

Utility layer

The utility layer connects page actions to shared BunkerWeb facilities. It provides the database and configuration objects, instance access, Redis access, persistent UI state, plugin loading, validation helpers, and the background task path used by pages.

The layer has four broad responsibilities:

  • Shared access: dependencies exposes the UI database, configuration model, instance helpers, and plugin locations.
  • Operator safety: utils centralizes password checks, session revocation, safe redirects, CSV escaping, editable-source checks, and user messages.
  • Work coordination: route utilities prevent overlapping configuration work, wait for an active scheduler change to finish, and keep the loading screen tied to task state.
  • Extension loading: plugin utilities validate stored plugin data, place it in its runtime location, and refresh UI hooks and pages without mixing lower-priority content over higher-priority content.

The utility layer therefore keeps route modules focused on operator intent. A route says what the operator wants to do, while shared helpers decide how to validate it, persist it, wait for the scheduler, and expose the result.

References: src/…/dependencies.py• L25-52 src/…/utils.py• L53-80 src/…/utils.py• L447-489 src/…/utils.py• L56-109 src/…/dependencies.py• L82-189

Shared state

The UI has two kinds of shared state. The database holds durable BunkerWeb configuration, operator accounts, templates, plugins, instances, jobs, and stored results. A small UI state file holds short-lived coordination data such as reload status, notices, version checks, and read-only status so separate UI workers can see the same progress.

This split lets a browser request remain short while a background task continues. It also lets the UI show a clear difference between a change that is recorded and a change that the scheduler has applied.

References: src/…/dependencies.py• L30-34 src/…/ui_data.py• L6-43 src/…/utils.py• L28-83 src/…/main.py• L1052-1157

Plugin extension model

The UI can load plugin pages, actions, templates, hooks, scripts, and styles. Core, external, and Pro plugins are considered in priority order, with the higher-priority source used when the same plugin is available in more than one source. Administrators can upload or remove UI plugins through the UI. Uploaded archives are checked and stored as shared plugin data so other UI workers can use the same extension set.

A plugin can add an operator page or contribute to the shared request and template context without changing the built-in pages. A page can run a plugin action, render its own template, or redirect to a registered plugin page. Plugin failures fail closed for request hooks that may affect authorization. A plugin refresh also rebuilds the active plugin view and restarts workers when needed, so all workers use the same extension set.

References: src/…/main.py• L131-164 src/…/main.py• L388-425 src/…/main.py• L425-665 src/…/plugins.py• L32-39 src/…/plugins.py• L87-226 src/…/plugins.py• L229-422 src/…/plugins.py• L495-656

Container entrypoint

The container entrypoint prepares the UI process and keeps its shutdown behavior tied to the container lifecycle. It loads shared helpers, prepares persistent data, handles secrets, records the deployment integration, and starts the web workers.

The container starts two Gunicorn applications:

  • The main UI serves the operator application with multiple threaded workers.
  • A temporary UI serves the early setup or error path while the main UI is starting, restarting, or stopping.

The main process listens on port 7000 by default in the container. The image runs as the ui user, stores persistent state below /data, exposes a UI health check, and stops both Gunicorn processes when the container receives a termination signal. The entrypoint also removes stale process markers and handles stop signals that arrive before either child has written its PID file. The systemd service used by Linux packages provides the same UI role through the package start script.

References: src/…/entrypoint.sh• L1-15 src/…/entrypoint.sh• L58-73 src/…/entrypoint.sh• L75-124 src/…/entrypoint.sh• L133-158 src/…/Dockerfile• L82-128 src/…/bunkerweb-ui.service• L1-20

Startup readiness

Startup creates or loads the UI's signing and encryption material, waits for the shared database to be initialized, creates the standard roles when needed, and provisions the administrator from the setup flow or supplied credentials. It then restores plugins and marks the UI ready for traffic.

The UI cannot provide a complete management surface until the database is ready. If required startup state cannot be established within its wait period, the process records an error and exits instead of serving a partly initialized control plane.

References: src/…/gunicorn.conf.py• L156-241 src/…/gunicorn.conf.py• L243-436 src/…/gunicorn.conf.py• L438-478 src/…/gunicorn.conf.py• L482-668

Request serving

Gunicorn loads main:app as the WSGI entry point, where WSGI means the standard interface between the Python web application and the web server. The application accepts direct HTTP access and reverse-proxied access, applies trusted proxy information, and adds security headers and cache rules to each response.

The request boundary also checks host values when an allowlist is set, rejects work while the server is stopping, enforces session and TOTP rules, detects database read-only state, and runs plugin request hooks. Static assets bypass the expensive state checks so the browser can load the interface without creating operator work.

References: src/…/gunicorn.conf.py• L64-134 src/…/main.py• L1263-1483 src/…/main.py• L1495-1580 src/…/main.py• L1599-1674

Operator surface

The operator surface is organized around the state an operator needs to understand and the action that state permits. The UI presents live and stored data together, but it keeps changes subject to database ownership rules and scheduler application.

Operator goalMain UI areaResulting system effect
Protect a new site or change a siteServices, global settings, templatesShared configuration changes and the scheduler updates the gateway.
Check whether protection worksHome, reports, bans, logsThe operator sees request outcomes, blocked clients, and gateway evidence.
Operate a group of gatewaysInstances, jobsThe UI queries instances or asks the API and scheduler to perform work.
Extend or reuse behaviorPlugins and templatesNew UI behavior or reusable configuration becomes available to operators.
Recover or explain a problemSupport, logs, cacheThe operator gets redacted diagnostics and stored job output.
Secure access to the control planeProfile, TOTP, sessionsAccount credentials and active sessions change without changing gateway traffic.

The UI is most useful as the operator's view of the wider management system. Read the management services page for the wider service map. For API-level automation, use the management API page. For host-side administration, use the administration CLI page.

References: src/…/services.py• L77-86 src/…/instances.py• L23-26 src/…/plugins.py• L32-39 src/…/logs.py• L109-120 src/…/support.py• L34-65

Change checklist

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

  • Changes to route-owned configuration must preserve the method and draft rules shared by services, configs, global_settings, and the configuration model.
  • Changes to background configuration tasks must keep the loading state, task markers, scheduler wait, and failover messages consistent.
  • Changes to plugin storage or priority must be reflected in both plugin extraction and application-context refresh so every worker sees the same pages and hooks.
  • Changes to plugin archive handling must preserve the shared plugin metadata, page data, action data, and safe extraction rules as one contract.
  • Changes to session or account state must preserve the database session records, login-failure lockout, session-store revocation markers, TOTP flow, and logout behavior together.
  • Changes to proxy handling must keep the listener settings, forwarded-header trust, reverse-proxy wrapper, and security headers aligned.
  • Changes to the container startup contract must preserve persistent secret paths, health files, PID files, and graceful shutdown for both Gunicorn processes.

Important failure modes

TriggerConsequenceGuard
Shared database is unavailable or read-onlyPages can be read but changes are refused or held in read-only mode.Startup waits for initialization. Requests test database state and show a write warning.
Scheduler is still applying an earlier changeA new UI task can race with the active configuration apply.Configuration tasks wait for scheduler changes and the loading view tracks active work.
Scheduler rejects the generated configurationThe gateway keeps the last working configuration and the UI reports failover.The UI reads scheduler metadata before clearing the loading state.
Persistent UI data is lostFlask, TOTP, or authorization keys can change. Existing sessions or TOTP enrollment may stop working.Persist /data in containers or the UI state directory in package installs.
Redis is unavailableShared session, metric, or ban behavior becomes local or falls back to instance/API data.The UI uses a local session fallback and explicit Redis-aware paths.
Repeated login failures reach the lockout thresholdLogin is blocked for the lockout period for the affected user name or client address.The UI stores recent failures and checks both keys before accepting a login.
A plugin archive is invalid or contains unsafe pathsThe plugin is rejected and is not added to shared UI state.Upload checks require supported archive forms, plugin metadata, valid names, and safe extraction.
Plugin hook loading failsThe affected request is denied instead of running without a possible authorization hook.Plugin refresh records the failure and installs a fail-closed request guard.
UI is exposed without a trusted proxy and access boundaryAn operator-facing control plane is reachable by unintended clients.Put the UI behind BunkerWeb or another trusted proxy and set proxy and host allowlists.

Key files

FileWhy to read it
src/…/main.pyShows application assembly, request lifecycle, authentication gates, response policy, and built-in routes.
src/…/dependencies.pyShows the shared database, configuration, instance, plugin, and task dependencies.
src/…/utils.pyShows the cross-cutting safety and operator-state rules used by routes.
src/…/utils.pyShows how long-running configuration actions wait for the scheduler and update the loading state.
src/…/services.pyShows the central service configuration workflow, including drafts and ownership rules.
src/…/global_settings.pyShows the global configuration workflow and its relationship to drafts.
src/…/login.py, src/…/profile.py, and src/…/ui_database.pyShow login protection, account security, TOTP, recovery codes, sessions, and persistent user state.
src/…/instances.py and src/…/instance.pyShow how the UI discovers and operates connected BunkerWeb instances.
src/…/plugins.pyShows plugin upload, validation, storage, actions, pages, and administrator controls.
src/…/gunicorn.conf.pyShows readiness, secret setup, database startup checks, worker settings, and health state.
src/…/entrypoint.sh and src/ui/DockerfileShow the container process topology, persistent paths, user, port, health check, and shutdown contract.