-
Notifications
You must be signed in to change notification settings - Fork 537
Open
Labels
Description
What happened?
Summary
When migrating or reinstalling CrowdSec, restoring a backed-up online_api_credentials.yaml
after a fresh install can leave the agent using a stale, cached JWT stored in the local database. On startup, CrowdSec does not verify that the JWT’s username matches the credentials in online_api_credentials.yaml
, so it reuses the cached token. This causes enrollment issues and mis-attributed alerts until the JWT expires.
Impact / Side effects
- Alerts are attributed to the wrong username (from the cached JWT) for the period between token creation and token expiry.
- Enrollment remains offline until the cached JWT expires or is cleared.
- Running console enrollment appears as a new machine, because the JWT corresponds to the old username.
Workarounds
- Clear the cached JWT from the local database, then restart CrowdSec so it re-authenticates.
- Wait a minute after installation since the cache JWT is compared agaisnt creation time of > 1 minute, if you wait at least a minute before restarting the CrowdSec service it will not reuse the cached JWT.
What did you expect to happen?
Expected Behavior
- On startup (or when credentials change), the agent should validate the cached JWT against the username in
online_api_credentials.yaml
. - If there’s a mismatch or the token cannot be validated, the agent should discard the cached JWT and re-authenticate using the credentials file so enrollment comes back under the correct account/machine.
Actual Behavior
- The agent reuses the cached JWT from the DB even when the credentials file has been replaced with different (restored) credentials.
- Enrollment stays broken and alerts—if any—are sent under the wrong username until the JWT expires.
How can we reproduce it (as minimally and precisely as possible)?
Follow the steps:
- Install CrowdSec and Enroll into the console.
- Move
mv /etc/crowdsec/online_api.credentials.yaml{,.bak}
cscli capi register
and wait at least a minute.- To simulate a "fresh install" just simply restart CrowdSec to ensure the JWT is populated in database
mv /etc/crowdsec/online_api.credentials.yaml{.bak,}
systemctl restart crowdsec
Now the JWT token in the database is reused even though the file on disk has changed, in half an hour the console will report the engine has not contacted and classified as offline.
Anything else we need to know?
No response
Crowdsec version
$ cscli version
# paste output here
OS version
# On Linux:
$ cat /etc/os-release
# paste output here
$ uname -a
# paste output here
# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here
Enabled collections and parsers
$ cscli hub list -o raw
# paste output here
Acquisition config
```console
# On Linux:
$ cat /etc/crowdsec/acquis.yaml /etc/crowdsec/acquis.d/*
# paste output here
On Windows:
C:> Get-Content C:\ProgramData\CrowdSec\config\acquis.yaml
paste output here
Config show
$ cscli config show
# paste output here
Prometheus metrics
$ cscli metrics
# paste output here