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: use modifiedIndex as lru key when merge plugins from route and consumer #7968

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .github/workflows/chaos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Setup go
uses: actions/setup-go@v3
with:
go-version: "1.16"
go-version: "1.17"

- uses: actions/cache@v2.1.7
with:
Expand Down
1 change: 1 addition & 0 deletions apisix/consumer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ local function plugin_consumer()
-- is 'username' field in admin
new_consumer.consumer_name = new_consumer.id
new_consumer.auth_conf = config
new_consumer.modifiedIndex = consumer.modifiedIndex
core.log.info("consumer:", core.json.delay_encode(new_consumer))
core.table.insert(plugins[name].nodes, new_consumer)
end
Expand Down
3 changes: 2 additions & 1 deletion apisix/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,8 @@ function _M.merge_consumer_route(route_conf, consumer_conf, api_ctx)
core.log.info("route conf: ", core.json.delay_encode(route_conf))
core.log.info("consumer conf: ", core.json.delay_encode(consumer_conf))

local flag = tostring(route_conf) .. tostring(consumer_conf)
local flag = route_conf.value.id .. "#" .. route_conf.modifiedIndex
.. "#" .. consumer_conf.id .. "#" .. consumer_conf.modifiedIndex
local new_conf = merged_route(flag, nil,
merge_consumer_route, route_conf, consumer_conf)

Expand Down
2 changes: 1 addition & 1 deletion ci/pod/nacos/service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.
#

FROM java
FROM eclipse-temurin:8

ENV SUFFIX_NUM=${SUFFIX_NUM:-1}
ENV NACOS_ADDR=${NACOS_ADDR:-127.0.0.1:8848}
Expand Down
132 changes: 132 additions & 0 deletions t/node/consumer-plugin2.t
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,135 @@ apikey: auth-jack
--- error_code: 403
--- response_body
{"message":"Your IP address is not allowed"}



=== TEST 9: use the latest consumer modifiedIndex as lrucache key
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/consumers',
ngx.HTTP_PUT,
[[{
"username": "foo",
"plugins": {
"basic-auth": {
"username": "foo",
"password": "bar"
}
}
}]]
)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end

local code, body = t('/apisix/admin/plugin_configs/1',
ngx.HTTP_PUT,
[[{
"plugins": {
"ip-restriction": {
"whitelist": ["1.1.1.1"]
},
"basic-auth": {}
}
}]]
)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end

local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"plugin_config_id": "1",
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uris": ["/hello"]
}]]
)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end
ngx.sleep(0.5)

local http = require "resty.http"
local httpc = http.new()
local uri = "http://127.0.0.1:" .. ngx.var.server_port
.. "/hello"
local headers = {
["Authorization"] = "Basic Zm9vOmJhcg=="
}
local res, err = httpc:request_uri(uri, {headers = headers})
ngx.print(res.body)

local code, body = t('/apisix/admin/plugin_configs/1',
ngx.HTTP_PUT,
[[{
"plugins": {
"ip-restriction": {
"whitelist": ["1.1.1.1", "127.0.0.1"]
},
"basic-auth": {}
}
}]]
)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end
ngx.sleep(0.5)

local res, err = httpc:request_uri(uri, {headers = headers})
if not res then
ngx.say(err)
return
end
ngx.print(res.body)

local code, body = t('/apisix/admin/consumers',
ngx.HTTP_PUT,
[[{
"username": "foo",
"plugins": {
"basic-auth": {
"username": "foo",
"password": "bala"
}
}
}]]
)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end
ngx.sleep(0.5)

local headers = {
["Authorization"] = "Basic Zm9vOmJhbGE="
}
local res, err = httpc:request_uri(uri, {headers = headers})
if not res then
ngx.say(err)
return
end
ngx.print(res.body)
}
}
--- response_body
{"message":"Your IP address is not allowed"}
hello world
hello world
102 changes: 102 additions & 0 deletions t/node/plugin-configs.t
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,105 @@ property "block_rules" validation failed
--- response_body
hello
hello world



=== TEST 5: use the latest plugin_consigs after merge the plugins from consumer and route
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/consumers',
ngx.HTTP_PUT,
[[{
"username": "foo",
"plugins": {
"basic-auth": {
"username": "foo",
"password": "bar"
}
}
}]]
)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end

local code, body = t('/apisix/admin/plugin_configs/1',
ngx.HTTP_PUT,
[[{
"plugins": {
"ip-restriction": {
"whitelist": ["1.1.1.1"]
},
"basic-auth": {}
}
}]]
)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end

local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"plugin_config_id": "1",
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uris": ["/hello"]
}]]
)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end
ngx.sleep(0.5)

local http = require "resty.http"
local httpc = http.new()
local uri = "http://127.0.0.1:" .. ngx.var.server_port
.. "/hello"
local headers = {
["Authorization"] = "Basic Zm9vOmJhcg=="
}
local res, err = httpc:request_uri(uri, {headers = headers})
ngx.print(res.body)

local code, body = t('/apisix/admin/plugin_configs/1',
ngx.HTTP_PUT,
[[{
"plugins": {
"ip-restriction": {
"whitelist": ["1.1.1.1", "127.0.0.1"]
},
"basic-auth": {}
}
}]]
)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end
ngx.sleep(0.5)

local res, err = httpc:request_uri(uri, {headers = headers})
if not res then
ngx.say(err)
return
end
ngx.print(res.body)
}
}
--- response_body
{"message":"Your IP address is not allowed"}
hello world