bug: use dashboard2.0 set jwt-auth, it will return 404 when generate JWT credential
Please answer these questions before submitting your issue.
- Why do you submit this issue?
- [ ] Question or discussion
- [x] Bug
- [ ] Requirements
- [ ] Feature or performance improvement
- [ ] Other
Bug
- Which version of Apache APISIX Dashboard, OS, and Browser? dashboard 2.0 + APISIX 2.0
- What happened?
step 1: use dashboard2.0 set a consumer and config the value of the jwt-auth option
step2: use dashboard2.0 add a Route, and enable the jwt-auth plugin
setp3: generate JWT credential
curl http://127.0.0.1:9080/apisix/plugin/jwt/sign?key=your-key-seting-in-step1
it will return 404.
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>openresty</center>
</body>
</html>
BUT, it will not 404 when I use admin API do the same thing!
the etcd data after use dashboard2.0 set jwt-auth:
/apisix/consumers/test_hj
{"id":"test_hj","create_time":1604724760,"update_time":1604724760,"username":"test_hj",
"plugins":{"jwt-auth":{"algorithm":"HS256","base64_secret":false,"key":"dd","secret":"my-secret-key"}}}
/apisix/routes/327483191025729827
{"id":"327483191025729827","create_time":1604724792,"update_time":1604724792,"uris":["/"],
"name":"test_hj","methods":["GET","HEAD","POST","PUT","DELETE","OPTIONS","PATCH"],"vars":[],
"plugins":{"jwt-auth":{}},"upstream":{"nodes":[{"host":"139.217.190.60","port":80,"weight":1}],"timeout":{"connect":6000,"read":6000,"send":6000},"type":"roundrobin"}}
the etcd data after use admin API set jwt-auth:
/apisix/consumers/user123
{"username":"user123","plugins":{"jwt-auth":{"exp":86400,"algorithm":"HS256","secret":"my-secret-key","key":"dd"}}}
/apisix/routes/1
{"priority":0,"plugins":{"jwt-auth":{"algorithm":"HS256","secret":"e10d5rmIfZFBF6W0JqOv60v1UcVF0uMiBwAIzf2pXQY=","exp":86400}},
"upstream":{"hash_on":"vars","pass_host":"pass","nodes":{"139.217.190.60:80":1},
"type":"roundrobin"},"id":"1","uri":"\/"}
@idbeta It works fine at my side when I try to use the dashboard data.
# create by dashboard data:
$ etcdctl put /apisix/consumers/test_hj '
{
"username": "test_hj",
"id": "test_hj",
"plugins": {
"jwt-auth": {
"base64_secret": false,
"secret": "my-secret-key",
"exp": 86400,
"key": "ee",
"algorithm": "HS256"
}
},
"update_time": 1604724760,
"create_time": 1604724760
}'
OK
# setp3: generate JWT credential
$ curl http://127.0.0.1:9080/apisix/plugin/jwt/sign\?key\=ee -i
HTTP/1.1 200 OK
Date: Sat, 07 Nov 2020 08:28:24 GMT
Content-Type: text/plain; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Server: APISIX/2.0
... ...
@juzhiyuan Only after it is determined that this is a problem can the milestone be scheduled.
@membphis I create a consumer again, and it returns 500 when I generate JWT credential, what I do was exactly the same as before. etcd data
/apisix/consumers/test_hj
{"id":"test_hj","create_time":1604737871,"update_time":1604737871,"username":"test_hj","plugins":{"jwt-auth":{"algorithm":"HS256","base64_secret":false,"key":"dd","secret":"my-secret-key"}}}
error.log
2020/11/07 16:41:07 [error] 84990#1547973: *120907 lua entry thread aborted: runtime error: /Users/idbeta/1106/apisix-2.0/apisix/plugins/jwt-auth.lua:218: attempt to perform arithmetic on field 'exp' (a nil value)
stack traceback:
coroutine 0:
/Users/idbeta/1106/apisix-2.0/apisix/plugins/jwt-auth.lua: in function 'handler'
/Users/idbeta/1106/apisix-2.0/apisix/api_router.lua:107: in function 'handler'
.../1106/apisix-2.0//deps/share/lua/5.1/resty/radixtree.lua:730: in function 'dispatch'
/Users/idbeta/1106/apisix-2.0/apisix/api_router.lua:133: in function 'match'
/Users/idbeta/1106/apisix-2.0/apisix/init.lua:373: in function 'http_access_phase'
access_by_lua(nginx.conf:173):2: in main chunk, client: 127.0.0.1, server: , request: "GET /apisix/plugin/jwt/sign?key=dd HTTP/1.1", host: "127.0.0.1:9080"
@idbeta one issue for one thing. if you have a different issue, please create a different issue for discussing.
2020/11/07 16:41:07 [error] 84990#1547973: *120907 lua entry thread aborted: runtime error: /Users/idbeta/1106/apisix-2.0/apisix/plugins/jwt-auth.lua:218: attempt to perform arithmetic on field 'exp' (a nil value) stack traceback: coroutine 0: /Users/idbeta/1106/apisix-2.0/apisix/plugins/jwt-auth.lua: in function 'handler' /Users/idbeta/1106/apisix-2.0/apisix/api_router.lua:107: in function 'handler'
I think that is a new bug: https://github.com/apache/apisix/issues/2649
@idbeta please confirm them, if that is not a bug, we can close this issue.
https://github.com/apache/apisix-dashboard/issues/716#issuecomment-723417617
@idbeta please confirm them, if that is not a bug, we can close this issue.
I can't reproduce 404 now. So you can close it.