Skip to content
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(hmac-auth) add deprecation transition for pr #3339 #3699

Merged

Conversation

mlehner616
Copy link
Contributor

Summary

Add deprecation transition for PR #3339 by adding support for older signatures generated from request-line without the query_string. This is intended to be a patch on 0.13.1 but may apply to 0.14+ although I haven't tested this.

Full changelog

Issues resolved

Fix #3672

Fix PR Kong#3339 by adding support for older signatures generated from `request-line` without the query_string. 

To reduce performance impact, calculate the new signature version first. Only if that first validation fails, try again with the deprecated signing function.
Only calculate deprecated hash if the new hash validation fails.
@thibaultcha
Copy link
Member

@mlehner616 Thanks for taking the initiative here!

@shashiranjan84 Will you help review the proposed patch for this behaviour? Thanks!

Copy link
Contributor

@shashiranjan84 shashiranjan84 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mlehner616 thanks for PR. Did a high level review, please address the comments I left and request you to add some tests.

local function validate_signature(request, hmac_params, headers)
local signature_1 = create_hash(request, hmac_params, headers)
local signature_2 = ngx_decode_base64(hmac_params.signature)
local signature_1 = create_hash(request, hmac_params, headers)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need extra space before assignment operator.

local signature_1 = create_hash(request, hmac_params, headers)
local signature_2 = ngx_decode_base64(hmac_params.signature)
local signature_1 = create_hash(request, hmac_params, headers)
local signature_2 = ngx_decode_base64(hmac_params.signature)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we don't need to create both the signature at once, one should be fall back and only be created if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shashiranjan84 Whitespace removed, My commit from yesterday should have included the deprecated signature creation into the conditional. This looks like it would do what you're describing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. Thanks again for your effort, we just need to add test, which would be very similar to https://github.com/Kong/kong/blob/master/spec/03-plugins/20-hmac-auth/03-access_spec.lua#L1150, you would just need to create request signature without query-param

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Added

@shashiranjan84 shashiranjan84 added pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. and removed pr/please review labels Aug 13, 2018
@mlehner616
Copy link
Contributor Author

@shashiranjan84 I made the changes you requested, I haven't had a chance to write tests for this yet.

Add test to validate request-line containing query params but with the signature generated without them.
@shashiranjan84 shashiranjan84 added pr/please review and removed pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. labels Aug 13, 2018
@shashiranjan84
Copy link
Contributor

@mlehner616 thanks, we will review it.

Copy link
Contributor

@shashiranjan84 shashiranjan84 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@thibaultcha thibaultcha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the patch @mlehner616. We would love to ship it in our next release (0.14.1) next week. Would you mind addressing the feedback I provided? Thanks!

if not header_value then
if header == "request-line" then
-- request-line in hmac headers list
local request_line = fmt("%s %s HTTP/%s", ngx.req.get_method(), ngx.var.uri, ngx.req.http_version())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of duplicating the whole function, we should be able to simply specify ngx.var.uri or ngx.var.request_uri as an argument. That would be preferable.

return signature_1 == signature_2
if signature_1 == signature_2 then
return true
else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for this else branch if the above branch already returns.

@@ -1080,6 +1080,47 @@ for _, strategy in helpers.each_strategy() do
assert.res_status(200, res)
end)

it("should pass with GET with request-line having query param but signed without query param", function()

This comment was marked as resolved.

This comment was marked as resolved.

@thibaultcha thibaultcha added pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. and removed pr/please review labels Aug 16, 2018
Refactor create_hash and validate_signature function to removed duplicate code. We now pass in the ngx.var.uri or the ngx.var.request_uri as an argument to create_hash.
Adding comment to regression test
@mlehner616
Copy link
Contributor Author

@thibaultcha @shashiranjan84 Thanks for the feedback. I've committed changes that address your latest suggestions. Let me know if there are any other tweaks needed. Is there any chance this PR will get backported to a 0.13.2+ release? We're actually blocked on the 0.14 versions right now since we're not ready to drop API support.

@thibaultcha
Copy link
Member

@mlehner616 We do not have plans for a 0.13.2 version so far.

not ready to drop API support.

Not sure what you mean by that. In 0.14, the API entity is still supported (/apis on the Admin API). or are you talking about other specific changes in the Admin API itself?

@mlehner616
Copy link
Contributor Author

mlehner616 commented Aug 17, 2018

@thibaultcha Sorry, I thought I remember seeing 0.14 dropped API entities so it looks like I misread that section. Thanks for the clarification, I'll wait for the release to get cut and give it a shot.

@thibaultcha thibaultcha merged commit 73bec0f into Kong:master Aug 17, 2018
@thibaultcha
Copy link
Member

@mlehner616 Great, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PR #3339 in Kong 0.13.1 breaks existing hmac auth clients
3 participants