Docker based log parser not connecting to Opnsense running LAPI

I am working on setting up crowdsec on my second network and im running into issues getting another machine connected to the LAPI running on opnsense. My opnsense crowdsec config can be see in the attached picture as well as the firewall rule on the LAN interface that allows the docker machine (an unraidbox) to connect to port 8080 on the router. When running the sudo cscli lapi register -u http://192.168.20.1:8080 command on my crowdsec docker it says its successful and saves the creds into local_api_credentials.yaml. I then stopped the docker and edit config.yaml in the docker server and disable the server api. On the Opnsense lapi i validate the machine. now whenever trying to start the crowdsec docker it will not start successfully. It gets stuck in a loop of crashing over and over. This can be found in the logs:
Error: no matches found
level=warning msg="crowdsec local API is disabled because 'enable' is set to false"
Error: local API is disabled -- this command must be run on the local API machine
Generate local agent credentials
Error: no matches found
level=warning msg="crowdsec local API is disabled because 'enable' is set to false"
Error: local API is disabled -- this command must be run on the local API machine
Generate local agent credentials
It is repeated over and over. I have verified using curl that the docker server is able to connect to the opnsense box over 8080. There is also nothing being blocked in the opnsense firewall logs from either machine. Running cscli machines list shows that the creds generated havent been used even once. I have also attached a censored screenshot of the local creds file on the docker server and you can see the machine ids match lapi. I have also verified the client creds path matches the file with the info on the docker server. I played with this for a couple hours yesterday and Im at a loss of what to try next
No description
No description
No description
No description
7 Replies
Willpower
WillpowerOP3w ago
I've tried to increase the verbosity of the logging but it doesnt seem to make a difference in what is outputted in the container logs. (when the lapi is enabled it does have debug output but then it starts up correctly) Its also worth adding when the crowdsec container is in this state it doesnt even try to send any packets to the lapi on opnsense. (according to firewall logs anyway) My current theory is that something is broken in the docker image for crowdsec as turning off the lapi without any additional configuration yields basically the same results. (crowdsecurity/crowdsec:latest) Please let me know if any additional info would be helpful or if anything isn't clear @iiamloz Do you have any incite on this?
iiamloz
iiamloz3w ago
So connecting a external docker to a LAPI currently sucks, you have to define everything as environment variables you need
LOCAL_API_URL: "http://your.lapi:8080"
DISABLE_LOCAL_API: true
AGENT_USERNAME: ${USERNAME}
AGENT_PASSWORD: ${PASSWORD}
LOCAL_API_URL: "http://your.lapi:8080"
DISABLE_LOCAL_API: true
AGENT_USERNAME: ${USERNAME}
AGENT_PASSWORD: ${PASSWORD}
to get username and password either run cscli lapi register then grab it from the local_api_credentials.yaml before a restart or on the lapi run cscli machines add -f- --auto then copy the output.
Willpower
WillpowerOP3w ago
Thanks for the help! I noticed it wiped out local_api_credentials.yaml on a restart so i had been saving it locally and turning off lapi before restarting it. I will try this out sometime this weekend
Willpower
WillpowerOP3w ago
It worked!
No description
Willpower
WillpowerOP3w ago
Was that something I missed in the documentation? I'd assume theres not many people trying to do this?
iiamloz
iiamloz3w ago
Its kind off is, but I need to find time to have a "how to connect to external LAPI" section cause it relies on you reading the env section and understand that you need to do it https://docs.crowdsec.net/u/getting_started/installation/docker#environment-variables
Docker | CrowdSec
Prerequisites are written for bare metal installations. Please keep in mind the containerization layer may make some of these items unnecessary.
Willpower
WillpowerOP3w ago
Gotcha. That explains it, I didn’t realize it was required for agent only mode when running in docker. Thanks for the support as always

Did you find this page helpful?