Skip to content

Require json #17

Open
Open

Description

@rocklee44

Hi all,
My environment : Centos 8 + haproxy-2.2.10 + lua-5.3.5 install from source following instruction : https://kifarunix.com/install-haproxy-on-rocky-linux-8/
I followed instruction at : https://www.authelia.com/docs/deployment/supported-proxies/haproxy.html

global
# Path to haproxy-lua-http, below example assumes /usr/local/etc/haproxy/haproxy-lua-http/http.lua
lua-prepend-path /usr/local/etc/haproxy/http.lua
# Path to haproxy-auth-request
lua-load /usr/local/etc/haproxy/auth-request.lua
log stdout format raw local0 debug

When I check haproxy cfg I get errors:

haproxy -c -f haproxy.cfg
[NOTICE] (26946) : haproxy version is 2.4.2-553dee3
[NOTICE] (26946) : path to executable is /usr/local/sbin/haproxy
[ALERT] (26946) : parsing [haproxy.cfg:5] : Lua runtime error: error loading module 'json' from file '/usr/local/etc/haproxy/http.lua':
/usr/local/etc/haproxy/http.lua:673: too many C levels (limit is 200) in function at line 619 near 'v'

[ALERT] (26946) : parsing [haproxy.cfg:51]: 'http-request' expects 'wait-for-handshake', 'use-service', 'send-spoe-group', 'sc-inc-gpc0()', 'sc-inc-gpc1()', 'sc-set-gpt0()', 'do-resolve()', 'cache-use', 'add-acl()', 'add-header', 'allow', 'auth', 'capture', 'del-acl()', 'del-header', 'del-map()', 'deny', 'disable-l7-retry', 'early-hint', 'normalize-uri', 'redirect', 'reject', 'replace-header', 'replace-path', 'replace-pathq', 'replace-uri', 'replace-value', 'return', 'set-header', 'set-log-level', 'set-map()', 'set-method', 'set-mark', 'set-nice', 'set-path', 'set-pathq', 'set-query', 'set-tos', 'set-uri', 'strict-mode', 'tarpit', 'track-sc()', 'set-timeout', 'wait-for-body', 'set-var()', 'unset-var(*)', 'set-priority-class', 'set-priority-offset', 'silent-drop', 'set-src', 'set-src-port', 'set-dst', 'set-dst-port', but got 'lua.auth-request'.
[ALERT] (26946) : Error(s) found in configuration file : haproxy.cfg

How can I fix it ? Please give me some advice , thank you very much.

Activity

  1. rocklee44 commented on May 25, 2022

    @rocklee44
    Author

    My server Centos 8(minimal) has already lua-5.3.4 installed , and I also installed lua-json

    rpm -qa | grep lua
    lua-json-1.3.2-9.el8.noarch
    lua-libs-5.3.4-12.el8.x86_64
    lua-lpeg-1.0.1-6.el8.x86_64
    lua-5.3.4-12.el8.x86_64
    

    I fixed it by editing /usr/local/etc/haproxy/http.lua

    --local json = require "json"
    local json = { _version = "1.3.2" }
    

    It works fine now.

  2. schklom commented on Apr 23, 2023

    @schklom

    I don't remember where I read this, but I loaded https://github.com/rxi/json.lua with

    	lua-load		/var/etc/haproxy/luascript_json.lua
    	lua-load		/var/etc/haproxy/luascript_auth-request.lua
    	lua-prepend-path /usr/local/share/lua/5.3/haproxy-lua-http.lua
    

    to work for Authelia, and it works.

  3. james-d-elliott commented on Apr 12, 2024

    @james-d-elliott

    Pretty sure this is a dist issue with the various operating systems. Here's my test script I used to help diagnose it:

    local json = require "json"
    
    print("hello world")

    Running that reveals the if the issue is exists because of the install or if it's something else (if it prints an error it's due to the versions installed of lua and lua-json which are conflicting, if it runs it's something else, if it runs after suggested fixes it shows it should now work), also reveals the search path lua is using (snippet 2). If you then use a tool like mlocate to find the locations json.lua exists you'll note that it may not exist for the version of lua you have installed. In which case you have to install a compatible lua version or use the workaround by @schklom.

    Some example outputs for Ubuntu 22.04:

    # lua -v
    Lua 5.4.4  Copyright (C) 1994-2022 Lua.org, PUC-Rio
    # lua example.lua
    lua: example.lua:1: module 'json' not found:
    	no field package.preload['json']
    	no file '/usr/local/share/lua/5.4/json.lua'
    	no file '/usr/local/share/lua/5.4/json/init.lua'
    	no file '/usr/local/lib/lua/5.4/json.lua'
    	no file '/usr/local/lib/lua/5.4/json/init.lua'
    	no file '/usr/share/lua/5.4/json.lua'
    	no file '/usr/share/lua/5.4/json/init.lua'
    	no file './json.lua'
    	no file './json/init.lua'
    	no file '/usr/local/lib/lua/5.4/json.so'
    	no file '/usr/lib/x86_64-linux-gnu/lua/5.4/json.so'
    	no file '/usr/lib/lua/5.4/json.so'
    	no file '/usr/local/lib/lua/5.4/loadall.so'
    	no file './json.so'
    stack traceback:
    	[C]: in function 'require'
    	example.lua:1: in main chunk
    	[C]: in ?
    # locate json.lua
    /usr/share/lua/5.1/json.lua
    /usr/share/lua/5.2/json.lua
    /usr/share/lua/5.3/json.lua

    Fix for Ubuntu 22.04:

    apt remove lua5.4 && apt install lua5.3

    Seems in this specific fix it doesn't fix it for haproxy, it still has issues loading the module which is very odd.

  4. piengeng commented on Dec 26, 2024

    @piengeng

    was on ubuntu 24.04 with lua-json package, have to workaround with below, since 5.2/5.3 all point back to 5.1

    sudo cp -R /usr/share/lua/5.3/json /usr/share/lua/5.4
    sudo cp -P /usr/share/lua/5.3/json.lua /usr/share/lua/5.4/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions