You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I have a user backend route which integrates the key-auth plugin, that works fine so i have a consumer with his username and token.
But if I try to also use casbin, it always gives me access denied even though the user has the role and should have access, is apisix able to identify the username based on the token and then pass it to casbin?
**** consumer list ****
curl -X GET http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: "
{"total":2,"list":[{"value":{"create_time":1738917958,"update_time":1739180980,"plugins":{"key-auth":{"key":"24a5ff7f-d742-40f6-b13d-9b842b5ef463"}},"username":"root"},"modifiedIndex":416,"key":"/apisix/consumers/root","createdIndex":347},{"value":{"create_time":1739180966,"update_time":1739182611,"plugins":{"key-auth":{"key":"595d8167-8725-442d-95f2-b87433c03ca4"}},"username":"rouaa"},"modifiedIndex":421,"key":"/apisix/consumers/rouaa","createdIndex":414}]}
how to make it identify the username based on the token)
Environment
APISIX version (run apisix version):
Operating system (run uname -a):
OpenResty / Nginx version (run openresty -V or nginx -V):
etcd version, if relevant (run curl http://127.0.0.1:9090/v1/server_info):
APISIX Dashboard version, if relevant:
Plugin runner version, for issues related to plugin runners:
LuaRocks version, for installation issues (run luarocks --version):
The text was updated successfully, but these errors were encountered:
Description
Hello, I have a user backend route which integrates the key-auth plugin, that works fine so i have a consumer with his username and token.
But if I try to also use casbin, it always gives me access denied even though the user has the role and should have access, is apisix able to identify the username based on the token and then pass it to casbin?
***** with just key-auth plugin works fine: ******
curl -X GET "http://localhost:9080/user/project-users/Project1?userId=33"
-H "Content-Type: application/json"
-H "apikey: 595d8167-8725-442d-95f2-b87433c03ca4"
[{"id":33,"userName":"rouaa","email":"","rolesAndProjects":[{"roleName":"PROJECT_ADMINISTRATOR","projectName":"Project1"}],"globalRoles":[]}]
***** route config with casbin ****
curl -X PUT http://127.0.0.1:9180/apisix/admin/routes/UserBackend
-H "X-API-KEY: "
-d '
{
"uri": "/user/",
"priority": 0,
"methods": ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
"status": 1,
"upstream": {
"type": "roundrobin",
"nodes": {
"rbac-service:8082": 1
},
"scheme": "http",
"pass_host": "pass",
"hash_on": "vars"
},
"plugins": {
"cors": {
"allow_origins": "",
"allow_methods": "GET, POST, PUT, DELETE, OPTIONS",
"allow_headers": "",
"expose_headers": "",
"max_age": 3600,
"allow_credentials": true
},
"key-auth": {},
"authz-casbin": {
"username": "$consumer_name"
}
}
}'
***** casbin config (directly on the metadata so no config files) *****
curl -X GET http://127.0.0.1:9180/apisix/admin/plugin_metadata/authz-casbin -H "X-API-KEY: "
{"value":{"value":{"model":"[request_definition]\nr = sub, obj, act\n\n[policy_definition]\np = sub, obj, act\n\n[role_definition]\ng = , \n\n[policy_effect]\ne = some(where (p.eft == allow))\n\n[matchers]\nm = (g(r.sub, p.sub) || keyMatch(r.sub, p.sub)) && keyMatch(r.obj, p.obj) && keyMatch(r.act, p.act)","id":"authz-casbin","policy":"p, GLOBAL_ADMINISTRATOR, /admin/create-user, POST\np, GLOBAL_ADMINISTRATOR, /admin/createadmin, POST\np, GLOBAL_ADMINISTRATOR, /admin/list-users, GET\np, GLOBAL_ADMINISTRATOR, /admin/delete-user, POST\np, GLOBAL_ADMINISTRATOR, /admin/projectusers, GET\np, GLOBAL_ADMINISTRATOR, /admin/user-byrole, GET\np, GLOBAL_ADMINISTRATOR, /admin/role-byuser, GET\np, GLOBAL_ADMINISTRATOR, /admin/userprojects, GET\np, GLOBAL_ADMINISTRATOR, /admin/assign-role, POST\np, GLOBAL_ADMINISTRATOR, /admin/createproject, POST\np, GLOBAL_ADMINISTRATOR, /admin/list-projects, GET\np, PROJECT_ADMINISTRATOR{projectName}, /user/project-users/{projectName}, GET\np, PROJECT_ADMINISTRATOR{projectName}, /user/create-userrole, POST\np, PROJECT_MANAGER_{projectName}, /user/project-users/{projectName}, GET\np, PROJECT_USER_{projectName}, /user/project-users/{projectName}, GET\np, PROJECT_VIEWER_{projectName}, /user/project-users/{projectName}, GET\np, *, /user/changecredentials, POST\np, *, /user/login, POST\np, *, /user/updateprofile, PUT\np, *, /user/forgotpassword, POST\np, *, /user/resetpassword, POST\ng, root, GLOBAL_ADMINISTRATOR"},"id":"authz-casbin","createdIndex":305,"key":"/apisix/plugin_metadata/authz-casbin","modifiedIndex":440,"model":"[request_definition]\nr = sub, obj, act\n\n[policy_definition]\np = sub, obj, act\n\n[role_definition]\ng = _, _\n\n[policy_effect]\ne = some(where (p.eft == allow))\n\n[matchers]\nm = (g(r.sub, p.sub) || keyMatch(r.sub, p.sub)) && keyMatch(r.obj, p.obj) && keyMatch(r.act, p.act)","policy":"g, rouaa, PROJECT_ADMINISTRATOR_Project1"},"modifiedIndex":441,"key":"/apisix/plugin_metadata/authz-casbin","createdIndex":305}
**** consumer list ****
curl -X GET http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: "
{"total":2,"list":[{"value":{"create_time":1738917958,"update_time":1739180980,"plugins":{"key-auth":{"key":"24a5ff7f-d742-40f6-b13d-9b842b5ef463"}},"username":"root"},"modifiedIndex":416,"key":"/apisix/consumers/root","createdIndex":347},{"value":{"create_time":1739180966,"update_time":1739182611,"plugins":{"key-auth":{"key":"595d8167-8725-442d-95f2-b87433c03ca4"}},"username":"rouaa"},"modifiedIndex":421,"key":"/apisix/consumers/rouaa","createdIndex":414}]}
how to make it identify the username based on the token)
Environment
apisix version
):uname -a
):openresty -V
ornginx -V
):curl http://127.0.0.1:9090/v1/server_info
):luarocks --version
):The text was updated successfully, but these errors were encountered: