Skip to content

Conversation

@julienloizelet
Copy link
Collaborator

@julienloizelet julienloizelet commented Oct 27, 2025

Description

  • Add a new js worker decisions-sync-worker that synchronizes decisions using a scheduled task and updates KV accordingly
  • Add a new -S option to configure the Cloudflare infrastructure and deploy this new worker. This is what we call "autonomous mode": the background go process is not needed anymore, and the deployed bouncers are sufficient to perform the bouncer role: one worker to synchronize decisions (decisions-sync-worker) and one worker to apply decisions (crowdsec-cloudflare-worker-bouncer)

How to test

  • To test the autonomous mode, run the process with -S option

./crowdsec-cloudflare-worker-bouncer -S -c <PATH_TO_CONFIG.yaml>

  • Backward compatibility: the "non automous mode" should work as before (go process run in daemon and the decisions-sync-worker worker is not deployed):

./crowdsec-cloudflare-worker-bouncer -c <PATH_TO_CONFIG.yaml>

Others

For the related documentation, please refer to the related PR

@julienloizelet julienloizelet marked this pull request as ready for review October 27, 2025 05:12
@julienloizelet julienloizelet changed the title feat(*): Automous mode feat(*): Autonomous mode Oct 27, 2025
@julienloizelet julienloizelet requested a review from blotus October 27, 2025 05:16
@julienloizelet julienloizelet marked this pull request as draft November 5, 2025 04:14
@julienloizelet julienloizelet marked this pull request as ready for review November 7, 2025 05:45
@rr404
Copy link
Contributor

rr404 commented Nov 7, 2025

Tests from 2025-11-07 were conclusive for the fix on pulling large number of IPs with batch technique.
will still need to mention limitations of BLaaS updates in readme and/or doc @rr404 if they are still present by time of release.

Copy link
Contributor

@rr404 rr404 left a comment

Choose a reason for hiding this comment

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

sorry forgot to push review

* @param {KVNamespace} kvNamespace - Cloudflare KV namespace
*/
export async function markAsWarmed(kvNamespace) {
await kvNamespace.put(WARMUP_KEY, 'true');
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe renamed it WARMED_UP. When i first read it I thought it meant the opposite

Copy link
Contributor

Choose a reason for hiding this comment

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

That would be more correct written : WARMED_UP

const origins = env.ONLY_INCLUDE_ORIGINS ? env.ONLY_INCLUDE_ORIGINS.split(',').map((s) => s.trim()) : [];

// Fetch decisions from LAPI
const decisions = await fetchDecisionsStream(lapiUrl, env.LAPI_KEY, {
Copy link
Contributor

Choose a reason for hiding this comment

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

pourrait t'on faire un test de charge, voir s'il timeout pas si on lui balance 100k+ ips
Meme s'il les met pas toutes en KV dû aux limitations FREE, juste voir s'il timeout pas au startup sur de GROSSES subscriptions

// Step 1: Get existing IP_RANGES from KV
const existingRanges = await getIpRanges(env.CROWDSECCFBOUNCERNS);
// Step 2: Get all string-based keys (IP, AS, Country) that we need to check
const allStringKeys = [
Copy link
Contributor

Choose a reason for hiding this comment

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

pareil ça à timer, voir si ce filter est pas un peu heavy et qu'il faille trouver une alternative.
On peut tester ça en local d'ailleurs pour le timer.

Copy link
Contributor

Choose a reason for hiding this comment

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

je me dis que les workers Cloudflare un peu comme des lambda AWS ça aura pas un temps d'execution illimité autorisé ils veulent surmeent que ça soit plutot light weight comme scripts


import logger from '../utils/logger.js';

const BATCH_SIZE = 10000; // Cloudflare KV limit for batch operations
Copy link
Contributor

Choose a reason for hiding this comment

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

Ca pose peut etre problème si ta limite est de 1000 en free, peut etre pour du free passer le batch size à 100 ? pouvoir le changer ?

});

// Write each entry in the batch
const promises = batch.map((entry) => kvNamespace.put(entry.key, entry.value));
Copy link
Contributor

Choose a reason for hiding this comment

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

tu fais des put individuels, du coup je comprend plus la notion de batch et batch size

Copy link
Contributor

Choose a reason for hiding this comment

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

c'est par rapport aux promises ?

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.

3 participants