-
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
feat: rewrite hmac-auth plugin for usability #11581
feat: rewrite hmac-auth plugin for usability #11581
Conversation
bad title, we can not use pls add more description about why we need this PR? |
done |
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.
LGTM, except some minor issues
apisix/plugins/hmac-auth.lua
Outdated
date = auth_data[5] | ||
signed_headers = auth_data[6] | ||
end | ||
if not auth_string:match("^Signature") 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.
a high performance way: core.string.has_prefix
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.
apisix/plugins/hmac-auth.lua
Outdated
if not validated_consumer then | ||
core.log.warn("client request can't be validated: ", err or "Invalid signature") | ||
return 401, {message = "client request can't be validated"} | ||
end | ||
|
||
local consumer_conf = consumer.plugin(plugin_name) | ||
consumer.attach_consumer(ctx, validated_consumer, consumer_conf) | ||
core.log.info("hit hmac-auth rewrite") |
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 do not need to remove it
5793e98
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.
LGTM
Currently the hmac-auth plugin has a lot of headers that need to be configured, which makes it confusing to use the plugin. This PR also makes it so that it follows the RFC.
This PR refactors the plugin as following:
Authorization
header instead of multiple headers for ease of use. Now you can provide 4 parameters(key_id,signature, headers,algorithm) in Authorization header separated by comma in any order, this makes it easy to use@Request-target definition comes from: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-message-signatures-03#name-request-target
Signing string generation logic: https://datatracker.ietf.org/doc/html/draft-cavage-http-signatures-00#section-2.1.2