-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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(jwt) preflight: revert workaround, implement migration #2751
Conversation
kong/dao/migrations/cassandra.lua
Outdated
name = "2017-07-31-113200_jwt_preflight_default", | ||
up = function(_, _, dao) | ||
local rows, err = dao.db:query([[ | ||
SELECT * FROM plugins WHERE name = 'jwt'; |
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 default page size for the driver is (currently) 1000. However, if the page size ever changes, or becomes configurable, or if such an entity has more than a 1000 rows, or simply because we wish to enforce best C* practices to avoid spreading bad code snippets by copy/paste, then we should use the proper way of aggregating all rows:
for rows, err in cluster:iterate("SELECT * FROM plugins WHERE name = 'jwt'") do
if err then
return err
end
if row.config.authenticate_preflight == nil then
-- do update
end
end
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.
Additionally, this migration does not belong to the core, but to the JWT plugin.
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.
This is plugin configuration, which is in the core. The plugins own daos.lua
file is what the plugin specific migrations target.
Do you want plugin specific migrations to start updating core entities?
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.
This is how plugins migrations are already handled. The configuration of the plugins themselves does not belong to the core, but to the plugins themselves (and rightfully so).
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.
yes, figured that out myself. will update
kong/dao/migrations/postgres.lua
Outdated
@@ -371,4 +371,27 @@ return { | |||
end, | |||
down = function(_, _, dao) end | |||
}, | |||
{ | |||
name = "2017-07-31-113200_jwt_preflight_default", |
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: move to jwt plugin migrations
kong/plugins/jwt/handler.lua
Outdated
@@ -171,7 +172,12 @@ end | |||
|
|||
function JwtHandler:access(conf) | |||
JwtHandler.super.access(self) | |||
|
|||
|
|||
-- check if preflight request and wether it should be authenticated |
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.
(whether)
kong/plugins/jwt/handler.lua
Outdated
|
||
|
||
-- check if preflight request and wether it should be authenticated | ||
if conf.authenticate_preflight and get_method() == "OPTIONS" then |
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.
According to this condition, it seems that authenticate_preflight = true
means "ignore and proxy upstream".
However, one can interpret authenticate_preflight
as to mean "enforce the JWT verification (authentication step) even if preflight". Which is the opposite, and which would mean that authenticate_preflight = true
would mean: enforce instead of ignore.
I think the name is thus confusing, and does not carry enough meaning to infer its functionality. In the CORS plugin, we have preflight_continue
which, if enabled, will make the plugin ignore, and thus proxy the request upstream. I thus see 2 possibilities:
-
use the same terminology as the CORS plugin:
config.preflight_continue = true
means: **ignore this plugin on preflight, got directly upstream) -
Rename to
config.run_on_preflight
, which is a more explicit name -
is consistent with the CORS, and 2. carries (I feel) the most meaning.
Note: this is yet another instance of plugins deciding for themselves when to run and when not to. Something they shouldn't be allowed to do in the future :)
Shall we deprecate (close) #2743 since this is the proper long term solution (it follows our policy of running migrations to include a new configuration property). |
Understood, but we should also respect the merge windows from now on (especially for 0.11.0). Maybe we can include those old PRs in 0.11.1? |
I had no intent otherwise. Did you get the impression somewhere? |
Not at all! Just explicitly stating the reason for not merging those today :) |
84e4066
to
65d3944
Compare
65d3944
to
3edaba2
Compare
This belongs to PR #2744 which went into a minor version.
3edaba2
to
df7cab1
Compare
This builds on top of #2744, but targets the
next
branch. The additional commit reverts the workaround and implements the proper migrations.