lua-resty-openidc: Entry thread aborted: runtime error: attempt to call field 'start' (a nil value)

1.5k Views Asked by At
Environment
  • lua-resty-openidc : v1.7.5
  • OpenID Connect provider: Keycloak
This is what I'm doing

For the info, I'm using it on our ingress-nginx-controller, with the entire content copied from /usr/local/openresty/lualib/resty to /etc/nginx/lua/. When the UI endpoint (i.e. https://ingress.myproject.local/myui) is called, it supposed to redirect the the connection to Keycloak. I have a client called myui under the master realm in Keycloak.

This my current code
location ~* "^/myui(/|$)(.*)" {
  .....
  .....
  access_by_lua_block {
      local opts = {
          redirect_uri = "/redirect_uri",
          accept_none_alg = true,
          discovery = "http://keycloak.myproject.local:8080/auth/realms/master/.well-known/openid-configuration",
          client_id = "myui",
          client_secret = "ABCDEFgHIJKLMnOPQRSTuVWXYZ",
          redirect_uri_scheme = "https",
          logout_path = "/logout",
          redirect_after_logout_uri = "http://keycloak.myproject.local:8080/auth/realms/master/protocol/openid-connect/logout?redirect_uri=https://ingress.myproject.local/myui/",
          redirect_after_logout_with_id_token_hint = false,
          session_contents = {id_token=true}
      }
      -- call introspect for OAuth 2.0 Bearer Access Token validation
      local res, err = require("resty.openidc").authenticate(opts)
           if err then
             ngx.status = 403
             ngx.say(err)
             ngx.exit(ngx.HTTP_FORBIDDEN)
           end
      }
     
      expires       0;
      add_header    Cache-Control private;
  }
}
This is what I get

Upon running, I get 500 Internal Server Error on the browser, with the error msg:

[error] 549#549: *123249 lua entry thread aborted:  run time error: /etc/nginx/lua/resty/openidc.lua:1459: attempt to call field 'start' (a nil value)
stack traceback:
coroutin 0:
     /etc/nginx/lua/resty/openidc.lua: in function 'authenticate' 
     access_by_lua(nginx.conf:1075): 16: in main chunk, client xx.xx.xx.xx , server:  ingress.myproject.local, request: "GET /myui HTTP/2.0", host: "ingress.myproject.local"

I don't see anything significant in the log related to that. Any idea why I'm getting this or what am I doing wrong?

-S

1

There are 1 best solutions below

6
On

The documentation for https://github.com/zmartzone/lua-resty-openidc says:

You will need to install two extra pure-Lua dependencies that implement session management and HTTP client functions:

It would appear that you didn't install lua-resty-session. The error you're getting is because r_session is nil, which was defined as local r_session = require("resty.session").