Skip to content

feat(filters): add SCENARIOS_CONTAINING and SCENARIOS_NOT_CONTAINING options#143

Open
tommy-ng0 wants to merge 1 commit into
crowdsecurity:mainfrom
tommy-ng0:feat/scenario-filters
Open

feat(filters): add SCENARIOS_CONTAINING and SCENARIOS_NOT_CONTAINING options#143
tommy-ng0 wants to merge 1 commit into
crowdsecurity:mainfrom
tommy-ng0:feat/scenario-filters

Conversation

@tommy-ng0

Copy link
Copy Markdown

What

Adds two configuration options that flow through to the LAPI decision queries:

  • SCENARIOS_CONTAINING — only enforce decisions whose scenario contains one of the comma-separated substrings
  • SCENARIOS_NOT_CONTAINING — ignore decisions whose scenario contains one of the comma-separated substrings

These map directly to the scenarios_containing / scenarios_not_containing filters the LAPI already supports on both /v1/decisions/stream and /v1/decisions (matching is done server-side, case-insensitive substring per comma-separated value — see pkg/database/decisionfilter.go in crowdsecurity/crowdsec).

Why

The bouncer currently pulls every decision the LAPI streams. When running several remediation components against one LAPI, it's useful for a given nginx bouncer to only enforce a subset of scenarios (e.g. only http- scenarios at a web edge, or excluding ssh-bf bans that another component handles). Other remediation components (e.g. the blocklist mirror) already expose decision filtering; this brings the nginx/openresty bouncer in line.

How

  • config.lua: two new string options, both defaulting to "" (no behaviour change when unset)
  • utils.lua: M.scenario_filters() builds the query-string fragment, URL-encoding the values (ngx.escape_uri); returns "" when both options are empty
  • stream.lua / live.lua: the fragment is appended to the stream pull and live query URLs, in both the API-key and TLS-auth paths
  • config_example.conf: documented

Example: SCENARIOS_CONTAINING=crowdsecurity/http-,wordpress produces

/v1/decisions/stream?startup=true&scenarios_containing=crowdsecurity%2Fhttp-%2Cwordpress

Testing

  • All touched files compile (luajit -bl)
  • scenario_filters() verified for both-set / one-set / none-set inputs (empty string when unset, so existing URLs are byte-identical)
  • Verified the resulting query strings against a CrowdSec LAPI: filtered stream pulls return only matching decisions

…options

Expose the LAPI scenarios_containing / scenarios_not_containing decision
filters as bouncer configuration. The values are comma-separated substrings,
matched server-side by the LAPI, and are appended (URL-encoded) to both the
stream pull (/v1/decisions/stream) and live query (/v1/decisions) URLs, for
both API-key and TLS authentication paths.

Both options default to empty, leaving existing behavior unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant