Skip to content

bug: the plugin metadata obtained from etcd has not been validated by schema #11216

Description

@nic-6443

Current Behavior

Part 1

We created an etcd client to handle plugin metadata in:

apisix/apisix/plugin.lua

Lines 816 to 821 in 64b81c4

local plugin_metadatas, err = core.config.new("/plugin_metadata",
{
automatic = true,
checker = check_plugin_metadata
}
)

in check_plugin_metadata function, we need a item.id(expectation is the plugin name) to check metadata schema of specific plugin.

apisix/apisix/plugin.lua

Lines 1040 to 1042 in 64b81c4

check_plugin_metadata = function(item)
local ok, err = check_single_plugin_schema(item.id, item,
core.schema.TYPE_METADATA, true)

but plugin metadata don't have a id field in our admin api, so when apisix startup with a exist plugin metadata, the checker will be triggered in config_etcd:load_full_data
if data_valid and self.checker then
data_valid, err = self.checker(item.value)
if not data_valid then
log.error("failed to check item data of [", self.key,
"] err:", err, " ,val: ", json.delay_encode(item.value))
end
end

and then checker failed with this log:
image

Part 2

When watch a new data from etcd, config_etcd.lua only check configuration that has configure with a item_schema

if res.value and self.item_schema then
local ok, err = check_schema(self.item_schema, res.value)
if not ok then
self:upgrade_version(res.modifiedIndex)
return false, "failed to check item data of ["
.. self.key .. "] err:" .. err
end
if self.checker then
local ok, err = self.checker(res.value)
if not ok then
self:upgrade_version(res.modifiedIndex)
return false, "failed to check item data of ["
.. self.key .. "] err:" .. err
end
end
end

because plugin_metadata only set checker field without item_schema, so the new plugin metadata watch from etcd don't validate by schema too.

Expected Behavior

No response

Error Logs

No response

Steps to Reproduce

/

Environment

/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions