Skip to content

feat: integrate CrowdSec protection #64

Closed

Description

@RentnerKev

Summary

Integrate CrowdSec as a first-class security feature for RentnerProxy on top of the
published v1.0.0-alpha.6 architecture.

CrowdSec must remain part of the existing flow:

Web / PostgreSQL -> Rust controller -> typed Caddy JSON -> Caddy

It must not introduce a second proxy engine, arbitrary user-supplied Caddy JSON, or a
parallel policy platform.

Alpha 6 baseline

The implementation must preserve the current Alpha 6 contracts:

  • Caddy 2.11.4 and the single Caddy Admin API data plane
  • runtime snapshot version 7, revision-checked reconciliation, and rollback to the last
    verified configuration
  • strict trusted-proxy/client-IP handling on both HTTP and HTTPS listeners
  • existing Basic Auth and IPv4/IPv6 Access Policy behavior
  • certificate candidates, durable certificate operations/events, retry state, and
    host/certificate binding jobs
  • HTTP/3, WebSockets, force-HTTPS handling, ACME HTTP-01, canonical management origin, and
    live administration state

Goals

  • global CrowdSec enable/disable
  • CrowdSec Local API (LAPI) connection with validated endpoint configuration
  • secure bouncer credential handling
  • decision enforcement in the Caddy request path
  • clear Connected, Degraded, and Disabled status
  • correct behavior with direct clients and explicitly trusted upstream proxies
  • deliberate integration with Proxy Hosts and the existing Access Policy model where it adds
    value without creating a second policy engine
  • preserve existing public-host behavior while CrowdSec is disabled

AppSec/WAF remains an evaluation item. Ship it only if the current integration is stable,
testable, and does not introduce disproportionate runtime or supply-chain risk.

Architecture and deployment

The accepted deployment is a single RentnerProxy appliance: one container, one existing
rentnerproxy volume, and the same public Compose file. No second CrowdSec service, Docker
socket, new public port, mandatory CrowdSec environment variable, or manually managed volume.

Three explicit modes share the same Caddy HTTP enforcement layer:

  1. Disabled (default): no CrowdSec engine, Local API traffic, or bouncer in the active request
    path. Alpha 6 upgrades retain their previous traffic behavior until an administrator opts in.
  2. Managed by RentnerProxy (recommended): the production image bundles a pinned CrowdSec
    runtime and Caddy collection. The engine runs as an unprivileged user, acquires bounded Caddy
    access logs without a Docker socket, stores durable state under
    /var/lib/rentnerproxy/crowdsec, and exposes its Local API only on loopback. RentnerProxy
    provisions and rotates the internal bouncer credential; no key entry or CrowdSec CLI is
    required for normal operation.
  3. External CrowdSec (advanced): Caddy connects to an operator-managed Local API with a
    validated endpoint and encrypted, write-only bouncer credential. The internal engine is stopped.

Managed → External validates the external provider before switching traffic, then stops the
internal engine. External → Managed starts and verifies the internal engine and bouncer before
switching traffic. Mode changes retain managed detection state. AppSec/WAF and Layer 4 remain
outside this integration; the pinned Caddy HTTP bouncer is the only additional Caddy module.

The PR must document source, version/digest pinning, licenses, security scanning, image impact,
and the backup/restore handoff to #71.

Client IP and trusted proxies

CrowdSec must use the same effective client-IP semantics as the existing Caddy runtime.

  • Direct traffic: the socket peer is authoritative.
  • Trusted upstream traffic: forwarded client data is accepted only through the configured
    RENTNERPROXY_PROXY_TRUSTED_PROXY_CIDRS chain and Caddy strict trusted-proxy behavior.
  • Never trust arbitrary X-Forwarded-For, Forwarded, X-Real-IP, or
    X-Forwarded-Proto input.
  • Preserve the existing IPv4-mapped IPv6 protections.

Tests must demonstrate that forged forwarding headers from an untrusted peer cannot bypass a
decision.

Secrets, RBAC, and audit

  • Never return a CrowdSec credential to the browser or include it in logs/errors.
  • Persist credentials encrypted with contextual authenticated encryption when persistence is
    required; otherwise use a narrowly permissioned secret file.
  • Add explicit server-side permissions for viewing status and changing configuration.
  • Audit configuration and credential rotation without recording secret material.
  • Redact downstream and validation errors before they reach users or logs.

Failure behavior

Define and test behavior for LAPI downtime, timeout, invalid credentials, stale decision state,
Caddy module failure, configuration reload, controller restart, and Caddy restart.

The request path must remain bounded and must not create retry loops. Cached/streamed decisions
should continue to be enforced while valid. Temporary LAPI loss should degrade explicitly and,
by default, must not permanently take public traffic offline. Any fail-closed mode must be an
explicit, documented administrator choice with a narrow error-class definition.

UI

Add a focused Security -> CrowdSec experience in the existing design language:

  • status: Connected, Degraded, or Disabled
  • enabled state
  • endpoint
  • credential set/replace state without secret disclosure
  • only safe, supportable options

Do not add a SIEM dashboard or fabricate statistics.

Tests

Unit and integration

  • configuration validation and serialization
  • encryption, redaction, RBAC, and audit behavior
  • enabled/disabled, decision allow/deny, unavailable LAPI, invalid credential, restart, and
    configuration update
  • direct, trusted-proxy, untrusted-proxy, forged-header, IPv4, and IPv6 cases

Runtime and production smoke

  • a real Caddy request is denied by a real CrowdSec decision
  • allowed requests continue to the upstream
  • Basic Auth, IP policies, force HTTPS, ACME HTTP-01, WebSockets, HTTP/1.1, HTTP/2, and HTTP/3
    continue to work where applicable
  • runtime reload, controller restart, and Caddy restart recover correctly
  • no production credential is stored in CI

Out of scope

  • full SIEM or analytics platform
  • generic plugin platform
  • a new proxy engine
  • TCP/UDP stream proxying
  • unrelated monitoring/dashboard work

Acceptance criteria

  • Current upstream integration and supply-chain decision are documented in the PR.
  • Real CrowdSec decisions block requests and disabled mode leaves hosts unaffected.
  • Trusted client-IP behavior and forged-header resistance are verified.
  • Credentials remain server-side, encrypted or file-backed, redacted, RBAC-protected, and
    audited.
  • Failure behavior is bounded, documented, and covered by automated tests.
  • Reconciliation and restart behavior are reliable.
  • Production image, smoke tests, dependency/security scans, and required checks pass.
  • User and deployment documentation covers setup, trust boundaries, and failure semantics.

Priority and sequencing

P0 / major Beta feature. Builds on completed Access Policies #28, Basic Auth #30, IP rules #31,
and the Alpha 6 trusted-proxy/runtime foundations. The final security review #72 must include the
shipped implementation. Required for #75 unless explicitly deferred with rationale.

Activity

  1. added this to the v1.0.0-beta.1 milestone on Sep 12, 2026
  2. added
    enhancement
    security
    area: proxy
    area: runtime
    on Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: proxyarea: runtimeenhancementsecurity

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions