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

request help: does apisix authentication plugin support multiple authentication methods at the same time #6217

Closed
sapphire0929 opened this issue Jan 27, 2022 · 15 comments · Fixed by #10482

Comments

@sapphire0929
Copy link

Issue description

https://docs.konghq.com/gateway/2.7.x/configure/auth/allowing-multiple-authentication-methods/
https://docs.konghq.com/gateway/2.7.x/configure/auth/
测试apisix开启多个认证插件,需要同时满足条件才能通过验证,是and的关系,能否像kong一样,可以设置成or的关系,满足任何一个验证就能通过呢?

Environment

  • apisix version (cmd: apisix version):
  • OS (cmd: uname -a):
  • OpenResty / Nginx version (cmd: nginx -V or openresty -V):
  • etcd version, if have (cmd: run curl http://127.0.0.1:9090/v1/server_info to get the info from server-info API):
  • apisix-dashboard version, if have:
  • the plugin runner version, if the issue is about a plugin runner (cmd: depended on the kind of runner):
  • luarocks version, if the issue is about installation (cmd: luarocks --version):
@tzssangglass tzssangglass changed the title request help: apisix认证插件是否同时支持多种认证方式? request help: does apisix authentication plugin support multiple authentication methods at the same time Jan 27, 2022
@tzssangglass
Copy link
Member

Not supported yet, can you describe the scenario?

@sapphire0929
Copy link
Author

比如想使一个服务或者路由既支持jwt-auth 又能支持key-auth 或者也支持hamc-auth

@tzssangglass
Copy link
Member

比如想使一个服务或者路由既支持jwt-auth 又能支持key-auth 或者也支持hamc-auth

This is possible, but the OR relationship is something I haven't thought of how to support.

@tokers
Copy link
Contributor

tokers commented Jan 28, 2022

This can be implemented by created another plugin like "auth-combiner", which invokes some specific auth plugins and customize their logical relationships like OR or AND.

@tzssangglass
Copy link
Member

In fact, I have doubts about this OR approach, which I now feel adds complexity.
We now have the public-API plugin and maybe we can achieve similar functionality with the help of this plugin approach.

Why do you need to support so many authentication methods on only one route? Is the upstream service a compatible SSO service?

@tokers
Copy link
Contributor

tokers commented Jan 28, 2022

In fact, I have doubts about this OR approach, which I now feel adds complexity. We now have the public-API plugin and maybe we can achieve similar functionality with the help of this plugin approach.

Why do you need to support so many authentication methods on only one route? Is the upstream service a compatible SSO service?

Exactly, we may need some real scenarios to help us to understand this use.

@ntyrrell
Copy link

ntyrrell commented Feb 3, 2022

We have a scenario where we are transitioning from an older provider to a newer one, and there will be a transitionary period where we need to support users from both.

@ntyrrell
Copy link

ntyrrell commented Feb 3, 2022

This can be implemented by created another plugin like "auth-combiner", which invokes some specific auth plugins and customize their logical relationships like OR or AND.

Would you be able to provide a basic example of how one would go about creating a plugin that performs this functionality?

@tzssangglass
Copy link
Member

Would you be able to provide a basic example of how one would go about creating a plugin that performs this functionality?

@tokers are talking about just one porposal

@github-actions
Copy link

This issue has been marked as stale due to 350 days of inactivity. It will be closed in 2 weeks if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the dev@apisix.apache.org list. Thank you for your contributions.

@github-actions github-actions bot added the stale label Jan 20, 2023
@github-actions
Copy link

github-actions bot commented Feb 4, 2023

This issue has been closed due to lack of activity. If you think that is incorrect, or the issue requires additional review, you can revive the issue at any time.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 4, 2023
@montmirail
Copy link

I'm reopening this issue as I have a specific use case to propose.

Our API is protected by the oidc plugin backed by a Keycloack IdP. We now require an anonymous access to the api to allow resource sharing. We want to use the jwt-auth plugin to handle those anonymous access and with the current setup we would need specific endpoint to handle the anonymous request which is not ideal.

@Boburmirzo
Copy link
Contributor

It seems an interesting and needed feature for APISIX, already 3 community users asked on APISIX if it is possible to enable Multiple Authentication Methods per API route endpoint.

With two different routes with the same URI path "/anything/*" but different plugin configs with Key and Basic Auth, I tested it:

This works fine:
curl -i "http://127.0.0.1:9080/anything/test" -H 'apikey: auth-one'

This does not work:
curl -i "http://127.0.0.1:9080/anything/test" -ufoo:bar

Maybe the route could do an OR if multiple authentication plugins are configured.

@Boburmirzo
Copy link
Contributor

It seems an interesting and needed feature for APISIX, already 3 community users asked on APISIX if it is possible to enable Multiple Authentication Methods per API route endpoint.

With two different routes with the same URI path "/anything/*" but different plugin configs with Key and Basic Auth, I tested it:

This works fine: curl -i "http://127.0.0.1:9080/anything/test" -H 'apikey: auth-one'

This does not work: curl -i "http://127.0.0.1:9080/anything/test" -ufoo:bar

Maybe the route could do an OR if multiple authentication plugins are configured.

The real-use case scenario could be when KEY/Token is not present in the header for the key-auth/JWT plugin, it should fall back on another auth plugin such as open-id connect for authentication.

But currently passing no key/JWT results invalid key and gives a 401 error.

@Madaditya
Copy link

Would be interested in this kind of OR between authentication methods too.

Use-case - Host a backend service that can be accessed from browser and some programmatic client too.
for browser access - use basic-auth or an IDP
for programatic access - use jwt/key auth

@shreemaan-abhishek shreemaan-abhishek linked a pull request Nov 15, 2023 that will close this issue
5 tasks
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Apache APISIX backlog Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

8 participants