bukaleyang / zhongkui-waf

WAF based on lua-nginx-module.
Apache License 2.0
164 stars 38 forks source link

mysql连接失败resty.rsa is not installed #51

Closed YEDEDD closed 3 months ago

YEDEDD commented 3 months ago

安装完钟馗页面开启mysql后日志报错:

2024/08/12 07:16:30 [error] 37#37: *1680 lua entry thread aborted: runtime error: /usr/local/openresty/lualib/resty/mysql.lua:929: auth plugin caching_sha2_password or sha256_password are not supported because resty.rsa is not installed
stack traceback:
coroutine 0:
    [C]: in function 'error'
    /usr/local/openresty/lualib/resty/mysql.lua:895: in function '_encrypt_password'
    /usr/local/openresty/lualib/resty/mysql.lua:929: in function '_write_encode_password'
    /usr/local/openresty/lualib/resty/mysql.lua:1072: in function '_handle_auth_result'
    /usr/local/openresty/lualib/resty/mysql.lua:1212: in function 'connect'
    /usr/local/openresty/zhongkui-waf/lib/mysqlCli.lua:33: in function 'getConnection'
    /usr/local/openresty/zhongkui-waf/lib/mysqlCli.lua:54: in function 'query'
    /usr/local/openresty/zhongkui-waf/lib/sql.lua:270: in function </usr/local/openresty/zhongkui-waf/lib/sql.lua:213>, context: ngx.timer
2024/08/12 07:16:30 [error] 37#37: *1678 lua entry thread aborted: runtime error: /usr/local/openresty/lualib/resty/mysql.lua:929: auth plugin caching_sha2_password or sha256_password are not supported because resty.rsa is not installed
stack traceback:
coroutine 0:
    [C]: in function 'error'
    /usr/local/openresty/lualib/resty/mysql.lua:895: in function '_encrypt_password'
    /usr/local/openresty/lualib/resty/mysql.lua:929: in function '_write_encode_password'
    /usr/local/openresty/lualib/resty/mysql.lua:1072: in function '_handle_auth_result'
    /usr/local/openresty/lualib/resty/mysql.lua:1212: in function 'connect'
    /usr/local/openresty/zhongkui-waf/lib/mysqlCli.lua:33: in function 'getConnection'
    /usr/local/openresty/zhongkui-waf/lib/mysqlCli.lua:54: in function 'query'
    /usr/local/openresty/zhongkui-waf/lib/sql.lua:297: in function </usr/local/openresty/zhongkui-waf/lib/sql.lua:276>, context: ngx.timer

根据这篇文档https://forum.openresty.us/d/6656-luamysql/3 https://github.com/spacewander/lua-resty-rsa 安装lua-resty-rsa到mysql.lua目录

root@6273954eddf6:/usr/local/openresty/lualib/resty# ls
aes.lua   limit     **lua-resty-rsa**  random.lua  sha224.lua  shell.lua   upstream
core      lock.lua  md5.lua        redis.lua   sha256.lua  signal.lua  websocket
core.lua  lrucache  memcached.lua  sha.lua     sha384.lua  string.lua
dns   lrucache.lua  mysql.lua      sha1.lua    sha512.lua  upload.lua
root@6273954eddf6:/usr/local/openresty/lualib/resty# pwd
/usr/local/openresty/lualib/resty

就是把下载下来的目录放在上边路径上。

然后还需要local resty_rsa = require "resty.rsa" 添加变量,但是不知道具体哪个文件中,尝试了几个如 /usr/local/openresty/lualib/resty/mysql.lua 都不行,还是会报错,正确的该如何处理

bukaleyang commented 3 months ago
  1. 确保你安装了openssl
  2. rsa.lua放到lualib/resty目录下面
  3. nginx -s reload

或者更换你mysql用户的验证插件 ALTER USER 'your_username'@'your_host' IDENTIFIED WITH mysql_native_password BY 'your_password';
FLUSH PRIVILEGES;

YEDEDD commented 3 months ago

问题已经解决了,需要在

root@10b760402550:/usr/local/openresty/zhongkui-waf/conf# vim waf.conf
lua_package_path "/usr/local/openresty/lualib/resty/lua-resty-rsa/lib/?.lua;/usr/local/openresty/zhongkui-waf/?.lua;/usr/local/openresty/zhongkui-waf/lib/?.lua;/usr/local/openresty/zhongkui-waf/admin/lua/?.lua;;";

添加 /usr/local/openresty/lualib/resty/lua-resty-rsa/lib/?.lua

下载的文件在

root@10b760402550:/usr/local/openresty/lualib/resty# ls lua-resty-rsa
LICENSE   README.md  lib                 lua-resty-rsa-1.1.0-1.rockspec  test_with_valgrind.sh
Makefile  dist.ini   lua-resty-rsa-1.0.2-1.rockspec  t                   valgrind.suppress

然后我在 mysql.lua中添加了local rsa = require "resty.rsa" #这个应该可以不用加

以上步骤就可以了