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.
|
Beta Was this translation helpful? Give feedback.
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 to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Beta Was this translation helpful? Give feedback.
-
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-upstream
id: 1
type: roundrobin
nodes:
- host: 172.17.0.1
port: 3000
weight: 1
routes:
- uri: /public/*
upstream_id: 1
plugins:
# This plugin will remove the prefix "/public"
proxy-rewrite:
regex_uri:
- ^/public/(.*)
- /$1
- uri: /api/*
upstream_id: 1
plugins:
# Uncomment this if you also need the same behaviour for "/api"
# proxy-rewrite:
# regex_uri:
# - ^/api/(.*)
# - /$1
openid-connect:
client_id: apisix
client_secret: 6dE1dzUQFX1r7wa1hgyYGknJjaNrhmi1
discovery: http://172.17.0.1:8441/realms/users/.well-known/openid-configuration
introspection_endpoint: http://172.17.0.1:8441/realms/users/protocol/openid-connect/token/introspect
bearer_only: true
realm: users
scope: openid email profile
session:
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: 3600
allow_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 🙂 |
Beta Was this translation helpful? Give feedback.
To achieve what you described (and I think I understood 😄), you'll need to use
proxy-rewrite
plugin, to remove the prefix before forwarding the request to the upstream.Here's an example with your configuration: