Skip to content

Conversation

@SkyeYoung
Copy link
Member

@SkyeYoung SkyeYoung commented Sep 9, 2025

Description

This PR removes the logic of populating default values before writing in the admin API.

This solves the following problems:

  1. Modifying the user-provided configuration can easily lead to user
    confusion, which is clearly not best practice.
  2. This also affects the diff logic in the adc that the apisix ingress
    controller depends on.

Since when using GET to retrieve data from the admin API, it will be read directly from etcd, the changes introduced by this PR are compatible with the old version.

Which issue(s) this PR fixes:

Fixes #

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)

@SkyeYoung SkyeYoung marked this pull request as ready for review September 15, 2025 00:42
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Sep 15, 2025
-- metadata
if schema_type == core.schema.TYPE_METADATA then
local conf = body.node and body.node.value
decrypt_func(conf.name, conf, schema_type)
Copy link
Member Author

@SkyeYoung SkyeYoung Sep 15, 2025

Choose a reason for hiding this comment

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

There is an amazing problem here:

In error-log-logger.lua, the following code exists:

name = {type = "string", default = plugin_name},

This is a property not marked in the document.

The intention of its design cannot be seen from the original PR #2592.

At the same time, it is also the only one that contains encrypt_fields in metadata_schema.

encrypt_fields = {"clickhouse.password"},

This causes this logic in the actual decrypt_params to take effect only for error-log-logger.lua when schema_type == core.schema.TYPE_METADATA.

However, due to the cancellation of the default value padding, this logic no longer takes effect.

Anyway, I think this is wrong. And it needs to be repaired in subsequent PRs.

The reasons are as follows:

  1. There should not be a hidden property in the schema that is used for plugin-unrelated logic.
  2. fix: plugin metadata add id value for etcd checker #11452 implements a standardized id, which can be consistent with other resources.

Comment on lines +54 to +57
default = {
length = 16,
char_set = "abcdefghijklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ0123456789"
}
Copy link
Member Author

Choose a reason for hiding this comment

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

The tests revealed that this is the only way to properly populate default values when range_id doesn't exist.

The original one should be because it's filled again after writing default={}.




=== TEST 15: not unwanted data, PUT with use_real_request_uri_unsafe
Copy link
Member Author

Choose a reason for hiding this comment

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

Add tests, when including property use_real_request_uri_unsafe, it will be filled normally.

=== TEST 15: PUT with limit-count policy=local
Copy link
Member Author

Choose a reason for hiding this comment

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

Add tests, when including property policy, it will be filled normally.

Copy link
Member Author

Choose a reason for hiding this comment

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

Because I found that most of the tests covered non-required fields, I didn't add similar tests later.

res = require("toolkit.json").decode(res)
assert(res.value.plugins["jwt-auth"].exp == 86400)
local core = require("apisix.core")
Copy link
Member Author

Choose a reason for hiding this comment

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

Because the original method can no longer detect whether the exp variable exists, it's changed to direct validation through the schema, according to the internal logic.

properties = {},
}
end
inject_metadata_schema(plugin_object)
Copy link
Contributor

Choose a reason for hiding this comment

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

Although it is not introduced by your PR, it is strange to actively inject an empty schema and use ordinary schema or metadata_schema according to certain conditions for configuration verification for some non-plugin metadata.

If a plugin does not indicate that it supports plugin metadata configuration by actively declaring metadata_schema, it should not be configured in this way. Specifically, if this happens, it may be more appropriate to reject this configuration directly. For example, key-auth does not have the meaning of plugin metadata configuration.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's wait for what others think.

Copy link
Member

Choose a reason for hiding this comment

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

agree with @bzp2010 , it's strange to inject a empty metadata schema for plugins that don't need plugin metadata, look like we need a refactor for this, I think we can deal with it in another PR.

Comment on lines +127 to +128
local conf_for_check = tbl_deepcopy(conf)
local ok, err = self.checker(id, conf_for_check, need_id, self.schema, {secret_type = typ})
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if it's necessary to keep a switch enabled by a specific querystring to retain the old behavior?

For example, when fillin_default=true, still fill in the default value? This may have some meaning for debugging, otherwise we have to rely only on the correctness of the document. Historical experience tells me that this is usually difficult.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is actually a question I've thought about. Let's wait for other people's comments.

Copy link
Member

Choose a reason for hiding this comment

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

I can't think of any issues that require specifying fillin_default=true to troubleshoot, but adding this option doesn't really have any drawbacks either, making it difficult to decide.

Copy link
Contributor

Choose a reason for hiding this comment

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

In terms of debugging purposes only, this PR should not be blocked, and the default value can be confirmed through the version of apisix.



local function encrypt_conf(id, conf)
plugins_encrypt_conf(conf.plugins)
Copy link
Member

@membphis membphis Sep 16, 2025

Choose a reason for hiding this comment

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

pls confirm it never failed

for me, I prefer return plugins_encrypt_conf(conf.plugins)

Copy link
Member Author

Choose a reason for hiding this comment

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

CleanShot 2025-09-16 at 18 52 42@2x

It looks like they are the same?

Copy link
Member Author

Choose a reason for hiding this comment

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

CleanShot 2025-09-16 at 19 07 07@2x CleanShot 2025-09-16 at 19 09 13@2x

Regarding the calling method, it references the original local schema_plugin = require(“apisix.admin.plugins”).check_schema. And in the current scenario, no issues have been detected.

Copy link
Member Author

Choose a reason for hiding this comment

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

@SkyeYoung SkyeYoung requested a review from bzp2010 September 17, 2025 00:48
@SkyeYoung SkyeYoung merged commit 1f2c541 into apache:master Sep 19, 2025
90 of 99 checks passed
jizhuozhi pushed a commit to jizhuozhi/apisix that referenced this pull request Oct 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants