Skip to content
This repository has been archived by the owner on Jun 23, 2021. It is now read-only.

Error when no JWT token provided #8

Closed
jtbonhomme opened this issue Nov 18, 2020 · 2 comments
Closed

Error when no JWT token provided #8

jtbonhomme opened this issue Nov 18, 2020 · 2 comments

Comments

@jtbonhomme
Copy link

The following lines cause an error when executing request without any JWT token (access.lua):

    -- access allowed
    kong.log.debug(interp("Access allowed to ${method} ${path} for user ${subject}", {
        method = input.method,
        path = input.path,
        subject = token.payload.sub
    }))

The error is:

2020/11/18 16:23:19 [error] 25#0: *53180 lua coroutine: runtime error: /usr/local/share/lua/5.1/kong/plugins/opa/access.lua:78: attempt to index field 'payload' (a nil value)
stack traceback:
coroutine 0:
	/usr/local/share/lua/5.1/kong/plugins/opa/access.lua: in function 'execute'
	/usr/local/share/lua/5.1/kong/plugins/opa/handler.lua:13: in function </usr/local/share/lua/5.1/kong/plugins/opa/handler.lua:11>
coroutine 1:
	[C]: in function 'resume'
	coroutine.wrap:21: in function <coroutine.wrap:21>
	/usr/local/share/lua/5.1/kong/init.lua:756: in function 'access'

May you consider removing this log ?

@zahiyo
Copy link
Contributor

zahiyo commented Nov 18, 2020

This issue can be fixed with

    -- access allowed
    kong.log.debug(interp("Access allowed to ${method} ${path} for user ${subject}", {
        method = input.method,
        path = input.path,
        subject = (token.payload and token.payload.sub or 'anonymous')
    }))

but it needs to be done in the OPA contrib repo: https://github.com/open-policy-agent/contrib/tree/master/kong_api_authz

@zahiyo
Copy link
Contributor

zahiyo commented Jun 23, 2021

Closing this issue for open-policy-agent/contrib#146.

@zahiyo zahiyo closed this as completed Jun 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants