[PR #5722] [management, proxy] Add CrowdSec IP reputation integration for reverse proxy #28421

Closed
opened 2026-08-05 08:06:20 -04:00 by saavagebueno · 0 comments
Owner

Original Pull Request: https://github.com/netbirdio/netbird/pull/5722

State: closed
Merged: Yes


Describe your changes

Add CrowdSec IP reputation checking to the reverse proxy, controlled per-service (off/enforce/observe) via the management API.

  • Add stream bouncer with local decision cache and refcounted lifecycle (starts on first service, stops on last)
  • Extend restrict.Filter with CrowdSec verdicts and observe mode support
  • Proxy reports supports_crowdsec capability so dashboard/API can gate the feature
  • Access log carries CrowdSec metadata for both enforce and observe hits
  • Configured via --crowdsec-api-url / --crowdsec-api-key flags or NB_PROXY_CROWDSEC_API_URL / NB_PROXY_CROWDSEC_API_KEY env vars

Restriction evaluation order

Access restrictions are evaluated as a pipeline: CIDR, country, then CrowdSec. Each layer can only further restrict. A denial at any layer is final and short-circuits later layers.

Layer What it does Deny behavior
1. CIDR Allowlist narrows to specific ranges; blocklist removes specific ranges Deny stops here, CrowdSec never runs
2. Country Allowlist/blocklist by geolocation Deny stops here, CrowdSec never runs
3. CrowdSec IP reputation check against LAPI decision cache Can block IPs that passed layers 1 and 2

Examples:

Config Client IP CIDR Country CrowdSec Result
allow 10.0.0.0/8 + enforce 10.1.2.3 (banned) pass skip ban crowdsec_ban
allow 10.0.0.0/8 + enforce 10.2.3.4 (clean) pass skip clean allow
allow 10.0.0.0/8 + enforce 192.168.1.1 deny skip skip ip_restricted
block 10.1.0.0/16 + enforce 10.1.2.3 (banned) deny skip skip ip_restricted
allow country US + enforce 1.2.3.4 US (banned) skip pass ban crowdsec_ban
allow country US + enforce 5.6.7.8 CN skip deny skip country_restricted
allow 10.0.0.0/8 + block country CN + enforce 10.1.2.3 US (banned) pass pass ban crowdsec_ban
allow 10.0.0.0/8 + observe 10.1.2.3 (banned) pass skip ban (logged) allow (observe)

CrowdSec can never relax a CIDR or country denial. Observe mode returns the verdict for logging but does not block.

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

Summary by CodeRabbit

  • New Features

    • CrowdSec integration: runtime bouncer + shared registry with enforce/observe modes (observe logs but doesn't block).
    • Server accepts CrowdSec API URL/key, advertises cluster CrowdSec capability, and exposes per-domain CrowdSec support.
    • Access restrictions gain crowdsec_mode with stricter validation; access logs and API now include optional per-request metadata.
  • Chores

    • Updated Go module dependency versions and added CrowdSec client libraries.
**Original Pull Request:** https://github.com/netbirdio/netbird/pull/5722 **State:** closed **Merged:** Yes --- ## Describe your changes Add CrowdSec IP reputation checking to the reverse proxy, controlled per-service (off/enforce/observe) via the management API. - Add stream bouncer with local decision cache and refcounted lifecycle (starts on first service, stops on last) - Extend restrict.Filter with CrowdSec verdicts and observe mode support - Proxy reports `supports_crowdsec` capability so dashboard/API can gate the feature - Access log carries CrowdSec metadata for both enforce and observe hits - Configured via `--crowdsec-api-url` / `--crowdsec-api-key` flags or `NB_PROXY_CROWDSEC_API_URL` / `NB_PROXY_CROWDSEC_API_KEY` env vars ### Restriction evaluation order Access restrictions are evaluated as a pipeline: CIDR, country, then CrowdSec. Each layer can only further restrict. A denial at any layer is final and short-circuits later layers. | Layer | What it does | Deny behavior | |---|---|---| | 1. CIDR | Allowlist narrows to specific ranges; blocklist removes specific ranges | Deny stops here, CrowdSec never runs | | 2. Country | Allowlist/blocklist by geolocation | Deny stops here, CrowdSec never runs | | 3. CrowdSec | IP reputation check against LAPI decision cache | Can block IPs that passed layers 1 and 2 | Examples: | Config | Client IP | CIDR | Country | CrowdSec | Result | |---|---|---|---|---|---| | allow `10.0.0.0/8` + enforce | `10.1.2.3` (banned) | pass | skip | **ban** | `crowdsec_ban` | | allow `10.0.0.0/8` + enforce | `10.2.3.4` (clean) | pass | skip | clean | `allow` | | allow `10.0.0.0/8` + enforce | `192.168.1.1` | **deny** | skip | skip | `ip_restricted` | | block `10.1.0.0/16` + enforce | `10.1.2.3` (banned) | **deny** | skip | skip | `ip_restricted` | | allow country US + enforce | `1.2.3.4` US (banned) | skip | pass | **ban** | `crowdsec_ban` | | allow country US + enforce | `5.6.7.8` CN | skip | **deny** | skip | `country_restricted` | | allow `10.0.0.0/8` + block country CN + enforce | `10.1.2.3` US (banned) | pass | pass | **ban** | `crowdsec_ban` | | allow `10.0.0.0/8` + observe | `10.1.2.3` (banned) | pass | skip | ban (logged) | `allow` (observe) | CrowdSec can never relax a CIDR or country denial. Observe mode returns the verdict for logging but does not block. ## Issue ticket number and link ## Stack <!-- branch-stack --> ### Checklist - [ ] Is it a bug fix - [ ] Is a typo/documentation fix - [x] Is a feature enhancement - [ ] It is a refactor - [x] Created tests that fail without the change (if possible) > By submitting this pull request, you confirm that you have read and agree to the terms of the [Contributor License Agreement](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). ## Documentation Select exactly one: - [ ] I added/updated documentation for this change - [x] Documentation is **not needed** for this change (explain why) ### Docs PR URL (required if "docs added" is checked) Paste the PR link from https://github.com/netbirdio/docs here: https://github.com/netbirdio/docs/pull/__ <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * CrowdSec integration: runtime bouncer + shared registry with enforce/observe modes (observe logs but doesn't block). * Server accepts CrowdSec API URL/key, advertises cluster CrowdSec capability, and exposes per-domain CrowdSec support. * Access restrictions gain crowdsec_mode with stricter validation; access logs and API now include optional per-request metadata. * **Chores** * Updated Go module dependency versions and added CrowdSec client libraries. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
saavagebueno added the pull-request label 2026-08-05 08:06:20 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#28421