Skip to content

fix: disallow creating duplicate plugins in global rules#12800

Merged
shreemaan-abhishek merged 17 commits into
apache:masterfrom
shreemaan-abhishek:fix/global-rule-dup
Jan 8, 2026
Merged

fix: disallow creating duplicate plugins in global rules#12800
shreemaan-abhishek merged 17 commits into
apache:masterfrom
shreemaan-abhishek:fix/global-rule-dup

Conversation

@shreemaan-abhishek

@shreemaan-abhishek shreemaan-abhishek commented Dec 8, 2025

Copy link
Copy Markdown
Contributor

Description

When the same plugin is configured across different global rules, there will be no guarantee on which plugin config will be executed first. Additionally, the current architecture does not guarantee plugin execution order according to the priority.

We address this problem by disallowing configuring same plugin across multiple global_rules and sorting the plugins to their priority and executing in order.

Fixes: #12704

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. plugin labels Dec 8, 2025
Comment thread apisix/admin/global_rules.lua Outdated
Comment thread apisix/plugin.lua Outdated
Signed-off-by: Abhishek Choudhary <[email protected]>
@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Dec 9, 2025
Comment thread apisix/plugin.lua Outdated
Signed-off-by: Abhishek Choudhary <[email protected]>
Comment thread apisix/plugin.lua Outdated
Comment thread apisix/plugin.lua Outdated
Signed-off-by: Abhishek Choudhary <[email protected]>
Signed-off-by: Abhishek Choudhary <[email protected]>
nic-6443
nic-6443 previously approved these changes Dec 9, 2025
membphis
membphis previously approved these changes Dec 12, 2025
Comment thread apisix/admin/global_rules.lua
@Baoyuantop Baoyuantop linked an issue Dec 15, 2025 that may be closed by this pull request
Signed-off-by: Abhishek Choudhary <[email protected]>
@shreemaan-abhishek
shreemaan-abhishek dismissed stale reviews from membphis and nic-6443 via 4df44ed December 16, 2025 07:02
Signed-off-by: Abhishek Choudhary <[email protected]>
Comment thread apisix/plugin.lua Outdated

-- remove duplicate plugins
for plugin_name, _ in pairs(duplicate_plugins) do
all_plugins[plugin_name] = nil

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should warn which plugins are not working.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

you are right, thanks. I pushed a new commit that contains:

        core.log.warn("found ", plugin_name, " configured across different global rules ",
                      " it won't get executed")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think duplicate_plugins are redundant.
Can we merge three loops into one?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Signed-off-by: Abhishek Choudhary <[email protected]>
Signed-off-by: Abhishek Choudhary <[email protected]>
Signed-off-by: Abhishek Choudhary <[email protected]>
bzp2010
bzp2010 previously approved these changes Dec 19, 2025
AlinsRan
AlinsRan previously approved these changes Dec 19, 2025
nic-6443
nic-6443 previously approved these changes Dec 19, 2025
Signed-off-by: Abhishek Choudhary <[email protected]>
Signed-off-by: Abhishek Choudhary <[email protected]>
This reverts commit 6313730.
This reverts commit 0e6c6ce.
@membphis

Copy link
Copy Markdown
Member

lots of CI failed

f
Signed-off-by: Nic <[email protected]>
@nic-6443 nic-6443 changed the title change: disallow creating duplicate plugins in global rules fix: disallow creating duplicate plugins in global rules Jan 6, 2026
nic-6443
nic-6443 previously approved these changes Jan 7, 2026
Comment thread apisix/plugin.lua Outdated
if global_rule.value and global_rule.value.plugins then
for plugin_name, plugin_conf in pairs(global_rule.value.plugins) do
if seen_plugin[plugin_name] then
core.log.warn("Found ", plugin_name,

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 should use error log level

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.

it is an important error message

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.

if we used one plugin about 3 or 5 times

we should throw an error in this case

current way seems wrong

Signed-off-by: Abhishek Choudhary <[email protected]>
@shreemaan-abhishek
shreemaan-abhishek merged commit 3af5759 into apache:master Jan 8, 2026
30 of 34 checks passed
@rgalex2034

rgalex2034 commented Feb 17, 2026

Copy link
Copy Markdown

Maybe it's too late to consider, but I've been testing around this change, and it does not consider that multiple global rules may be defined with different _meta.filter configuration that do not overlap.

On the place I work for, we use this behaviour to define multiple traversal limit-count configurations where this limit changes based on the request.

It make sense to consider this situation to allow multiple definitions that ensure only one is executed?

It would require to traverse and discard the plugins by checking it's filtering first. If it's doable and make sense to allow this, I'm willing to try an implementation.

If it sounds interesting, I can open a new issue.

Thank you all :)

@Baoyuantop

Copy link
Copy Markdown
Contributor

Hi @rgalex2034, welcome to create an issue with your use case and configuration examples, and we will continue the discussion in your issue.

wistefan pushed a commit to wistefan/apisix that referenced this pull request Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: wrong plugin execution order

7 participants