You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "Rouaaba (via GitHub)" <gi...@apache.org> on 2025/02/10 13:21:48 UTC
[I] help request: Integrating key-aith and casbin plugins [apisix]
Rouaaba opened a new issue, #11962:
URL: https://github.com/apache/apisix/issues/11962
### 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: <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: <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_ADMI
NISTRATOR_{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: <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`):
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org