Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(admin): reject unknown stream plugin #6813

Merged
merged 2 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions apisix/admin/plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
local require = require
local core = require("apisix.core")
local check_schema = require("apisix.plugin").check_schema
local stream_check_schema = require("apisix.plugin").stream_check_schema
local ipairs = ipairs
local pcall = pcall
local table_sort = table.sort
Expand All @@ -33,11 +32,6 @@ function _M.check_schema(plugins_conf, schema_type)
end


function _M.stream_check_schema(plugins_conf, schema_type)
return stream_check_schema(plugins_conf, schema_type, false)
end


function _M.get(name)
local arg = get_uri_args()
if arg and arg["all"] == "true" then
Expand Down
2 changes: 1 addition & 1 deletion apisix/admin/stream_routes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ local function check_conf(id, conf, need_id)
end
end

local ok, err = stream_route_checker(conf)
local ok, err = stream_route_checker(conf, true)
if not ok then
return nil, {error_msg = err}
end
Expand Down
4 changes: 2 additions & 2 deletions apisix/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,9 @@ function _M.plugin_checker(item, schema_type)
end


function _M.stream_plugin_checker(item)
function _M.stream_plugin_checker(item, in_cp)
if item.plugins then
return stream_check_schema(item.plugins, nil, true)
return stream_check_schema(item.plugins, nil, not in_cp)
end

return true
Expand Down
4 changes: 2 additions & 2 deletions apisix/stream/router/ip_port.lua
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ function _M.routes()
return user_routes.values, user_routes.conf_version
end

local function stream_route_checker(item)
local function stream_route_checker(item, in_cp)
if item.plugins then
local err, message = stream_plugin_checker(item)
local err, message = stream_plugin_checker(item, in_cp)
if not err then
return err, message
end
Expand Down
32 changes: 32 additions & 0 deletions t/admin/stream-routes.t
Original file line number Diff line number Diff line change
Expand Up @@ -562,3 +562,35 @@ GET /t
GET /t
--- no_error_log
[error]



=== TEST 15: set route with unknown plugin
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/stream_routes/1',
ngx.HTTP_PUT,
[[{
"remote_addr": "127.0.0.1",
"plugins": {
"mqttt-proxy": {
}
}
}]]
)

if code >= 300 then
ngx.status = code
end
ngx.print(body)
}
}
--- request
GET /t
--- error_code: 400
--- response_body
{"error_msg":"unknown plugin [mqttt-proxy]"}
--- no_error_log
[error]