- Notifications
You must be signed in to change notification settings - Fork2.6k
Why using the same upstream twice w/ different auth methods does not work?#11942
-
Hello, I've been struggling a bit configuring APISIX with multiple authentication methods for the same upstream. That's why I've decided to only protect one of my routes and leave the other "public" so that I can at least test that it works. Running APISIX 3.11.0 in STANDALONE mode Unfortunately that's not the case:
I've tried/looked into the following things:
I know it's pretty stupid to serve the same upstream both protected and public but for the sake of testing I've decided to pick this approach. It might very well be the sole reason why it's not working in the first place but I could not find any information regarding this. Ultimately I'd like to be able to setup mTLS authentication for the Would be greatly appreciated if I can get some pointers as to why this is not working in the first place.
|
BetaWas this translation helpful?Give feedback.
All reactions
changed the uri to /* and it DID work, but obviously I'd like a prefix :D
To achieve what you described (and I think I understood 😄), you'll need to useproxy-rewrite
plugin, to remove the prefix before forwarding the request to the upstream.
Here's an example with your configuration:
upstreams: -name:backend-api-upstreamid:1type:roundrobinnodes: -host:172.17.0.1port:3000weight:1routes: -uri:/public/*upstream_id:1plugins:# This plugin will remove the prefix "/public"proxy-rewrite:regex_uri: -^/public/(.*) -/$1 -uri:/api/*upstream_id:1plugins:# Uncomment t…
Replies: 2 comments 3 replies
-
I found a similar closed issue that might be relevant to your situation:Allow multiple authentication methods per route. This issue was resolved by a pull request that added the In your case, it seems like the issue might be related to how the routes are configured. Here are a few pointers that might help:
If you want to provide multiple authentication methods for the same backend resource, consider using the To continue talking toDosu, mention@dosu. Help Dosu learn! Give it feedback:Great Response |Irrelevant Answer |Incorrect Sources |Too Verbose |Hallucination |Other |
BetaWas this translation helpful?Give feedback.
All reactions
-
@dosu sure makes sense but as far as I'm aware mTLS configuration is not a plugin of type |
BetaWas this translation helpful?Give feedback.
All reactions
-
You're correct that mTLS is not configured as an authentication plugin in APISIX. Instead, mTLS is set up through SSL configuration, where you specify client certificate verification as part of the SSL settings for a route or service. This is done by configuring the SSL settings in APISIX to require client certificates, which is separate from the plugin-based authentication methods like OIDC. To use mTLS alongside other authentication methods, you would configure mTLS at the SSL level and use plugins for additional authentication methods. The To continue talking toDosu, mention@dosu. Help Dosu learn! Give it feedback:Great Response |Irrelevant Answer |Incorrect Sources |Too Verbose |Hallucination |Other |
BetaWas this translation helpful?Give feedback.
All reactions
😕 1
-
To achieve what you described (and I think I understood 😄), you'll need to use Here's an example with your configuration: upstreams: -name:backend-api-upstreamid:1type:roundrobinnodes: -host:172.17.0.1port:3000weight:1routes: -uri:/public/*upstream_id:1plugins:# This plugin will remove the prefix "/public"proxy-rewrite:regex_uri: -^/public/(.*) -/$1 -uri:/api/*upstream_id:1plugins:# Uncomment this if you also need the same behaviour for "/api"# proxy-rewrite:# regex_uri:# - ^/api/(.*)# - /$1openid-connect:client_id:apisixclient_secret:6dE1dzUQFX1r7wa1hgyYGknJjaNrhmi1discovery:http://172.17.0.1:8441/realms/users/.well-known/openid-configurationintrospection_endpoint:http://172.17.0.1:8441/realms/users/protocol/openid-connect/token/introspectbearer_only:truerealm:usersscope:openid email profilesession:secret:"MjMzZDFlYzAtN2Y3OC00M2MyLTg1OGYtZTk1NGVkZDEyZjZhCg=="cors:allow_origins:"https://localhost:8000"allow_methods:"GET, POST, OPTIONS"allow_headers:"Authorization, Content-Type"expose_headers:"Content-Length, X-Access-Token"max_age:3600allow_credential:true#END The reason it works like that is due to how APISIX handles route pattern matching with wildcard characters: when you define a route like You could also make it work by changing the upstream server/service to handle both Hope that helped 🙂 |
BetaWas this translation helpful?Give feedback.
All reactions
🎉 1
-
Thank you for the taking the time to propose a solution@mikyll. Incredibly appreciated :) |
BetaWas this translation helpful?Give feedback.
All reactions
❤️ 1