crowdsecurity / cs-nginx-bouncer

CrowdSec bouncer for Nginx
MIT License
48 stars 8 forks source link

Bug/ crowdsec-nginx-bouncer: is looking for lua 5.1 files instead 5.3 #33

Closed franciscopaniskaseker closed 2 years ago

franciscopaniskaseker commented 2 years ago

Describe the bug crowdsec.lua is looking for 5.1 files instead of 5.3

To Reproduce

  1. install fresh updated ubuntu
  2. setup crowdsec repository
  3. install crowdsec and its dependencies according official doc https://doc.crowdsec.net/docs/bouncers/nginx/
  4. remove crowdsed (it will note automatically remove /etc/nginx/conf.d/crowdsec_nginx.conf as is expected)
  5. do the same procedure to setup (/etc/nginx/conf.d/crowdsec_nginx.conf will not be installed) and nginx -t will start to show errors because crowdsec.lua can not find some lua files

Expected behavior install and reinstall without problem.

Technical Information (please complete the following information):

Additional context Add any other context about the problem here, for example /var/log/crowdsec.log or error messages.

root@panel:/usr/local/share/lua# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: [error] init_by_lua error: /usr/local/lua/crowdsec/crowdsec.lua:5: module 'resty.http' not found:
    no field package.preload['resty.http']
    no file '/usr/local/lua/crowdsec/resty/http.lua'
    no file './resty/http.lua'
    no file '/usr/share/luajit-2.1.0-beta3/resty/http.lua'
    no file '/usr/local/share/lua/5.1/resty/http.lua'
    no file '/usr/local/share/lua/5.1/resty/http/init.lua'
    no file '/usr/share/lua/5.1/resty/http.lua'
    no file '/usr/share/lua/5.1/resty/http/init.lua'
    no file './resty/http.lua'
    no file './resty/http.so'
    no file '/usr/local/lib/lua/5.1/resty/http.so'
    no file '/usr/lib/x86_64-linux-gnu/lua/5.1/resty/http.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
    no file './resty.so'
    no file '/usr/local/lib/lua/5.1/resty.so'
    no file '/usr/lib/x86_64-linux-gnu/lua/5.1/resty.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
    [C]: in function 'require'
    /usr/local/lua/crowdsec/crowdsec.lua:5: in main chunk
    [C]: in function 'require'
    init_by_lua:2: in main chunk
nginx: configuration file /etc/nginx/nginx.conf test failed
root@panel:/usr/local/share/lua# ls /usr/local/share/lua/
5.3

root@panel:/usr/local/share/lua# ls -l /usr/local/lib/luarocks/rocks/
total 24
-rw-r--r-- 1 root root 1304 Mar  9 18:51 index.html
drwxr-xr-x 3 root root 4096 Mar  9 18:56 lua-resty-http
-rw-r--r-- 1 root root  994 Mar  9 18:57 manifest
-rw-r--r-- 1 root root   43 Mar  9 18:51 manifest-5.1
-rw-r--r-- 1 root root   43 Mar  9 18:51 manifest-5.2
-rw-r--r-- 1 root root   43 Mar  9 18:51 manifest-5.3
root@panel:/usr/local/share/lua# ls -l /usr/local/lib/luarocks/rocks/lua-resty-http/
total 4
drwxr-xr-x 3 root root 4096 Mar  9 18:57 0.17.0.beta.1-0
root@panel:/usr/local/share/lua# ls -l /usr/local/lib/luarocks/rocks/lua-resty-http/0.17.0.beta.1-0/
total 12
drwxr-xr-x 2 root root 4096 Mar  9 18:57 doc
-rw-r--r-- 1 root root  653 Mar  9 18:57 lua-resty-http-0.17.0.beta.1-0.rockspec
-rw-r--r-- 1 root root  466 Mar  9 18:57 rock_manifest
root@panel:/usr/local/share/lua#

root@panel:/usr/local/share/lua# ls -l /usr/local/lua/crowdsec/
total 24
-rw-r--r-- 1 root root 17826 Mar  9 18:55 crowdsec.lua
drwxr-xr-x 3 root root  4096 Mar  9 18:51 plugins
root@panel:/usr/local/share/lua# ls -l /usr/local/lua/crowdsec/plugins/
total 4
drwxr-xr-x 2 root root 4096 Mar  9 18:55 crowdsec
root@panel:/usr/local/share/lua# ls -l /usr/local/lua/crowdsec/plugins/crowdsec/
total 44
-rw-r--r-- 1 root root 1306 Mar  9 18:55 ban.lua
-rw-r--r-- 1 root root 6869 Mar  9 18:55 bitop.lua
-rw-r--r-- 1 root root 4694 Mar  9 18:55 config.lua
-rw-r--r-- 1 root root 9233 Mar  9 18:55 iputils.lua
-rw-r--r-- 1 root root 2768 Mar  9 18:55 recaptcha.lua
-rw-r--r-- 1 root root  239 Mar  9 18:55 template.lua
-rw-r--r-- 1 root root 1257 Mar  9 18:55 utils.lua
root@panel:/usr/local/share/lua#
AlteredCoder commented 2 years ago

Hello @franciscopaniskaseker ,

The package that you deployed is not from crowdsec stable repository (it is actually in testing). How did you install the bouncer please ?

franciscopaniskaseker commented 2 years ago

I followed these instructions: https://docs.crowdsec.net/docs/bouncers/nginx/

with official repositories: https://docs.crowdsec.net/docs/getting_started/install_crowdsec#install-our-repositories

it was working normally and was communicating with https://app.crowdsec.net/overview . After I removed the nginx bouncer (i needed to disable it a little from nginx and I did not find an official way to do that), i tried to install using same procedures.

AlteredCoder commented 2 years ago

Hello @franciscopaniskaseker ,

I don't know how did you get those files since they were only in the testing repository. Can you please try to apt update and upgrade the bouncer from the stable repository please? We have released the v1.0.0 of the nginx bouncer this morning.

franciscopaniskaseker commented 2 years ago

@AlteredCoder thank you. worked. i did

apt clean
apt update
# and the official procedure to setup nginx bouncer.
AlteredCoder commented 2 years ago

Cool :)