Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for centralized allowlists #3355

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open

Conversation

blotus
Copy link
Member

@blotus blotus commented Dec 8, 2024

This PR adds a new type of allowlist that is managed by LAPI and applies to alerts, blocklists content and appsec (but not to manual decisions with cscli):

  • alerts are dropped (with a log message)
  • blocklist content matching an allowlist is ignored
  • appsec requests matching an allowlist are not processed

Compared to existing types of allowlists in crowdsec (in parsers, postoverflows, custom profiles or appsec hooks), they only support IPs and ranges (ie, no arbitrary expression), but they can have an optional expiration.

An alert is considered allowlisted in the following situations:

  • The source of the alert is an exact match with a non-expired allowlist item
  • The source of the alert belongs to a non-expired (range) allowlist item
  • The source of the alert contains a non-expired allowlisted item (eg, 1.2.3.4 is allowlisted, and an alert on 1.2.3.0/24 is generated): while this seems counter-intuitive, range alerts are rare and it would be add a lot of complexity to carve out the specific IPs that are allowlisted from the alert source (and generate multiple sub-alerts).

They can be managed with:

  • cscli
  • The console (allowlists created from the console are not editable with cscli to avoid conflict), in which case they are pulled from CAPI or PAPI.

If a local allowlist is created, and another one with the same name is created in the console, the one from the console will replace the local one.

Copy link

github-actions bot commented Dec 8, 2024

@blotus: There are no 'kind' label on this PR. You need a 'kind' label to generate the release automatically.

  • /kind feature
  • /kind enhancement
  • /kind refactoring
  • /kind fix
  • /kind chore
  • /kind dependencies
Details

I am a bot created to help the crowdsecurity developers manage community feedback and contributions. You can check out my manifest file to understand my behavior and what I can do. If you want to use this for your project, you can check out the BirthdayResearch/oss-governance-bot repository.

Copy link

github-actions bot commented Dec 8, 2024

@blotus: There are no area labels on this PR. You can add as many areas as you see fit.

  • /area agent
  • /area local-api
  • /area cscli
  • /area appsec
  • /area security
  • /area configuration
Details

I am a bot created to help the crowdsecurity developers manage community feedback and contributions. You can check out my manifest file to understand my behavior and what I can do. If you want to use this for your project, you can check out the BirthdayResearch/oss-governance-bot repository.

@blotus
Copy link
Member Author

blotus commented Dec 8, 2024

/kind feature
/area local-api

Copy link

codecov bot commented Dec 9, 2024

Codecov Report

Attention: Patch coverage is 22.72408% with 3302 lines in your changes missing coverage. Please review.

Project coverage is 55.24%. Comparing base (bfed861) to head (9f8d286).
Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
cmd/crowdsec-cli/cliallowlists/allowlists.go 17.52% 394 Missing and 6 partials ⚠️
pkg/database/ent/allowlistitem_query.go 12.82% 355 Missing and 12 partials ⚠️
pkg/database/ent/allowlist_query.go 23.27% 305 Missing and 18 partials ⚠️
pkg/database/ent/allowlistitem_update.go 0.00% 311 Missing ⚠️
pkg/database/ent/allowlist_update.go 18.18% 219 Missing and 6 partials ⚠️
pkg/database/ent/allowlistitem/where.go 17.60% 220 Missing ⚠️
pkg/database/ent/allowlist/where.go 2.31% 169 Missing ⚠️
pkg/database/ent/allowlistitem_create.go 35.40% 160 Missing and 6 partials ⚠️
pkg/database/ent/allowlist_create.go 27.05% 143 Missing and 8 partials ⚠️
pkg/database/allowlists.go 56.52% 92 Missing and 8 partials ⚠️
... and 23 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3355      +/-   ##
==========================================
- Coverage   59.35%   55.24%   -4.12%     
==========================================
  Files         362      387      +25     
  Lines       38979    43196    +4217     
==========================================
+ Hits        23137    23863     +726     
- Misses      13916    17305    +3389     
- Partials     1926     2028     +102     
Flag Coverage Δ
bats 38.36% <10.46%> (-3.22%) ⬇️
unit-linux 33.15% <14.40%> (-0.50%) ⬇️
unit-windows 25.00% <16.54%> (-3.41%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@blotus blotus force-pushed the centralized-allowlists branch from 3a34d3a to 8385b05 Compare December 9, 2024 00:19
@blotus blotus force-pushed the centralized-allowlists branch from 8385b05 to dbb9adc Compare December 9, 2024 00:21
@LaurenceJJones LaurenceJJones added this to the 1.6.6 milestone Jan 21, 2025
@@ -166,6 +168,8 @@ func (cli *cliRoot) initialize() error {
}
}

csConfig.DbConfig.LogLevel = ptr.Of(cli.wantedLogLevel())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated change ?

pkg/apiserver/papi_cmd.go Outdated Show resolved Hide resolved
@@ -31,6 +32,8 @@ const (
)

var DefaultAuthCacheDuration = (1 * time.Minute)
var negativeAllowlistCacheDuration = (5 * time.Minute)
var positiveAllowlistCacheDuration = (5 * time.Minute)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like a lot to me, but it depends if SE gets a force_pull via PAPI when the allowlist is updated ?

pkg/apiclient/auth_jwt.go Outdated Show resolved Hide resolved
@@ -186,10 +186,6 @@ func (t *JWTTransport) RoundTrip(req *http.Request) (*http.Response, error) {
}

resp, err = t.transport().RoundTrip(clonedReq)
if log.GetLevel() >= log.TraceLevel {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated change ?

@@ -205,6 +205,7 @@ func (lc *LokiClient) getURLFor(endpoint string, params map[string]string) strin
func (lc *LokiClient) Ready(ctx context.Context) error {
tick := time.NewTicker(500 * time.Millisecond)
url := lc.getURLFor("ready", nil)
lc.Logger.Debugf("Using url: %s for ready check", url)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated change?

@@ -154,6 +175,11 @@ func (c *Controller) CreateAlert(gctx *gin.Context) {
}
}

if allowlisted, reason := c.isAllowListed(ctx, alert); allowlisted {
log.Infof("alert source %s is allowlisted by %s, skipping", *alert.Source.Value, reason)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add scenario, and if we can the allowlist name

@buixor
Copy link
Contributor

buixor commented Feb 10, 2025

Todo:

  • Add bats tests on the cscli + crowdsec part (w/ the help of @mmetc )
  • Add proper in-memory cache at the appsec level

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants