Re: [I] help request: Plugin receives consumer config but I need the route config [apisix]
SkyeYoung closed issue #12349: help request: Plugin receives consumer config but I need the route config URL: https://github.com/apache/apisix/issues/12349 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [I] help request: Plugin receives consumer config but I need the route config [apisix]
SkyeYoung commented on issue #12349: URL: https://github.com/apache/apisix/issues/12349#issuecomment-3177933019 If you're still encountering problems, you can try opening the issue again. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [I] help request: Plugin receives consumer config but I need the route config [apisix]
Baoyuantop commented on issue #12349: URL: https://github.com/apache/apisix/issues/12349#issuecomment-3116926121 Hi @guilhermevillote, any updates? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [I] help request: Plugin receives consumer config but I need the route config [apisix]
Baoyuantop commented on issue #12349:
URL: https://github.com/apache/apisix/issues/12349#issuecomment-2999090285
Hi @guilhermevillote, let me address your three questions one by one:
### 1) Accessing route and consumer configurations separately
**Current State**: You're absolutely correct that currently only the merged
configuration is available in the access phase. Based on source code analysis
([apisix/plugin.lua:711-750](https://github.com/apache/apisix/blob/master/apisix/plugin.lua#L711-L750)),
consumer configuration directly overwrites route configuration:
```lua
for name, conf in pairs(consumer_conf.plugins) do
new_route_conf.value.plugins[name] = conf -- Direct overwrite
end
```
**Solution**: Your idea is correct - saving the original configuration in
the rewrite phase is the most viable approach.
### 2) How the merge strategy works internally
The current merge strategy is indeed **complete replacement** rather than
hierarchical merging. As evident from your example:
- `acl` plugin: route's `{"allow_groups": ["infra"]}` is completely replaced
by consumer's `{"groups": ["devops"]}`
- This is plugin-level complete overwrite, not field-level intelligent
merging
APISIX currently doesn't have built-in hierarchical merging - this is a
design choice for simplicity.
### 3) Recommended solution
**I don't recommend using `type = 'auth'`** - as you correctly worry, this
would indeed mix responsibilities.
Your analysis is very accurate. The current limitation does exist, and
saving the original configuration in the rewrite phase is currently the most
practical solution.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Re: [I] help request: Plugin receives consumer config but I need the route config [apisix]
guilhermevillote commented on issue #12349:
URL: https://github.com/apache/apisix/issues/12349#issuecomment-2988301341
Yes, I believe it is possible to save the original route configuration
during the rewrite phase (when the consumer config has not yet been merged) and
store it in the ctx for use in the access phase — that seems technically
feasible.
However, I would like to confirm if this is indeed the best approach for
scenarios where we need access to both the route-level and consumer-level
plugin configurations separately.
Also, I’d like to correct a mistake in my previous message:
The matched route does contain the plugin configuration (I overlooked this
before). So, this part of my previous statement was incorrect.
Still, when a plugin is defined on both the route and the consumer, the
plugin configuration shown in the matched route seems to be the merged version,
and I can no longer see the original route-level configuration.
For example:
```json
"plugins": {
"proxy-rewrite": {
"regex_uri": ["^/admin/test/(.*)", "/apisix/admin/$1"]
},
"key-auth": {
"_skip_rewrite_in_consumer": true,
"key": "auth-one"
},
"acl": {
"groups": ["devops"]
}
}
```
Here, proxy-rewrite appears as defined on the route (it is not set on the
consumer), but key-auth and acl reflect only the consumer-side config, even
though I defined them on both.
So, I have three main questions:
1) Is it possible to access both the route and consumer configurations
separately within the plugin logic? Right now, it seems like only the merged
result is available, making it difficult to distinguish what was defined where.
2) How does the merge strategy work internally? Is there any way to support
a hierarchical merge, where the route-level config serves as the base, and the
consumer config only overrides the specific conflicting fields — instead of
completely replacing the route config?
3) Is saving the route config during the rewrite phase into ctx (before the
consumer merge) the recommended solution to preserve the original route
configuration, or is there a better or more idiomatic way to handle this in
custom plugins?
Thanks again for your help!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Re: [I] help request: Plugin receives consumer config but I need the route config [apisix]
Baoyuantop commented on issue #12349: URL: https://github.com/apache/apisix/issues/12349#issuecomment-2986518026 Is it possible to save the original routing configuration in the rewrite phase (when there is no merged consumer configuration), and save it in the ctx for use in subsequent phases? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [I] help request: Plugin receives consumer config but I need the route config [apisix]
guilhermevillote commented on issue #12349:
URL: https://github.com/apache/apisix/issues/12349#issuecomment-2986451687
Thanks for the suggestion!
I checked ctx.matched_route, and it does include the route metadata, but the
plugins field only shows a shallow reference like this:
```json
"matched_route": {
"value": {
"id": "398c7dd4",
"priority": 0,
"upstream_id": "52c52e36",
"name": "apisix-ingress_admin-teste_main",
"hosts": [
"xxx"
],
"labels": {
"managed-by": "apisix-ingress-controller",
},
"uris": [
"/admin/teste/*"
],
"desc": "Created by apisix-ingress-controller, DO NOT
modify it manually",
"status": 1,
"plugins": {
"acl": "table: 0x78bafb3d9410",
"proxy-rewrite": "table: 0x78baf5abada0",
"key-auth": "table: 0x78bafb3d9318"
},
"update_time": 1750219153,
"create_time": 1750218190
},
"orig_modifiedIndex": 1167,
"has_domain": false,
"createdIndex": 1141,
"modifiedIndex": 1167,
"clean_handlers": {},
"key": "/apisix/routes/398c7dd4"
},
```
So I don’t have direct access to the actual plugin config values — just Lua
table references as strings.
Is there a recommended way to dereference these or access the actual plugin
configuration defined on the route from within the plugin logic?
Again, my use case is:
I need to access the route-level plugin configuration, even when the plugin
is also configured on the consumer — which is where the current conf value
comes from during the access phase.
I considered doing a manual fetch of the route-level plugin configuration
based on something like the plugin ID or Lua table reference, but I’m concerned
this could introduce unnecessary latency into the request path.
I also tried using the rewrite phase with type = "auth" (to skip
rewrite_in_consumer), and this does provide access to the route-level plugin
config.
However, I’m concerned that this might mix responsibilities — according to
the docs, type = "auth" is intended for authentication plugins, whereas mine is
for authorization. It doesn’t handle consumer attachment itself, but instead
relies on the ctx.consumer set by authentication plugins like key-auth.
Is there a built-in or efficient way to retrieve the route-level plugin
config within the access phase?
Or is using the rewrite phase with type = "auth" the recommended approach in
this case?
Thanks again!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Re: [I] help request: Plugin receives consumer config but I need the route config [apisix]
Baoyuantop commented on issue #12349: URL: https://github.com/apache/apisix/issues/12349#issuecomment-2986422975 You can try to use `ctx.matched_route` to get the configuration information of the matched route. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
