-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: authz-keycloak plugin should not be marked as auth-type and should run in access phase, basic-auth plugin should run in rewrite phase. #2859
Conversation
Authentication type plug-ins should run in the rewrite phase |
How do you suggest this get's fixed then when The plugin development guidelines are currently not in line with the actual code base. Also, what's the rationale for running authentication/authorization in the rewrite phase when the access phase is the one that specifically caters for that purpose? It's not obvious why you would run in a different phase. |
reply you later need more time to read your issue and pr first |
@membphis @jenskeiner |
doc/plugin-develop.md
Outdated
@@ -168,8 +168,8 @@ local _M = { | |||
Determine which phase to run, generally access or rewrite. If you don't know the [Openresty life cycle](https://openresty-reference.readthedocs.io/en/latest/Directives/), it's | |||
recommended to know it in advance. For example key-auth is an authentication plugin, thus the authentication should be completed | |||
before forwarding the request to any upstream service. Therefore, the plugin can be executed in the rewrite and access phases. | |||
In APISIX, the authentication logic is implemented in the rewrite phase. Generally, IP access and interface | |||
permission are completed in the access phase. | |||
In APISIX, the authentication logic is implemented in the access phase. Generally, IP access and interface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to change it as authz-keycloak is for authorization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I can revert this one. However, note that some authentication plugins currently run in the access phase, not the rewrite one. So the document doesn’t reflect the current state correctly, I believe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jenskeiner
We can fix it later, but in those plugins, not the documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jenskeiner
Thank you for the problem you point out. I just search for all plugins which has type = 'auth'
(excluding the authz-keycloak) and find out basic-auth
doesn't run the phase correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason why we need to run authentication plugins in the rewrite phases:
Lines 508 to 520 in f4161d3
run_plugin("rewrite", plugins, api_ctx) | |
if api_ctx.consumer then | |
local changed | |
route, changed = plugin.merge_consumer_route( | |
route, | |
api_ctx.consumer, | |
api_ctx | |
) | |
if changed then | |
core.table.clear(api_ctx.plugins) | |
api_ctx.plugins = plugin.filter(route, api_ctx.plugins) | |
end | |
end |
And:
apisix/apisix/admin/consumers.lua
Line 50 in f4161d3
if plugin_obj.type == 'auth' then |
Plugins has type = 'auth'
should run in rewrite phase and set up the consumer for current api_ctx.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, understood why you need to run in the rewrite phase. Then I would propose to change the phase for all authentication-type plugins to rewrite, instead of adjusting the phase for authz-keycloak
from rewrite to access. Also, I think it would make the plugin development guidelines clearer if the reason they need to run in the rewrite phase was pointed out more clearly.
If you're fine with this, I can update this PR accordingly. Just let me know what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to change it as authz-keycloak is for authorization.
Reverted.
many thx for your explain. @spacewander |
… authz-keycloak as authentication plugin anymore, since it's only concerned with authorization.
@@ -125,7 +125,7 @@ do | |||
end | |||
end | |||
|
|||
function _M.access(conf, ctx) | |||
function _M.rewrite(conf, ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a test case to check if the ctx.consumer
set by this plugin can be used by other plugin runs in access phase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to add a test case. I don't have much experience writing them yet, so if you could point to a similar example, that would be helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add a stub:
diff --git apisix/init.lua apisix/init.lua
index 7333dd1..411cdd4 100644
--- apisix/init.lua
+++ apisix/init.lua
@@ -514,6 +514,10 @@ function _M.http_access_phase()
api_ctx.consumer,
api_ctx
)
+
+ core.log.info("find consumer ", api_ctx.consumer.username,
+ ", config changed: ", changed)
+
if changed then
core.table.clear(api_ctx.plugins)
api_ctx.plugins = plugin.filter(route, api_ctx.plugins)
And then check it in:
Line 192 in e66dd9a
=== TEST 8: verify |
Add something like:
--- error_log
find consumer foo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think I've seen an example in the test cases for key-auth
. I'll try to add test cases acceding for basic-auth
.
doc/plugin-develop.md
Outdated
@@ -168,8 +168,8 @@ local _M = { | |||
Determine which phase to run, generally access or rewrite. If you don't know the [Openresty life cycle](https://openresty-reference.readthedocs.io/en/latest/Directives/), it's | |||
recommended to know it in advance. For example key-auth is an authentication plugin, thus the authentication should be completed | |||
before forwarding the request to any upstream service. Therefore, the plugin can be executed in the rewrite and access phases. | |||
In APISIX, the authentication logic is implemented in the rewrite phase. Generally, IP access and interface | |||
permission are completed in the access phase. | |||
In APISIX, the authentication logic is implemented in the access phase. Generally, IP access and interface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to revert this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
…un in the rewrite phase.
@@ -125,7 +125,7 @@ do | |||
end | |||
end | |||
|
|||
function _M.access(conf, ctx) | |||
function _M.rewrite(conf, ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need to change another plugin?
one PR for one thing, we should only update something about plugin authz-keycloak
please revert this code
@@ -49,6 +49,7 @@ local schema = { | |||
local _M = { | |||
version = 0.1, | |||
priority = 2599, | |||
type = 'auth', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
you can create a new PR to fix this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry but I currently can't afford the time to split this into separate PRs. I think the change set is reasonably small to be considered in one PR. If you prefer more fine-grained PRs, then please consider creating these yourself, e.g. based on the changes in this branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found you have submitted new PR: https://github.com/apache/apisix/pull/2905/files
Many thanks for your nice job.
Small PR is important, it easy to find problems and we can merge it asap when it is small.
By the way, it is a clearer way to show what we are doing.
Many thx for nice contribution again @jenskeiner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, you're very welcome. Thanks for the info. I'll try to put the remaining outstanding changes from this one into a separate new PR and then we take it from there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have created #2910 which should contain the outstanding changes from this PR.
Closing this one as it has since been superseded by other PRs addressing the same issues. |
What this PR does / why we need it:
See #2857.
Pre-submission checklist: