Skip to content

feat: rewrite hmac-auth plugin for usability#11581

Merged
Revolyssup merged 8 commits into
apache:masterfrom
Revolyssup:revolyssup/backport/hmacauth
Sep 19, 2024
Merged

feat: rewrite hmac-auth plugin for usability#11581
Revolyssup merged 8 commits into
apache:masterfrom
Revolyssup:revolyssup/backport/hmacauth

Conversation

@Revolyssup

@Revolyssup Revolyssup commented Sep 17, 2024

Copy link
Copy Markdown
Contributor

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:

  • Use single 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
  • change the name of access_key to key_id
  • simplifies the schema of consumer resource and moves most parameters at route/service level.(except key_id and secret_key)
  • Use @Request-target as mentioned in RFC in signing string.

@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

@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. plugin labels Sep 17, 2024
@membphis

Copy link
Copy Markdown
Member

bad title, we can not use backport in this PR

pls add more description about why we need this PR?

@Revolyssup Revolyssup changed the title feat: backport hmac-auth plugin refactor feat: rewrite hmac-auth plugin to match rfc Sep 18, 2024
@Revolyssup Revolyssup changed the title feat: rewrite hmac-auth plugin to match rfc feat: rewrite hmac-auth plugin for usability Sep 18, 2024
@Revolyssup

Copy link
Copy Markdown
Contributor Author

bad title, we can not use backport in this PR

pls add more description about why we need this PR?

done

moonming
moonming previously approved these changes Sep 18, 2024
nic-6443
nic-6443 previously approved these changes Sep 18, 2024
membphis
membphis previously approved these changes Sep 18, 2024

@membphis membphis left a comment

Copy link
Copy Markdown
Member

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

Comment thread apisix/plugins/hmac-auth.lua
Comment thread apisix/plugins/hmac-auth.lua Outdated
date = auth_data[5]
signed_headers = auth_data[6]
end
if not auth_string:match("^Signature") then

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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


local consumer_conf = consumer.plugin(plugin_name)
consumer.attach_consumer(ctx, validated_consumer, consumer_conf)
core.log.info("hit hmac-auth rewrite")

Copy link
Copy Markdown
Member

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

@Revolyssup
Revolyssup dismissed stale reviews from membphis, nic-6443, and moonming via 5793e98 September 18, 2024 09:30

@membphis membphis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@Revolyssup
Revolyssup merged commit a393320 into apache:master Sep 19, 2024
@ssquan

ssquan commented Nov 18, 2024

Copy link
Copy Markdown

What was the reason for changing the property name from 'access_key' to 'key_id'?
Applications that automatically create consumers will need to update their code when upgrading to the new version of APISIX.

@coder2z

coder2z commented Mar 5, 2025

Copy link
Copy Markdown

Why is this completely incompatible update not opening a new plugin? Or compatible with the previous usage method? Have you not considered us users? Do you want us to remain on one version? Not to update?

@caibirdme

Copy link
Copy Markdown

Maybe we can rename this newly hmac-auth as hmac-auth-v2? Since hmac-auth is widely used in many different users' prod environment, this breaking change will rise many problems. There're many different consumers that use hmac-auth, it's impossible to have them adopt the new hmac sign algorithm, which means we have to keep the old hmac-auth plugin, thus we only have two choices: donnot upgrade apisix or remove this change in my fork version. Neither is good way.
Since this change isn't really that much important, not related to architecture, just for ease of use, I really suggest that we don't need to bring this new breaking change. Renaming is better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants